From 032a4c75d6be64ab82e4ce1eb9aa9a18d57e45fa Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 3 Feb 2021 23:52:23 +0100 Subject: [PATCH] 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; } }