ScriptEvents #45
@ -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);
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren