SteamWar/BauSystem2.0
Archiviert
12
0

Commits vergleichen

...
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.

1 Commits

Autor SHA1 Nachricht Datum
yoyosource
3984098883 Add CustomScript.CustomGUIItem
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Signed-off-by: yoyosource <yoyosource@nidido.de>
2022-01-20 19:54:13 +01:00
3 geänderte Dateien mit 103 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -395,6 +395,7 @@ SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Klicke mit einem Buch zum hinzufügen
SCRIPT_MENU_GUI_DUPLICATE_COMMAND = §cCommand '{0}' bereits definiert SCRIPT_MENU_GUI_DUPLICATE_COMMAND = §cCommand '{0}' bereits definiert
SCRIPT_MENU_GUI_UNKNOWN_EVENT = §cEvent '{0}' ist nicht definierbar SCRIPT_MENU_GUI_UNKNOWN_EVENT = §cEvent '{0}' ist nicht definierbar
SCRIPT_MENU_GUI_UNKNOWN_GUI = §cGui Item '{0}' ist nicht definierbar
SCRIPT_MENU_GUI_LIMIT = §cScript-Buch Limit erreicht SCRIPT_MENU_GUI_LIMIT = §cScript-Buch Limit erreicht
## ScriptCommand ## ScriptCommand

Datei anzeigen

@ -32,6 +32,7 @@ import org.bukkit.inventory.meta.BookMeta;
import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONMap; import yapion.hierarchy.types.YAPIONMap;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -251,4 +252,69 @@ public class CustomScript {
return swItem; return swItem;
} }
} }
public interface CustomGUIItem extends Script {
Material material();
String name();
List<String> lore();
boolean execute(Player p, Map<String, Value> variables);
}
@RequiredArgsConstructor
public static class MenuCustomGUIItem implements CustomGUIItem, MenuScript {
public final Material material;
public final String name;
public final List<String> pages;
@Override
public Material material() {
return material;
}
@Override
public String name() {
return name;
}
@Override
public List<String> lore() {
if (!pages.isEmpty()) {
String[] lines = pages.get(0).split("\n");
List<String> lore = new ArrayList<>();
if (lines.length > 1) {
for (int i = 1; i < lines.length; i++) {
if (lines[i].isEmpty()) continue;
if (lines[i].startsWith("#")) {
lore.add(lines[i].substring(1));
} else {
break;
}
}
}
return lore;
}
return new ArrayList<>();
}
@Override
public boolean execute(Player p, Map<String, Value> variables) {
return false;
}
@Override
public void toYAPION(YAPIONMap yapionMap) {
YAPIONArray yapionArray = new YAPIONArray();
pages.forEach(yapionArray::add);
yapionMap.put(material.name() + " " + name, yapionArray);
}
@Override
public SWItem toItem(Player p) {
SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_COMMAND_ITEM_NAME", p, material.name() + " " + name));
BookMeta bookMeta = (BookMeta) swItem.getItemMeta();
bookMeta.setPages(pages.toArray(new String[0]));
swItem.setItemMeta(bookMeta);
return swItem;
}
}
} }

Datei anzeigen

@ -129,6 +129,13 @@ public class CustomScriptListener implements Listener {
List<String> pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList()); List<String> pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList());
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new CustomScript.MenuEvent(pages, event)); playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new CustomScript.MenuEvent(pages, event));
}); });
yapionObject.getYAPIONMapOrSetDefault("guis", new YAPIONMap()).forEach((key, value) -> {
String[] gui = ((YAPIONValue<String>) key).get().split(" ");
List<String> pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList());
Material material = Material.getMaterial(gui[0]);
playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new CustomScript.MenuCustomGUIItem(material, String.join(" ", Arrays.copyOfRange(gui, 1, gui.length)), pages));
});
} }
@EventHandler @EventHandler
@ -150,6 +157,11 @@ public class CustomScriptListener implements Listener {
playerMap.get(p).stream().filter(CustomScript.MenuEvent.class::isInstance).map(CustomScript.MenuEvent.class::cast).forEach(menuCommand -> { playerMap.get(p).stream().filter(CustomScript.MenuEvent.class::isInstance).map(CustomScript.MenuEvent.class::cast).forEach(menuCommand -> {
menuCommand.toYAPION(eventsMap); menuCommand.toYAPION(eventsMap);
}); });
YAPIONMap guisMap = new YAPIONMap();
yapionObject.add("guis", guisMap);
playerMap.get(p).stream().filter(CustomScript.MenuCustomGUIItem.class::isInstance).map(CustomScript.MenuCustomGUIItem.class::cast).forEach(menuCommand -> {
menuCommand.toYAPION(guisMap);
});
return yapionObject; return yapionObject;
} }
@ -182,7 +194,9 @@ public class CustomScriptListener implements Listener {
playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomScript.MenuScript.class::isInstance).map(CustomScript.MenuScript.class::cast).forEach(menuItem -> { playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomScript.MenuScript.class::isInstance).map(CustomScript.MenuScript.class::cast).forEach(menuItem -> {
SWItem swItem = menuItem.toItem(p); SWItem swItem = menuItem.toItem(p);
ItemStack itemStack = swItem.getItemStack(); ItemStack itemStack = swItem.getItemStack();
if (menuItem instanceof CustomScript.MenuEvent) { if (menuItem instanceof CustomScript.MenuCustomGUIItem) {
itemStack.setType(Material.CHAIN_COMMAND_BLOCK);
} else if (menuItem instanceof CustomScript.MenuEvent) {
itemStack.setType(Material.REPEATING_COMMAND_BLOCK); itemStack.setType(Material.REPEATING_COMMAND_BLOCK);
} else { } else {
itemStack.setType(Material.COMMAND_BLOCK); itemStack.setType(Material.COMMAND_BLOCK);
@ -243,6 +257,27 @@ public class CustomScriptListener implements Listener {
return; return;
} }
scriptBookLimit(p, menuEvent); scriptBookLimit(p, menuEvent);
} else if (s.startsWith("#!GUI ")) {
String[] strings = s.substring(5).split(" ");
if (strings.length != 2) {
BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_UNKNOWN_GUI", p, s.substring(5));
return;
}
Material material = null;
try {
material = Material.valueOf(strings[0]);
if (!material.isItem()) {
material = null;
}
} catch (Exception e) {
}
if (material == null) {
BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_UNKNOWN_GUI", p, s.substring(5));
return;
}
String name = String.join(" ", Arrays.copyOfRange(strings, 1, strings.length));
CustomScript.MenuCustomGUIItem menuCustomGUIItem = new CustomScript.MenuCustomGUIItem(material, name, bookMeta.getPages());
scriptBookLimit(p, menuCustomGUIItem);
} }
})); }));
menuCommandSWListInv.open(); menuCommandSWListInv.open();