mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 13:15:44 +01:00
Refactor op command detection
This commit is contained in:
parent
92e008ff0a
commit
1eab127f50
@ -38,7 +38,11 @@ import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.server.RemoteServerCommandEvent;
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class BukkitPlatformListener implements Listener {
|
||||
private static final Pattern OP_COMMAND_PATTERN = Pattern.compile("^/?(\\w+:)?(deop|op)( .*)?$");
|
||||
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public BukkitPlatformListener(LPBukkitPlugin plugin) {
|
||||
@ -60,8 +64,8 @@ public class BukkitPlatformListener implements Listener {
|
||||
handleCommand(e.getSender(), e.getCommand().toLowerCase(), e);
|
||||
}
|
||||
|
||||
private void handleCommand(CommandSender sender, String s, Cancellable event) {
|
||||
if (s.isEmpty()) {
|
||||
private void handleCommand(CommandSender sender, String cmdLine, Cancellable event) {
|
||||
if (cmdLine.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -69,15 +73,7 @@ public class BukkitPlatformListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.charAt(0) == '/') {
|
||||
s = s.substring(1);
|
||||
}
|
||||
|
||||
if (s.contains(":")) {
|
||||
s = s.substring(s.indexOf(':') + 1);
|
||||
}
|
||||
|
||||
if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) {
|
||||
if (OP_COMMAND_PATTERN.matcher(cmdLine).matches()) {
|
||||
event.setCancelled(true);
|
||||
sender.sendMessage(Message.OP_DISABLED.asString(this.plugin.getLocaleManager()));
|
||||
}
|
||||
|
@ -37,7 +37,11 @@ import cn.nukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import cn.nukkit.event.server.RemoteServerCommandEvent;
|
||||
import cn.nukkit.event.server.ServerCommandEvent;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class NukkitPlatformListener implements Listener {
|
||||
private static final Pattern OP_COMMAND_PATTERN = Pattern.compile("^/?(\\w+:)?(deop|op)( .*)?$");
|
||||
|
||||
private final LPNukkitPlugin plugin;
|
||||
|
||||
public NukkitPlatformListener(LPNukkitPlugin plugin) {
|
||||
@ -59,8 +63,8 @@ public class NukkitPlatformListener implements Listener {
|
||||
handleCommand(e.getSender(), e.getCommand().toLowerCase(), e);
|
||||
}
|
||||
|
||||
private void handleCommand(CommandSender sender, String s, Cancellable event) {
|
||||
if (s.isEmpty()) {
|
||||
private void handleCommand(CommandSender sender, String cmdLine, Cancellable event) {
|
||||
if (cmdLine.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -68,15 +72,7 @@ public class NukkitPlatformListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.charAt(0) == '/') {
|
||||
s = s.substring(1);
|
||||
}
|
||||
|
||||
if (s.contains(":")) {
|
||||
s = s.substring(s.indexOf(':') + 1);
|
||||
}
|
||||
|
||||
if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) {
|
||||
if (OP_COMMAND_PATTERN.matcher(cmdLine).matches()) {
|
||||
event.setCancelled(true);
|
||||
sender.sendMessage(Message.OP_DISABLED.asString(this.plugin.getLocaleManager()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user