From 080d810bc4196da98954706776d0e2501a2a3e94 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 2 Feb 2021 23:44:46 +0100 Subject: [PATCH] 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