Simplify command check

This commit is contained in:
mathiascode 2019-12-15 19:26:25 +02:00
parent c246fb9b27
commit d805770131
5 changed files with 130 additions and 134 deletions

View file

@ -320,16 +320,25 @@ public class Main extends JavaPlugin {
"ewarps", "ewarps",
"ewhisper", "ewhisper",
"extras:bcraw",
"extras:broadcastraw",
"extras:cc", "extras:cc",
"extras:clearchat", "extras:clearchat",
"extras:console", "extras:console",
"extras:jumpscare",
"extras:scare",
"extras:tellraw", "extras:tellraw",
"bcraw",
"broadcastraw",
"cc", "cc",
"clearchat", "clearchat",
"console", "console",
"jumpscare",
"scare",
"tellraw", "tellraw",
"minecraft:clear", "minecraft:clear",
"minecraft:clone",
"minecraft:datapack", "minecraft:datapack",
"minecraft:effect", "minecraft:effect",
"minecraft:execute", "minecraft:execute",
@ -345,6 +354,7 @@ public class Main extends JavaPlugin {
"minecraft:tp", "minecraft:tp",
"minecraft:worldborder", "minecraft:worldborder",
"clear", "clear",
"clone",
"datapack", "datapack",
"effect", "effect",
"execute", "execute",

View file

@ -45,12 +45,16 @@ class SkinDownloader {
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() {
if (player.isOnline()) { try {
player.setPlayerProfile(profile); if (player.isOnline()) {
player.setPlayerProfile(profile);
if (shouldChangeName && shouldSendMessage) {
player.sendMessage("Successfully set your username to \"" + name + "\""); if (shouldChangeName && shouldSendMessage) {
player.sendMessage("Successfully set your username to \"" + name + "\"");
}
} }
} catch (Exception exception) {
// Do nothing
} }
Main.skinInProgress.remove(player.getUniqueId()); Main.skinInProgress.remove(player.getUniqueId());
} }

View file

@ -73,12 +73,12 @@ class BlockPhysics implements Listener {
} }
} }
@EventHandler /*@EventHandler
void onBlockPhysics(BlockPhysicsEvent event) { void onBlockPhysics(BlockPhysicsEvent event) {
if (event.getSourceBlock().getState() instanceof CommandBlock) { if (event.getSourceBlock().getState() instanceof CommandBlock) {
event.getSourceBlock().getState().update(); event.getSourceBlock().getState().update();
} }
} }*/
@EventHandler @EventHandler
void onBlockRedstone(BlockRedstoneEvent event) { void onBlockRedstone(BlockRedstoneEvent event) {

View file

@ -38,8 +38,6 @@ import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent; import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -194,10 +192,6 @@ class EntitySpawn implements Listener {
if (Z < minValue) if (Z < minValue)
Z = minValue; Z = minValue;
System.out.println(X);
System.out.println(Y);
System.out.println(Z);
return new Location(location.getWorld(), X, Y, Z); return new Location(location.getWorld(), X, Y, Z);
} }

View file

@ -24,141 +24,129 @@ class ServerCommand implements Listener {
commandName = "/" + arr[0].toLowerCase(); commandName = "/" + arr[0].toLowerCase();
} }
switch (commandName) { try {
case "/minecraft:execute": switch (commandName) {
case "/execute": case "/minecraft:execute":
if (arr.length >= 2) { case "/execute":
int asAtCount = 0; if (arr.length >= 2) {
int asAtCount = 0;
for (int i = 1; i < arr.length; i++) {
if ("run".equalsIgnoreCase(arr[i])) { for (int i = 1; i < arr.length; i++) {
if (i+1 < arr.length) { if ("run".equalsIgnoreCase(arr[i])) {
if ("execute".equalsIgnoreCase(arr[i+1]) || if (i+1 < arr.length) {
"particle".equalsIgnoreCase(arr[i+1]) || if ("execute".equalsIgnoreCase(arr[i+1]) ||
"save-off".equalsIgnoreCase(arr[i+1]) || "particle".equalsIgnoreCase(arr[i+1]) ||
"stop".equalsIgnoreCase(arr[i+1])) { "save-off".equalsIgnoreCase(arr[i+1]) ||
Command.broadcastCommandMessage(sender, "Forbidden execute command detected"); "spreadplayers".equalsIgnoreCase(arr[i+1]) ||
return "cancel"; "stop".equalsIgnoreCase(arr[i+1])) {
} else if (i+3 < arr.length && Command.broadcastCommandMessage(sender, "Forbidden execute command detected");
"gamerule".equalsIgnoreCase(arr[i+1])) { return "cancel";
if ("randomTickSpeed".equalsIgnoreCase(arr[i+2]) && } else if (i+3 < arr.length &&
Double.parseDouble(arr[i+3]) > 6) { "gamerule".equalsIgnoreCase(arr[i+1])) {
return command.replaceFirst("(?i)" + "randomTickSpeed " + arr[i+3], "randomTickSpeed 6"); if ("randomTickSpeed".equalsIgnoreCase(arr[i+2]) &&
} else if ("spawnRadius".equalsIgnoreCase(arr[i+2]) && Double.parseDouble(arr[i+3]) > 6) {
Double.parseDouble(arr[i+3]) > 100) { return command.replaceFirst("(?i)" + "randomTickSpeed " + arr[i+3], "randomTickSpeed 6");
return command.replaceFirst("(?i)" + "spawnRadius " + arr[i+3], "spawnRadius 100"); } else if ("spawnRadius".equalsIgnoreCase(arr[i+2]) &&
} Double.parseDouble(arr[i+3]) > 100) {
} else if (i+5 < arr.length && return command.replaceFirst("(?i)" + "spawnRadius " + arr[i+3], "spawnRadius 100");
"spreadplayers".equalsIgnoreCase(arr[i+1])) {
if (Double.parseDouble(arr[i+5]) > 75) {
final StringBuilder stringBuilder = new StringBuilder();
for (int i2 = 0; i2 < i+5; i2++) {
stringBuilder.append(arr[i2]).append(" ");
} }
stringBuilder.append("75 "); } else if ("give".equalsIgnoreCase(arr[i+1])) {
for (int i2 = i+6; i2 < arr.length; i2++) { if (Double.parseDouble(arr[arr.length-1]) > 1024) {
stringBuilder.append(arr[i2]).append(" "); arr[arr.length-1] = "1024";
return String.join(" ", arr);
} }
return stringBuilder.toString();
} }
} }
break;
}
if ("as".equalsIgnoreCase(arr[i]) ||
"at".equalsIgnoreCase(arr[i])) {
asAtCount++;
} }
break;
} }
if ("as".equalsIgnoreCase(arr[i]) || if (asAtCount >= 2) {
"at".equalsIgnoreCase(arr[i])) { Command.broadcastCommandMessage(sender, "Forbidden execute pattern detected");
asAtCount++; return "cancel";
} }
} }
break;
if (asAtCount >= 2) { case "/minecraft:gamerule":
Command.broadcastCommandMessage(sender, "Forbidden execute pattern detected"); case "/gamerule":
if (arr.length >= 3) {
if ("randomTickSpeed".equalsIgnoreCase(arr[1]) &&
Double.parseDouble(arr[2]) > 6) {
return command.replaceFirst(arr[2], "6");
} else if ("spawnRadius".equalsIgnoreCase(arr[1]) &&
Double.parseDouble(arr[2]) > 100) {
return command.replaceFirst(arr[2], "100");
}
}
break;
case "/minecraft:give":
case "/give":
if (Double.parseDouble(arr[arr.length-1]) > 1024) {
arr[arr.length-1] = "1024";
return String.join(" ", arr);
}
break;
case "/minecraft:particle":
case "/particle":
if (arr.length >= 10 &&
Double.parseDouble(arr[9]) > 10) {
arr[9] = "10";
return String.join(" ", arr);
}
break;
case "/bukkit:reload":
case "/bukkit:rl":
case "/reload":
case "/rl":
if (sender.hasPermission("bukkit.command.reload") &&
arr.length >= 2 &&
"confirm".equalsIgnoreCase(arr[1])) {
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
return "cancel"; return "cancel";
} }
} break;
break; case "/spigot:restart":
case "/minecraft:gamerule": case "/restart":
case "/gamerule": if (sender.hasPermission("bukkit.command.restart")) {
if (arr.length >= 3) { return "cancel";
if ("randomTickSpeed".equalsIgnoreCase(arr[1]) &&
Double.parseDouble(arr[2]) > 6) {
return command.replaceFirst(arr[2], "6");
} else if ("spawnRadius".equalsIgnoreCase(arr[1]) &&
Double.parseDouble(arr[2]) > 100) {
return command.replaceFirst(arr[2], "100");
} }
} break;
break; case "/minecraft:save-off":
case "/minecraft:particle": case "/save-off":
case "/particle": if (sender.hasPermission("minecraft.command.save.disable")) {
if (arr.length >= 10) { Command.broadcastCommandMessage(sender, "Automatic saving is now disabled");
if (Double.parseDouble(arr[9]) > 10) { return "cancel";
final StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 9; i++) {
stringBuilder.append(arr[i]).append(" ");
}
stringBuilder.append("10 ");
for (int i = 10; i < arr.length; i++) {
stringBuilder.append(arr[i]).append(" ");
}
return stringBuilder.toString();
} }
} break;
break; case "/minecraft:spreadplayers":
case "/bukkit:reload": case "/spreadplayers":
case "/bukkit:rl": if (arr.length >= 5) {
case "/reload": if (Double.parseDouble(arr[3]) > 0)
case "/rl": arr[3] = "0";
if (sender.hasPermission("bukkit.command.reload") && if (Double.parseDouble(arr[4]) < 8)
arr.length >= 2 && arr[4] = "8";
"confirm".equalsIgnoreCase(arr[1])) { if (Double.parseDouble(arr[4]) > 50)
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins."); arr[4] = "50";
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete."); return String.join(" ", arr);
return "cancel";
}
break;
case "/spigot:restart":
case "/restart":
if (sender.hasPermission("bukkit.command.restart")) {
return "cancel";
}
break;
case "/minecraft:save-off":
case "/save-off":
if (sender.hasPermission("minecraft.command.save.disable")) {
Command.broadcastCommandMessage(sender, "Automatic saving is now disabled");
return "cancel";
}
break;
case "/minecraft:spreadplayers":
case "/spreadplayers":
if (arr.length >= 5 &&
Double.parseDouble(arr[4]) > 75) {
final StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 4; i++) {
stringBuilder.append(arr[i]).append(" ");
} }
stringBuilder.append("75 "); break;
for (int i = 5; i < arr.length; i++) { case "/minecraft:stop":
stringBuilder.append(arr[i]).append(" "); case "/stop":
if (sender.hasPermission("minecraft.command.stop")) {
Command.broadcastCommandMessage(sender, "Stopping the server");
return "cancel";
} }
}
return stringBuilder.toString(); } catch (NumberFormatException exception) {
} // Do nothing
break;
case "/minecraft:stop":
case "/stop":
if (sender.hasPermission("minecraft.command.stop")) {
Command.broadcastCommandMessage(sender, "Stopping the server");
return "cancel";
}
} }
return null; return null;
} }