Remove overhead from sleep Command
Dieser Commit ist enthalten in:
Ursprung
552649f884
Commit
45eea9b26e
@ -42,35 +42,6 @@ public class ScriptListener implements Listener {
|
|||||||
|
|
||||||
private static final String scriptPrefix = "§eScriptSystem§8» §7";
|
private static final String scriptPrefix = "§eScriptSystem§8» §7";
|
||||||
|
|
||||||
private static final List<ScriptCommand> scriptCommands = new ArrayList<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
scriptCommands.add(new ScriptCommand() {
|
|
||||||
@Override
|
|
||||||
public String command() {
|
|
||||||
return "sleep";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(ScriptExecutor scriptExecutor, String[] args) {
|
|
||||||
int sleepTime = 1;
|
|
||||||
if (args.length > 0) {
|
|
||||||
try {
|
|
||||||
sleepTime = Integer.parseInt(args[0]);
|
|
||||||
if (sleepTime <= 0) {
|
|
||||||
scriptExecutor.player.sendMessage(scriptPrefix + "Sleep kleiner gleich 0, default 1 GameTick");
|
|
||||||
sleepTime = 1;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
scriptExecutor.player.sendMessage(scriptPrefix + "Sleep ohne Zahl, default 1 GameTick");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), scriptExecutor::resume, sleepTime);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<Player> playerSet = new HashSet<>();
|
private Set<Player> playerSet = new HashSet<>();
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
@ -131,14 +102,10 @@ public class ScriptListener implements Listener {
|
|||||||
while (index < commands.size()) {
|
while (index < commands.size()) {
|
||||||
String command = commands.get(index++);
|
String command = commands.get(index++);
|
||||||
|
|
||||||
for (ScriptCommand scriptCommand : scriptCommands) {
|
if (command.toLowerCase().startsWith("sleep")) {
|
||||||
if (command.toLowerCase().startsWith(scriptCommand.command())) {
|
ScriptListener.sleepCommand(this, generateArgumentArray("sleep", command));
|
||||||
String[] args = command.substring(scriptCommand.command().length() + 1).split(" ");
|
|
||||||
if (!scriptCommand.execute(this, args)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command);
|
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(preprocessEvent);
|
Bukkit.getServer().getPluginManager().callEvent(preprocessEvent);
|
||||||
@ -153,15 +120,24 @@ public class ScriptListener implements Listener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface ScriptCommand {
|
private static String[] generateArgumentArray(String command, String fullCommand) {
|
||||||
|
return fullCommand.substring(command.length() + 1).split(" ");
|
||||||
String command();
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Should return {@code true} if execution should not stop, {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
boolean execute(ScriptExecutor scriptExecutor, String[] args);
|
|
||||||
|
|
||||||
|
private static void sleepCommand(ScriptExecutor scriptExecutor, String[] args) {
|
||||||
|
int sleepTime = 1;
|
||||||
|
if (args.length > 0) {
|
||||||
|
try {
|
||||||
|
sleepTime = Integer.parseInt(args[0]);
|
||||||
|
if (sleepTime <= 0) {
|
||||||
|
scriptExecutor.player.sendMessage(scriptPrefix + "Sleep kleiner gleich 0, default 1 GameTick");
|
||||||
|
sleepTime = 1;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
scriptExecutor.player.sendMessage(scriptPrefix + "Sleep ohne Zahl, default 1 GameTick");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), scriptExecutor::resume, sleepTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren