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