mirror of
https://github.com/kaboomserver/extras.git
synced 2025-01-07 23:17:55 +00:00
Cleaned up code + unblocked a few things (#301)
This commit is contained in:
parent
67a9095a73
commit
a57a6030b1
2 changed files with 35 additions and 59 deletions
|
@ -23,6 +23,17 @@ import pw.kaboom.extras.Main;
|
|||
import pw.kaboom.extras.modules.server.ServerTabComplete;
|
||||
|
||||
public final class PlayerConnection implements Listener {
|
||||
|
||||
private final String title = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinTitle");
|
||||
private final String subtitle = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinSubtitle");
|
||||
private final int fadeIn = 10;
|
||||
private final int stay = 160;
|
||||
private final int fadeOut = 5;
|
||||
private final boolean enableKick = JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("enableKick");
|
||||
private final boolean enableJoinRestrictions = JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("enableJoinRestrictions");
|
||||
private final boolean allowJoinOnFullServer = JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("allowJoinOnFullServer");
|
||||
private final boolean opOnJoin = JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("opOnJoin");
|
||||
|
||||
@EventHandler
|
||||
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
|
||||
if (Bukkit.getPlayer(event.getName()) != null
|
||||
|
@ -46,11 +57,6 @@ public final class PlayerConnection implements Listener {
|
|||
@EventHandler
|
||||
void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final String title = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinTitle");
|
||||
final String subtitle = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinSubtitle");
|
||||
final int fadeIn = 10;
|
||||
final int stay = 160;
|
||||
final int fadeOut = 5;
|
||||
|
||||
if (title != null
|
||||
|| subtitle != null) {
|
||||
|
@ -68,7 +74,7 @@ public final class PlayerConnection implements Listener {
|
|||
|
||||
@EventHandler
|
||||
void onPlayerKick(final PlayerKickEvent event) {
|
||||
if (!JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("enableKick")) {
|
||||
if (!enableKick) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -81,19 +87,17 @@ public final class PlayerConnection implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("enableJoinRestrictions")) {
|
||||
if (!enableJoinRestrictions) {
|
||||
event.allow();
|
||||
}
|
||||
|
||||
if (Result.KICK_FULL.equals(event.getResult())
|
||||
&& JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("allowJoinOnFullServer")) {
|
||||
if (Result.KICK_FULL.equals(event.getResult()) && allowJoinOnFullServer) {
|
||||
event.allow();
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if (JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("opOnJoin")
|
||||
&& !player.isOp()) {
|
||||
if (opOnJoin && !player.isOp()) {
|
||||
player.setOp(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package pw.kaboom.extras.modules.server;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.block.CommandBlock;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -16,17 +18,10 @@ public final class ServerCommand implements Listener {
|
|||
|
||||
public static boolean checkExecuteCommand(final String cmd) {
|
||||
return ("execute".equalsIgnoreCase(cmd)
|
||||
|| "banlist".equalsIgnoreCase(cmd)
|
||||
|| "clone".equalsIgnoreCase(cmd)
|
||||
|| "data".equalsIgnoreCase(cmd)
|
||||
|| "datapack".equalsIgnoreCase(cmd)
|
||||
|| "debug".equalsIgnoreCase(cmd)
|
||||
|| "difficulty".equalsIgnoreCase(cmd)
|
||||
|| "fill".equalsIgnoreCase(cmd)
|
||||
|| "forceload".equalsIgnoreCase(cmd)
|
||||
|| "help".equalsIgnoreCase(cmd)
|
||||
|| "kick".equalsIgnoreCase(cmd)
|
||||
|| "list".equalsIgnoreCase(cmd)
|
||||
|| "locate".equalsIgnoreCase(cmd)
|
||||
|| "locatebiome".equalsIgnoreCase(cmd)
|
||||
|| "me".equalsIgnoreCase(cmd)
|
||||
|
@ -34,11 +29,8 @@ public final class ServerCommand implements Listener {
|
|||
|| "reload".equalsIgnoreCase(cmd)
|
||||
|| "save-all".equalsIgnoreCase(cmd)
|
||||
|| "say".equalsIgnoreCase(cmd)
|
||||
|| "seed".equalsIgnoreCase(cmd)
|
||||
|| "setblock".equalsIgnoreCase(cmd)
|
||||
|| "spreadplayers".equalsIgnoreCase(cmd)
|
||||
|| "stop".equalsIgnoreCase(cmd)
|
||||
|| "summon".equalsIgnoreCase(cmd)
|
||||
|| "teammsg".equalsIgnoreCase(cmd)
|
||||
|| "teleport".equalsIgnoreCase(cmd)
|
||||
|| "tell".equalsIgnoreCase(cmd)
|
||||
|
@ -46,7 +38,6 @@ public final class ServerCommand implements Listener {
|
|||
|| "tm".equalsIgnoreCase(cmd)
|
||||
|| "tp".equalsIgnoreCase(cmd)
|
||||
|| "w".equalsIgnoreCase(cmd)
|
||||
|| "whitelist".equalsIgnoreCase(cmd)
|
||||
);
|
||||
}
|
||||
public static String checkCommand(final CommandSender sender, final String command, final boolean isConsoleCommand) {
|
||||
|
@ -92,45 +83,25 @@ public final class ServerCommand implements Listener {
|
|||
|
||||
for (int i = 1; i < arr.length; i++) {
|
||||
if ("run".equalsIgnoreCase(arr[i])) {
|
||||
if (i + 1 < arr.length) {
|
||||
if (checkExecuteCommand(arr[i + 1])) {
|
||||
return "cancel";
|
||||
} else if (i + 3 < arr.length
|
||||
&& "gamerule".equalsIgnoreCase(arr[i + 1])) {
|
||||
if ("randomTickSpeed".equalsIgnoreCase(arr[i + 2])
|
||||
&& Double.parseDouble(arr[i + 3]) > 6) {
|
||||
return command.replaceFirst("(?i)" + "randomTickSpeed " + arr[i + 3], "randomTickSpeed 6");
|
||||
}
|
||||
} else if ("give".equalsIgnoreCase(arr[i + 1])) {
|
||||
if (Double.parseDouble(arr[arr.length - 1]) > 64) {
|
||||
// Limit item count
|
||||
arr[arr.length - 1] = "64";
|
||||
return String.join(" ", arr);
|
||||
}
|
||||
} else if ("particle".equalsIgnoreCase(arr[i + 1])) {
|
||||
int[] numArgs = {i + 15, i + 11};
|
||||
for (int j : numArgs) {
|
||||
if (arr.length < j || arr.length > j + 2) {
|
||||
continue;
|
||||
}
|
||||
if (Double.parseDouble(arr[j - 1]) > 10) {
|
||||
// Limit particle count
|
||||
arr[j - 1] = "10";
|
||||
return String.join(" ", arr);
|
||||
}
|
||||
}
|
||||
} else if ("bossbar".equalsIgnoreCase(arr[i + 1])
|
||||
|| "fill".equalsIgnoreCase(arr[i + 1])
|
||||
|| "setblock".equalsIgnoreCase(arr[i + 1])
|
||||
|| "tellraw".equalsIgnoreCase(arr[i + 1])
|
||||
|| "title".equalsIgnoreCase(arr[i + 1])) {
|
||||
final String charCommand = parseCharCodes(command);
|
||||
if (charCommand.contains("selector")) {
|
||||
if (i + 1 == arr.length) {
|
||||
break;
|
||||
}
|
||||
if (checkExecuteCommand(arr[i + 1])) {
|
||||
return "cancel";
|
||||
} else {
|
||||
final String[] executeCommand = Arrays.copyOfRange(arr, i + 1, arr.length);
|
||||
String result = checkCommand(sender, String.join(" ", executeCommand), true);
|
||||
if (result == null) {
|
||||
break;
|
||||
}
|
||||
switch (result) {
|
||||
case "cancel":
|
||||
return "cancel";
|
||||
}
|
||||
default:
|
||||
String pureExecute = String.join(" ", Arrays.copyOfRange(arr, 0, i + 1));
|
||||
return (pureExecute + " " + result);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +114,7 @@ public final class ServerCommand implements Listener {
|
|||
if (command.contains("selector")) {
|
||||
return "cancel";
|
||||
}
|
||||
break;
|
||||
case "/minecraft:gamerule":
|
||||
case "/gamerule":
|
||||
if (arr.length >= 3) {
|
||||
|
@ -176,7 +148,7 @@ public final class ServerCommand implements Listener {
|
|||
break;
|
||||
case "/minecraft:spreadplayers":
|
||||
case "/spreadplayers":
|
||||
if (arr.length == 7 && arr[6].contains("@")) {
|
||||
if (arr.length == 7 && (arr[6].contains("@e") || arr[6].contains("@a"))) {
|
||||
return "cancel";
|
||||
} else if (arr.length >= 5) {
|
||||
if (Double.parseDouble(arr[3]) > 0) {
|
||||
|
|
Loading…
Reference in a new issue