From 870fc285e7cddfe9479f13fe87eff293bbb9efe1 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 18:55:13 +0100 Subject: [PATCH] Fix PR stuff --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../TNTSimulator.java | 48 +++++++++---------- .../TNTSimulatorAnvil.java | 2 +- .../TNTSimulatorListener.java | 18 ++++++- .../TNTSpawn.java | 2 +- .../bausystem/commands/CommandSimulator.java | 2 +- 6 files changed, 44 insertions(+), 30 deletions(-) rename BauSystem_Main/src/de/steamwar/bausystem/{canonsimulator => cannonsimulator}/TNTSimulator.java (86%) rename BauSystem_Main/src/de/steamwar/bausystem/{canonsimulator => cannonsimulator}/TNTSimulatorAnvil.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/{canonsimulator => cannonsimulator}/TNTSimulatorListener.java (79%) rename BauSystem_Main/src/de/steamwar/bausystem/{canonsimulator => cannonsimulator}/TNTSpawn.java (98%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index cd8e70b..e1191a2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem; -import de.steamwar.bausystem.canonsimulator.TNTSimulatorListener; +import de.steamwar.bausystem.cannonsimulator.TNTSimulatorListener; import de.steamwar.bausystem.commands.*; import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java similarity index 86% rename from BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java rename to BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java index ca96905..9810a89 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java @@ -19,7 +19,7 @@ * / */ -package de.steamwar.bausystem.canonsimulator; +package de.steamwar.bausystem.cannonsimulator; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWInventory; @@ -42,17 +42,18 @@ public class TNTSimulator { private static final Vector NY_VECTOR = new Vector(0, -0.0625, 0); private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625); private static final Vector NZ_VECTOR = new Vector(0, 0, -0.0625); - private static final List LORE = Collections.singletonList("§7Klicken zum ändern"); + private static final List LORE = Collections.singletonList("§7Zum ändern klicken"); static Map tntSimulatorMap = new HashMap<>(); - public static final ItemStack WAND = new SWItem(Material.TRIPWIRE_HOOK, "§6Kanonen Simulator", Arrays.asList("§eRechts Klick Block §8- §7Füge einen TNT hinzu", "§eRechts Klick Luft §8- §7Öffne den Simulator", "§eLinks Klick §8- §7Starte die Simulation"), false, null).getItemStack(); + public static final ItemStack WAND = new SWItem(Material.TRIPWIRE_HOOK, "§eKanonen Simulator", Arrays.asList("§eRechtsklick Block §8- §7Füge einen TNT hinzu", "§eRechtsklick Luft §8- §7Öffne den Simulator", "§eLinksklick §8- §7Starte die Simulation"), false, null).getItemStack(); + + public static TNTSimulator get(Player player) { + return tntSimulatorMap.computeIfAbsent(player, p -> new TNTSimulator()); + } public static void openSimulator(Player player) { - if (!tntSimulatorMap.containsKey(player)) { - tntSimulatorMap.put(player, new TNTSimulator()); - } - TNTSimulator tntSimulator = tntSimulatorMap.get(player); + TNTSimulator tntSimulator = get(player); List> swListEntryList = new ArrayList<>(); tntSimulator.tntSpawns.forEach(tntSpawn -> { @@ -66,11 +67,11 @@ public class TNTSimulator { lore.add("§eX§8: §7" + tntSpawn.getPosition().getX()); lore.add("§eY§8: §7" + tntSpawn.getPosition().getY()); lore.add("§eZ§8: §7" + tntSpawn.getPosition().getZ()); - swListEntryList.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT, "§6TNT", lore, false, null), tntSpawn)); + swListEntryList.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT, "§eTNT", lore, false, null), tntSpawn)); }); swListEntryList.sort(Comparator.comparing(SWListInv.SWListEntry::getObject)); - SWListInv swListInv = new SWListInv<>(player, "Kanonen Simulator", false, swListEntryList, (clickType, tntSpawn) -> { + SWListInv swListInv = new SWListInv<>(player, "Kanonensimulator", false, swListEntryList, (clickType, tntSpawn) -> { editTNT(player, tntSpawn); }); swListInv.setItem(51, new SWItem(Material.BARRIER, "§cLösche alle TNT", clickType -> { @@ -91,7 +92,7 @@ public class TNTSimulator { tntSimulator.tntSpawns.add(tntSpawn); editTNT(player, tntSpawn); })); - swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation Starten", clickType -> { + swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation starten", clickType -> { startSimulation(player); player.closeInventory(); })); @@ -99,18 +100,15 @@ public class TNTSimulator { } static void editTNT(Player player, TNTSpawn tntSpawn) { - if (!tntSimulatorMap.containsKey(player)) { - tntSimulatorMap.put(player, new TNTSimulator()); - } - TNTSimulator tntSimulator = tntSimulatorMap.get(player); + TNTSimulator tntSimulator = get(player); SWInventory swInventory = new SWInventory(player, 54, "TNT"); swInventory.setItem(49, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { openSimulator(player); })); - // Delete icon - swInventory.setItem(53, new SWItem(Material.BARRIER, "§cDelete", clickType -> { + // Delete tnt + swInventory.setItem(53, new SWItem(Material.BARRIER, "§cEntfernen", clickType -> { tntSimulator.tntSpawns.remove(tntSpawn); openSimulator(player); })); @@ -118,15 +116,15 @@ public class TNTSimulator { // Change Count of spawned TNT swInventory.setItem(10, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { tntSpawn.setCount(tntSpawn.getCount() + 1); - if (tntSpawn.getCount() > 1000) { - tntSpawn.setCount(1000); + if (tntSpawn.getCount() > 400) { + tntSpawn.setCount(400); } editTNT(player, tntSpawn); })); swInventory.setItem(19, new SWItem(Material.TNT, "§eAnzahl §8- §7" + tntSpawn.getCount(), LORE, false, clickType -> { changeCount(player, tntSpawn.getCount(), count -> { if (count < 1) count = 1; - if (count > 1000) count = 1000; + if (count > 400) count = 400; tntSpawn.setCount(count); editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); @@ -188,15 +186,15 @@ public class TNTSimulator { })); // Velocity Settings - swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_WOOL : Material.RED_WOOL, "§7Start §eVelocity X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> { + swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> { tntSpawn.setxVelocity(!tntSpawn.isxVelocity()); editTNT(player, tntSpawn); })); - swInventory.setItem(22, new SWItem(tntSpawn.isyVelocity() ? Material.LIME_WOOL : Material.RED_WOOL, "§7Start §eVelocity Y §8- §7" + active(tntSpawn.isyVelocity()), clickType -> { + swInventory.setItem(22, new SWItem(tntSpawn.isyVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity Y §8- §7" + active(tntSpawn.isyVelocity()), clickType -> { tntSpawn.setyVelocity(!tntSpawn.isyVelocity()); editTNT(player, tntSpawn); })); - swInventory.setItem(31, new SWItem(tntSpawn.iszVelocity() ? Material.LIME_WOOL : Material.RED_WOOL, "§7Start §eVelocity Z §8- §7" + active(tntSpawn.iszVelocity()), clickType -> { + swInventory.setItem(31, new SWItem(tntSpawn.iszVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity Z §8- §7" + active(tntSpawn.iszVelocity()), clickType -> { tntSpawn.setzVelocity(!tntSpawn.iszVelocity()); editTNT(player, tntSpawn); })); @@ -206,7 +204,7 @@ public class TNTSimulator { tntSpawn.getPosition().add(X_VECTOR); editTNT(player, tntSpawn); })); - swInventory.setItem(23, new SWItem(Material.PAPER, "§ePosition-X §8- §7" + tntSpawn.getPosition().getX(), LORE, false, clickType -> { + swInventory.setItem(23, new SWItem(Material.PAPER, "§ex-Position §8- §7" + tntSpawn.getPosition().getX(), LORE, false, clickType -> { changePosition(player, tntSpawn.getPosition().getX(), x -> { tntSpawn.getPosition().setX(clamp(x)); editTNT(player, tntSpawn); @@ -222,7 +220,7 @@ public class TNTSimulator { tntSpawn.getPosition().add(Y_VECTOR); editTNT(player, tntSpawn); })); - swInventory.setItem(24, new SWItem(Material.PAPER, "§ePosition-Y §8- §7" + tntSpawn.getPosition().getY(), LORE, false, clickType -> { + swInventory.setItem(24, new SWItem(Material.PAPER, "§ey-Position §8- §7" + tntSpawn.getPosition().getY(), LORE, false, clickType -> { changePosition(player, tntSpawn.getPosition().getY(), y -> { tntSpawn.getPosition().setY(clamp(y)); editTNT(player, tntSpawn); @@ -238,7 +236,7 @@ public class TNTSimulator { tntSpawn.getPosition().add(Z_VECTOR); editTNT(player, tntSpawn); })); - swInventory.setItem(25, new SWItem(Material.PAPER, "§ePosition-Z §8- §7" + tntSpawn.getPosition().getZ(), LORE, false, clickType -> { + swInventory.setItem(25, new SWItem(Material.PAPER, "§ez-Position §8- §7" + tntSpawn.getPosition().getZ(), LORE, false, clickType -> { changePosition(player, tntSpawn.getPosition().getZ(), z -> { tntSpawn.getPosition().setZ(clamp(z)); editTNT(player, tntSpawn); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorAnvil.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorAnvil.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorAnvil.java rename to BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorAnvil.java index b155778..1250f8b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorAnvil.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorAnvil.java @@ -19,7 +19,7 @@ * / */ -package de.steamwar.bausystem.canonsimulator; +package de.steamwar.bausystem.cannonsimulator; import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java similarity index 79% rename from BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java rename to BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java index a6c57d3..4c062bb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java @@ -19,8 +19,12 @@ * / */ -package de.steamwar.bausystem.canonsimulator; +package de.steamwar.bausystem.cannonsimulator; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Welt; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; @@ -32,11 +36,23 @@ public class TNTSimulatorListener implements Listener { private static final Vector HALF = new Vector(0.5, 0, 0.5); + private boolean permissionCheck(Player player) { + if (Welt.noPermission(player, Permission.build)) { + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Simulator nutzen"); + return false; + } + return true; + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getItem() == null) return; if (!event.getItem().isSimilar(TNTSimulator.WAND)) return; event.setCancelled(true); + if (permissionCheck(event.getPlayer())) { + return; + } + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { TNTSimulator.startSimulation(event.getPlayer()); return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java similarity index 98% rename from BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java rename to BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java index d625e2a..c71b234 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java @@ -19,7 +19,7 @@ * / */ -package de.steamwar.bausystem.canonsimulator; +package de.steamwar.bausystem.cannonsimulator; import org.bukkit.Bukkit; import org.bukkit.World; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index e4f4b8e..79443a2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -23,7 +23,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.canonsimulator.TNTSimulator; +import de.steamwar.bausystem.cannonsimulator.TNTSimulator; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor;