mirror of
https://github.com/kaboomserver/extras.git
synced 2025-01-07 23:17:55 +00:00
Improved execute as/at/facing detection (#298)
* Improved execute as/at/facing detection * Made atAsPattern a class attribute
This commit is contained in:
parent
4f1d2a0eab
commit
e22044a158
1 changed files with 12 additions and 8 deletions
|
@ -1,5 +1,8 @@
|
|||
package pw.kaboom.extras.modules.server;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.block.CommandBlock;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -9,6 +12,8 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
public final class ServerCommand implements Listener {
|
||||
private static Pattern asAtPattern = Pattern.compile("\\b(as|at|facing entity) @[ae]\\b");
|
||||
|
||||
public static boolean checkExecuteCommand(final String cmd) {
|
||||
return ("execute".equalsIgnoreCase(cmd)
|
||||
|| "banlist".equalsIgnoreCase(cmd)
|
||||
|
@ -77,6 +82,13 @@ public final class ServerCommand implements Listener {
|
|||
case "/execute":
|
||||
if (arr.length >= 2) {
|
||||
int asAtCount = 0;
|
||||
Matcher asAtMatcher = asAtPattern.matcher(command.toLowerCase());
|
||||
while (asAtMatcher.find()) {
|
||||
asAtCount++;
|
||||
}
|
||||
if (asAtCount >= 2) {
|
||||
return "cancel";
|
||||
}
|
||||
|
||||
for (int i = 1; i < arr.length; i++) {
|
||||
if ("run".equalsIgnoreCase(arr[i])) {
|
||||
|
@ -107,14 +119,6 @@ public final class ServerCommand implements Listener {
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ("as".equalsIgnoreCase(arr[i]) || "at".equalsIgnoreCase(arr[i]) || "facing".equalsIgnoreCase(arr[i])) {
|
||||
asAtCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (asAtCount >= 2) {
|
||||
return "cancel";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue