SteamWar/BauSystem2.0
Archiviert
12
0

Update ScriptCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-02-02 15:59:13 +01:00
Ursprung 91c64fa26b
Commit 8173703855

Datei anzeigen

@ -11,7 +11,6 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@ -27,8 +26,6 @@ public class ScriptCommand extends SWCommand {
@LinkedInstance @LinkedInstance
private CustomScriptManager customScriptManager = null; private CustomScriptManager customScriptManager = null;
private static List<SWListInv.SWListEntry<SpecialCommand>> swItems = new ArrayList<>();
private List<String> loreBuilder(Player p, String prefix, int start, int end) { private List<String> loreBuilder(Player p, String prefix, int start, int end) {
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
for (int i = start; i <= end; i++) { for (int i = start; i <= end; i++) {
@ -48,15 +45,70 @@ public class ScriptCommand extends SWCommand {
@Register(description = "SCRIPT_COMMAND_HELP") @Register(description = "SCRIPT_COMMAND_HELP")
public void menuCommand(Player p) { public void menuCommand(Player p) {
if (swItems.isEmpty()) { List<SWListInv.SWListEntry<SpecialCommand>> swItems = new ArrayList<>();
addEmptyItems(3); addEmptyItems(swItems, 3);
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_CUSTOM_COMMANDS", p), loreBuilder(p, "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_", 1, 13), false, clickType -> { swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_COMMANDS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_", 1, 13)), null));
swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_EVENTS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_", 1, 20, loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_", 1, 2))), null));
swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_OTHER", loreBuilder(p, "SCRIPT_GUI_OTHER_LORE_", 1, 9)), null));
addEmptyItems(swItems, 3);
addCustomScriptsItems(swItems, p);
addEmptyItems(swItems, 44 + 4);
swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_VARIABLES", new ArrayList<>()), null));
addEmptyItems(swItems, 4);
addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_NAME", "SCRIPT_GUI_CONSTANT_TRACE_LORE", false);
addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME", "SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE", false);
addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_TNT_NAME", "SCRIPT_GUI_CONSTANT_TNT_LORE", false);
addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_ONLY_TB_NAME", "SCRIPT_GUI_CONSTANT_ONLY_TB_LORE", false);
addConstantItem(swItems, p, Material.GUNPOWDER, "SCRIPT_GUI_CONSTANT_FREEZE_NAME", "SCRIPT_GUI_CONSTANT_FREEZE_LORE", false);
addConstantItem(swItems, p, Material.FIRE_CHARGE, "SCRIPT_GUI_CONSTANT_FIRE_NAME", "SCRIPT_GUI_CONSTANT_FIRE_LORE", false);
addConstantItem(swItems, p, Material.OBSIDIAN, "SCRIPT_GUI_CONSTANT_PROTECT_NAME", "SCRIPT_GUI_CONSTANT_PROTECT_LORE", false);
addConstantItem(swItems, p, Material.IRON_SWORD, "SCRIPT_GUI_CONSTANT_DAMAGE_NAME", "SCRIPT_GUI_CONSTANT_DAMAGE_LORE", false);
addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_X_NAME", "SCRIPT_GUI_CONSTANT_X_LORE", true);
addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Y_NAME", "SCRIPT_GUI_CONSTANT_Y_LORE", true);
addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Z_NAME", "SCRIPT_GUI_CONSTANT_Z_LORE", true);
addConstantItem(swItems, p, Material.NAME_TAG, "SCRIPT_GUI_CONSTANT_NAME_NAME", "SCRIPT_GUI_CONSTANT_NAME_LORE", false);
addConstantItem(swItems, p, Material.IRON_BOOTS, "SCRIPT_GUI_CONSTANT_SNEAK_NAME", "SCRIPT_GUI_CONSTANT_SNEAK_LORE", false);
addConstantItem(swItems, p, Material.DIAMOND_BOOTS, "SCRIPT_GUI_CONSTANT_SPRINTING_NAME", "SCRIPT_GUI_CONSTANT_SPRINTING_LORE", false);
addConstantItem(swItems, p, Material.ARROW, "SCRIPT_GUI_CONSTANT_SLOT_NAME", "SCRIPT_GUI_CONSTANT_SLOT_LORE", false);
addConstantItem(swItems, p, Material.GRASS_BLOCK, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE", false);
addConstantItem(swItems, p, Material.IRON_BLOCK, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE", false);
addConstantItem(swItems, p, Material.BIRCH_SIGN, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE", false);
addConstantItem(swItems, p, Material.ACACIA_SIGN, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE", false);
addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME", "SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE", false);
addEmptyItems(swItems, 2 * 9 - 2);
SWListInv<SpecialCommand> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("SCRIPT_GUI_NAME", p), swItems, (clickType, o) -> {
if (o != null) {
BauSystem.MESSAGE.send("SCRIPT_GUI_COMMAND_CHAT", p, o.command());
for (String s : o.description()) {
BauSystem.MESSAGE.send(s.isEmpty() ? "PREFIX" : s, p);
}
p.closeInventory();
}
});
swListInv.open();
}
private void addEmptyItems(List<SWListInv.SWListEntry<SpecialCommand>> swItems, int count) {
for (int i = 0; i < count; i++) {
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", new ArrayList<>(), false, clickType -> {
}), null)); }), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_CUSTOM_EVENTS", p), loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_", 1, 20, loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_", 1, 2)), false, clickType -> { }
}), null)); }
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_OTHER", p), loreBuilder(p, "SCRIPT_GUI_OTHER_LORE_", 1, 9), false, clickType -> {
}), null)); private SWItem createItem(Player p, Material material, String name, List<String> lore) {
addEmptyItems(3); return new SWItem(material, BauSystem.MESSAGE.parse(name, p), lore, false, clickType -> {
});
}
private void addConstantItem(List<SWListInv.SWListEntry<SpecialCommand>> swItems, Player p, Material material, String name, String lore, boolean overrideable) {
List<String> itemLore = new ArrayList<>();
itemLore.add(BauSystem.MESSAGE.parse(lore, p));
if (overrideable) itemLore.add(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OVERRIDEABLE", p));
swItems.add(new SWListInv.SWListEntry<>(createItem(p, material, name, itemLore), null));
}
private void addCustomScriptsItems(List<SWListInv.SWListEntry<SpecialCommand>> swItems, Player p) {
List<SpecialCommand> specialCommands = new ArrayList<>(SPECIAL_COMMANDS); List<SpecialCommand> specialCommands = new ArrayList<>(SPECIAL_COMMANDS);
specialCommands.sort(Comparator.comparing(specialCommand -> specialCommand.getClass().getTypeName())); specialCommands.sort(Comparator.comparing(specialCommand -> specialCommand.getClass().getTypeName()));
specialCommands.forEach(specialCommand -> { specialCommands.forEach(specialCommand -> {
@ -89,74 +141,6 @@ public class ScriptCommand extends SWCommand {
}); });
swItems.add(new SWListInv.SWListEntry<>(swItem, specialCommand)); swItems.add(new SWListInv.SWListEntry<>(swItem, specialCommand));
}); });
addEmptyItems(3 + 45);
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_CUSTOM_VARIABLES", p), new ArrayList<>(), false, clickType -> {
}), null));
addEmptyItems(4);
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_TRACE_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_TRACE_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_TNT_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_TNT_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_ONLY_TB_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_ONLY_TB_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GUNPOWDER, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_FREEZE_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_FREEZE_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.FIRE_CHARGE, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_FIRE_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_FIRE_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.OBSIDIAN, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_PROTECT_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_PROTECT_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.IRON_SWORD, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_DAMAGE_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_DAMAGE_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.PLAYER_HEAD, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_X_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_X_LORE", p), BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OVERRIDEABLE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.PLAYER_HEAD, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_Y_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_Y_LORE", p), BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OVERRIDEABLE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.PLAYER_HEAD, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_Z_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_Z_LORE", p), BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OVERRIDEABLE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_NAME_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_NAME_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.IRON_BOOTS, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SNEAK_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SNEAK_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.DIAMOND_BOOTS, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SPRINTING_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SPRINTING_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SLOT_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SLOT_LORE", p), BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OVERRIDEABLE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRASS_BLOCK, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.IRON_BLOCK, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.BIRCH_SIGN, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.ACACIA_SIGN, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE", p)), false, clickType -> {
}), null));
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.MAP, BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE", p)), false, clickType -> {
}), null));
addEmptyItems(2 * 9 - 2);
}
SWListInv<SpecialCommand> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("SCRIPT_GUI_NAME", p), swItems, (clickType, o) -> {
if (o != null) {
BauSystem.MESSAGE.send("SCRIPT_GUI_COMMAND_CHAT", p, o.command());
for (String s : o.description()) {
if (s.isEmpty()) {
BauSystem.MESSAGE.send("PREFIX", p);
} else {
BauSystem.MESSAGE.send(s, p);
}
}
p.closeInventory();
}
});
swListInv.open();
}
private void addEmptyItems(int count) {
for (int i = 0; i < count; i++) {
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", new ArrayList<>(), false, clickType -> {
}), null));
}
} }
@Register(value = "menu", description = "SCRIPT_COMMAND_HELP_MENU") @Register(value = "menu", description = "SCRIPT_COMMAND_HELP_MENU")