SteamWar/BauSystem2.0
Archiviert
12
0

ScriptEvents #45

Zusammengeführt
YoyoNow hat 11 Commits von ScriptEvents nach master 2021-09-22 08:02:40 +02:00 zusammengeführt
2 geänderte Dateien mit 41 neuen und 18 gelöschten Zeilen
Nur Änderungen aus Commit a88573aaec werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -191,6 +191,27 @@ public class CustomScript {
return true; return true;
} }
public boolean equals(MenuCommand menuCommand) {
if (menuCommand.args.length != args.length) {
return false;
}
for (int i = 0; i < args.length; i++) {
if (i == 0) continue;
String s1 = args[i];
String s2 = menuCommand.args[i];
if (s1.equals(s2)) {
return true;
}
if (s1.startsWith("<") && s1.endsWith(">") && s2.startsWith("<") && s2.endsWith(">")) {
return true;
}
if (s1.startsWith("[<") && s1.endsWith(">]") && s2.startsWith("[<") && s2.endsWith(">]")) {
return true;
}
}
return false;
}
@Override @Override
public void toYAPION(YAPIONMap yapionMap) { public void toYAPION(YAPIONMap yapionMap) {
YAPIONArray yapionArray = new YAPIONArray(); YAPIONArray yapionArray = new YAPIONArray();
@ -200,7 +221,7 @@ public class CustomScript {
@Override @Override
public SWItem toItem() { public SWItem toItem() {
SWItem swItem = new SWItem(Material.WRITABLE_BOOK, "§8/§e" + String.join(" ", args)); SWItem swItem = new SWItem(Material.WRITABLE_BOOK, "§7Command§8: §e" + String.join(" ", args));
BookMeta bookMeta = (BookMeta) swItem.getItemMeta(); BookMeta bookMeta = (BookMeta) swItem.getItemMeta();
bookMeta.setPages(pages.toArray(new String[0])); bookMeta.setPages(pages.toArray(new String[0]));
swItem.setItemMeta(bookMeta); swItem.setItemMeta(bookMeta);

Datei anzeigen

@ -156,22 +156,6 @@ public class CustomScriptListener implements Listener {
} }
} }
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
if (e.getMessage().startsWith("/script:")) {
e.setMessage("/" + e.getMessage().substring(8));
return;
}
List<CustomScript.CustomCommand> customCommands = playerMap.getOrDefault(e.getPlayer(), new ArrayList<>()).stream().filter(CustomScript.CustomCommand.class::isInstance).map(CustomScript.CustomCommand.class::cast).collect(Collectors.toList());
String[] command = e.getMessage().split(" ");
for (CustomScript.CustomCommand customCommand : customCommands) {
if (customCommand.execute(command, e)) {
return;
}
}
}
private boolean isNoBook(ItemStack item) { private boolean isNoBook(ItemStack item) {
return VersionedCallable.call(new VersionedCallable<>(() -> ScriptListener_15.isNoBook(item), 15)); return VersionedCallable.call(new VersionedCallable<>(() -> ScriptListener_15.isNoBook(item), 15));
} }
@ -229,7 +213,7 @@ public class CustomScriptListener implements Listener {
if (!(script instanceof CustomScript.MenuCommand)) { if (!(script instanceof CustomScript.MenuCommand)) {
continue; continue;
} }
if (Arrays.equals(((CustomScript.MenuCommand) script).args, menuCommand.args)) { if (((CustomScript.MenuCommand) script).equals(menuCommand)) {
p.sendMessage("§cCommand '" + (String.join(" ", menuCommand.args)) + "' bereits definiert"); p.sendMessage("§cCommand '" + (String.join(" ", menuCommand.args)) + "' bereits definiert");
return; return;
} }
@ -251,4 +235,22 @@ public class CustomScriptListener implements Listener {
})); }));
menuCommandSWListInv.open(); menuCommandSWListInv.open();
} }
// EventListener for Commands as well as Events
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) {
if (e.getMessage().startsWith("/script:")) {
e.setMessage("/" + e.getMessage().substring(8));
return;
}
List<CustomScript.CustomCommand> customCommands = playerMap.getOrDefault(e.getPlayer(), new ArrayList<>()).stream().filter(CustomScript.CustomCommand.class::isInstance).map(CustomScript.CustomCommand.class::cast).collect(Collectors.toList());
String[] command = e.getMessage().split(" ");
for (CustomScript.CustomCommand customCommand : customCommands) {
if (customCommand.execute(command, e)) {
return;
}
}
}
} }