From 080d810bc4196da98954706776d0e2501a2a3e94 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 2 Feb 2021 23:44:46 +0100 Subject: [PATCH 01/20] First Prototype of ChaosBauGUI --- .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../bausystem/commands/CommandFreeze.java | 2 - .../bausystem/commands/CommandGUI.java | 120 ++++++++++++++++++ .../bausystem/commands/CommandGills.java | 18 +-- .../bausystem/commands/CommandNV.java | 22 ++-- .../bausystem/commands/CommandTNT.java | 4 + BauSystem_Main/src/plugin.yml | 3 +- 7 files changed, 148 insertions(+), 22 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 96bde54..d7b45a7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -97,6 +97,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("detonator").setExecutor(new CommandDetonator()); getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter()); getCommand("script").setExecutor(new CommandScript()); + getCommand("gui").setExecutor(new CommandGUI()); Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index c158459..2485159 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -19,8 +19,6 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.world.Region; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; import org.bukkit.event.entity.EntityChangeBlockEvent; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java new file mode 100644 index 0000000..0da1d9d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -0,0 +1,120 @@ +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.world.Detonator; +import de.steamwar.core.VersionedCallable; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffectType; + +public class CommandGUI implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if(!(commandSender instanceof Player)) + return false; + Player player = ((Player) commandSender); + openBauGui(player); + return true; + } + + public static void openBauGui(Player player) { + SWInventory inv = new SWInventory(player, 5*9, SteamwarUser.get(BauSystem.getOwner()).getUserName() + "s Bau"); + + inv.setItem(3, Detonator.WAND, clickType -> { + player.closeInventory(); + player.getInventory().setItemInMainHand(Detonator.WAND); + }); + + inv.setItem(4, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", clickType -> { + player.closeInventory(); + player.performCommand("/wand"); + }); + + if(CommandFreeze.getInstance().isOn()) { + inv.setItem(30, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", clickType -> { + CommandFreeze.getInstance().toggle(); + openBauGui(player); + }); + } else { + inv.setItem(30, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", clickType -> { + CommandFreeze.getInstance().toggle(); + openBauGui(player); + }); + } + + switch (CommandTNT.getTntMode()) { + case OFF: + inv.setItem(31, Material.MINECART, "§7TNT: §eAusgeschaltet", clickType -> { + CommandTNT.setTntMode(CommandTNT.TNTMode.ONLY_TB); + openBauGui(player); + }); + break; + case ONLY_TB: + inv.setItem(31, Material.TNT_MINECART, "§7TNT: §enur Testblock", clickType -> { + CommandTNT.setTntMode(CommandTNT.TNTMode.ON); + openBauGui(player); + }); + break; + default: + inv.setItem(31, Material.TNT, "§7TNT: §eEingeschaltet", clickType -> { + CommandTNT.setTntMode(CommandTNT.TNTMode.OFF); + openBauGui(player); + }); + } + + if(CommandFire.getInstance().isOn()) { + inv.setItem(32, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", clickType -> { + CommandFire.getInstance().toggle(); + openBauGui(player); + }); + } else { + inv.setItem(32, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", clickType -> { + CommandFire.getInstance().toggle(); + openBauGui(player); + }); + } + + if(player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { + inv.setItem(38, Material.POTION, "§7Nightvision: §eEingeschaltet", clickType -> { + CommandNV.toggleNightvision(player); + openBauGui(player); + }); + } else { + inv.setItem(38, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", clickType -> { + CommandNV.toggleNightvision(player); + openBauGui(player); + }); + } + + if(player.hasPotionEffect(PotionEffectType.WATER_BREATHING)) { + inv.setItem(40, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", clickType -> { + CommandGills.toggleGills(player); + openBauGui(player); + }); + } else { + inv.setItem(40, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", clickType -> { + CommandGills.toggleGills(player); + openBauGui(player); + }); + } + + inv.open(); + } + + private static Material getMaterial(String... names) { + for (String name:names) { + try { + Material mat = Material.valueOf(name); + return mat; + }catch (NullPointerException ignored) {} + } + return null; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGills.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGills.java index 77845cb..927ef5a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGills.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGills.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -26,8 +27,6 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import de.steamwar.bausystem.BauSystem; - public class CommandGills implements CommandExecutor { @Override @@ -35,16 +34,17 @@ public class CommandGills implements CommandExecutor { if(!(sender instanceof Player)) return false; Player player = (Player) sender; + toggleGills(player); + return false; + } - for(PotionEffect effect : player.getActivePotionEffects()){ - if(effect.getType().equals(PotionEffectType.WATER_BREATHING)){ - player.sendMessage(BauSystem.PREFIX + "Wassersicht deaktiviert"); - player.removePotionEffect(PotionEffectType.WATER_BREATHING); - return false; - } + public static void toggleGills(Player player) { + if(player.hasPotionEffect(PotionEffectType.WATER_BREATHING)) { + player.sendMessage(BauSystem.PREFIX + "Wassersicht deaktiviert"); + player.removePotionEffect(PotionEffectType.WATER_BREATHING); + return; } player.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, 1000000, 255, false, false)); player.sendMessage(BauSystem.PREFIX + "Wassersicht aktiviert"); - return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandNV.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandNV.java index fbd79ca..5155659 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandNV.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandNV.java @@ -34,16 +34,18 @@ public class CommandNV implements CommandExecutor { if(!(sender instanceof Player)) return false; Player player = (Player) sender; - - for(PotionEffect effect : player.getActivePotionEffects()){ - if(effect.getType().equals(PotionEffectType.NIGHT_VISION)){ - player.sendMessage(BauSystem.PREFIX + "Nachtsicht deaktiviert"); - player.removePotionEffect(PotionEffectType.NIGHT_VISION); - return false; - } - } - player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1000000, 255, false, false)); - player.sendMessage(BauSystem.PREFIX + "Nachtsicht aktiviert"); + toggleNightvision(player); return false; } + + public static void toggleNightvision(Player player) { + if(player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { + player.sendMessage(BauSystem.PREFIX + "Nachtsicht deaktiviert"); + player.removePotionEffect(PotionEffectType.NIGHT_VISION); + return; + } + + player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1000000, 255, false, false)); + player.sendMessage(BauSystem.PREFIX + "Nachtsicht aktiviert"); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 91eb203..57c45aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -42,6 +42,10 @@ public class CommandTNT implements CommandExecutor, Listener { return tntMode; } + public static void setTntMode(TNTMode tntMode) { + CommandTNT.tntMode = tntMode; + } + public enum TNTMode { ON("§aan"), ONLY_TB("§7nur §eTestblock"), diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 5460f05..da1e1db 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -33,4 +33,5 @@ commands: lockschem: detonator: aliases: dt - script: \ No newline at end of file + script: + gui: \ No newline at end of file From 0b95df4bda9eee273b1e8c369252138627b0cd04 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 3 Feb 2021 20:14:52 +0100 Subject: [PATCH 02/20] Expanding Inventory --- .../bausystem/commands/CommandGUI.java | 185 +++++++++++++----- .../de/steamwar/bausystem/world/Region.java | 9 + 2 files changed, 144 insertions(+), 50 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 0da1d9d..602ae3b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -2,7 +2,8 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Detonator; -import de.steamwar.core.VersionedCallable; +import de.steamwar.bausystem.world.Region; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.sql.SteamwarUser; @@ -11,100 +12,184 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffectType; +import java.util.*; + public class CommandGUI implements CommandExecutor { + private static final Set OPEN_INVS = new HashSet<>(); + private static boolean isRefreshing = false; + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { if(!(commandSender instanceof Player)) return false; Player player = ((Player) commandSender); openBauGui(player); + OPEN_INVS.add(player); return true; } public static void openBauGui(Player player) { + Region region = Region.getRegionIn(player.getLocation()); SWInventory inv = new SWInventory(player, 5*9, SteamwarUser.get(BauSystem.getOwner()).getUserName() + "s Bau"); - - inv.setItem(3, Detonator.WAND, clickType -> { - player.closeInventory(); - player.getInventory().setItemInMainHand(Detonator.WAND); + inv.setCallback(-1, clickType -> { + if(!isRefreshing) + OPEN_INVS.remove(player); }); - inv.setItem(4, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", clickType -> { + inv.setItem(2, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + + ItemStack dtWand = Detonator.WAND.clone(); + ItemMeta meta = dtWand.getItemMeta(); + List lore = meta.getLore(); + lore.add("§8/§7dt wand"); + meta.setLore(lore); + dtWand.setItemMeta(meta); + inv.setItem(3, dtWand, clickType -> { + player.closeInventory(); + player.performCommand("dt wand"); + }); + + inv.setItem(4, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", Arrays.asList("§8//§7wand"), false, clickType -> { player.closeInventory(); player.performCommand("/wand"); }); + inv.setItem(5, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(6, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); - if(CommandFreeze.getInstance().isOn()) { - inv.setItem(30, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", clickType -> { - CommandFreeze.getInstance().toggle(); - openBauGui(player); - }); - } else { - inv.setItem(30, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", clickType -> { - CommandFreeze.getInstance().toggle(); - openBauGui(player); - }); - } + inv.setItem(9, Material.COMPASS, "§7TPS Limitieren", Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e1 - 20§8]"), false, clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "TPS Limitieren"); + anvilInv.setItem(Material.COMPASS); + anvilInv.setCallback(s -> player.performCommand("tpslimit " + s)); + anvilInv.open(); + }); + inv.setItem(18, Material.FEATHER, "§7Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + player.getFlySpeed() * 10, "§8/§7speed §8[§e1 - 10§8]"), false, clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Geschwindigkeit"); + anvilInv.setItem(Material.FEATHER); + anvilInv.setCallback(s -> player.performCommand("speed " + s)); + anvilInv.open(); + }); + inv.setItem(27, getMaterial("PLAYER_HEAD", "SKULL_ITEM"), (byte) 3, "§7Spielerkopf geben", Arrays.asList("§8/§7skull §8[§eSpieler§8]"), false, clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Spielerköpfe"); + anvilInv.setItem(Material.NAME_TAG); + anvilInv.setCallback(s -> player.performCommand("skull " + s)); + anvilInv.open(); + }); - switch (CommandTNT.getTntMode()) { - case OFF: - inv.setItem(31, Material.MINECART, "§7TNT: §eAusgeschaltet", clickType -> { - CommandTNT.setTntMode(CommandTNT.TNTMode.ONLY_TB); - openBauGui(player); - }); - break; - case ONLY_TB: - inv.setItem(31, Material.TNT_MINECART, "§7TNT: §enur Testblock", clickType -> { - CommandTNT.setTntMode(CommandTNT.TNTMode.ON); - openBauGui(player); - }); - break; - default: - inv.setItem(31, Material.TNT, "§7TNT: §eEingeschaltet", clickType -> { - CommandTNT.setTntMode(CommandTNT.TNTMode.OFF); - openBauGui(player); - }); - } + if(region == null) { + inv.setItem(17, Material.BARRIER, "§eKeine Region", clickType -> {}); + inv.setItem(26, Material.BARRIER, "§eKeine Region", clickType -> {}); + inv.setItem(35, Material.BARRIER, "§eKeine Region", clickType -> {}); + }else { + inv.setItem(17, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", Arrays.asList("§8/§7reset"), false, clickType -> + confirmationInventory(player, "Region Reseten?", () -> player.performCommand("reset"), () -> openBauGui(player))); - if(CommandFire.getInstance().isOn()) { - inv.setItem(32, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", clickType -> { - CommandFire.getInstance().toggle(); - openBauGui(player); - }); - } else { - inv.setItem(32, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", clickType -> { - CommandFire.getInstance().toggle(); - openBauGui(player); - }); + if(region.hasProtection()) { + inv.setItem(26, Material.OBSIDIAN, "§eRegion Protecten", Arrays.asList("§8/§7protect"), false, clickType -> + confirmationInventory(player, "Region Protecten", () -> player.performCommand("protect"), () -> openBauGui(player))); + } else { + inv.setItem(26, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> {}); + } + + if(region.hasTestblock()) { + inv.setItem(35, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", Arrays.asList("§8/§7testblock"), false, clickType -> + confirmationInventory(player, "Testblock erneuern", () -> player.performCommand("testblock"), () -> openBauGui(player))); + } else { + inv.setItem(35, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> {}); + } } if(player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - inv.setItem(38, Material.POTION, "§7Nightvision: §eEingeschaltet", clickType -> { + inv.setItem(38, Material.POTION, "§7Nightvision: §eEingeschaltet", Arrays.asList("§8/§7nv"), false, clickType -> { CommandNV.toggleNightvision(player); openBauGui(player); }); } else { - inv.setItem(38, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", clickType -> { + inv.setItem(38, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", Arrays.asList("§8/§7nv"), false, clickType -> { CommandNV.toggleNightvision(player); openBauGui(player); }); } if(player.hasPotionEffect(PotionEffectType.WATER_BREATHING)) { - inv.setItem(40, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", clickType -> { + inv.setItem(39, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", Arrays.asList("§8/§7wv"), false, clickType -> { CommandGills.toggleGills(player); openBauGui(player); }); } else { - inv.setItem(40, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", clickType -> { + inv.setItem(39, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", Arrays.asList("§8/§7wv"), false, clickType -> { CommandGills.toggleGills(player); openBauGui(player); }); } + switch (CommandTNT.getTntMode()) { + case OFF: + inv.setItem(40, Material.MINECART, "§7TNT: §eAusgeschaltet", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { + CommandTNT.setTntMode(Region.buildAreaEnabled()?CommandTNT.TNTMode.ONLY_TB: CommandTNT.TNTMode.ON); + updateInventories(); + }); + break; + case ONLY_TB: + inv.setItem(40, Material.TNT_MINECART, "§7TNT: §enur Testblock", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { + CommandTNT.setTntMode(CommandTNT.TNTMode.ON); + updateInventories(); + }); + break; + default: + inv.setItem(40, Material.TNT, "§7TNT: §eEingeschaltet", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { + CommandTNT.setTntMode(CommandTNT.TNTMode.OFF); + updateInventories(); + }); + } + + if(CommandFreeze.getInstance().isOn()) { + inv.setItem(41, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", Arrays.asList("§8/§7freeze"), false, clickType -> { + CommandFreeze.getInstance().toggle(); + updateInventories(); + }); + } else { + inv.setItem(41, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", Arrays.asList("§8/§7freeze"), false, clickType -> { + CommandFreeze.getInstance().toggle(); + updateInventories(); + }); + } + + if(CommandFire.getInstance().isOn()) { + inv.setItem(42, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", Arrays.asList("§8/§7fire"), false, clickType -> { + CommandFire.getInstance().toggle(); + updateInventories(); + }); + } else { + inv.setItem(42, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", Arrays.asList("§8/§7fire"), false, clickType -> { + CommandFire.getInstance().toggle(); + updateInventories(); + }); + } + + inv.open(); + } + + private static void updateInventories() { + isRefreshing = true; + OPEN_INVS.forEach(CommandGUI::openBauGui); + isRefreshing = false; + } + + private static void confirmationInventory(Player player, String title, Runnable confirm, Runnable decline) { + SWInventory inv = new SWInventory(player, 9, title); + inv.setItem(0, SWItem.getDye(1), "§cAbbrechen", clickType -> { + player.closeInventory(); + decline.run(); + }); + inv.setItem(8, SWItem.getDye(10), "§aBestätigen", clickType -> { + player.closeInventory(); + confirm.run(); + }); inv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index 82e9f96..03035f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -68,6 +68,15 @@ public class Region { return regions; } + public static Region getRegionIn(Location location) { + for(Region region : Region.getRegions()) { + if (region.inRegion(location)) { + return region; + } + } + return null; + } + private final int minX; private final int minY; private final int minZ; From 886cf5607d9f477c631c3ea7a0abf5b65c8d69ca Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 3 Feb 2021 21:01:21 +0100 Subject: [PATCH 03/20] New Region System --- .../bausystem/commands/CommandGUI.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 602ae3b..eae86b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -34,7 +34,7 @@ public class CommandGUI implements CommandExecutor { } public static void openBauGui(Player player) { - Region region = Region.getRegionIn(player.getLocation()); + Region region = Region.getRegion(player.getLocation()); SWInventory inv = new SWInventory(player, 5*9, SteamwarUser.get(BauSystem.getOwner()).getUserName() + "s Bau"); inv.setCallback(-1, clickType -> { if(!isRefreshing) @@ -127,46 +127,46 @@ public class CommandGUI implements CommandExecutor { }); } - switch (CommandTNT.getTntMode()) { + switch (region.getTntMode()) { case OFF: inv.setItem(40, Material.MINECART, "§7TNT: §eAusgeschaltet", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { - CommandTNT.setTntMode(Region.buildAreaEnabled()?CommandTNT.TNTMode.ONLY_TB: CommandTNT.TNTMode.ON); + region.setTntMode(Region.buildAreaEnabled()?CommandTNT.TNTMode.ONLY_TB: CommandTNT.TNTMode.ON); updateInventories(); }); break; case ONLY_TB: inv.setItem(40, Material.TNT_MINECART, "§7TNT: §enur Testblock", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { - CommandTNT.setTntMode(CommandTNT.TNTMode.ON); + region.setTntMode(CommandTNT.TNTMode.ON); updateInventories(); }); break; default: inv.setItem(40, Material.TNT, "§7TNT: §eEingeschaltet", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { - CommandTNT.setTntMode(CommandTNT.TNTMode.OFF); + region.setTntMode(CommandTNT.TNTMode.OFF); updateInventories(); }); } - if(CommandFreeze.getInstance().isOn()) { + if(region.isFreeze()) { inv.setItem(41, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", Arrays.asList("§8/§7freeze"), false, clickType -> { - CommandFreeze.getInstance().toggle(); + region.setFreeze(false); updateInventories(); }); } else { inv.setItem(41, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", Arrays.asList("§8/§7freeze"), false, clickType -> { - CommandFreeze.getInstance().toggle(); + region.setFreeze(true); updateInventories(); }); } - if(CommandFire.getInstance().isOn()) { + if(region.isFire()) { inv.setItem(42, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", Arrays.asList("§8/§7fire"), false, clickType -> { - CommandFire.getInstance().toggle(); + region.setFire(false); updateInventories(); }); } else { inv.setItem(42, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", Arrays.asList("§8/§7fire"), false, clickType -> { - CommandFire.getInstance().toggle(); + region.setFire(true); updateInventories(); }); } From 032a4c75d6be64ab82e4ce1eb9aa9a18d57e45fa Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 3 Feb 2021 23:52:23 +0100 Subject: [PATCH 04/20] Adding and Fixing more Stuff --- .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../bausystem/commands/CommandGUI.java | 91 +++++++++++++++++-- .../bausystem/commands/CommandSkull.java | 6 +- 3 files changed, 89 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index d7b45a7..5843f1a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -104,6 +104,7 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new ScriptListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); + Bukkit.getPluginManager().registerEvents(new CommandGUI(), this); new AFKStopper(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index eae86b1..f0df403 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -1,6 +1,9 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.tracer.record.RecordStatus; +import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Region; import de.steamwar.inventory.SWAnvilInv; @@ -12,15 +15,20 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffectType; import java.util.*; -public class CommandGUI implements CommandExecutor { +public class CommandGUI implements CommandExecutor, Listener { private static final Set OPEN_INVS = new HashSet<>(); + private static final Set OPEN_TRACER_INVS = new HashSet<>(); private static boolean isRefreshing = false; @Override @@ -73,6 +81,13 @@ public class CommandGUI implements CommandExecutor { anvilInv.setCallback(s -> player.performCommand("speed " + s)); anvilInv.open(); }); + + inv.setItem(22, Material.OBSERVER, "§7Tracer", Arrays.asList("§7Status: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> { + player.closeInventory(); + OPEN_TRACER_INVS.add(player); + traceGUI(player); + }); + inv.setItem(27, getMaterial("PLAYER_HEAD", "SKULL_ITEM"), (byte) 3, "§7Spielerkopf geben", Arrays.asList("§8/§7skull §8[§eSpieler§8]"), false, clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, "Spielerköpfe"); anvilInv.setItem(Material.NAME_TAG); @@ -80,7 +95,7 @@ public class CommandGUI implements CommandExecutor { anvilInv.open(); }); - if(region == null) { + if(region == Region.GlobalRegion.getInstance()) { inv.setItem(17, Material.BARRIER, "§eKeine Region", clickType -> {}); inv.setItem(26, Material.BARRIER, "§eKeine Region", clickType -> {}); inv.setItem(35, Material.BARRIER, "§eKeine Region", clickType -> {}); @@ -129,19 +144,19 @@ public class CommandGUI implements CommandExecutor { switch (region.getTntMode()) { case OFF: - inv.setItem(40, Material.MINECART, "§7TNT: §eAusgeschaltet", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { - region.setTntMode(Region.buildAreaEnabled()?CommandTNT.TNTMode.ONLY_TB: CommandTNT.TNTMode.ON); + inv.setItem(40, Material.MINECART, "§7TNT: §eAusgeschaltet", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { + region.setTntMode(region.buildAreaEnabled()?CommandTNT.TNTMode.ONLY_TB: CommandTNT.TNTMode.ON); updateInventories(); }); break; case ONLY_TB: - inv.setItem(40, Material.TNT_MINECART, "§7TNT: §enur Testblock", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { + inv.setItem(40, Material.TNT_MINECART, "§7TNT: §enur Testblock", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { region.setTntMode(CommandTNT.TNTMode.ON); updateInventories(); }); break; default: - inv.setItem(40, Material.TNT, "§7TNT: §eEingeschaltet", Arrays.asList("§8/§7tnt §8[" + (Region.buildAreaEnabled()?"§etb§8, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { + inv.setItem(40, Material.TNT, "§7TNT: §eEingeschaltet", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { region.setTntMode(CommandTNT.TNTMode.OFF); updateInventories(); }); @@ -174,9 +189,60 @@ public class CommandGUI implements CommandExecutor { inv.open(); } + private static void traceGUI(Player player) { + SWInventory inv = new SWInventory(player, 9, "Tracer"); + inv.setCallback(-1, clickType -> { + if(!isRefreshing) + OPEN_TRACER_INVS.remove(player); + }); + switch (RecordStateMachine.getRecordStatus()) { + case IDLE: + inv.setItem(0, getMaterial("SNOWBALL", "SNOW_BALL"), "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> { + RecordStateMachine.commandAuto(); + updateInventories(); + }); + break; + case IDLE_AUTO: + inv.setItem(0, Material.ENDER_PEARL, "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> { + RecordStateMachine.commandStart(); + updateInventories(); + }); + break; + case RECORD: + case RECORD_AUTO: + inv.setItem(0, getMaterial("ENDER_EYE", "EYE_OF_ENDER"), "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> { + RecordStateMachine.commandStop(); + updateInventories(); + }); + } + if(TraceShowManager.hasActiveShow(player)) { + inv.setItem(2, Material.TNT, "§7Showstatus", Arrays.asList("§7Aktuell: §eGezeigt"), false, clickType -> { + player.performCommand("trace hide"); + traceGUI(player); + }); + } else { + inv.setItem(2, Material.GLASS, "§7Showstatus", Arrays.asList("§7Aktuell: §eVersteckt"), false, clickType -> { + player.performCommand("trace show"); + traceGUI(player); + }); + } + + inv.setItem(4, Material.TNT_MINECART, "§7Trace GUI", Collections.singletonList("§8/§7trace show gui"), false, clickType -> { + player.closeInventory(); + player.performCommand("trace show gui"); + }); + + inv.setItem(6, getMaterial("GRAY_STAINED_GLASS_PANE", "STAINED_GLASS_PANE"), (byte) 7, "§7Coming soon.", Collections.emptyList(), false, clickType -> {}); + + inv.setItem(8, Material.BARRIER, "§7Trace löschen", clickType -> confirmationInventory(player, "Trace löschen", () -> player.performCommand("trace delete"), () -> {})); + + inv.open(); + } + private static void updateInventories() { isRefreshing = true; OPEN_INVS.forEach(CommandGUI::openBauGui); + OPEN_TRACER_INVS.forEach(CommandGUI::traceGUI); isRefreshing = false; } @@ -196,10 +262,19 @@ public class CommandGUI implements CommandExecutor { private static Material getMaterial(String... names) { for (String name:names) { try { - Material mat = Material.valueOf(name); - return mat; + return Material.valueOf(name); }catch (NullPointerException ignored) {} } return null; } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + if(event.getItem().getType() != Material.NETHER_STAR) + return; + openBauGui(event.getPlayer()); + OPEN_INVS.add(event.getPlayer()); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java index 0208ca7..ed0f820 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; +import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -46,7 +47,10 @@ public class CommandSkull implements CommandExecutor { assert sm != null; sm.setDisplayName("§e" + args[0] + "§8s Kopf"); is.setItemMeta(sm); - p.getInventory().setItemInMainHand(is); + if(p.getInventory().getItemInMainHand().getType() == Material.AIR) + p.getInventory().setItemInMainHand(is); + else + p.getInventory().setItemInOffHand(is); return false; } } From d557e164bab965401b0d21ee127a8a5463e01f9b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 4 Feb 2021 20:56:25 +0100 Subject: [PATCH 05/20] Some TM Fixes and Inventory Layout --- .../commands/CommandDebugStick_15.java | 5 +- .../bausystem/commands/CommandDetonator.java | 6 +- .../bausystem/commands/CommandGUI.java | 355 +++++++++++++++--- .../steamwar/bausystem/world/AutoLoader.java | 8 + .../steamwar/bausystem/world/Detonator.java | 2 +- 5 files changed, 331 insertions(+), 45 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java index ec1560c..abbfc71 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java @@ -27,6 +27,9 @@ class CommandDebugStick_15 { private CommandDebugStick_15(){} static void giveStick(Player player){ - player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK, 1)); + if(player.getInventory().getItemInMainHand().getType() == Material.AIR) + player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK, 1)); + else + player.getInventory().setItemInOffHand(new ItemStack(Material.DEBUG_STICK, 1)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 52bc21e..c45f3a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Welt; +import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -62,7 +63,10 @@ public class CommandDetonator implements CommandExecutor { case "wand": case "detonator": case "item": - player.getInventory().setItemInMainHand(Detonator.WAND); + if(player.getInventory().getItemInMainHand().getType() == Material.AIR) + player.getInventory().setItemInMainHand(Detonator.WAND); + else + player.getInventory().setItemInOffHand(Detonator.WAND); player.updateInventory(); Detonator.getDetonator(player); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index f0df403..cce3173 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -1,15 +1,24 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; -import de.steamwar.bausystem.tracer.record.RecordStatus; import de.steamwar.bausystem.tracer.show.TraceShowManager; +import de.steamwar.bausystem.world.AutoLoader; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Region; +import de.steamwar.bausystem.world.Welt; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import de.steamwar.sql.BauweltMember; import de.steamwar.sql.SteamwarUser; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -19,6 +28,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffectType; @@ -29,8 +39,13 @@ public class CommandGUI implements CommandExecutor, Listener { private static final Set OPEN_INVS = new HashSet<>(); private static final Set OPEN_TRACER_INVS = new HashSet<>(); + private static final Set LAST_F_PLAYER = new HashSet<>(); private static boolean isRefreshing = false; + public CommandGUI() { + Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getPlugin(), LAST_F_PLAYER::clear, 0, 20); + } + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { if(!(commandSender instanceof Player)) @@ -49,143 +64,211 @@ public class CommandGUI implements CommandExecutor, Listener { OPEN_INVS.remove(player); }); - inv.setItem(2, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(20, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(22, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(24, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); ItemStack dtWand = Detonator.WAND.clone(); ItemMeta meta = dtWand.getItemMeta(); List lore = meta.getLore(); lore.add("§8/§7dt wand"); + if(Welt.noPermission(player, Permission.world)) + lore.add("§cDu hast keine Worldrechte"); meta.setLore(lore); dtWand.setItemMeta(meta); - inv.setItem(3, dtWand, clickType -> { + inv.setItem(38, dtWand, clickType -> { player.closeInventory(); player.performCommand("dt wand"); }); - inv.setItem(4, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", Arrays.asList("§8//§7wand"), false, clickType -> { + inv.setItem(40, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", getNoPermsLore(Arrays.asList("§8//§7wand"), player, "§cDu hast keine Worldeditrechte", Permission.worldedit), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; player.closeInventory(); player.performCommand("/wand"); }); - inv.setItem(5, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); - inv.setItem(6, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(41, Material.DEBUG_STICK, "§7Debugstick", Arrays.asList("§8/§7debugstick"), false, clickType -> { + player.closeInventory(); + player.performCommand("debugstick"); + }); + inv.setItem(42, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); - inv.setItem(9, Material.COMPASS, "§7TPS Limitieren", Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e1 - 20§8]"), false, clickType -> { + inv.setItem(26, Material.COMPASS, "§7TPS Limitieren", getNoPermsLore(Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e1 - 20§8]"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, "TPS Limitieren"); anvilInv.setItem(Material.COMPASS); anvilInv.setCallback(s -> player.performCommand("tpslimit " + s)); anvilInv.open(); }); - inv.setItem(18, Material.FEATHER, "§7Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + player.getFlySpeed() * 10, "§8/§7speed §8[§e1 - 10§8]"), false, clickType -> { + inv.setItem(6, Material.FEATHER, "§7Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + player.getFlySpeed() * 10, "§8/§7speed §8[§e1 - 10§8]"), false, clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, "Geschwindigkeit"); anvilInv.setItem(Material.FEATHER); anvilInv.setCallback(s -> player.performCommand("speed " + s)); anvilInv.open(); }); - inv.setItem(22, Material.OBSERVER, "§7Tracer", Arrays.asList("§7Status: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> { + if(player.getUniqueId().equals(BauSystem.getOwner())) { + SWItem skull = SWItem.getPlayerSkull(player.getName()); + skull.setName("§7Bau verwalten"); + List skullLore = new ArrayList<>(); + skullLore.add("§7TNT: §e" + region.getTntMode().getName()); + skullLore.add("§7StopLag: §e" + (region.isFreeze()?"Eingeschaltet":"Ausgeschaltet")); + skullLore.add("§7Fire: §e" + (region.isFire()?"Ausgeschaltet":"Eingeschaltet")); + skullLore.add("§7Members: §e" + (BauweltMember.getMembers(BauSystem.getOwnerID()).size() - 1)); + skull.setLore(skullLore); + skull.setCallback(clickType -> { + player.closeInventory(); + bauManagementGUI(player); + }); + inv.setItem(4, skull); + } + + inv.setItem(39, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + 0 + " §7Bücher"), true, clickType -> { + // TODO: 04.02.2021 Implement Script Book Database + }); + + inv.setItem(21, Material.OBSERVER, "§7Tracer", getNoPermsLore(Arrays.asList("§7Status: §e" + RecordStateMachine.getRecordStatus().getName()), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; player.closeInventory(); OPEN_TRACER_INVS.add(player); traceGUI(player); }); - inv.setItem(27, getMaterial("PLAYER_HEAD", "SKULL_ITEM"), (byte) 3, "§7Spielerkopf geben", Arrays.asList("§8/§7skull §8[§eSpieler§8]"), false, clickType -> { + inv.setItem(23, Material.DISPENSER, "§7Auto-Loader", getNoPermsLore(Collections.emptyList(), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + player.closeInventory(); + autoLoaderGUI(player); + }); + + inv.setItem(8, getMaterial("PLAYER_HEAD", "SKULL_ITEM"), (byte) 3, "§7Spielerkopf geben", Arrays.asList("§8/§7skull §8[§eSpieler§8]"), false, clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, "Spielerköpfe"); anvilInv.setItem(Material.NAME_TAG); anvilInv.setCallback(s -> player.performCommand("skull " + s)); anvilInv.open(); }); - if(region == Region.GlobalRegion.getInstance()) { - inv.setItem(17, Material.BARRIER, "§eKeine Region", clickType -> {}); - inv.setItem(26, Material.BARRIER, "§eKeine Region", clickType -> {}); - inv.setItem(35, Material.BARRIER, "§eKeine Region", clickType -> {}); + if(Region.GlobalRegion.isGlobalRegion(region)) { + inv.setItem(18, Material.BARRIER, "§eKeine Region", clickType -> {}); + inv.setItem(27, Material.BARRIER, "§eKeine Region", clickType -> {}); + inv.setItem(36, Material.BARRIER, "§eKeine Region", clickType -> {}); }else { - inv.setItem(17, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", Arrays.asList("§8/§7reset"), false, clickType -> + inv.setItem(18, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", getNoPermsLore(Arrays.asList("§8/§7reset"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> confirmationInventory(player, "Region Reseten?", () -> player.performCommand("reset"), () -> openBauGui(player))); if(region.hasProtection()) { - inv.setItem(26, Material.OBSIDIAN, "§eRegion Protecten", Arrays.asList("§8/§7protect"), false, clickType -> + inv.setItem(27, Material.OBSIDIAN, "§eRegion Protecten", getNoPermsLore(Arrays.asList("§8/§7protect"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> confirmationInventory(player, "Region Protecten", () -> player.performCommand("protect"), () -> openBauGui(player))); } else { - inv.setItem(26, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> {}); + inv.setItem(27, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> {}); } if(region.hasTestblock()) { - inv.setItem(35, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", Arrays.asList("§8/§7testblock"), false, clickType -> + inv.setItem(36, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", getNoPermsLore(Arrays.asList("§8/§7testblock"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> confirmationInventory(player, "Testblock erneuern", () -> player.performCommand("testblock"), () -> openBauGui(player))); } else { - inv.setItem(35, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> {}); + inv.setItem(36, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> {}); } } if(player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - inv.setItem(38, Material.POTION, "§7Nightvision: §eEingeschaltet", Arrays.asList("§8/§7nv"), false, clickType -> { + inv.setItem(35, Material.POTION, "§7Nightvision: §eEingeschaltet", Collections.singletonList("§8/§7nv"), false, clickType -> { CommandNV.toggleNightvision(player); openBauGui(player); }); } else { - inv.setItem(38, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", Arrays.asList("§8/§7nv"), false, clickType -> { + inv.setItem(35, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", Collections.singletonList("§8/§7nv"), false, clickType -> { CommandNV.toggleNightvision(player); openBauGui(player); }); } if(player.hasPotionEffect(PotionEffectType.WATER_BREATHING)) { - inv.setItem(39, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", Arrays.asList("§8/§7wv"), false, clickType -> { + inv.setItem(44, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", Collections.singletonList("§8/§7wv"), false, clickType -> { CommandGills.toggleGills(player); openBauGui(player); }); } else { - inv.setItem(39, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", Arrays.asList("§8/§7wv"), false, clickType -> { + inv.setItem(44, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", Collections.singletonList("§8/§7wv"), false, clickType -> { CommandGills.toggleGills(player); openBauGui(player); }); } + boolean isBuildArea = region.buildAreaEnabled(); + List tntLore = getNoPermsLore(Arrays.asList("§8/§7tnt §8[" + (isBuildArea?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), player, "§cDu hast keine Worldrechte", Permission.world); switch (region.getTntMode()) { case OFF: - inv.setItem(40, Material.MINECART, "§7TNT: §eAusgeschaltet", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { - region.setTntMode(region.buildAreaEnabled()?CommandTNT.TNTMode.ONLY_TB: CommandTNT.TNTMode.ON); + inv.setItem(0, Material.MINECART, "§7TNT: §eAusgeschaltet", tntLore, false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + player.performCommand("tnt " + (isBuildArea?"tb":"on")); updateInventories(); }); break; case ONLY_TB: - inv.setItem(40, Material.TNT_MINECART, "§7TNT: §enur Testblock", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { - region.setTntMode(CommandTNT.TNTMode.ON); + inv.setItem(0, Material.TNT_MINECART, "§7TNT: §enur Testblock", tntLore, false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + player.performCommand("tnt on"); updateInventories(); }); break; default: - inv.setItem(40, Material.TNT, "§7TNT: §eEingeschaltet", Arrays.asList("§8/§7tnt §8[" + (region.buildAreaEnabled()?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), false, clickType -> { - region.setTntMode(CommandTNT.TNTMode.OFF); + inv.setItem(0, Material.TNT, "§7TNT: §eEingeschaltet", tntLore, false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + player.performCommand("tnt off"); updateInventories(); }); } if(region.isFreeze()) { - inv.setItem(41, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", Arrays.asList("§8/§7freeze"), false, clickType -> { - region.setFreeze(false); + inv.setItem(1, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + player.performCommand("freeze"); updateInventories(); }); } else { - inv.setItem(41, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", Arrays.asList("§8/§7freeze"), false, clickType -> { - region.setFreeze(true); + inv.setItem(1, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + player.performCommand("freeze"); updateInventories(); }); } if(region.isFire()) { - inv.setItem(42, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", Arrays.asList("§8/§7fire"), false, clickType -> { - region.setFire(false); + inv.setItem(2, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + player.performCommand("fire"); updateInventories(); }); } else { - inv.setItem(42, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", Arrays.asList("§8/§7fire"), false, clickType -> { - region.setFire(true); + inv.setItem(2, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + player.performCommand("fire"); updateInventories(); }); } + inv.setItem(7, Material.ENDER_PEARL, "§7Teleporter", getNoPermsLore(Arrays.asList("§8/§7tp §8[§eSpieler§8]"), player, "§cDu hast keine Buildrechte", Permission.build), false, clickType -> { + List> playerSWListEntry = new ArrayList<>(); + Bukkit.getOnlinePlayers().forEach(player1 -> { + if(player1.equals(player)) + return; + playerSWListEntry.add(new SWListInv.SWListEntry<>(SWItem.getPlayerSkull(player1.getName()), player1.getName())); + }); + SWListInv playerSWListInv = new SWListInv<>(player, "Teleporter", playerSWListEntry, (clickType1, player1) -> { + player.closeInventory(); + player.performCommand("tp " + player1); + }); + playerSWListInv.open(); + }); + inv.open(); } @@ -216,12 +299,12 @@ public class CommandGUI implements CommandExecutor, Listener { }); } if(TraceShowManager.hasActiveShow(player)) { - inv.setItem(2, Material.TNT, "§7Showstatus", Arrays.asList("§7Aktuell: §eGezeigt"), false, clickType -> { + inv.setItem(2, Material.TNT, "§7Showstatus", Arrays.asList("§7Aktuell: §eGezeigt", "§8/§7trace show§e/§7hide"), false, clickType -> { player.performCommand("trace hide"); traceGUI(player); }); } else { - inv.setItem(2, Material.GLASS, "§7Showstatus", Arrays.asList("§7Aktuell: §eVersteckt"), false, clickType -> { + inv.setItem(2, Material.GLASS, "§7Showstatus", Arrays.asList("§7Aktuell: §eVersteckt", "§8/§§7trace show§e/§7hide"), false, clickType -> { player.performCommand("trace show"); traceGUI(player); }); @@ -232,13 +315,191 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("trace show gui"); }); - inv.setItem(6, getMaterial("GRAY_STAINED_GLASS_PANE", "STAINED_GLASS_PANE"), (byte) 7, "§7Coming soon.", Collections.emptyList(), false, clickType -> {}); + inv.setItem(6, Material.BARRIER, "§7Trace löschen", clickType -> confirmationInventory(player, "Trace löschen", () -> player.performCommand("trace delete"), () -> {})); - inv.setItem(8, Material.BARRIER, "§7Trace löschen", clickType -> confirmationInventory(player, "Trace löschen", () -> player.performCommand("trace delete"), () -> {})); + inv.setItem(8, Material.ARROW, "§7Zurück", clickType -> { + player.closeInventory(); + openBauGui(player); + OPEN_INVS.add(player); + }); inv.open(); } + private static void autoLoaderGUI(Player player) { + SWInventory inv = new SWInventory(player, 9, "Autoloader"); + + boolean hasLoader = AutoLoader.hasLoader(player); + + if(hasLoader) { + AutoLoader loader = AutoLoader.getLoader(player); + if(loader.isSetup()) { + inv.setItem(0, Material.DROPPER, "§7Loader Starten", Collections.singletonList("§8/§7loader start"), false, clickType -> { + loader.start(); + autoLoaderGUI(player); + }); + + inv.setItem(2, Material.ARROW, "§7Letzte Aktion entfernen", Collections.singletonList("§8/§7loader undo"), false, clickType -> { + + }); + } else { + inv.setItem(0, Material.BLAZE_ROD, "§7Loader Bearbeiten", Collections.singletonList("§8/§7loader setup"), false, clickType -> { + loader.setup(); + autoLoaderGUI(player); + }); + } + + inv.setItem(4, Material.COMPASS, "§7Schuss Delay", Arrays.asList("§7Aktuell: §e" + loader.getTicksBetweenShots(), "§8/§7loader wait §8[§eTicks§8]"), false, clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Schuss Delay", loader.getTicksBetweenShots() + ""); + anvilInv.setItem(Material.STONE); + anvilInv.setCallback(s -> { + player.performCommand("loader wait " + s); + autoLoaderGUI(player); + }); + anvilInv.open(); + }); + + inv.setItem(6, Material.CLOCK, "§7Block platzier Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + loader.getTicksBetweenBlocks(), "§8/§7loader speed §8[§eTicks§8]"), false, clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Platzier Geschwindigkeit", loader.getTicksBetweenBlocks() + ""); + anvilInv.setItem(Material.STONE); + anvilInv.setCallback(s -> { + player.performCommand("loader speed " + s); + autoLoaderGUI(player); + }); + anvilInv.open(); + }); + + inv.setItem(8, Material.BARRIER, "§7Loader löschen", Collections.singletonList("§8/§7loader stop"), false, clickType -> confirmationInventory(player, "Loader löschen?", () -> { + loader.stop(); + autoLoaderGUI(player); + }, () -> autoLoaderGUI(player))); + } else { + inv.setItem(4, Material.GOLD_NUGGET, "§eNeuer Autoloader", clickType -> { + AutoLoader.getLoader(player); + player.closeInventory(); + }); + inv.setItem(8, Material.ARROW, "§7Zurück", clickType -> { + player.closeInventory(); + openBauGui(player); + OPEN_INVS.add(player); + }); + } + + inv.open(); + } + + private static void bauManagementGUI(Player player) { + bauManagementGUI(player, ""); + } + + private static void bauManagementGUI(Player player, String search) { + List members = BauweltMember.getMembers(BauSystem.getOwnerID()); + List> items = new ArrayList<>(); + members.forEach(member -> { + if(member.getMemberID() == BauSystem.getOwnerID()) + return; + + SteamwarUser user = SteamwarUser.get(member.getMemberID()); + if(!user.getUserName().toLowerCase().contains(search.toLowerCase())) + return; + + SWItem item = SWItem.getPlayerSkull(user.getUserName()); + item.setName("§7" + user.getUserName()); + List lore = new ArrayList<>(); + lore.add("§7Online: §e" + (Bukkit.getPlayer(user.getUUID()) == null?"Offline":"Online")); + lore.add("§7Bauen: §e" + (member.isBuild()?"Ja":"Nein")); + lore.add("§7Worldedit: §e" + (member.isWorldEdit()?"Ja":"Nein")); + lore.add("§7World: §e" + (member.isWorld()?"Ja":"Nein")); + item.setLore(lore); + items.add(new SWListInv.SWListEntry<>(item, member)); + }); + + SWListInv inv = new SWListInv<>(player, "Bauweltmembers", false, items, (clickType, member) -> bauweltMemberGUI(player, member)); + + inv.setItem(48, Material.NETHER_STAR, "§7Member hinzufühgen", clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Member hinzufühgen"); + anvilInv.setItem(Material.NAME_TAG); + anvilInv.setCallback(s -> { + player.closeInventory(); + confirmChatMessage(player, "/bau addmember " + s); + }); + anvilInv.open(); + }); + + inv.setItem(50, Material.NAME_TAG, "§7Suchen", clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(player, "Member suchen"); + anvilInv.setItem(Material.PAPER); + anvilInv.setCallback(s -> { + player.closeInventory(); + bauManagementGUI(player, s); + }); + anvilInv.open(); + }); + + inv.open(); + } + + private static void bauweltMemberGUI(Player player, BauweltMember member) { + SteamwarUser user = SteamwarUser.get(member.getMemberID()); + SWInventory inv = new SWInventory(player, 9, "Member: " + user.getUserName()); + if(member.isBuild()) + inv.setItem(2, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Bauen", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { + member.setBuild(false); + bauweltMemberGUI(player, member); + }); + else + inv.setItem(2, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7Bauen", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { + member.setBuild(true); + bauweltMemberGUI(player, member); + }); + + if(member.isWorldEdit()) + inv.setItem(4, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Worldedit", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { + member.setWorldEdit(false); + bauweltMemberGUI(player, member); + }); + else + inv.setItem(4, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7Worldedit", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { + member.setWorldEdit(true); + bauweltMemberGUI(player, member); + }); + + if(member.isWorld()) + inv.setItem(6, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7World", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { + member.setWorld(false); + bauweltMemberGUI(player, member); + }); + else + inv.setItem(6, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7World", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { + member.setWorld(true); + bauweltMemberGUI(player, member); + }); + + inv.setItem(8, Material.BARRIER, "§7Member entfernen", clickType -> { + player.closeInventory(); + confirmChatMessage(player, "/bau delmember " + user.getUserName()); + }); + inv.open(); + } + + private static void confirmChatMessage(Player player, String command) { + player.sendMessage(BauSystem.PREFIX + "§7Klicke auf die Nachricht zum bestätigen"); + TextComponent t = new TextComponent(); + t.setText("[Hier]"); + t.setColor(ChatColor.YELLOW); + t.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); + t.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§8/§7" + command))); + player.spigot().sendMessage(t); + } + + private static List getNoPermsLore(List lore, Player player, String noPerms, Permission perm) { + if(Welt.noPermission(player, perm)) { + lore = new ArrayList<>(lore); + lore.add(noPerms); + } + return lore; + } + private static void updateInventories() { isRefreshing = true; OPEN_INVS.forEach(CommandGUI::openBauGui); @@ -272,9 +533,19 @@ public class CommandGUI implements CommandExecutor, Listener { public void onPlayerInteract(PlayerInteractEvent event) { if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - if(event.getItem().getType() != Material.NETHER_STAR) + if(event.getItem() == null || event.getItem().getType() != Material.NETHER_STAR) return; openBauGui(event.getPlayer()); OPEN_INVS.add(event.getPlayer()); } + + @EventHandler + public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { + if(LAST_F_PLAYER.contains(event.getPlayer())) { + openBauGui(event.getPlayer()); + OPEN_INVS.add(event.getPlayer()); + } else { + LAST_F_PLAYER.add(event.getPlayer()); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java index 6763ac7..cb21940 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/AutoLoader.java @@ -140,6 +140,14 @@ public class AutoLoader extends IAutoLoader implements Listener { ticksBetweenBlocks = time; } + public int getTicksBetweenShots() { + return ticksBetweenShots; + } + + public int getTicksBetweenBlocks() { + return ticksBetweenBlocks; + } + public boolean isSetup() { return setup; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 6a7e214..6ffb1f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -48,7 +48,7 @@ public class Detonator implements Listener { static { - WAND = new ItemStack(Material.TRIPWIRE_HOOK, 1); + WAND = new ItemStack(Material.BLAZE_ROD, 1); ItemMeta im = WAND.getItemMeta(); im.setDisplayName("§6Fernzünder"); From 7c4b944c4dffc09bdcf3ad811be76def4d9c13c9 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 4 Feb 2021 21:24:04 +0100 Subject: [PATCH 06/20] Change Layout --- .../bausystem/commands/CommandGUI.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index cce3173..eb21c6d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -64,9 +64,9 @@ public class CommandGUI implements CommandExecutor, Listener { OPEN_INVS.remove(player); }); - inv.setItem(20, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); - inv.setItem(22, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); - inv.setItem(24, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(37, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(38, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(43, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); ItemStack dtWand = Detonator.WAND.clone(); ItemMeta meta = dtWand.getItemMeta(); @@ -76,7 +76,7 @@ public class CommandGUI implements CommandExecutor, Listener { lore.add("§cDu hast keine Worldrechte"); meta.setLore(lore); dtWand.setItemMeta(meta); - inv.setItem(38, dtWand, clickType -> { + inv.setItem(39, dtWand, clickType -> { player.closeInventory(); player.performCommand("dt wand"); }); @@ -93,13 +93,13 @@ public class CommandGUI implements CommandExecutor, Listener { }); inv.setItem(42, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); - inv.setItem(26, Material.COMPASS, "§7TPS Limitieren", getNoPermsLore(Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e1 - 20§8]"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(20, Material.COMPASS, "§7TPS Limitieren", getNoPermsLore(Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e1 - 20§8]"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, "TPS Limitieren"); anvilInv.setItem(Material.COMPASS); anvilInv.setCallback(s -> player.performCommand("tpslimit " + s)); anvilInv.open(); }); - inv.setItem(6, Material.FEATHER, "§7Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + player.getFlySpeed() * 10, "§8/§7speed §8[§e1 - 10§8]"), false, clickType -> { + inv.setItem(5, Material.FEATHER, "§7Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + player.getFlySpeed() * 10, "§8/§7speed §8[§e1 - 10§8]"), false, clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, "Geschwindigkeit"); anvilInv.setItem(Material.FEATHER); anvilInv.setCallback(s -> player.performCommand("speed " + s)); @@ -122,7 +122,7 @@ public class CommandGUI implements CommandExecutor, Listener { inv.setItem(4, skull); } - inv.setItem(39, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + 0 + " §7Bücher"), true, clickType -> { + inv.setItem(6, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + 0 + " §7Bücher"), true, clickType -> { // TODO: 04.02.2021 Implement Script Book Database }); @@ -134,14 +134,14 @@ public class CommandGUI implements CommandExecutor, Listener { traceGUI(player); }); - inv.setItem(23, Material.DISPENSER, "§7Auto-Loader", getNoPermsLore(Collections.emptyList(), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(22, Material.DISPENSER, "§7Auto-Loader", getNoPermsLore(Collections.emptyList(), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.closeInventory(); autoLoaderGUI(player); }); - inv.setItem(8, getMaterial("PLAYER_HEAD", "SKULL_ITEM"), (byte) 3, "§7Spielerkopf geben", Arrays.asList("§8/§7skull §8[§eSpieler§8]"), false, clickType -> { + inv.setItem(17, getMaterial("PLAYER_HEAD", "SKULL_ITEM"), (byte) 3, "§7Spielerkopf geben", Arrays.asList("§8/§7skull §8[§eSpieler§8]"), false, clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, "Spielerköpfe"); anvilInv.setItem(Material.NAME_TAG); anvilInv.setCallback(s -> player.performCommand("skull " + s)); @@ -149,47 +149,47 @@ public class CommandGUI implements CommandExecutor, Listener { }); if(Region.GlobalRegion.isGlobalRegion(region)) { + inv.setItem(9, Material.BARRIER, "§eKeine Region", clickType -> {}); inv.setItem(18, Material.BARRIER, "§eKeine Region", clickType -> {}); inv.setItem(27, Material.BARRIER, "§eKeine Region", clickType -> {}); - inv.setItem(36, Material.BARRIER, "§eKeine Region", clickType -> {}); }else { - inv.setItem(18, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", getNoPermsLore(Arrays.asList("§8/§7reset"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> + inv.setItem(27, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", getNoPermsLore(Arrays.asList("§8/§7reset"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> confirmationInventory(player, "Region Reseten?", () -> player.performCommand("reset"), () -> openBauGui(player))); if(region.hasProtection()) { - inv.setItem(27, Material.OBSIDIAN, "§eRegion Protecten", getNoPermsLore(Arrays.asList("§8/§7protect"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> + inv.setItem(18, Material.OBSIDIAN, "§eRegion Protecten", getNoPermsLore(Arrays.asList("§8/§7protect"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> confirmationInventory(player, "Region Protecten", () -> player.performCommand("protect"), () -> openBauGui(player))); } else { - inv.setItem(27, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> {}); + inv.setItem(18, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> {}); } if(region.hasTestblock()) { - inv.setItem(36, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", getNoPermsLore(Arrays.asList("§8/§7testblock"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> + inv.setItem(9, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", getNoPermsLore(Arrays.asList("§8/§7testblock"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> confirmationInventory(player, "Testblock erneuern", () -> player.performCommand("testblock"), () -> openBauGui(player))); } else { - inv.setItem(36, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> {}); + inv.setItem(9, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> {}); } } if(player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - inv.setItem(35, Material.POTION, "§7Nightvision: §eEingeschaltet", Collections.singletonList("§8/§7nv"), false, clickType -> { + inv.setItem(26, Material.POTION, "§7Nightvision: §eEingeschaltet", Collections.singletonList("§8/§7nv"), false, clickType -> { CommandNV.toggleNightvision(player); openBauGui(player); }); } else { - inv.setItem(35, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", Collections.singletonList("§8/§7nv"), false, clickType -> { + inv.setItem(26, Material.GLASS_BOTTLE, "§7Nightvision: §eAusgeschaltet", Collections.singletonList("§8/§7nv"), false, clickType -> { CommandNV.toggleNightvision(player); openBauGui(player); }); } if(player.hasPotionEffect(PotionEffectType.WATER_BREATHING)) { - inv.setItem(44, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", Collections.singletonList("§8/§7wv"), false, clickType -> { + inv.setItem(35, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", Collections.singletonList("§8/§7wv"), false, clickType -> { CommandGills.toggleGills(player); openBauGui(player); }); } else { - inv.setItem(44, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", Collections.singletonList("§8/§7wv"), false, clickType -> { + inv.setItem(35, Material.BUCKET, "§7Waterbreathing: §eAusgeschaltet", Collections.singletonList("§8/§7wv"), false, clickType -> { CommandGills.toggleGills(player); openBauGui(player); }); @@ -199,7 +199,7 @@ public class CommandGUI implements CommandExecutor, Listener { List tntLore = getNoPermsLore(Arrays.asList("§8/§7tnt §8[" + (isBuildArea?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), player, "§cDu hast keine Worldrechte", Permission.world); switch (region.getTntMode()) { case OFF: - inv.setItem(0, Material.MINECART, "§7TNT: §eAusgeschaltet", tntLore, false, clickType -> { + inv.setItem(23, Material.MINECART, "§7TNT: §eAusgeschaltet", tntLore, false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("tnt " + (isBuildArea?"tb":"on")); @@ -207,7 +207,7 @@ public class CommandGUI implements CommandExecutor, Listener { }); break; case ONLY_TB: - inv.setItem(0, Material.TNT_MINECART, "§7TNT: §enur Testblock", tntLore, false, clickType -> { + inv.setItem(23, Material.TNT_MINECART, "§7TNT: §enur Testblock", tntLore, false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("tnt on"); @@ -215,7 +215,7 @@ public class CommandGUI implements CommandExecutor, Listener { }); break; default: - inv.setItem(0, Material.TNT, "§7TNT: §eEingeschaltet", tntLore, false, clickType -> { + inv.setItem(23, Material.TNT, "§7TNT: §eEingeschaltet", tntLore, false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("tnt off"); @@ -224,14 +224,14 @@ public class CommandGUI implements CommandExecutor, Listener { } if(region.isFreeze()) { - inv.setItem(1, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(24, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("freeze"); updateInventories(); }); } else { - inv.setItem(1, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(24, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("freeze"); @@ -240,14 +240,14 @@ public class CommandGUI implements CommandExecutor, Listener { } if(region.isFire()) { - inv.setItem(2, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(3, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("fire"); updateInventories(); }); } else { - inv.setItem(2, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(3, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("fire"); @@ -255,7 +255,7 @@ public class CommandGUI implements CommandExecutor, Listener { }); } - inv.setItem(7, Material.ENDER_PEARL, "§7Teleporter", getNoPermsLore(Arrays.asList("§8/§7tp §8[§eSpieler§8]"), player, "§cDu hast keine Buildrechte", Permission.build), false, clickType -> { + inv.setItem(2, Material.ENDER_PEARL, "§7Teleporter", getNoPermsLore(Arrays.asList("§8/§7tp §8[§eSpieler§8]"), player, "§cDu hast keine Buildrechte", Permission.build), false, clickType -> { List> playerSWListEntry = new ArrayList<>(); Bukkit.getOnlinePlayers().forEach(player1 -> { if(player1.equals(player)) From bd7fbb33a269684f2015df5543fc03dcdb3115f4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 4 Feb 2021 22:30:09 +0100 Subject: [PATCH 07/20] Changesset --- .../src/de/steamwar/bausystem/commands/CommandGUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index eb21c6d..d04e363 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -134,7 +134,7 @@ public class CommandGUI implements CommandExecutor, Listener { traceGUI(player); }); - inv.setItem(22, Material.DISPENSER, "§7Auto-Loader", getNoPermsLore(Collections.emptyList(), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(22, Material.DISPENSER, "§7Auto-Loader", getNoPermsLore(Arrays.asList((AutoLoader.hasLoader(player) ? "§aan" : "§caus")), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.closeInventory(); From d825a19a9876e6e2b41c38187407a10552193e5f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 6 Feb 2021 01:41:25 +0100 Subject: [PATCH 08/20] Add Script Book Inventory --- .../bausystem/commands/CommandGUI.java | 21 +++- .../steamwar/bausystem/world/ScriptBook.java | 114 ++++++++++++++++++ 2 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index d04e363..b2a78a6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -4,10 +4,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.TraceShowManager; -import de.steamwar.bausystem.world.AutoLoader; -import de.steamwar.bausystem.world.Detonator; -import de.steamwar.bausystem.world.Region; -import de.steamwar.bausystem.world.Welt; +import de.steamwar.bausystem.world.*; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -122,8 +119,9 @@ public class CommandGUI implements CommandExecutor, Listener { inv.setItem(4, skull); } - inv.setItem(6, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + 0 + " §7Bücher"), true, clickType -> { - // TODO: 04.02.2021 Implement Script Book Database + inv.setItem(6, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + ScriptBook.getBookCount() + " §7Bücher"), true, clickType -> { + player.closeInventory(); + scriptBooksGUI(player); }); inv.setItem(21, Material.OBSERVER, "§7Tracer", getNoPermsLore(Arrays.asList("§7Status: §e" + RecordStateMachine.getRecordStatus().getName()), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { @@ -326,6 +324,17 @@ public class CommandGUI implements CommandExecutor, Listener { inv.open(); } + private static void scriptBooksGUI(Player player) { + List> entries = new ArrayList<>(); + List books = ScriptBook.getBooks(); + books.forEach(scriptBook -> entries.add(new SWListInv.SWListEntry<>(new SWItem(scriptBook.getBookMat(), scriptBook.getName()), scriptBook))); + SWListInv inv = new SWListInv<>(player, "Script Bücher", entries, (clickType, scriptBook) -> { + player.closeInventory(); + player.getInventory().addItem(scriptBook.toItemStack()); + }); + inv.open(); + } + private static void autoLoaderGUI(Player player) { SWInventory inv = new SWInventory(player, 9, "Autoloader"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java new file mode 100644 index 0000000..abbac5c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java @@ -0,0 +1,114 @@ +package de.steamwar.bausystem.world; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.VersionedCallable; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class ScriptBook { + + private static final FileConfiguration configuration; + private static List bookCache; + + static { + configuration = YamlConfiguration.loadConfiguration(new File(BauSystem.getPlugin().getDataFolder(), "books.yml")); + } + + public static List getBooks() { + if(bookCache != null) + return bookCache; + List books = new ArrayList<>(); + for (String book:configuration.getKeys(false)) { + ConfigurationSection section = Objects.requireNonNull(configuration.getConfigurationSection(book)); + books.add(new ScriptBook(section)); + } + bookCache = books; + return books; + } + + public static int getBookCount() { + return configuration.getKeys(false).size(); + } + + private List lines; + private String author; + private String name; + + ScriptBook(ConfigurationSection section) { + this.lines = section.getStringList("lines"); + this.author = section.getString("author", "§8Steam§eWar"); + this.name = section.getName(); + } + + public ItemStack toItemStack() { + ItemStack book = new ItemStack(getBookMat()); + BookMeta meta = (BookMeta) book.getItemMeta(); + meta.setPages(getPages()); + meta.setDisplayName(name); + meta.setTitle(name); + meta.setAuthor(author); + meta.setGeneration(BookMeta.Generation.ORIGINAL); + book.setItemMeta(meta); + return book; + } + + public Material getBookMat() { + return Material.WRITTEN_BOOK; + } + + public List getLines() { + return lines; + } + + public String getAuthor() { + return author; + } + + public String getName() { + return name; + } + + private String[] getPages() { + List pages = new ArrayList<>(); + pages.add(0, new StringBuilder()); + int charsPerLine = 19; + int currentLine = 0; + int currentpage = 0; + boolean first = true; + for (String line:lines) { + int linesPlus = (int) Math.ceil((double) line.length() / charsPerLine); + currentLine += linesPlus; + if(currentLine >= 14 || line.equals("!")) { + currentLine = linesPlus; + currentpage++; + if(currentpage > 50) + throw new IllegalStateException("Book " + name + " has more pages than 50"); + pages.add(currentpage, new StringBuilder()); + first = true; + if(line.equals("!")) + continue; + } + if(!first) { + pages.get(currentpage).append("\n"); + }else { + first = false; + } + pages.get(currentpage).append(line); + } + + String[] finalPages = new String[pages.size()]; + for (int i = 0; i < pages.size(); i++) { + finalPages[i] = pages.get(i).toString(); + } + return finalPages; + } +} \ No newline at end of file From d36700e663d5a54690002b5a8c0f4245237c6cc3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 6 Feb 2021 01:47:25 +0100 Subject: [PATCH 09/20] Fix Debugstick in 1.12 and some more things --- .../de/steamwar/bausystem/commands/CommandDebugStick_15.java | 4 ++-- .../src/de/steamwar/bausystem/commands/CommandDetonator.java | 2 +- .../src/de/steamwar/bausystem/commands/CommandGUI.java | 3 ++- .../src/de/steamwar/bausystem/commands/CommandSkull.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java index abbfc71..88e5b3b 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java @@ -28,8 +28,8 @@ class CommandDebugStick_15 { static void giveStick(Player player){ if(player.getInventory().getItemInMainHand().getType() == Material.AIR) - player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK, 1)); + player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK)); else - player.getInventory().setItemInOffHand(new ItemStack(Material.DEBUG_STICK, 1)); + player.getInventory().addItem(new ItemStack(Material.DEBUG_STICK)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index c45f3a0..4446023 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -66,7 +66,7 @@ public class CommandDetonator implements CommandExecutor { if(player.getInventory().getItemInMainHand().getType() == Material.AIR) player.getInventory().setItemInMainHand(Detonator.WAND); else - player.getInventory().setItemInOffHand(Detonator.WAND); + player.getInventory().addItem(Detonator.WAND); player.updateInventory(); Detonator.getDetonator(player); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index b2a78a6..23ff0f4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -5,6 +5,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.world.*; +import de.steamwar.core.Core; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -84,7 +85,7 @@ public class CommandGUI implements CommandExecutor, Listener { player.closeInventory(); player.performCommand("/wand"); }); - inv.setItem(41, Material.DEBUG_STICK, "§7Debugstick", Arrays.asList("§8/§7debugstick"), false, clickType -> { + inv.setItem(41, getMaterial("DEBUG_STICK", "STICK"), "§7Debugstick", Arrays.asList("§8/§7debugstick"), Core.getVersion() < 13,clickType -> { player.closeInventory(); player.performCommand("debugstick"); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java index ed0f820..4a4cbf4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java @@ -50,7 +50,7 @@ public class CommandSkull implements CommandExecutor { if(p.getInventory().getItemInMainHand().getType() == Material.AIR) p.getInventory().setItemInMainHand(is); else - p.getInventory().setItemInOffHand(is); + p.getInventory().addItem(is); return false; } } From 004108854629aac936ff2b7605622a700ae3e9ba Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 6 Feb 2021 14:24:38 +0100 Subject: [PATCH 10/20] Add Lore to Script Books --- .../src/de/steamwar/bausystem/commands/CommandGUI.java | 2 +- .../src/de/steamwar/bausystem/world/ScriptBook.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 23ff0f4..5f16601 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -328,7 +328,7 @@ public class CommandGUI implements CommandExecutor, Listener { private static void scriptBooksGUI(Player player) { List> entries = new ArrayList<>(); List books = ScriptBook.getBooks(); - books.forEach(scriptBook -> entries.add(new SWListInv.SWListEntry<>(new SWItem(scriptBook.getBookMat(), scriptBook.getName()), scriptBook))); + books.forEach(scriptBook -> entries.add(new SWListInv.SWListEntry<>(new SWItem(scriptBook.getBookMat(), scriptBook.getName(), scriptBook.getLore(), false, clickType -> {}), scriptBook))); SWListInv inv = new SWListInv<>(player, "Script Bücher", entries, (clickType, scriptBook) -> { player.closeInventory(); player.getInventory().addItem(scriptBook.toItemStack()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java index abbac5c..cc1d03d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java @@ -39,12 +39,14 @@ public class ScriptBook { return configuration.getKeys(false).size(); } - private List lines; + private List lines; + private List lore; private String author; private String name; ScriptBook(ConfigurationSection section) { this.lines = section.getStringList("lines"); + this.lore = section.getStringList("lore"); this.author = section.getString("author", "§8Steam§eWar"); this.name = section.getName(); } @@ -57,6 +59,7 @@ public class ScriptBook { meta.setTitle(name); meta.setAuthor(author); meta.setGeneration(BookMeta.Generation.ORIGINAL); + meta.setLore(lore); book.setItemMeta(meta); return book; } @@ -77,6 +80,10 @@ public class ScriptBook { return name; } + public List getLore() { + return lore; + } + private String[] getPages() { List pages = new ArrayList<>(); pages.add(0, new StringBuilder()); From 81c510c8cc6881999f6bc61e9b9616faa4111147 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 6 Feb 2021 18:25:49 +0100 Subject: [PATCH 11/20] Fix some Formatting and Inventory Stuff --- .../bausystem/commands/CommandGUI.java | 55 ++++++++++++++----- .../steamwar/bausystem/world/Detonator.java | 2 +- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 5f16601..c9231bc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -49,8 +49,17 @@ public class CommandGUI implements CommandExecutor, Listener { if(!(commandSender instanceof Player)) return false; Player player = ((Player) commandSender); - openBauGui(player); - OPEN_INVS.add(player); + if(strings.length == 0) { + openBauGui(player); + OPEN_INVS.add(player); + }else { + if ("item".equalsIgnoreCase(strings[0])) { + if (player.getInventory().getItemInMainHand().getType() == Material.AIR) + player.getInventory().setItemInMainHand(new ItemStack(Material.NETHER_STAR)); + else + player.getInventory().addItem(new ItemStack(Material.NETHER_STAR)); + } + } return true; } @@ -65,6 +74,10 @@ public class CommandGUI implements CommandExecutor, Listener { inv.setItem(37, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); inv.setItem(38, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); inv.setItem(43, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(42, Material.NETHER_STAR, "§7Bau GUI Item", Arrays.asList("§7Du kannst dieses Item zum Öffnen der BauGUI nutzen", "§7oder Doppel F (Swap hands) drücken."), false, clickType -> { + player.closeInventory(); + player.performCommand("gui item"); + }); ItemStack dtWand = Detonator.WAND.clone(); ItemMeta meta = dtWand.getItemMeta(); @@ -75,6 +88,8 @@ public class CommandGUI implements CommandExecutor, Listener { meta.setLore(lore); dtWand.setItemMeta(meta); inv.setItem(39, dtWand, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; player.closeInventory(); player.performCommand("dt wand"); }); @@ -85,13 +100,16 @@ public class CommandGUI implements CommandExecutor, Listener { player.closeInventory(); player.performCommand("/wand"); }); - inv.setItem(41, getMaterial("DEBUG_STICK", "STICK"), "§7Debugstick", Arrays.asList("§8/§7debugstick"), Core.getVersion() < 13,clickType -> { + inv.setItem(41, getMaterial("DEBUG_STICK", "STICK"), "§eDebugstick", getNoPermsLore(Arrays.asList("§8/§7debugstick"), player, "§cDu hast keine Worldrechte", Permission.world), Core.getVersion() < 13,clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; player.closeInventory(); player.performCommand("debugstick"); }); - inv.setItem(42, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); inv.setItem(20, Material.COMPASS, "§7TPS Limitieren", getNoPermsLore(Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e1 - 20§8]"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; SWAnvilInv anvilInv = new SWAnvilInv(player, "TPS Limitieren"); anvilInv.setItem(Material.COMPASS); anvilInv.setCallback(s -> player.performCommand("tpslimit " + s)); @@ -133,7 +151,7 @@ public class CommandGUI implements CommandExecutor, Listener { traceGUI(player); }); - inv.setItem(22, Material.DISPENSER, "§7Auto-Loader", getNoPermsLore(Arrays.asList((AutoLoader.hasLoader(player) ? "§aan" : "§caus")), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(22, Material.DISPENSER, "§7Auto-Loader", getNoPermsLore(Arrays.asList("§7Status: " + (AutoLoader.hasLoader(player) ? "§aan" : "§caus")), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.closeInventory(); @@ -152,19 +170,28 @@ public class CommandGUI implements CommandExecutor, Listener { inv.setItem(18, Material.BARRIER, "§eKeine Region", clickType -> {}); inv.setItem(27, Material.BARRIER, "§eKeine Region", clickType -> {}); }else { - inv.setItem(27, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", getNoPermsLore(Arrays.asList("§8/§7reset"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> - confirmationInventory(player, "Region Reseten?", () -> player.performCommand("reset"), () -> openBauGui(player))); + inv.setItem(27, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", getNoPermsLore(Arrays.asList("§8/§7reset"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + confirmationInventory(player, "Region Reseten?", () -> player.performCommand("reset"), () -> openBauGui(player)); + }); if(region.hasProtection()) { - inv.setItem(18, Material.OBSIDIAN, "§eRegion Protecten", getNoPermsLore(Arrays.asList("§8/§7protect"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> - confirmationInventory(player, "Region Protecten", () -> player.performCommand("protect"), () -> openBauGui(player))); + inv.setItem(18, Material.OBSIDIAN, "§eRegion Protecten", getNoPermsLore(Arrays.asList("§8/§7protect"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + confirmationInventory(player, "Region Protecten", () -> player.performCommand("protect"), () -> openBauGui(player)); + }); } else { inv.setItem(18, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> {}); } if(region.hasTestblock()) { - inv.setItem(9, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", getNoPermsLore(Arrays.asList("§8/§7testblock"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> - confirmationInventory(player, "Testblock erneuern", () -> player.performCommand("testblock"), () -> openBauGui(player))); + inv.setItem(9, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", getNoPermsLore(Arrays.asList("§8/§7testblock"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if(Welt.noPermission(player, Permission.world)) + return; + confirmationInventory(player, "Testblock erneuern", () -> player.performCommand("testblock"), () -> openBauGui(player)); + }); } else { inv.setItem(9, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> {}); } @@ -194,8 +221,8 @@ public class CommandGUI implements CommandExecutor, Listener { }); } - boolean isBuildArea = region.buildAreaEnabled(); - List tntLore = getNoPermsLore(Arrays.asList("§8/§7tnt §8[" + (isBuildArea?"§eTB§7, ":"") + "§eOff §7oder §eOn§7]"), player, "§cDu hast keine Worldrechte", Permission.world); + boolean isBuildArea = region.hasBuildRegion(); + List tntLore = getNoPermsLore(Arrays.asList("§8/§7tnt §8[" + (isBuildArea ? "§eTB§7, " : "") + "§eOff §7oder §eOn§7]"), player, "§cDu hast keine Worldrechte", Permission.world); switch (region.getTntMode()) { case OFF: inv.setItem(23, Material.MINECART, "§7TNT: §eAusgeschaltet", tntLore, false, clickType -> { @@ -255,6 +282,8 @@ public class CommandGUI implements CommandExecutor, Listener { } inv.setItem(2, Material.ENDER_PEARL, "§7Teleporter", getNoPermsLore(Arrays.asList("§8/§7tp §8[§eSpieler§8]"), player, "§cDu hast keine Buildrechte", Permission.build), false, clickType -> { + if(Welt.noPermission(player, Permission.build)) + return; List> playerSWListEntry = new ArrayList<>(); Bukkit.getOnlinePlayers().forEach(player1 -> { if(player1.equals(player)) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 6ffb1f2..d63472d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -51,7 +51,7 @@ public class Detonator implements Listener { WAND = new ItemStack(Material.BLAZE_ROD, 1); ItemMeta im = WAND.getItemMeta(); - im.setDisplayName("§6Fernzünder"); + im.setDisplayName("§eFernzünder"); List lorelist = Arrays.asList("§eLinks Klick §8- §7Setzte einen Punkt zum Aktivieren", "§eLinks Klick + Shift §8- §7Füge einen Punkt hinzu", "§eRechts Klick §8- §7Löse alle Punkte aus"); From ed1c03e0ac96ea5d2db98e19fb5685378dad4a43 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 8 Feb 2021 17:49:20 +0100 Subject: [PATCH 12/20] Fix Message --- .../src/de/steamwar/bausystem/commands/CommandGUI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index c9231bc..a13bc31 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -327,12 +327,12 @@ public class CommandGUI implements CommandExecutor, Listener { }); } if(TraceShowManager.hasActiveShow(player)) { - inv.setItem(2, Material.TNT, "§7Showstatus", Arrays.asList("§7Aktuell: §eGezeigt", "§8/§7trace show§e/§7hide"), false, clickType -> { + inv.setItem(2, Material.TNT, "§7Showstatus", Arrays.asList("§7Aktuell: §eGezeigt", "§8/§7trace §8[§eshow§8/§ehide§8]"), false, clickType -> { player.performCommand("trace hide"); traceGUI(player); }); } else { - inv.setItem(2, Material.GLASS, "§7Showstatus", Arrays.asList("§7Aktuell: §eVersteckt", "§8/§§7trace show§e/§7hide"), false, clickType -> { + inv.setItem(2, Material.GLASS, "§7Showstatus", Arrays.asList("§7Aktuell: §eVersteckt", "§8/§7trace §8[§eshow§8/§ehide§8]"), false, clickType -> { player.performCommand("trace show"); traceGUI(player); }); From 94c4d8107e95f57089e2f805b30ddf09755e7732 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 13 Feb 2021 09:31:16 +0100 Subject: [PATCH 13/20] Fixing Some PR Stuff --- .../bausystem/commands/CommandDebugStick_15.java | 5 +---- .../bausystem/commands/CommandDetonator.java | 6 +----- .../steamwar/bausystem/commands/CommandFreeze.java | 4 ++-- .../de/steamwar/bausystem/commands/CommandGUI.java | 12 ++++++------ .../steamwar/bausystem/commands/CommandSkull.java | 6 +----- .../de/steamwar/bausystem/commands/CommandTNT.java | 6 ------ .../world/{ScriptBook.java => PredefinedBook.java} | 13 ++++++------- 7 files changed, 17 insertions(+), 35 deletions(-) rename BauSystem_Main/src/de/steamwar/bausystem/world/{ScriptBook.java => PredefinedBook.java} (91%) diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java index 88e5b3b..ec1560c 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java @@ -27,9 +27,6 @@ class CommandDebugStick_15 { private CommandDebugStick_15(){} static void giveStick(Player player){ - if(player.getInventory().getItemInMainHand().getType() == Material.AIR) - player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK)); - else - player.getInventory().addItem(new ItemStack(Material.DEBUG_STICK)); + player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK, 1)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 4446023..52bc21e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Welt; -import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -63,10 +62,7 @@ public class CommandDetonator implements CommandExecutor { case "wand": case "detonator": case "item": - if(player.getInventory().getItemInMainHand().getType() == Material.AIR) - player.getInventory().setItemInMainHand(Detonator.WAND); - else - player.getInventory().addItem(Detonator.WAND); + player.getInventory().setItemInMainHand(Detonator.WAND); player.updateInventory(); Detonator.getDetonator(player); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 0ba82ad..f770e21 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -1,6 +1,6 @@ -/* +/* This file is a part of the SteamWar software. - + Copyright (C) 2020 SteamWar.de-Serverteam This program is free software: you can redistribute it and/or modify diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index a13bc31..bea3c47 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -138,7 +138,7 @@ public class CommandGUI implements CommandExecutor, Listener { inv.setItem(4, skull); } - inv.setItem(6, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + ScriptBook.getBookCount() + " §7Bücher"), true, clickType -> { + inv.setItem(6, Material.BOOK, "§7Script Bücher", Arrays.asList("§7Aktuell §e" + PredefinedBook.getBookCount() + " §7Bücher"), true, clickType -> { player.closeInventory(); scriptBooksGUI(player); }); @@ -355,12 +355,12 @@ public class CommandGUI implements CommandExecutor, Listener { } private static void scriptBooksGUI(Player player) { - List> entries = new ArrayList<>(); - List books = ScriptBook.getBooks(); - books.forEach(scriptBook -> entries.add(new SWListInv.SWListEntry<>(new SWItem(scriptBook.getBookMat(), scriptBook.getName(), scriptBook.getLore(), false, clickType -> {}), scriptBook))); - SWListInv inv = new SWListInv<>(player, "Script Bücher", entries, (clickType, scriptBook) -> { + List> entries = new ArrayList<>(); + List books = PredefinedBook.getBooks(); + books.forEach(predefinedBook -> entries.add(new SWListInv.SWListEntry<>(new SWItem(predefinedBook.getBookMat(), predefinedBook.getName(), predefinedBook.getLore(), false, clickType -> {}), predefinedBook))); + SWListInv inv = new SWListInv<>(player, "Script Bücher", entries, (clickType, predefinedBook) -> { player.closeInventory(); - player.getInventory().addItem(scriptBook.toItemStack()); + player.getInventory().addItem(predefinedBook.toItemStack()); }); inv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java index 4a4cbf4..0208ca7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; -import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -47,10 +46,7 @@ public class CommandSkull implements CommandExecutor { assert sm != null; sm.setDisplayName("§e" + args[0] + "§8s Kopf"); is.setItemMeta(sm); - if(p.getInventory().getItemInMainHand().getType() == Material.AIR) - p.getInventory().setItemInMainHand(is); - else - p.getInventory().addItem(is); + p.getInventory().setItemInMainHand(is); return false; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java index 658e8a4..d528f37 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNT.java @@ -34,12 +34,6 @@ import org.bukkit.event.entity.EntityExplodeEvent; public class CommandTNT implements CommandExecutor, Listener { - private static TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF; - - public static TNTMode getTntMode() { - return tntMode; - } - public enum TNTMode { ON("§aan"), ONLY_TB("§7Kein §eBaurahmen"), diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java b/BauSystem_Main/src/de/steamwar/bausystem/world/PredefinedBook.java similarity index 91% rename from BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java rename to BauSystem_Main/src/de/steamwar/bausystem/world/PredefinedBook.java index cc1d03d..22fd13f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptBook.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/PredefinedBook.java @@ -1,7 +1,6 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; -import de.steamwar.core.VersionedCallable; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -14,22 +13,22 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -public class ScriptBook { +public class PredefinedBook { private static final FileConfiguration configuration; - private static List bookCache; + private static List bookCache; static { configuration = YamlConfiguration.loadConfiguration(new File(BauSystem.getPlugin().getDataFolder(), "books.yml")); } - public static List getBooks() { + public static List getBooks() { if(bookCache != null) return bookCache; - List books = new ArrayList<>(); + List books = new ArrayList<>(); for (String book:configuration.getKeys(false)) { ConfigurationSection section = Objects.requireNonNull(configuration.getConfigurationSection(book)); - books.add(new ScriptBook(section)); + books.add(new PredefinedBook(section)); } bookCache = books; return books; @@ -44,7 +43,7 @@ public class ScriptBook { private String author; private String name; - ScriptBook(ConfigurationSection section) { + PredefinedBook(ConfigurationSection section) { this.lines = section.getStringList("lines"); this.lore = section.getStringList("lore"); this.author = section.getString("author", "§8Steam§eWar"); From 35902fac5672d9b3821201d080ed34e25a4dcda3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 13 Feb 2021 22:52:26 +0100 Subject: [PATCH 14/20] Improve some Stuff --- .../bausystem/commands/CommandGUI.java | 38 ++++++++++--------- .../bausystem/world/PredefinedBook.java | 4 ++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index bea3c47..c76bd9d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -71,9 +71,9 @@ public class CommandGUI implements CommandExecutor, Listener { OPEN_INVS.remove(player); }); - inv.setItem(37, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); - inv.setItem(38, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); - inv.setItem(43, Material.GLASS_PANE, "§7Platzhalter", clickType -> {}); + inv.setItem(37, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {}); + inv.setItem(38, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {}); + inv.setItem(43, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {}); inv.setItem(42, Material.NETHER_STAR, "§7Bau GUI Item", Arrays.asList("§7Du kannst dieses Item zum Öffnen der BauGUI nutzen", "§7oder Doppel F (Swap hands) drücken."), false, clickType -> { player.closeInventory(); player.performCommand("gui item"); @@ -107,7 +107,7 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("debugstick"); }); - inv.setItem(20, Material.COMPASS, "§7TPS Limitieren", getNoPermsLore(Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e1 - 20§8]"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(20, Material.COMPASS, "§7TPS Limitieren", getNoPermsLore(Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e0,5 - " + (TPSUtils.isWarpAllowed()?40:20) + "§8]"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; SWAnvilInv anvilInv = new SWAnvilInv(player, "TPS Limitieren"); @@ -273,7 +273,7 @@ public class CommandGUI implements CommandExecutor, Listener { updateInventories(); }); } else { - inv.setItem(3, Material.FIRE_CHARGE, "§7Fire: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(3, getMaterial("FIRE_CHARGE", "FIREBALL"), "§7Fire: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("fire"); @@ -306,22 +306,23 @@ public class CommandGUI implements CommandExecutor, Listener { if(!isRefreshing) OPEN_TRACER_INVS.remove(player); }); + List stateLore = Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName(), "§8/§7trace §8[§estart§8, stop §8oder §eauto§8]"); switch (RecordStateMachine.getRecordStatus()) { case IDLE: - inv.setItem(0, getMaterial("SNOWBALL", "SNOW_BALL"), "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> { + inv.setItem(0, getMaterial("SNOWBALL", "SNOW_BALL"), "§7Tracerstatus", stateLore, false, clickType -> { RecordStateMachine.commandAuto(); updateInventories(); }); break; case IDLE_AUTO: - inv.setItem(0, Material.ENDER_PEARL, "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> { + inv.setItem(0, Material.ENDER_PEARL, "§7Tracerstatus", stateLore, false, clickType -> { RecordStateMachine.commandStart(); updateInventories(); }); break; case RECORD: case RECORD_AUTO: - inv.setItem(0, getMaterial("ENDER_EYE", "EYE_OF_ENDER"), "§7Tracerstatus", Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName()), false, clickType -> { + inv.setItem(0, getMaterial("ENDER_EYE", "EYE_OF_ENDER"), "§7Tracerstatus", stateLore, false, clickType -> { RecordStateMachine.commandStop(); updateInventories(); }); @@ -343,7 +344,7 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("trace show gui"); }); - inv.setItem(6, Material.BARRIER, "§7Trace löschen", clickType -> confirmationInventory(player, "Trace löschen", () -> player.performCommand("trace delete"), () -> {})); + inv.setItem(6, Material.BARRIER, "§7Trace löschen", Arrays.asList("§8/§7trace delete"), false, clickType -> confirmationInventory(player, "Trace löschen", () -> player.performCommand("trace delete"), () -> {})); inv.setItem(8, Material.ARROW, "§7Zurück", clickType -> { player.closeInventory(); @@ -482,42 +483,43 @@ public class CommandGUI implements CommandExecutor, Listener { SteamwarUser user = SteamwarUser.get(member.getMemberID()); SWInventory inv = new SWInventory(player, 9, "Member: " + user.getUserName()); if(member.isBuild()) - inv.setItem(2, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Bauen", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { + inv.setItem(0, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Bauen", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { member.setBuild(false); bauweltMemberGUI(player, member); }); else - inv.setItem(2, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7Bauen", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { + inv.setItem(0, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7Bauen", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { member.setBuild(true); bauweltMemberGUI(player, member); }); if(member.isWorldEdit()) - inv.setItem(4, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Worldedit", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { + inv.setItem(2, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Worldedit", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { member.setWorldEdit(false); bauweltMemberGUI(player, member); }); else - inv.setItem(4, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7Worldedit", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { + inv.setItem(2, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7Worldedit", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { member.setWorldEdit(true); bauweltMemberGUI(player, member); }); if(member.isWorld()) - inv.setItem(6, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7World", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { + inv.setItem(4, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7World", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { member.setWorld(false); bauweltMemberGUI(player, member); }); else - inv.setItem(6, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7World", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { + inv.setItem(4, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7World", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { member.setWorld(true); bauweltMemberGUI(player, member); }); - inv.setItem(8, Material.BARRIER, "§7Member entfernen", clickType -> { + inv.setItem(6, Material.BARRIER, "§7Member entfernen", clickType -> { player.closeInventory(); confirmChatMessage(player, "/bau delmember " + user.getUserName()); }); + inv.setItem(8, Material.ARROW, "§7Zurück", clickType -> bauManagementGUI(player)); inv.open(); } @@ -527,7 +529,7 @@ public class CommandGUI implements CommandExecutor, Listener { t.setText("[Hier]"); t.setColor(ChatColor.YELLOW); t.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); - t.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§8/§7" + command))); + t.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7" + command))); player.spigot().sendMessage(t); } @@ -563,7 +565,7 @@ public class CommandGUI implements CommandExecutor, Listener { for (String name:names) { try { return Material.valueOf(name); - }catch (NullPointerException ignored) {} + }catch (IllegalArgumentException ignored) {} } return null; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/PredefinedBook.java b/BauSystem_Main/src/de/steamwar/bausystem/world/PredefinedBook.java index 22fd13f..a13baec 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/PredefinedBook.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/PredefinedBook.java @@ -42,6 +42,7 @@ public class PredefinedBook { private List lore; private String author; private String name; + private ItemStack finishedBook; PredefinedBook(ConfigurationSection section) { this.lines = section.getStringList("lines"); @@ -51,6 +52,8 @@ public class PredefinedBook { } public ItemStack toItemStack() { + if(finishedBook != null) + return finishedBook; ItemStack book = new ItemStack(getBookMat()); BookMeta meta = (BookMeta) book.getItemMeta(); meta.setPages(getPages()); @@ -60,6 +63,7 @@ public class PredefinedBook { meta.setGeneration(BookMeta.Generation.ORIGINAL); meta.setLore(lore); book.setItemMeta(meta); + finishedBook = book; return book; } From 8f176cd8cd42a5e8e7e008bf7d202c51b8d011db Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 13 Feb 2021 23:46:50 +0100 Subject: [PATCH 15/20] Fixing some 1.12 Stuff --- .../de/steamwar/bausystem/commands/CommandGUI.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index c76bd9d..926c8fc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -170,7 +170,7 @@ public class CommandGUI implements CommandExecutor, Listener { inv.setItem(18, Material.BARRIER, "§eKeine Region", clickType -> {}); inv.setItem(27, Material.BARRIER, "§eKeine Region", clickType -> {}); }else { - inv.setItem(27, Material.HEAVY_WEIGHTED_PRESSURE_PLATE, "§eRegion Reseten", getNoPermsLore(Arrays.asList("§8/§7reset"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(27, getMaterial("HEAVY_WEIGHTED_PRESSURE_PLATE", "IRON_PLATE"), "§eRegion Reseten", getNoPermsLore(Arrays.asList("§8/§7reset"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; confirmationInventory(player, "Region Reseten?", () -> player.performCommand("reset"), () -> openBauGui(player)); @@ -233,7 +233,7 @@ public class CommandGUI implements CommandExecutor, Listener { }); break; case ONLY_TB: - inv.setItem(23, Material.TNT_MINECART, "§7TNT: §enur Testblock", tntLore, false, clickType -> { + inv.setItem(23, getMaterial("TNT_MINECART", "EXPLOSIVE_MINECART"), "§7TNT: §enur Testblock", tntLore, false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("tnt on"); @@ -250,7 +250,7 @@ public class CommandGUI implements CommandExecutor, Listener { } if(region.isFreeze()) { - inv.setItem(24, Material.GUNPOWDER, "§7Freeze: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + inv.setItem(24, getMaterial("GUNPOWDER", "SULPHUR"), "§7Freeze: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { if(Welt.noPermission(player, Permission.world)) return; player.performCommand("freeze"); @@ -339,7 +339,7 @@ public class CommandGUI implements CommandExecutor, Listener { }); } - inv.setItem(4, Material.TNT_MINECART, "§7Trace GUI", Collections.singletonList("§8/§7trace show gui"), false, clickType -> { + inv.setItem(4, getMaterial("TNT_MINECART", "EXPLOSIVE_MINECART"), "§7Trace GUI", Collections.singletonList("§8/§7trace show gui"), false, clickType -> { player.closeInventory(); player.performCommand("trace show gui"); }); @@ -399,7 +399,7 @@ public class CommandGUI implements CommandExecutor, Listener { anvilInv.open(); }); - inv.setItem(6, Material.CLOCK, "§7Block platzier Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + loader.getTicksBetweenBlocks(), "§8/§7loader speed §8[§eTicks§8]"), false, clickType -> { + inv.setItem(6, getMaterial("CLOCK", "WATCH"), "§7Block platzier Geschwindigkeit", Arrays.asList("§7Aktuell: §e" + loader.getTicksBetweenBlocks(), "§8/§7loader speed §8[§eTicks§8]"), false, clickType -> { SWAnvilInv anvilInv = new SWAnvilInv(player, "Platzier Geschwindigkeit", loader.getTicksBetweenBlocks() + ""); anvilInv.setItem(Material.STONE); anvilInv.setCallback(s -> { @@ -550,11 +550,11 @@ public class CommandGUI implements CommandExecutor, Listener { private static void confirmationInventory(Player player, String title, Runnable confirm, Runnable decline) { SWInventory inv = new SWInventory(player, 9, title); - inv.setItem(0, SWItem.getDye(1), "§cAbbrechen", clickType -> { + inv.setItem(0, SWItem.getDye(1), (byte) 1, "§cAbbrechen", clickType -> { player.closeInventory(); decline.run(); }); - inv.setItem(8, SWItem.getDye(10), "§aBestätigen", clickType -> { + inv.setItem(8, SWItem.getDye(10), (byte) 10, "§aBestätigen", clickType -> { player.closeInventory(); confirm.run(); }); From 8c216527f798b1a74780abb8c30a6bf0650966c7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 17 Feb 2021 14:32:27 +0100 Subject: [PATCH 16/20] Code Refactor --- .../bausystem/commands/CommandGUI.java | 184 ++++++++++-------- 1 file changed, 98 insertions(+), 86 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 926c8fc..f15107c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -44,36 +44,20 @@ public class CommandGUI implements CommandExecutor, Listener { Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getPlugin(), LAST_F_PLAYER::clear, 0, 20); } - @Override - public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { - if(!(commandSender instanceof Player)) - return false; - Player player = ((Player) commandSender); - if(strings.length == 0) { - openBauGui(player); - OPEN_INVS.add(player); - }else { - if ("item".equalsIgnoreCase(strings[0])) { - if (player.getInventory().getItemInMainHand().getType() == Material.AIR) - player.getInventory().setItemInMainHand(new ItemStack(Material.NETHER_STAR)); - else - player.getInventory().addItem(new ItemStack(Material.NETHER_STAR)); - } - } - return true; - } - public static void openBauGui(Player player) { Region region = Region.getRegion(player.getLocation()); - SWInventory inv = new SWInventory(player, 5*9, SteamwarUser.get(BauSystem.getOwner()).getUserName() + "s Bau"); + SWInventory inv = new SWInventory(player, 5 * 9, SteamwarUser.get(BauSystem.getOwner()).getUserName() + "s Bau"); inv.setCallback(-1, clickType -> { - if(!isRefreshing) + if (!isRefreshing) OPEN_INVS.remove(player); }); - inv.setItem(37, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {}); - inv.setItem(38, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {}); - inv.setItem(43, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> {}); + inv.setItem(37, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> { + }); + inv.setItem(38, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> { + }); + inv.setItem(43, getMaterial("GLASS_PANE", "THIN_GLASS"), "§7Platzhalter", clickType -> { + }); inv.setItem(42, Material.NETHER_STAR, "§7Bau GUI Item", Arrays.asList("§7Du kannst dieses Item zum Öffnen der BauGUI nutzen", "§7oder Doppel F (Swap hands) drücken."), false, clickType -> { player.closeInventory(); player.performCommand("gui item"); @@ -83,32 +67,32 @@ public class CommandGUI implements CommandExecutor, Listener { ItemMeta meta = dtWand.getItemMeta(); List lore = meta.getLore(); lore.add("§8/§7dt wand"); - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) lore.add("§cDu hast keine Worldrechte"); meta.setLore(lore); dtWand.setItemMeta(meta); inv.setItem(39, dtWand, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.closeInventory(); player.performCommand("dt wand"); }); inv.setItem(40, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", getNoPermsLore(Arrays.asList("§8//§7wand"), player, "§cDu hast keine Worldeditrechte", Permission.worldedit), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.closeInventory(); player.performCommand("/wand"); }); - inv.setItem(41, getMaterial("DEBUG_STICK", "STICK"), "§eDebugstick", getNoPermsLore(Arrays.asList("§8/§7debugstick"), player, "§cDu hast keine Worldrechte", Permission.world), Core.getVersion() < 13,clickType -> { - if(Welt.noPermission(player, Permission.world)) + inv.setItem(41, getMaterial("DEBUG_STICK", "STICK"), "§eDebugstick", getNoPermsLore(Arrays.asList("§8/§7debugstick"), player, "§cDu hast keine Worldrechte", Permission.world), Core.getVersion() < 13, clickType -> { + if (Welt.noPermission(player, Permission.world)) return; player.closeInventory(); player.performCommand("debugstick"); }); - inv.setItem(20, Material.COMPASS, "§7TPS Limitieren", getNoPermsLore(Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e0,5 - " + (TPSUtils.isWarpAllowed()?40:20) + "§8]"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + inv.setItem(20, Material.COMPASS, "§7TPS Limitieren", getNoPermsLore(Arrays.asList("§7Aktuell: §e" + CommandTPSLimiter.getCurrentTPSLimit(), "§8/§7tpslimit §8[§e0,5 - " + (TPSUtils.isWarpAllowed() ? 40 : 20) + "§8]"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { + if (Welt.noPermission(player, Permission.world)) return; SWAnvilInv anvilInv = new SWAnvilInv(player, "TPS Limitieren"); anvilInv.setItem(Material.COMPASS); @@ -122,13 +106,13 @@ public class CommandGUI implements CommandExecutor, Listener { anvilInv.open(); }); - if(player.getUniqueId().equals(BauSystem.getOwner())) { + if (player.getUniqueId().equals(BauSystem.getOwner())) { SWItem skull = SWItem.getPlayerSkull(player.getName()); skull.setName("§7Bau verwalten"); List skullLore = new ArrayList<>(); skullLore.add("§7TNT: §e" + region.getTntMode().getName()); - skullLore.add("§7StopLag: §e" + (region.isFreeze()?"Eingeschaltet":"Ausgeschaltet")); - skullLore.add("§7Fire: §e" + (region.isFire()?"Ausgeschaltet":"Eingeschaltet")); + skullLore.add("§7StopLag: §e" + (region.isFreeze() ? "Eingeschaltet" : "Ausgeschaltet")); + skullLore.add("§7Fire: §e" + (region.isFire() ? "Ausgeschaltet" : "Eingeschaltet")); skullLore.add("§7Members: §e" + (BauweltMember.getMembers(BauSystem.getOwnerID()).size() - 1)); skull.setLore(skullLore); skull.setCallback(clickType -> { @@ -144,7 +128,7 @@ public class CommandGUI implements CommandExecutor, Listener { }); inv.setItem(21, Material.OBSERVER, "§7Tracer", getNoPermsLore(Arrays.asList("§7Status: §e" + RecordStateMachine.getRecordStatus().getName()), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.closeInventory(); OPEN_TRACER_INVS.add(player); @@ -152,7 +136,7 @@ public class CommandGUI implements CommandExecutor, Listener { }); inv.setItem(22, Material.DISPENSER, "§7Auto-Loader", getNoPermsLore(Arrays.asList("§7Status: " + (AutoLoader.hasLoader(player) ? "§aan" : "§caus")), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.closeInventory(); autoLoaderGUI(player); @@ -165,39 +149,44 @@ public class CommandGUI implements CommandExecutor, Listener { anvilInv.open(); }); - if(Region.GlobalRegion.isGlobalRegion(region)) { - inv.setItem(9, Material.BARRIER, "§eKeine Region", clickType -> {}); - inv.setItem(18, Material.BARRIER, "§eKeine Region", clickType -> {}); - inv.setItem(27, Material.BARRIER, "§eKeine Region", clickType -> {}); - }else { + if (Region.GlobalRegion.isGlobalRegion(region)) { + inv.setItem(9, Material.BARRIER, "§eKeine Region", clickType -> { + }); + inv.setItem(18, Material.BARRIER, "§eKeine Region", clickType -> { + }); + inv.setItem(27, Material.BARRIER, "§eKeine Region", clickType -> { + }); + } else { inv.setItem(27, getMaterial("HEAVY_WEIGHTED_PRESSURE_PLATE", "IRON_PLATE"), "§eRegion Reseten", getNoPermsLore(Arrays.asList("§8/§7reset"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; confirmationInventory(player, "Region Reseten?", () -> player.performCommand("reset"), () -> openBauGui(player)); }); - if(region.hasProtection()) { + if (region.hasProtection()) { inv.setItem(18, Material.OBSIDIAN, "§eRegion Protecten", getNoPermsLore(Arrays.asList("§8/§7protect"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; confirmationInventory(player, "Region Protecten", () -> player.performCommand("protect"), () -> openBauGui(player)); }); } else { - inv.setItem(18, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> {}); + inv.setItem(18, Material.BARRIER, "§eRegion nicht Protect bar", clickType -> { + }); } - if(region.hasTestblock()) { + if (region.hasTestblock()) { inv.setItem(9, getMaterial("END_STONE", "ENDER_STONE"), "§eTestblock erneuern", getNoPermsLore(Arrays.asList("§8/§7testblock"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; confirmationInventory(player, "Testblock erneuern", () -> player.performCommand("testblock"), () -> openBauGui(player)); }); } else { - inv.setItem(9, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> {}); + inv.setItem(9, Material.BARRIER, "§eDie Region hat keinen Testblock", clickType -> { + }); } } - if(player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { + if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { inv.setItem(26, Material.POTION, "§7Nightvision: §eEingeschaltet", Collections.singletonList("§8/§7nv"), false, clickType -> { CommandNV.toggleNightvision(player); openBauGui(player); @@ -209,7 +198,7 @@ public class CommandGUI implements CommandExecutor, Listener { }); } - if(player.hasPotionEffect(PotionEffectType.WATER_BREATHING)) { + if (player.hasPotionEffect(PotionEffectType.WATER_BREATHING)) { inv.setItem(35, Material.WATER_BUCKET, "§7Waterbreathing: §eEingeschaltet", Collections.singletonList("§8/§7wv"), false, clickType -> { CommandGills.toggleGills(player); openBauGui(player); @@ -226,15 +215,15 @@ public class CommandGUI implements CommandExecutor, Listener { switch (region.getTntMode()) { case OFF: inv.setItem(23, Material.MINECART, "§7TNT: §eAusgeschaltet", tntLore, false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; - player.performCommand("tnt " + (isBuildArea?"tb":"on")); + player.performCommand("tnt " + (isBuildArea ? "tb" : "on")); updateInventories(); }); break; case ONLY_TB: inv.setItem(23, getMaterial("TNT_MINECART", "EXPLOSIVE_MINECART"), "§7TNT: §enur Testblock", tntLore, false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.performCommand("tnt on"); updateInventories(); @@ -242,39 +231,39 @@ public class CommandGUI implements CommandExecutor, Listener { break; default: inv.setItem(23, Material.TNT, "§7TNT: §eEingeschaltet", tntLore, false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.performCommand("tnt off"); updateInventories(); }); } - if(region.isFreeze()) { + if (region.isFreeze()) { inv.setItem(24, getMaterial("GUNPOWDER", "SULPHUR"), "§7Freeze: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.performCommand("freeze"); updateInventories(); }); } else { inv.setItem(24, Material.REDSTONE, "§7Freeze: §eAusgeschaltet", getNoPermsLore(Arrays.asList("§8/§7freeze"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.performCommand("freeze"); updateInventories(); }); } - if(region.isFire()) { + if (region.isFire()) { inv.setItem(3, getMaterial("FIREWORK_STAR", "FIREWORK_CHARGE"), "§7Fire: §eAusgeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.performCommand("fire"); updateInventories(); }); } else { inv.setItem(3, getMaterial("FIRE_CHARGE", "FIREBALL"), "§7Fire: §eEingeschaltet", getNoPermsLore(Arrays.asList("§8/§7fire"), player, "§cDu hast keine Worldrechte", Permission.world), false, clickType -> { - if(Welt.noPermission(player, Permission.world)) + if (Welt.noPermission(player, Permission.world)) return; player.performCommand("fire"); updateInventories(); @@ -282,11 +271,11 @@ public class CommandGUI implements CommandExecutor, Listener { } inv.setItem(2, Material.ENDER_PEARL, "§7Teleporter", getNoPermsLore(Arrays.asList("§8/§7tp §8[§eSpieler§8]"), player, "§cDu hast keine Buildrechte", Permission.build), false, clickType -> { - if(Welt.noPermission(player, Permission.build)) + if (Welt.noPermission(player, Permission.build)) return; List> playerSWListEntry = new ArrayList<>(); Bukkit.getOnlinePlayers().forEach(player1 -> { - if(player1.equals(player)) + if (player1.equals(player)) return; playerSWListEntry.add(new SWListInv.SWListEntry<>(SWItem.getPlayerSkull(player1.getName()), player1.getName())); }); @@ -303,7 +292,7 @@ public class CommandGUI implements CommandExecutor, Listener { private static void traceGUI(Player player) { SWInventory inv = new SWInventory(player, 9, "Tracer"); inv.setCallback(-1, clickType -> { - if(!isRefreshing) + if (!isRefreshing) OPEN_TRACER_INVS.remove(player); }); List stateLore = Arrays.asList("§7Aktuell: §e" + RecordStateMachine.getRecordStatus().getName(), "§8/§7trace §8[§estart§8, stop §8oder §eauto§8]"); @@ -327,7 +316,7 @@ public class CommandGUI implements CommandExecutor, Listener { updateInventories(); }); } - if(TraceShowManager.hasActiveShow(player)) { + if (TraceShowManager.hasActiveShow(player)) { inv.setItem(2, Material.TNT, "§7Showstatus", Arrays.asList("§7Aktuell: §eGezeigt", "§8/§7trace §8[§eshow§8/§ehide§8]"), false, clickType -> { player.performCommand("trace hide"); traceGUI(player); @@ -344,7 +333,8 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("trace show gui"); }); - inv.setItem(6, Material.BARRIER, "§7Trace löschen", Arrays.asList("§8/§7trace delete"), false, clickType -> confirmationInventory(player, "Trace löschen", () -> player.performCommand("trace delete"), () -> {})); + inv.setItem(6, Material.BARRIER, "§7Trace löschen", Arrays.asList("§8/§7trace delete"), false, clickType -> confirmationInventory(player, "Trace löschen", () -> player.performCommand("trace delete"), () -> { + })); inv.setItem(8, Material.ARROW, "§7Zurück", clickType -> { player.closeInventory(); @@ -358,7 +348,8 @@ public class CommandGUI implements CommandExecutor, Listener { private static void scriptBooksGUI(Player player) { List> entries = new ArrayList<>(); List books = PredefinedBook.getBooks(); - books.forEach(predefinedBook -> entries.add(new SWListInv.SWListEntry<>(new SWItem(predefinedBook.getBookMat(), predefinedBook.getName(), predefinedBook.getLore(), false, clickType -> {}), predefinedBook))); + books.forEach(predefinedBook -> entries.add(new SWListInv.SWListEntry<>(new SWItem(predefinedBook.getBookMat(), predefinedBook.getName(), predefinedBook.getLore(), false, clickType -> { + }), predefinedBook))); SWListInv inv = new SWListInv<>(player, "Script Bücher", entries, (clickType, predefinedBook) -> { player.closeInventory(); player.getInventory().addItem(predefinedBook.toItemStack()); @@ -371,9 +362,9 @@ public class CommandGUI implements CommandExecutor, Listener { boolean hasLoader = AutoLoader.hasLoader(player); - if(hasLoader) { + if (hasLoader) { AutoLoader loader = AutoLoader.getLoader(player); - if(loader.isSetup()) { + if (loader.isSetup()) { inv.setItem(0, Material.DROPPER, "§7Loader Starten", Collections.singletonList("§8/§7loader start"), false, clickType -> { loader.start(); autoLoaderGUI(player); @@ -436,20 +427,20 @@ public class CommandGUI implements CommandExecutor, Listener { List members = BauweltMember.getMembers(BauSystem.getOwnerID()); List> items = new ArrayList<>(); members.forEach(member -> { - if(member.getMemberID() == BauSystem.getOwnerID()) + if (member.getMemberID() == BauSystem.getOwnerID()) return; SteamwarUser user = SteamwarUser.get(member.getMemberID()); - if(!user.getUserName().toLowerCase().contains(search.toLowerCase())) + if (!user.getUserName().toLowerCase().contains(search.toLowerCase())) return; SWItem item = SWItem.getPlayerSkull(user.getUserName()); item.setName("§7" + user.getUserName()); List lore = new ArrayList<>(); - lore.add("§7Online: §e" + (Bukkit.getPlayer(user.getUUID()) == null?"Offline":"Online")); - lore.add("§7Bauen: §e" + (member.isBuild()?"Ja":"Nein")); - lore.add("§7Worldedit: §e" + (member.isWorldEdit()?"Ja":"Nein")); - lore.add("§7World: §e" + (member.isWorld()?"Ja":"Nein")); + lore.add("§7Online: §e" + (Bukkit.getPlayer(user.getUUID()) == null ? "Offline" : "Online")); + lore.add("§7Bauen: §e" + (member.isBuild() ? "Ja" : "Nein")); + lore.add("§7Worldedit: §e" + (member.isWorldEdit() ? "Ja" : "Nein")); + lore.add("§7World: §e" + (member.isWorld() ? "Ja" : "Nein")); item.setLore(lore); items.add(new SWListInv.SWListEntry<>(item, member)); }); @@ -482,7 +473,7 @@ public class CommandGUI implements CommandExecutor, Listener { private static void bauweltMemberGUI(Player player, BauweltMember member) { SteamwarUser user = SteamwarUser.get(member.getMemberID()); SWInventory inv = new SWInventory(player, 9, "Member: " + user.getUserName()); - if(member.isBuild()) + if (member.isBuild()) inv.setItem(0, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Bauen", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { member.setBuild(false); bauweltMemberGUI(player, member); @@ -493,7 +484,7 @@ public class CommandGUI implements CommandExecutor, Listener { bauweltMemberGUI(player, member); }); - if(member.isWorldEdit()) + if (member.isWorldEdit()) inv.setItem(2, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Worldedit", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { member.setWorldEdit(false); bauweltMemberGUI(player, member); @@ -504,7 +495,7 @@ public class CommandGUI implements CommandExecutor, Listener { bauweltMemberGUI(player, member); }); - if(member.isWorld()) + if (member.isWorld()) inv.setItem(4, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7World", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { member.setWorld(false); bauweltMemberGUI(player, member); @@ -534,7 +525,7 @@ public class CommandGUI implements CommandExecutor, Listener { } private static List getNoPermsLore(List lore, Player player, String noPerms, Permission perm) { - if(Welt.noPermission(player, perm)) { + if (Welt.noPermission(player, perm)) { lore = new ArrayList<>(lore); lore.add(noPerms); } @@ -551,9 +542,9 @@ public class CommandGUI implements CommandExecutor, Listener { private static void confirmationInventory(Player player, String title, Runnable confirm, Runnable decline) { SWInventory inv = new SWInventory(player, 9, title); inv.setItem(0, SWItem.getDye(1), (byte) 1, "§cAbbrechen", clickType -> { - player.closeInventory(); - decline.run(); - }); + player.closeInventory(); + decline.run(); + }); inv.setItem(8, SWItem.getDye(10), (byte) 10, "§aBestätigen", clickType -> { player.closeInventory(); confirm.run(); @@ -562,19 +553,40 @@ public class CommandGUI implements CommandExecutor, Listener { } private static Material getMaterial(String... names) { - for (String name:names) { + for (String name : names) { try { return Material.valueOf(name); - }catch (IllegalArgumentException ignored) {} + } catch (IllegalArgumentException ignored) { + //Ignored /\ + } } return null; } + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (!(commandSender instanceof Player)) + return false; + Player player = ((Player) commandSender); + if (strings.length == 0) { + openBauGui(player); + OPEN_INVS.add(player); + } else { + if ("item".equalsIgnoreCase(strings[0])) { + if (player.getInventory().getItemInMainHand().getType() == Material.AIR) + player.getInventory().setItemInMainHand(new ItemStack(Material.NETHER_STAR)); + else + player.getInventory().addItem(new ItemStack(Material.NETHER_STAR)); + } + } + return true; + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - if(event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) + if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - if(event.getItem() == null || event.getItem().getType() != Material.NETHER_STAR) + if (event.getItem() == null || event.getItem().getType() != Material.NETHER_STAR) return; openBauGui(event.getPlayer()); OPEN_INVS.add(event.getPlayer()); @@ -582,7 +594,7 @@ public class CommandGUI implements CommandExecutor, Listener { @EventHandler public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { - if(LAST_F_PLAYER.contains(event.getPlayer())) { + if (LAST_F_PLAYER.contains(event.getPlayer())) { openBauGui(event.getPlayer()); OPEN_INVS.add(event.getPlayer()); } else { From b7f1834137300c4d8886bc923d1e48f86fa40df1 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 17 Feb 2021 14:36:32 +0100 Subject: [PATCH 17/20] Fix pr stuff --- .../steamwar/bausystem/commands/CommandGUI.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index f15107c..ef1a29f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -473,38 +473,41 @@ public class CommandGUI implements CommandExecutor, Listener { private static void bauweltMemberGUI(Player player, BauweltMember member) { SteamwarUser user = SteamwarUser.get(member.getMemberID()); SWInventory inv = new SWInventory(player, 9, "Member: " + user.getUserName()); - if (member.isBuild()) + if (member.isBuild()) { inv.setItem(0, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Bauen", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { member.setBuild(false); bauweltMemberGUI(player, member); }); - else + } else { inv.setItem(0, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7Bauen", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau togglebuild §8[§eSpieler§8]"), false, clickType -> { member.setBuild(true); bauweltMemberGUI(player, member); }); + } - if (member.isWorldEdit()) + if (member.isWorldEdit()) { inv.setItem(2, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7Worldedit", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { member.setWorldEdit(false); bauweltMemberGUI(player, member); }); - else + } else { inv.setItem(2, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7Worldedit", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau togglewe §8[§eSpieler§8]"), false, clickType -> { member.setWorldEdit(true); bauweltMemberGUI(player, member); }); + } - if (member.isWorld()) + if (member.isWorld()) { inv.setItem(4, getMaterial("GREEN_WOOL", "WOOL"), (byte) 13, "§7World", Arrays.asList("§7Aktuell: §eJa", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { member.setWorld(false); bauweltMemberGUI(player, member); }); - else + } else { inv.setItem(4, getMaterial("RED_WOOL", "WOOL"), (byte) 14, "§7World", Arrays.asList("§7Aktuell: §eNein", "§8/§7bau toggleworld §8[§eSpieler§8]"), false, clickType -> { member.setWorld(true); bauweltMemberGUI(player, member); }); + } inv.setItem(6, Material.BARRIER, "§7Member entfernen", clickType -> { player.closeInventory(); From 3c029adba26af0c126a8acae331d75375ee59acf Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 25 Feb 2021 11:27:30 +0100 Subject: [PATCH 18/20] Revert "Itemgiver improvements" due to player complaints --- .../steamwar/bausystem/commands/CommandDebugStick_15.java | 5 +---- .../de/steamwar/bausystem/commands/CommandDetonator.java | 6 +----- .../src/de/steamwar/bausystem/commands/CommandSkull.java | 6 +----- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java index 88e5b3b..3c1d189 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java @@ -27,9 +27,6 @@ class CommandDebugStick_15 { private CommandDebugStick_15(){} static void giveStick(Player player){ - if(player.getInventory().getItemInMainHand().getType() == Material.AIR) - player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK)); - else - player.getInventory().addItem(new ItemStack(Material.DEBUG_STICK)); + player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 4446023..52bc21e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Welt; -import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -63,10 +62,7 @@ public class CommandDetonator implements CommandExecutor { case "wand": case "detonator": case "item": - if(player.getInventory().getItemInMainHand().getType() == Material.AIR) - player.getInventory().setItemInMainHand(Detonator.WAND); - else - player.getInventory().addItem(Detonator.WAND); + player.getInventory().setItemInMainHand(Detonator.WAND); player.updateInventory(); Detonator.getDetonator(player); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java index 9a0ca95..6ac0d81 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; -import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -47,10 +46,7 @@ public class CommandSkull implements CommandExecutor { assert sm != null; sm.setDisplayName("§e" + args[0] + "§8s Kopf"); is.setItemMeta(sm); - if(p.getInventory().getItemInMainHand().getType() == Material.AIR) - p.getInventory().setItemInMainHand(is); - else - p.getInventory().addItem(is); + p.getInventory().setItemInMainHand(is); return false; } From bb598ba8ad974aa5888840ac180c5f8ac06874de Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 25 Feb 2021 13:23:44 +0100 Subject: [PATCH 19/20] Hotfix CommandReset NPE Hotfix CommandTestblock NPE --- .../src/de/steamwar/bausystem/commands/CommandReset.java | 2 +- .../src/de/steamwar/bausystem/commands/CommandTestblock.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java index 934a383..e53927d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandReset.java @@ -46,7 +46,7 @@ public class CommandReset implements CommandExecutor { } Region region = Region.getRegion(player.getLocation()); - if (region == null) { + if (region == Region.GlobalRegion.getInstance()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java index 87ffbf3..c8982b2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTestblock.java @@ -46,7 +46,7 @@ public class CommandTestblock implements CommandExecutor { } Region region = Region.getRegion(player.getLocation()); - if (region == null || !region.hasTestblock()) { + if (!region.hasTestblock()) { player.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region"); return false; } From cd6ad1a85ddfe2c9410c56860d5a31d231662522 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 25 Feb 2021 13:50:08 +0100 Subject: [PATCH 20/20] Fix Item giving --- .../commands/CommandDebugStick_15.java | 3 +- .../de/steamwar/bausystem/PlayerUtils.java | 36 +++++++++++++++++++ .../bausystem/commands/CommandDetonator.java | 3 +- .../bausystem/commands/CommandGUI.java | 10 ++---- .../bausystem/commands/CommandScript.java | 3 +- .../bausystem/commands/CommandSkull.java | 3 +- 6 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/PlayerUtils.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java index 3c1d189..8bbf9dd 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.PlayerUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -27,6 +28,6 @@ class CommandDebugStick_15 { private CommandDebugStick_15(){} static void giveStick(Player player){ - player.getInventory().setItemInMainHand(new ItemStack(Material.DEBUG_STICK)); + PlayerUtils.giveItemToPlayer(player, new ItemStack(Material.DEBUG_STICK)); } } diff --git a/BauSystem_API/src/de/steamwar/bausystem/PlayerUtils.java b/BauSystem_API/src/de/steamwar/bausystem/PlayerUtils.java new file mode 100644 index 0000000..8dd1181 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/PlayerUtils.java @@ -0,0 +1,36 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class PlayerUtils { + + public static void giveItemToPlayer(Player player, ItemStack itemStack) { + ItemStack current = player.getInventory().getItemInMainHand(); + player.getInventory().setItemInMainHand(itemStack); + if (current.getType() != Material.AIR) { + player.getInventory().addItem(current); + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 52bc21e..ab6ff39 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.PlayerUtils; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; @@ -62,7 +63,7 @@ public class CommandDetonator implements CommandExecutor { case "wand": case "detonator": case "item": - player.getInventory().setItemInMainHand(Detonator.WAND); + PlayerUtils.giveItemToPlayer(player, Detonator.WAND); player.updateInventory(); Detonator.getDetonator(player); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index ef1a29f..be01a34 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.PlayerUtils; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.world.*; @@ -574,13 +575,8 @@ public class CommandGUI implements CommandExecutor, Listener { if (strings.length == 0) { openBauGui(player); OPEN_INVS.add(player); - } else { - if ("item".equalsIgnoreCase(strings[0])) { - if (player.getInventory().getItemInMainHand().getType() == Material.AIR) - player.getInventory().setItemInMainHand(new ItemStack(Material.NETHER_STAR)); - else - player.getInventory().addItem(new ItemStack(Material.NETHER_STAR)); - } + } else if ("item".equalsIgnoreCase(strings[0])) { + PlayerUtils.giveItemToPlayer(player, new ItemStack(Material.NETHER_STAR)); } return true; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java index b093046..6f03dbe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.PlayerUtils; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -67,7 +68,7 @@ public class CommandScript implements CommandExecutor { if (!(sender instanceof Player)) { return false; } - ((Player) sender).getInventory().setItemInMainHand(BOOK); + PlayerUtils.giveItemToPlayer((Player) sender, BOOK); return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java index 6ac0d81..bd8d121 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.PlayerUtils; import de.steamwar.inventory.SWItem; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -46,7 +47,7 @@ public class CommandSkull implements CommandExecutor { assert sm != null; sm.setDisplayName("§e" + args[0] + "§8s Kopf"); is.setItemMeta(sm); - p.getInventory().setItemInMainHand(is); + PlayerUtils.giveItemToPlayer(p, is); return false; }