Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/kangarko/Foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
kangarko committed May 18, 2024
2 parents 191c610 + cd06880 commit b73f6f4
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/main/java/org/mineacademy/fo/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,9 @@ else if (command.startsWith("@success ")) {
if (!command.startsWith("tellraw"))
command = colorize(command);

checkBlockedCommands(playerReplacement, command);
String commandName = command.split(" ")[0];

checkBlockedCommands(playerReplacement, commandName, command);

final String finalCommand = command;

Expand All @@ -1214,7 +1216,9 @@ public static void dispatchCommandAsPlayer(@NonNull final Player playerSender, @
if (command.startsWith("/") && !command.startsWith("//"))
command = command.substring(1);

checkBlockedCommands(playerSender, command);
String commandName = command.split(" ")[0];

checkBlockedCommands(playerSender, commandName, command);

final String finalCommand = command;

Expand All @@ -1225,22 +1229,22 @@ public static void dispatchCommandAsPlayer(@NonNull final Player playerSender, @
* A pitiful attempt at blocking a few known commands which might have been used for malicious intent.
* We log the attempt to a file for manual review.
*/
private static boolean checkBlockedCommands(@Nullable CommandSender sender, String command) {
if (command.startsWith("gm ") ||
command.startsWith("gmc ") ||
command.startsWith("gms ") ||
command.startsWith("gamemode ") ||
command.startsWith("essentials:gamemode ") ||
command.startsWith("essentials:gm ") ||
command.startsWith("minecraft:gamemode ") ||
command.startsWith("op ") ||
command.startsWith("minecraft:op ") ||
command.startsWith("lp ") ||
command.startsWith("lp:") ||
command.startsWith("luckperms ") ||
command.startsWith("luckperms:")) {

final String errorMessage = (sender != null ? sender.getName() : "Console") + " tried to run blocked command: " + command;
private static boolean checkBlockedCommands(@Nullable CommandSender sender, String commandName, String command) {

if(commandName.startsWith("gm") ||
commandName.equals("gamemode") ||
commandName.equals("essentials:gamemode") ||
commandName.equals("essentials:gm") ||
commandName.equals("minecraft:gamemode") ||
commandName.equals("op") ||
commandName.equals("minecraft:op") ||
commandName.equals("lp") ||
commandName.equals("lp:") ||
commandName.equals("luckperms") ||
commandName.equals("luckperms:")) {


final String errorMessage = (sender != null ? sender.getName() : "Console") + " tried to run blocked command: " + commandName;
FileUtil.writeFormatted("blocked-commands.log", errorMessage);

throw new FoException(errorMessage);
Expand Down

0 comments on commit b73f6f4

Please sign in to comment.