Make ScriptListener.ScriptExecutor.player final
Make ScriptListener.ScriptExecutor.commands final Fixing commands without spaces Fixing negative and zero sleepTime Add Error message on sleep without number Remove throw-away-references
Dieser Commit ist enthalten in:
Ursprung
15570cab7c
Commit
93003de08d
@ -32,17 +32,40 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ScriptListener implements Listener {
|
||||
|
||||
private static final String scriptPrefix = "§eScriptSystem§8» §7";
|
||||
|
||||
@EventHandler
|
||||
public void onLeftClick(PlayerInteractEvent event) {
|
||||
if(event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.LEFT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
ItemStack item = event.getItem();
|
||||
if(item == null || isNoBook(item) || item.getItemMeta() == null)
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer());
|
||||
}
|
||||
|
||||
private boolean isNoBook(ItemStack item){
|
||||
switch(Core.getVersion()){
|
||||
case 12:
|
||||
return ScriptListener_12.isNoBook(item);
|
||||
case 15:
|
||||
default:
|
||||
return ScriptListener_15.isNoBook(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ScriptExecutor {
|
||||
|
||||
private Player player;
|
||||
private List<String> commands = new ArrayList<>();
|
||||
private final Player player;
|
||||
private final List<String> commands = new ArrayList<>();
|
||||
private int index = 0;
|
||||
|
||||
public ScriptExecutor(BookMeta bookMeta, Player player) {
|
||||
@ -59,27 +82,28 @@ public class ScriptListener implements Listener {
|
||||
|
||||
private void resume() {
|
||||
if (!player.isOnline()) {
|
||||
player = null;
|
||||
commands = null;
|
||||
return;
|
||||
}
|
||||
|
||||
while (index < commands.size()) {
|
||||
String command = commands.get(index++);
|
||||
|
||||
String[] strings = command.split(" ");
|
||||
if (strings.length > 0) {
|
||||
if (strings[0].equalsIgnoreCase("sleep")) {
|
||||
int sleepTime = 1;
|
||||
if (strings.length > 1) {
|
||||
try {
|
||||
sleepTime = Integer.parseInt(strings[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
// Ignored
|
||||
if (command.contains(" ")) {
|
||||
String[] strings = command.split(" ");
|
||||
if (strings.length > 0) {
|
||||
if (strings[0].equalsIgnoreCase("sleep")) {
|
||||
int sleepTime = 1;
|
||||
if (strings.length > 1) {
|
||||
try {
|
||||
sleepTime = Integer.parseInt(strings[1]);
|
||||
if (sleepTime <= 0) sleepTime = 1;
|
||||
} catch (NumberFormatException e) {
|
||||
player.sendMessage(scriptPrefix + "Sleep ohne Zahl, default 1 GameTick");
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), this::resume, sleepTime);
|
||||
break;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), this::resume, sleepTime);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,29 +119,4 @@ public class ScriptListener implements Listener {
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeftClick(PlayerInteractEvent event) {
|
||||
if(event.getAction() != Action.LEFT_CLICK_AIR && event.getAction() != Action.LEFT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
ItemStack item = event.getItem();
|
||||
if(item == null || isNoBook(item) || item.getItemMeta() == null)
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
Player player = event.getPlayer();
|
||||
BookMeta meta = (BookMeta) item.getItemMeta();
|
||||
new ScriptExecutor(meta, player);
|
||||
}
|
||||
|
||||
private boolean isNoBook(ItemStack item){
|
||||
switch(Core.getVersion()){
|
||||
case 12:
|
||||
return ScriptListener_12.isNoBook(item);
|
||||
case 15:
|
||||
default:
|
||||
return ScriptListener_15.isNoBook(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren