From a23608b1710491bfef9fd9c1c5c20c2737d9d51a Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 15:26:35 +0100 Subject: [PATCH 01/34] Add TNTSimulator --- .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../canonsimulator/TNTSimulator.java | 251 ++++++++++++++++++ .../bausystem/canonsimulator/TNTSpawn.java | 127 +++++++++ .../bausystem/commands/CommandSimulator.java | 41 +++ BauSystem_Main/src/plugin.yml | 4 +- 5 files changed, 423 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 9a7276b..0d92386 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -96,6 +96,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("detonator").setExecutor(new CommandDetonator()); getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter()); getCommand("script").setExecutor(new CommandScript()); + getCommand("simulator").setExecutor(new CommandSimulator()); Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java new file mode 100644 index 0000000..5a51c5b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java @@ -0,0 +1,251 @@ +/* + * + * 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.canonsimulator; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; + +import java.util.*; + +public class TNTSimulator { + + private static final Vector X_VECTOR = new Vector(0.0625, 0, 0); + private static final Vector NX_VECTOR = new Vector(-0.0625, 0, 0); + private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0); + 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 Map tntSimulatorMap = new HashMap<>(); + + public static void openSimulator(Player player) { + if (!tntSimulatorMap.containsKey(player)) { + tntSimulatorMap.put(player, new TNTSimulator()); + } + TNTSimulator tntSimulator = tntSimulatorMap.get(player); + + List> swListEntryList = new ArrayList<>(); + tntSimulator.tntSpawns.forEach(tntSpawn -> { + List lore = new ArrayList<>(); + lore.add("§eTNT-Anzahl§8: §7" + tntSpawn.getCount()); + lore.add("§eTick§8: §7" + tntSpawn.getTickOffset()); + lore.add(""); + 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, "§eTNT", lore, false, null), tntSpawn)); + }); + SWListInv swListInv = new SWListInv<>(player, "Kanonen Simulator", false, swListEntryList, (clickType, tntSpawn) -> { + editTNT(player, tntSpawn); + }); + swListInv.setItem(48, new SWItem(Material.BARRIER, "§cLösche alle TNT", clickType -> { + tntSimulator.tntSpawns.clear(); + openSimulator(player); + })); + swListInv.setItem(49, new SWItem(Material.TNT, "§aNeues TNT", clickType -> { + Vector vector = player.getLocation().toVector().multiply(16); + vector.setX((int) vector.getX()); + vector.setY((int) vector.getY()); + vector.setZ((int) vector.getZ()); + vector.multiply(0.0625); + + TNTSpawn tntSpawn = new TNTSpawn(vector); + if (tntSimulator.tntSpawns.contains(tntSpawn)) { + return; + } + tntSimulator.tntSpawns.add(tntSpawn); + editTNT(player, tntSpawn); + })); + swListInv.setItem(50, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation Starten", clickType -> { + tntSimulator.start(); + player.closeInventory(); + })); + swListInv.open(); + } + + private static void editTNT(Player player, TNTSpawn tntSpawn) { + SWInventory swInventory = new SWInventory(player, 45, "TNT"); + swInventory.setItem(44, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { + openSimulator(player); + })); + + // Change Count of spawned TNT + swInventory.setItem(10, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { + tntSpawn.setCount(tntSpawn.getCount() + 1); + editTNT(player, tntSpawn); + })); + swInventory.setItem(19, new SWItem(Material.TNT, "§eAnzahl §8- §7" + tntSpawn.getCount(), clickType -> { + changeCount(player, count -> { + if (count < 1) count = 1; + tntSpawn.setCount(count); + editTNT(player, tntSpawn); + }, () -> editTNT(player, tntSpawn)); + })); + swInventory.setItem(28, new SWItem(SWItem.getDye(1), "§c-1", clickType -> { + tntSpawn.setCount(tntSpawn.getCount() - 1); + if (tntSpawn.getCount() < 1) { + tntSpawn.setCount(1); + } + editTNT(player, tntSpawn); + })); + + // Change TickOffset + swInventory.setItem(11, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { + tntSpawn.setTickOffset(tntSpawn.getTickOffset() + 1); + editTNT(player, tntSpawn); + })); + swInventory.setItem(20, new SWItem(Material.CLOCK, "§eTick §8- §7" + tntSpawn.getTickOffset(), clickType -> { + changeCount(player, tick -> { + if (tick < 0) tick = 0; + tntSpawn.setTickOffset(tick); + editTNT(player, tntSpawn); + }, () -> editTNT(player, tntSpawn)); + })); + swInventory.setItem(29, new SWItem(SWItem.getDye(1), "§c-1", clickType -> { + tntSpawn.setTickOffset(tntSpawn.getTickOffset() - 1); + if (tntSpawn.getTickOffset() < 0) { + tntSpawn.setTickOffset(0); + } + editTNT(player, tntSpawn); + })); + + // Delete icon + swInventory.setItem(21, new SWItem(Material.BARRIER, "§cDelete", clickType -> { + tntSimulatorMap.get(player).tntSpawns.remove(tntSpawn); + openSimulator(player); + })); + + // Velocity Settings + swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_WOOL : Material.RED_WOOL, "§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, "§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, "§eVelocity-Z §8- §7" + active(tntSpawn.iszVelocity()), clickType -> { + tntSpawn.setzVelocity(!tntSpawn.iszVelocity()); + editTNT(player, tntSpawn); + })); + + // X Position + swInventory.setItem(14, new SWItem(SWItem.getDye(10), "§a+0,0625", clickType -> { + tntSpawn.getPosition().add(X_VECTOR); + editTNT(player, tntSpawn); + })); + swInventory.setItem(23, new SWItem(Material.PAPER, "§ePosition-X §8- §7" + tntSpawn.getPosition().getX(), clickType -> { + changePosition(player, x -> { + tntSpawn.getPosition().setX(clamp(x)); + editTNT(player, tntSpawn); + }, () -> editTNT(player, tntSpawn)); + })); + swInventory.setItem(32, new SWItem(SWItem.getDye(1), "§c-0,0625", clickType -> { + tntSpawn.getPosition().add(NX_VECTOR); + editTNT(player, tntSpawn); + })); + + // Y Position + swInventory.setItem(15, new SWItem(SWItem.getDye(10), "§a+0,0625", clickType -> { + tntSpawn.getPosition().add(Y_VECTOR); + editTNT(player, tntSpawn); + })); + swInventory.setItem(24, new SWItem(Material.PAPER, "§ePosition-Y §8- §7" + tntSpawn.getPosition().getY(), clickType -> { + changePosition(player, y -> { + tntSpawn.getPosition().setY(clamp(y)); + editTNT(player, tntSpawn); + }, () -> editTNT(player, tntSpawn)); + })); + swInventory.setItem(33, new SWItem(SWItem.getDye(1), "§c-0,0625", clickType -> { + tntSpawn.getPosition().add(NY_VECTOR); + editTNT(player, tntSpawn); + })); + + // Z Position + swInventory.setItem(16, new SWItem(SWItem.getDye(10), "§a+0,0625", clickType -> { + tntSpawn.getPosition().add(Z_VECTOR); + editTNT(player, tntSpawn); + })); + swInventory.setItem(25, new SWItem(Material.PAPER, "§ePosition-Z §8- §7" + tntSpawn.getPosition().getZ(), clickType -> { + changePosition(player, z -> { + tntSpawn.getPosition().setZ(clamp(z)); + editTNT(player, tntSpawn); + }, () -> editTNT(player, tntSpawn)); + })); + swInventory.setItem(34, new SWItem(SWItem.getDye(1), "§c-0,0625", clickType -> { + tntSpawn.getPosition().add(NZ_VECTOR); + editTNT(player, tntSpawn); + })); + swInventory.open(); + } + + private static String active(boolean b) { + return b ? "§aan" : "§caus"; + } + + private static void changeCount(Player player, Consumer result, Runnable failure) { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Zahl"); + swAnvilInv.setItem(Material.PAPER); + swAnvilInv.setCallback(s -> { + try { + result.accept(Integer.parseInt(s)); + } catch (NumberFormatException e) { + failure.run(); + } + }); + swAnvilInv.open(); + } + + private static void changePosition(Player player, Consumer result, Runnable failure) { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Position"); + swAnvilInv.setItem(Material.PAPER); + swAnvilInv.setCallback(s -> { + try { + result.accept(Double.parseDouble(s.replace(',', '.'))); + } catch (NumberFormatException e) { + failure.run(); + } + }); + swAnvilInv.open(); + } + + private static double clamp(double d) { + return (int)(d * 100) * 0.01; + } + + private Set tntSpawns = new TreeSet<>(); + + public void start() { + tntSpawns.forEach(tntSpawn -> { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), tntSpawn::spawn, tntSpawn.getTickOffset() + 1L); + }); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java new file mode 100644 index 0000000..cb93471 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java @@ -0,0 +1,127 @@ +/* + * + * 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.canonsimulator; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.util.Vector; + +import java.util.Objects; + +public class TNTSpawn implements Comparable { + + private static final World WORLD = Bukkit.getWorlds().get(0); + + private Vector position; + private int count = 1; + private int tickOffset = 0; + private boolean xVelocity = true; + private boolean yVelocity = true; + private boolean zVelocity = true; + + public TNTSpawn(Vector position) { + this.position = position; + } + + public void spawn() { + for (int i = 0; i < count; i++) { + WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { + if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); + if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); + if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); + }); + } + } + + public Vector getPosition() { + return position; + } + + public void setPosition(Vector position) { + this.position = position; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public int getTickOffset() { + return tickOffset; + } + + public void setTickOffset(int tickOffset) { + this.tickOffset = tickOffset; + } + + public boolean isxVelocity() { + return xVelocity; + } + + public void setxVelocity(boolean xVelocity) { + this.xVelocity = xVelocity; + } + + public boolean isyVelocity() { + return yVelocity; + } + + public void setyVelocity(boolean yVelocity) { + this.yVelocity = yVelocity; + } + + public boolean iszVelocity() { + return zVelocity; + } + + public void setzVelocity(boolean zVelocity) { + this.zVelocity = zVelocity; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof TNTSpawn)) return false; + TNTSpawn tntSpawn = (TNTSpawn) o; + return count == tntSpawn.count && + tickOffset == tntSpawn.tickOffset && + xVelocity == tntSpawn.xVelocity && + yVelocity == tntSpawn.yVelocity && + zVelocity == tntSpawn.zVelocity && + position.equals(tntSpawn.position); + } + + @Override + public int hashCode() { + return Objects.hash(position, count, tickOffset, xVelocity, yVelocity, zVelocity); + } + + @Override + public int compareTo(TNTSpawn tntSpawn) { + return -Integer.compare(tickOffset, tntSpawn.tickOffset); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java new file mode 100644 index 0000000..5c48636 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -0,0 +1,41 @@ +/* + * + * 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.commands; + +import de.steamwar.bausystem.canonsimulator.TNTSimulator; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandSimulator implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { + if(!(commandSender instanceof Player)) + return false; + Player p = (Player) commandSender; + TNTSimulator.openSimulator(p); + return false; + } + +} diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index bc85fb9..200cb28 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -33,4 +33,6 @@ commands: lockschem: detonator: aliases: dt - script: \ No newline at end of file + script: + simulator: + aliases: sim \ No newline at end of file From 7a8c3f20f1db965507b05297b4bdd036d5bb8f11 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 16:10:07 +0100 Subject: [PATCH 02/34] Fix TNTSet error Add TNTSpawn.fuseTicks --- .../canonsimulator/TNTSimulator.java | 49 ++++++++++++++++--- .../bausystem/canonsimulator/TNTSpawn.java | 28 ++++------- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java index 5a51c5b..f23153c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java @@ -56,12 +56,15 @@ public class TNTSimulator { List lore = new ArrayList<>(); lore.add("§eTNT-Anzahl§8: §7" + tntSpawn.getCount()); lore.add("§eTick§8: §7" + tntSpawn.getTickOffset()); + lore.add("§eFuse-Tick§8: §7" + tntSpawn.getFuseTicks()); lore.add(""); 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, "§eTNT", lore, false, null), tntSpawn)); }); + swListEntryList.sort(Comparator.comparing(SWListInv.SWListEntry::getObject)); + SWListInv swListInv = new SWListInv<>(player, "Kanonen Simulator", false, swListEntryList, (clickType, tntSpawn) -> { editTNT(player, tntSpawn); }); @@ -91,19 +94,29 @@ public class TNTSimulator { } private static void editTNT(Player player, TNTSpawn tntSpawn) { - SWInventory swInventory = new SWInventory(player, 45, "TNT"); - swInventory.setItem(44, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { + SWInventory swInventory = new SWInventory(player, 54, "TNT"); + swInventory.setItem(48, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { + openSimulator(player); + })); + + // Delete icon + swInventory.setItem(50, new SWItem(Material.BARRIER, "§cDelete", clickType -> { + tntSimulatorMap.get(player).tntSpawns.remove(tntSpawn); openSimulator(player); })); // 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); + } editTNT(player, tntSpawn); })); swInventory.setItem(19, new SWItem(Material.TNT, "§eAnzahl §8- §7" + tntSpawn.getCount(), clickType -> { changeCount(player, count -> { if (count < 1) count = 1; + if (count > 1000) count = 1000; tntSpawn.setCount(count); editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); @@ -119,11 +132,15 @@ public class TNTSimulator { // Change TickOffset swInventory.setItem(11, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { tntSpawn.setTickOffset(tntSpawn.getTickOffset() + 1); + if (tntSpawn.getTickOffset() > 8000) { + tntSpawn.setTickOffset(8000); + } editTNT(player, tntSpawn); })); swInventory.setItem(20, new SWItem(Material.CLOCK, "§eTick §8- §7" + tntSpawn.getTickOffset(), clickType -> { changeCount(player, tick -> { if (tick < 0) tick = 0; + if (tick > 8000) tick = 8000; tntSpawn.setTickOffset(tick); editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); @@ -136,10 +153,28 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); - // Delete icon - swInventory.setItem(21, new SWItem(Material.BARRIER, "§cDelete", clickType -> { - tntSimulatorMap.get(player).tntSpawns.remove(tntSpawn); - openSimulator(player); + // Change FuseTicks + swInventory.setItem(12, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { + tntSpawn.setFuseTicks(tntSpawn.getFuseTicks() + 1); + if (tntSpawn.getFuseTicks() > 80) { + tntSpawn.setFuseTicks(80); + } + editTNT(player, tntSpawn); + })); + swInventory.setItem(21, new SWItem(Material.CLOCK, "§eFuseTicks §8- §7" + tntSpawn.getFuseTicks(), clickType -> { + changeCount(player, tick -> { + if (tick < 0) tick = 0; + if (tick > 80) tick = 80; + tntSpawn.setFuseTicks(tick); + editTNT(player, tntSpawn); + }, () -> editTNT(player, tntSpawn)); + })); + swInventory.setItem(30, new SWItem(SWItem.getDye(1), "§c-1", clickType -> { + tntSpawn.setFuseTicks(tntSpawn.getFuseTicks() - 1); + if (tntSpawn.getFuseTicks() < 1) { + tntSpawn.setFuseTicks(1); + } + editTNT(player, tntSpawn); })); // Velocity Settings @@ -240,7 +275,7 @@ public class TNTSimulator { return (int)(d * 100) * 0.01; } - private Set tntSpawns = new TreeSet<>(); + private Set tntSpawns = new HashSet<>(); public void start() { tntSpawns.forEach(tntSpawn -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java index cb93471..fdbe831 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java @@ -33,6 +33,7 @@ public class TNTSpawn implements Comparable { private static final World WORLD = Bukkit.getWorlds().get(0); private Vector position; + private int fuseTicks = 80; private int count = 1; private int tickOffset = 0; private boolean xVelocity = true; @@ -46,6 +47,7 @@ public class TNTSpawn implements Comparable { public void spawn() { for (int i = 0; i < count; i++) { WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { + tntPrimed.setFuseTicks(fuseTicks); if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); @@ -61,6 +63,14 @@ public class TNTSpawn implements Comparable { this.position = position; } + public int getFuseTicks() { + return fuseTicks; + } + + public void setFuseTicks(int fuseTicks) { + this.fuseTicks = fuseTicks; + } + public int getCount() { return count; } @@ -101,24 +111,6 @@ public class TNTSpawn implements Comparable { this.zVelocity = zVelocity; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TNTSpawn)) return false; - TNTSpawn tntSpawn = (TNTSpawn) o; - return count == tntSpawn.count && - tickOffset == tntSpawn.tickOffset && - xVelocity == tntSpawn.xVelocity && - yVelocity == tntSpawn.yVelocity && - zVelocity == tntSpawn.zVelocity && - position.equals(tntSpawn.position); - } - - @Override - public int hashCode() { - return Objects.hash(position, count, tickOffset, xVelocity, yVelocity, zVelocity); - } - @Override public int compareTo(TNTSpawn tntSpawn) { return -Integer.compare(tickOffset, tntSpawn.tickOffset); From 1942a2c355f42e71b08a76cc8430082cfa6926a3 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 17:24:15 +0100 Subject: [PATCH 03/34] Add TNTSimulator.WAND Add TNTSimulatorListener Add CommandSimulatorTabCompleter Add TNTSimulatorAnvil --- .../src/de/steamwar/bausystem/BauSystem.java | 3 + .../canonsimulator/TNTSimulator.java | 65 ++++++++++++------- .../canonsimulator/TNTSimulatorAnvil.java | 61 +++++++++++++++++ .../canonsimulator/TNTSimulatorListener.java | 59 +++++++++++++++++ .../bausystem/canonsimulator/TNTSpawn.java | 2 - .../bausystem/commands/CommandSimulator.java | 9 ++- .../CommandSimulatorTabCompleter.java | 59 +++++++++++++++++ 7 files changed, 232 insertions(+), 26 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorAnvil.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 0d92386..cd8e70b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem; +import de.steamwar.bausystem.canonsimulator.TNTSimulatorListener; import de.steamwar.bausystem.commands.*; import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; @@ -97,12 +98,14 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter()); getCommand("script").setExecutor(new CommandScript()); getCommand("simulator").setExecutor(new CommandSimulator()); + getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter()); Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new ScriptListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); Bukkit.getPluginManager().registerEvents(new ClipboardListener(), this); + Bukkit.getPluginManager().registerEvents(new TNTSimulatorListener(), this); new AFKStopper(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java index f23153c..5589398 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java @@ -29,6 +29,7 @@ import de.steamwar.inventory.SWListInv; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Consumer; import org.bukkit.util.Vector; @@ -43,7 +44,9 @@ public class TNTSimulator { 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 Map tntSimulatorMap = new HashMap<>(); + 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 void openSimulator(Player player) { if (!tntSimulatorMap.containsKey(player)) { @@ -61,14 +64,14 @@ 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, "§eTNT", lore, false, null), tntSpawn)); + swListEntryList.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT, "§6TNT", lore, false, null), tntSpawn)); }); swListEntryList.sort(Comparator.comparing(SWListInv.SWListEntry::getObject)); SWListInv swListInv = new SWListInv<>(player, "Kanonen Simulator", false, swListEntryList, (clickType, tntSpawn) -> { editTNT(player, tntSpawn); }); - swListInv.setItem(48, new SWItem(Material.BARRIER, "§cLösche alle TNT", clickType -> { + swListInv.setItem(51, new SWItem(Material.BARRIER, "§cLösche alle TNT", clickType -> { tntSimulator.tntSpawns.clear(); openSimulator(player); })); @@ -86,22 +89,27 @@ public class TNTSimulator { tntSimulator.tntSpawns.add(tntSpawn); editTNT(player, tntSpawn); })); - swListInv.setItem(50, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation Starten", clickType -> { - tntSimulator.start(); + swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation Starten", clickType -> { + startSimulation(player); player.closeInventory(); })); swListInv.open(); } - private static void editTNT(Player player, TNTSpawn tntSpawn) { + static void editTNT(Player player, TNTSpawn tntSpawn) { + if (!tntSimulatorMap.containsKey(player)) { + tntSimulatorMap.put(player, new TNTSimulator()); + } + TNTSimulator tntSimulator = tntSimulatorMap.get(player); + SWInventory swInventory = new SWInventory(player, 54, "TNT"); - swInventory.setItem(48, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { + swInventory.setItem(49, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { openSimulator(player); })); // Delete icon - swInventory.setItem(50, new SWItem(Material.BARRIER, "§cDelete", clickType -> { - tntSimulatorMap.get(player).tntSpawns.remove(tntSpawn); + swInventory.setItem(53, new SWItem(Material.BARRIER, "§cDelete", clickType -> { + tntSimulator.tntSpawns.remove(tntSpawn); openSimulator(player); })); @@ -114,7 +122,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); swInventory.setItem(19, new SWItem(Material.TNT, "§eAnzahl §8- §7" + tntSpawn.getCount(), clickType -> { - changeCount(player, count -> { + changeCount(player, tntSpawn.getCount(), count -> { if (count < 1) count = 1; if (count > 1000) count = 1000; tntSpawn.setCount(count); @@ -138,7 +146,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); swInventory.setItem(20, new SWItem(Material.CLOCK, "§eTick §8- §7" + tntSpawn.getTickOffset(), clickType -> { - changeCount(player, tick -> { + changeCount(player, tntSpawn.getTickOffset(), tick -> { if (tick < 0) tick = 0; if (tick > 8000) tick = 8000; tntSpawn.setTickOffset(tick); @@ -162,7 +170,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); swInventory.setItem(21, new SWItem(Material.CLOCK, "§eFuseTicks §8- §7" + tntSpawn.getFuseTicks(), clickType -> { - changeCount(player, tick -> { + changeCount(player, tntSpawn.getFuseTicks(), tick -> { if (tick < 0) tick = 0; if (tick > 80) tick = 80; tntSpawn.setFuseTicks(tick); @@ -178,15 +186,15 @@ public class TNTSimulator { })); // Velocity Settings - swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_WOOL : Material.RED_WOOL, "§eVelocity-X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> { + swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_WOOL : Material.RED_WOOL, "§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, "§eVelocity-Y §8- §7" + active(tntSpawn.isyVelocity()), clickType -> { + swInventory.setItem(22, new SWItem(tntSpawn.isyVelocity() ? Material.LIME_WOOL : Material.RED_WOOL, "§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, "§eVelocity-Z §8- §7" + active(tntSpawn.iszVelocity()), clickType -> { + swInventory.setItem(31, new SWItem(tntSpawn.iszVelocity() ? Material.LIME_WOOL : Material.RED_WOOL, "§7Start §eVelocity Z §8- §7" + active(tntSpawn.iszVelocity()), clickType -> { tntSpawn.setzVelocity(!tntSpawn.iszVelocity()); editTNT(player, tntSpawn); })); @@ -197,7 +205,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); swInventory.setItem(23, new SWItem(Material.PAPER, "§ePosition-X §8- §7" + tntSpawn.getPosition().getX(), clickType -> { - changePosition(player, x -> { + changePosition(player, tntSpawn.getPosition().getX(), x -> { tntSpawn.getPosition().setX(clamp(x)); editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); @@ -213,7 +221,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); swInventory.setItem(24, new SWItem(Material.PAPER, "§ePosition-Y §8- §7" + tntSpawn.getPosition().getY(), clickType -> { - changePosition(player, y -> { + changePosition(player, tntSpawn.getPosition().getY(), y -> { tntSpawn.getPosition().setY(clamp(y)); editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); @@ -229,7 +237,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); swInventory.setItem(25, new SWItem(Material.PAPER, "§ePosition-Z §8- §7" + tntSpawn.getPosition().getZ(), clickType -> { - changePosition(player, z -> { + changePosition(player, tntSpawn.getPosition().getZ(), z -> { tntSpawn.getPosition().setZ(clamp(z)); editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); @@ -241,12 +249,25 @@ public class TNTSimulator { swInventory.open(); } + static void startSimulation(Player player) { + if (tntSimulatorMap.containsKey(player)) { + tntSimulatorMap.get(player).start(); + } + } + + static void addTNT(Player player, TNTSpawn tntSpawn) { + if (!tntSimulatorMap.containsKey(player)) { + tntSimulatorMap.put(player, new TNTSimulator()); + } + tntSimulatorMap.get(player).tntSpawns.add(tntSpawn); + } + private static String active(boolean b) { return b ? "§aan" : "§caus"; } - private static void changeCount(Player player, Consumer result, Runnable failure) { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Zahl"); + private static void changeCount(Player player, int defaultValue, Consumer result, Runnable failure) { + TNTSimulatorAnvil swAnvilInv = new TNTSimulatorAnvil(player, "Zahl", defaultValue + ""); swAnvilInv.setItem(Material.PAPER); swAnvilInv.setCallback(s -> { try { @@ -258,8 +279,8 @@ public class TNTSimulator { swAnvilInv.open(); } - private static void changePosition(Player player, Consumer result, Runnable failure) { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Position"); + private static void changePosition(Player player, double defaultValue, Consumer result, Runnable failure) { + TNTSimulatorAnvil swAnvilInv = new TNTSimulatorAnvil(player, "Position", defaultValue + ""); swAnvilInv.setItem(Material.PAPER); swAnvilInv.setCallback(s -> { try { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorAnvil.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorAnvil.java new file mode 100644 index 0000000..b155778 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorAnvil.java @@ -0,0 +1,61 @@ +/* + * + * 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.canonsimulator; + +import de.steamwar.core.Core; +import de.steamwar.inventory.SWItem; +import net.wesjd.anvilgui.AnvilGUI; +import net.wesjd.anvilgui.AnvilGUI.Response; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.function.Consumer; + +public class TNTSimulatorAnvil { + + private final AnvilGUI.Builder builder; + private final Player player; + private Consumer callback; + + public TNTSimulatorAnvil(Player p, String t, String defaultValue) { + this.builder = (new AnvilGUI.Builder()).plugin(Core.getInstance()).title(t).text("" + defaultValue).onComplete(this::onResult); + this.player = p; + } + + public void setItem(Material m) { + this.builder.itemLeft((new SWItem(m, "").getItemStack())); + } + + public void setCallback(Consumer callback) { + this.callback = callback; + } + + public void open() { + this.builder.open(this.player); + } + + private Response onResult(Player player, String s) { + this.callback.accept(s); + return Response.close(); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java new file mode 100644 index 0000000..7df0fe8 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java @@ -0,0 +1,59 @@ +/* + * + * 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.canonsimulator; + +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.PlayerQuitEvent; +import org.bukkit.util.Vector; + +public class TNTSimulatorListener implements Listener { + + private static final Vector HALF = new Vector(0.5, 0.5, 0.5); + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getItem() == null) return; + if (!event.getItem().isSimilar(TNTSimulator.WAND)) return; + event.setCancelled(true); + if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { + TNTSimulator.startSimulation(event.getPlayer()); + return; + } + if (event.getClickedBlock() == null) { + TNTSimulator.openSimulator(event.getPlayer()); + return; + } + Vector location = event.getClickedBlock().getLocation().toVector().add(event.getBlockFace().getDirection()).add(HALF); + TNTSpawn tntSpawn = new TNTSpawn(location); + TNTSimulator.addTNT(event.getPlayer(), tntSpawn); + TNTSimulator.editTNT(event.getPlayer(), tntSpawn); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + TNTSimulator.tntSimulatorMap.remove(event.getPlayer()); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java index fdbe831..d625e2a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSpawn.java @@ -26,8 +26,6 @@ import org.bukkit.World; import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; -import java.util.Objects; - public class TNTSpawn implements Comparable { private static final World WORLD = Bukkit.getWorlds().get(0); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index 5c48636..35cfb36 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -33,8 +33,13 @@ public class CommandSimulator implements CommandExecutor { public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { if(!(commandSender instanceof Player)) return false; - Player p = (Player) commandSender; - TNTSimulator.openSimulator(p); + Player player = (Player) commandSender; + if (args.length == 1 && args[0].equalsIgnoreCase("wand")) { + player.getInventory().setItemInMainHand(TNTSimulator.WAND); + player.updateInventory(); + return false; + } + TNTSimulator.openSimulator(player); return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java new file mode 100644 index 0000000..6ef43f4 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java @@ -0,0 +1,59 @@ +/* + * + * 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.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class CommandSimulatorTabCompleter implements TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) return new ArrayList<>(); + return detonaterTabComplete((Player) sender, args); + } + + private List detonaterTabComplete(Player player, String[] args) { + List tabComplete = new ArrayList<>(); + tabComplete.add("wand"); + + if (args.length >= 2) { + return new ArrayList<>(); + } + return manageList(tabComplete, args, 0); + } + + private List manageList(List strings, String[] args, int index) { + for (int i = strings.size() - 1; i >= 0; i--) { + if (!strings.get(i).startsWith(args[index])) { + strings.remove(i); + } + } + return strings; + } + +} From d5ed63f9385ee70b72b7852fbcf60802bca47167 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 17:37:05 +0100 Subject: [PATCH 04/34] Add TNTSimulator.LORE --- .../bausystem/canonsimulator/TNTSimulator.java | 16 +++++++++------- .../canonsimulator/TNTSimulatorListener.java | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java index 5589398..5d5e8c2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.canonsimulator; import de.steamwar.bausystem.BauSystem; -import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; @@ -43,6 +42,7 @@ 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 = Arrays.asList("§7Klicken zum ändern"); static Map tntSimulatorMap = new HashMap<>(); @@ -57,6 +57,8 @@ public class TNTSimulator { List> swListEntryList = new ArrayList<>(); tntSimulator.tntSpawns.forEach(tntSpawn -> { List lore = new ArrayList<>(); + lore.add("§7Klicken zum einstellen"); + lore.add(""); lore.add("§eTNT-Anzahl§8: §7" + tntSpawn.getCount()); lore.add("§eTick§8: §7" + tntSpawn.getTickOffset()); lore.add("§eFuse-Tick§8: §7" + tntSpawn.getFuseTicks()); @@ -121,7 +123,7 @@ public class TNTSimulator { } editTNT(player, tntSpawn); })); - swInventory.setItem(19, new SWItem(Material.TNT, "§eAnzahl §8- §7" + tntSpawn.getCount(), clickType -> { + 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; @@ -145,7 +147,7 @@ public class TNTSimulator { } editTNT(player, tntSpawn); })); - swInventory.setItem(20, new SWItem(Material.CLOCK, "§eTick §8- §7" + tntSpawn.getTickOffset(), clickType -> { + swInventory.setItem(20, new SWItem(Material.CLOCK, "§eTick §8- §7" + tntSpawn.getTickOffset(), LORE, false, clickType -> { changeCount(player, tntSpawn.getTickOffset(), tick -> { if (tick < 0) tick = 0; if (tick > 8000) tick = 8000; @@ -169,7 +171,7 @@ public class TNTSimulator { } editTNT(player, tntSpawn); })); - swInventory.setItem(21, new SWItem(Material.CLOCK, "§eFuseTicks §8- §7" + tntSpawn.getFuseTicks(), clickType -> { + swInventory.setItem(21, new SWItem(Material.CLOCK, "§eFuseTicks §8- §7" + tntSpawn.getFuseTicks(), LORE, false, clickType -> { changeCount(player, tntSpawn.getFuseTicks(), tick -> { if (tick < 0) tick = 0; if (tick > 80) tick = 80; @@ -204,7 +206,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(), clickType -> { + swInventory.setItem(23, new SWItem(Material.PAPER, "§ePosition-X §8- §7" + tntSpawn.getPosition().getX(), LORE, false, clickType -> { changePosition(player, tntSpawn.getPosition().getX(), x -> { tntSpawn.getPosition().setX(clamp(x)); editTNT(player, tntSpawn); @@ -220,7 +222,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(), clickType -> { + swInventory.setItem(24, new SWItem(Material.PAPER, "§ePosition-Y §8- §7" + tntSpawn.getPosition().getY(), LORE, false, clickType -> { changePosition(player, tntSpawn.getPosition().getY(), y -> { tntSpawn.getPosition().setY(clamp(y)); editTNT(player, tntSpawn); @@ -236,7 +238,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(), clickType -> { + swInventory.setItem(25, new SWItem(Material.PAPER, "§ePosition-Z §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/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java index 7df0fe8..a6c57d3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulatorListener.java @@ -30,7 +30,7 @@ import org.bukkit.util.Vector; public class TNTSimulatorListener implements Listener { - private static final Vector HALF = new Vector(0.5, 0.5, 0.5); + private static final Vector HALF = new Vector(0.5, 0, 0.5); @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { From e1271442238eecf8003f069c58002203e907cb27 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 17:51:44 +0100 Subject: [PATCH 05/34] Add CommandSimulator.permissionCheck --- .../bausystem/commands/CommandSimulator.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index 35cfb36..e4f4b8e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -21,7 +21,10 @@ 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.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -29,11 +32,23 @@ import org.bukkit.entity.Player; public class CommandSimulator implements CommandExecutor { + 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; + } + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { - if(!(commandSender instanceof Player)) + if (!(commandSender instanceof Player)) return false; Player player = (Player) commandSender; + if (permissionCheck(player)) { + return false; + } + if (args.length == 1 && args[0].equalsIgnoreCase("wand")) { player.getInventory().setItemInMainHand(TNTSimulator.WAND); player.updateInventory(); From b5f0dde9d18ea1880c6620d11389daf11dc1a5db Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 17:53:05 +0100 Subject: [PATCH 06/34] Optimize TNTSimulator --- .../src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java index 5d5e8c2..ca96905 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/canonsimulator/TNTSimulator.java @@ -42,7 +42,7 @@ 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 = Arrays.asList("§7Klicken zum ändern"); + private static final List LORE = Collections.singletonList("§7Klicken zum ändern"); static Map tntSimulatorMap = new HashMap<>(); From 870fc285e7cddfe9479f13fe87eff293bbb9efe1 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 18:55:13 +0100 Subject: [PATCH 07/34] 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; From bbdf02594b522071f500f17c0a0b9d0098978132 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 20:28:45 +0100 Subject: [PATCH 08/34] Add TNTSpawn naming --- .../bausystem/cannonsimulator/TNTSimulator.java | 15 +++++++++++++-- .../cannonsimulator/TNTSimulatorListener.java | 2 +- .../bausystem/cannonsimulator/TNTSpawn.java | 9 +++++++++ .../bausystem/commands/CommandSimulator.java | 16 ++++++++++++---- .../commands/CommandSimulatorTabCompleter.java | 1 + 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java index 9810a89..36c2a8e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.cannonsimulator; import de.steamwar.bausystem.BauSystem; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; @@ -102,7 +103,7 @@ public class TNTSimulator { static void editTNT(Player player, TNTSpawn tntSpawn) { TNTSimulator tntSimulator = get(player); - SWInventory swInventory = new SWInventory(player, 54, "TNT"); + SWInventory swInventory = new SWInventory(player, 54, "TNT" + (tntSpawn.getName().isEmpty() ? "§8- §e" + tntSpawn.getName() : "")); swInventory.setItem(49, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { openSimulator(player); })); @@ -113,6 +114,16 @@ public class TNTSimulator { openSimulator(player); })); + // tnt Name + swInventory.setItem(45, new SWItem(Material.NAME_TAG, "§eName", clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Name"); + swAnvilInv.setCallback(s -> { + tntSpawn.setName(s); + editTNT(player, tntSpawn); + }); + swAnvilInv.open(); + })); + // Change Count of spawned TNT swInventory.setItem(10, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { tntSpawn.setCount(tntSpawn.getCount() + 1); @@ -293,7 +304,7 @@ public class TNTSimulator { } private static double clamp(double d) { - return (int)(d * 100) * 0.01; + return (int)(d * 10000) * 0.0001; } private Set tntSpawns = new HashSet<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java index 4c062bb..a72fd68 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java @@ -49,7 +49,7 @@ public class TNTSimulatorListener implements Listener { if (event.getItem() == null) return; if (!event.getItem().isSimilar(TNTSimulator.WAND)) return; event.setCancelled(true); - if (permissionCheck(event.getPlayer())) { + if (!permissionCheck(event.getPlayer())) { return; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java index c71b234..2c6ca4c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java @@ -30,6 +30,7 @@ public class TNTSpawn implements Comparable { private static final World WORLD = Bukkit.getWorlds().get(0); + private String name = ""; private Vector position; private int fuseTicks = 80; private int count = 1; @@ -53,6 +54,14 @@ public class TNTSpawn implements Comparable { } } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + public Vector getPosition() { return position; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index 79443a2..c351462 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.cannonsimulator.TNTSimulator; import de.steamwar.bausystem.world.Welt; +import org.bukkit.block.data.type.TNT; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -45,13 +46,20 @@ public class CommandSimulator implements CommandExecutor { if (!(commandSender instanceof Player)) return false; Player player = (Player) commandSender; - if (permissionCheck(player)) { + if (!permissionCheck(player)) { return false; } - if (args.length == 1 && args[0].equalsIgnoreCase("wand")) { - player.getInventory().setItemInMainHand(TNTSimulator.WAND); - player.updateInventory(); + if (args.length == 1) { + switch (args[0].toLowerCase()) { + case "wand": + player.getInventory().setItemInMainHand(TNTSimulator.WAND); + player.updateInventory(); + break; + case "start": + TNTSimulator.get(player).start(); + break; + } return false; } TNTSimulator.openSimulator(player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java index 6ef43f4..de34b0c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java @@ -40,6 +40,7 @@ public class CommandSimulatorTabCompleter implements TabCompleter { private List detonaterTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); tabComplete.add("wand"); + tabComplete.add("start"); if (args.length >= 2) { return new ArrayList<>(); From 12ed389ae371076991c57dab3930e8018feba0f7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 20:30:24 +0100 Subject: [PATCH 09/34] Add TNTSpawn naming --- .../steamwar/bausystem/cannonsimulator/TNTSimulator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java index 36c2a8e..e1aae1a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java @@ -103,7 +103,7 @@ public class TNTSimulator { static void editTNT(Player player, TNTSpawn tntSpawn) { TNTSimulator tntSimulator = get(player); - SWInventory swInventory = new SWInventory(player, 54, "TNT" + (tntSpawn.getName().isEmpty() ? "§8- §e" + tntSpawn.getName() : "")); + SWInventory swInventory = new SWInventory(player, 54, "TNT" + (!tntSpawn.getName().isEmpty() ? "§8- §e" + tntSpawn.getName() : "")); swInventory.setItem(49, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { openSimulator(player); })); @@ -116,12 +116,12 @@ public class TNTSimulator { // tnt Name swInventory.setItem(45, new SWItem(Material.NAME_TAG, "§eName", clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Name"); - swAnvilInv.setCallback(s -> { + TNTSimulatorAnvil tntSimulatorAnvil = new TNTSimulatorAnvil(player, "Name", tntSpawn.getName()); + tntSimulatorAnvil.setCallback(s -> { tntSpawn.setName(s); editTNT(player, tntSpawn); }); - swAnvilInv.open(); + tntSimulatorAnvil.open(); })); // Change Count of spawned TNT From 43b90684158c7b97289f1d32c6d1de8e73b24187 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 20:31:26 +0100 Subject: [PATCH 10/34] Fix TNT naming --- .../src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java index e1aae1a..2e7a46a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java @@ -103,7 +103,7 @@ public class TNTSimulator { static void editTNT(Player player, TNTSpawn tntSpawn) { TNTSimulator tntSimulator = get(player); - SWInventory swInventory = new SWInventory(player, 54, "TNT" + (!tntSpawn.getName().isEmpty() ? "§8- §e" + tntSpawn.getName() : "")); + SWInventory swInventory = new SWInventory(player, 54, "TNT" + (!tntSpawn.getName().isEmpty() ? " - " + tntSpawn.getName() : "")); swInventory.setItem(49, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { openSimulator(player); })); From 99ed270424be875f5ba8a299409b5b8654745838 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 20:32:53 +0100 Subject: [PATCH 11/34] Fix TNT naming --- .../de/steamwar/bausystem/cannonsimulator/TNTSimulator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java index 2e7a46a..81ce7c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java @@ -116,8 +116,9 @@ public class TNTSimulator { // tnt Name swInventory.setItem(45, new SWItem(Material.NAME_TAG, "§eName", clickType -> { - TNTSimulatorAnvil tntSimulatorAnvil = new TNTSimulatorAnvil(player, "Name", tntSpawn.getName()); + TNTSimulatorAnvil tntSimulatorAnvil = new TNTSimulatorAnvil(player, "Name", "»" + tntSpawn.getName()); tntSimulatorAnvil.setCallback(s -> { + if (s.startsWith("»")) s = s.substring(1); tntSpawn.setName(s); editTNT(player, tntSpawn); }); From 8ccb282e17a43d7160f4576b3a827f4a396c128f Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 21:04:47 +0100 Subject: [PATCH 12/34] Fix TNTSimulator name --- .../src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java index 81ce7c6..498807a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java @@ -68,7 +68,7 @@ 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, "§eTNT", lore, false, null), tntSpawn)); + swListEntryList.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT, "§eTNT" + (!tntSpawn.getName().isEmpty() ? " §8- §e" + tntSpawn.getName() : ""), lore, false, null), tntSpawn)); }); swListEntryList.sort(Comparator.comparing(SWListInv.SWListEntry::getObject)); From 9373fe21f7be0ea89bcba226b7c2117773444773 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 21:06:32 +0100 Subject: [PATCH 13/34] Fix TNTSimulatorListener permission check --- .../bausystem/cannonsimulator/TNTSimulatorListener.java | 2 +- .../src/de/steamwar/bausystem/commands/CommandSimulator.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java index a72fd68..49dc743 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java @@ -37,7 +37,7 @@ 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)) { + if (Welt.noPermission(player, Permission.world)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Simulator nutzen"); return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index c351462..8e86f61 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.cannonsimulator.TNTSimulator; import de.steamwar.bausystem.world.Welt; -import org.bukkit.block.data.type.TNT; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -34,7 +33,7 @@ import org.bukkit.entity.Player; public class CommandSimulator implements CommandExecutor { private boolean permissionCheck(Player player) { - if (Welt.noPermission(player, Permission.build)) { + if (Welt.noPermission(player, Permission.world)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Simulator nutzen"); return false; } From cc929b88a7466035b2ac894cce7fb8a08c53f3e7 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 20 Jan 2021 23:42:04 +0100 Subject: [PATCH 14/34] Add TNTSimulator 0tick simulation capabilities --- .../cannonsimulator/TNTSimulator.java | 46 ++++++++++++++++++- .../bausystem/cannonsimulator/TNTSpawn.java | 23 ++++++---- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java index 498807a..c716b98 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java @@ -22,7 +22,6 @@ package de.steamwar.bausystem.cannonsimulator; import de.steamwar.bausystem.BauSystem; -import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; @@ -34,6 +33,7 @@ import org.bukkit.util.Consumer; import org.bukkit.util.Vector; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; public class TNTSimulator { @@ -197,6 +197,12 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); + // Repeater before Comparator + swInventory.setItem(4, new SWItem(tntSpawn.isComparator() ? Material.COMPARATOR : Material.REPEATER, "§7Gezündet durch §8- §e" + (tntSpawn.isComparator() ? "Comparator" : "Repeater"), clickType -> { + tntSpawn.setComparator(!tntSpawn.isComparator()); + editTNT(player, tntSpawn); + })); + // Velocity Settings 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()); @@ -310,10 +316,46 @@ public class TNTSimulator { private Set tntSpawns = new HashSet<>(); + private static class TNTSpawnPair { + + private int countLeft; + private TNTSpawn tntSpawn; + + public TNTSpawnPair(int countLeft, TNTSpawn tntSpawn) { + this.countLeft = countLeft; + this.tntSpawn = tntSpawn; + } + + private void spawn() { + tntSpawn.spawn(); + countLeft--; + } + + } + public void start() { + Map[]> tntSpawnMap = new HashMap<>(); tntSpawns.forEach(tntSpawn -> { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), tntSpawn::spawn, tntSpawn.getTickOffset() + 1L); + tntSpawnMap.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList[]{new ArrayList<>(), new ArrayList<>()})[tntSpawn.isComparator() ? 1 : 0].add(new TNTSpawnPair(tntSpawn.getCount(), tntSpawn)); + }); + tntSpawnMap.forEach((integer, tntSpawnPairs) -> { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + spawnRandomList(tntSpawnPairs[0]); + spawnRandomList(tntSpawnPairs[1]); + }, integer + 1L); }); } + private void spawnRandomList(List tntSpawnPairs) { + AtomicInteger index = new AtomicInteger(tntSpawnPairs.size() - 1); + while (!tntSpawnPairs.isEmpty()) { + TNTSpawnPair tntSpawnPair = tntSpawnPairs.get(index.get()); + tntSpawnPair.spawn(); + if (tntSpawnPair.countLeft <= 0) { + tntSpawnPairs.remove(index.get()); + } + if (index.decrementAndGet() < 0) index.set(tntSpawnPairs.size() - 1); + } + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java index 2c6ca4c..3a27cc3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java @@ -38,20 +38,19 @@ public class TNTSpawn implements Comparable { private boolean xVelocity = true; private boolean yVelocity = true; private boolean zVelocity = true; + private boolean comparator = false; public TNTSpawn(Vector position) { this.position = position; } public void spawn() { - for (int i = 0; i < count; i++) { - WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { - tntPrimed.setFuseTicks(fuseTicks); - if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); - if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); - if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); - }); - } + WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { + tntPrimed.setFuseTicks(fuseTicks); + if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); + if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); + if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); + }); } public String getName() { @@ -118,6 +117,14 @@ public class TNTSpawn implements Comparable { this.zVelocity = zVelocity; } + public boolean isComparator() { + return comparator; + } + + public void setComparator(boolean comparator) { + this.comparator = comparator; + } + @Override public int compareTo(TNTSpawn tntSpawn) { return -Integer.compare(tickOffset, tntSpawn.tickOffset); From 6c030c1f9dcdbf65a0e6687a34eb2de92e338de6 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 22 Jan 2021 16:35:40 +0100 Subject: [PATCH 15/34] Remove TNTSimulatorAnvil.java --- .../cannonsimulator/TNTSimulator.java | 7 ++- .../cannonsimulator/TNTSimulatorAnvil.java | 61 ------------------- 2 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorAnvil.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java index c716b98..ee7be08 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.cannonsimulator; import de.steamwar.bausystem.BauSystem; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; @@ -116,7 +117,7 @@ public class TNTSimulator { // tnt Name swInventory.setItem(45, new SWItem(Material.NAME_TAG, "§eName", clickType -> { - TNTSimulatorAnvil tntSimulatorAnvil = new TNTSimulatorAnvil(player, "Name", "»" + tntSpawn.getName()); + SWAnvilInv tntSimulatorAnvil = new SWAnvilInv(player, "Name", tntSpawn.getName()); tntSimulatorAnvil.setCallback(s -> { if (s.startsWith("»")) s = s.substring(1); tntSpawn.setName(s); @@ -285,7 +286,7 @@ public class TNTSimulator { } private static void changeCount(Player player, int defaultValue, Consumer result, Runnable failure) { - TNTSimulatorAnvil swAnvilInv = new TNTSimulatorAnvil(player, "Zahl", defaultValue + ""); + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Zahl", defaultValue + ""); swAnvilInv.setItem(Material.PAPER); swAnvilInv.setCallback(s -> { try { @@ -298,7 +299,7 @@ public class TNTSimulator { } private static void changePosition(Player player, double defaultValue, Consumer result, Runnable failure) { - TNTSimulatorAnvil swAnvilInv = new TNTSimulatorAnvil(player, "Position", defaultValue + ""); + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Position", defaultValue + ""); swAnvilInv.setItem(Material.PAPER); swAnvilInv.setCallback(s -> { try { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorAnvil.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorAnvil.java deleted file mode 100644 index 1250f8b..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorAnvil.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - * 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.cannonsimulator; - -import de.steamwar.core.Core; -import de.steamwar.inventory.SWItem; -import net.wesjd.anvilgui.AnvilGUI; -import net.wesjd.anvilgui.AnvilGUI.Response; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -import java.util.function.Consumer; - -public class TNTSimulatorAnvil { - - private final AnvilGUI.Builder builder; - private final Player player; - private Consumer callback; - - public TNTSimulatorAnvil(Player p, String t, String defaultValue) { - this.builder = (new AnvilGUI.Builder()).plugin(Core.getInstance()).title(t).text("" + defaultValue).onComplete(this::onResult); - this.player = p; - } - - public void setItem(Material m) { - this.builder.itemLeft((new SWItem(m, "").getItemStack())); - } - - public void setCallback(Consumer callback) { - this.callback = callback; - } - - public void open() { - this.builder.open(this.player); - } - - private Response onResult(Player player, String s) { - this.callback.accept(s); - return Response.close(); - } - -} From a219bfc7b01198b27341973f34b717b61cf216f8 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 28 Jan 2021 10:40:33 +0100 Subject: [PATCH 16/34] Simplify TNTSimulator --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/cannonsimulator/TNTSpawn.java | 133 --------------- .../bausystem/commands/CommandSimulator.java | 11 +- .../TNTSimulator.java | 160 +++++++++++++++--- .../TNTSimulatorListener.java | 17 +- 5 files changed, 153 insertions(+), 170 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java rename BauSystem_Main/src/de/steamwar/bausystem/{cannonsimulator => world}/TNTSimulator.java (76%) rename BauSystem_Main/src/de/steamwar/bausystem/{cannonsimulator => world}/TNTSimulatorListener.java (83%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index e1191a2..cd69556 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.cannonsimulator.TNTSimulatorListener; +import de.steamwar.bausystem.world.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/cannonsimulator/TNTSpawn.java b/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java deleted file mode 100644 index 3a27cc3..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSpawn.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * 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.cannonsimulator; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.util.Vector; - -public class TNTSpawn implements Comparable { - - private static final World WORLD = Bukkit.getWorlds().get(0); - - private String name = ""; - private Vector position; - private int fuseTicks = 80; - private int count = 1; - private int tickOffset = 0; - private boolean xVelocity = true; - private boolean yVelocity = true; - private boolean zVelocity = true; - private boolean comparator = false; - - public TNTSpawn(Vector position) { - this.position = position; - } - - public void spawn() { - WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { - tntPrimed.setFuseTicks(fuseTicks); - if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); - if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); - if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); - }); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Vector getPosition() { - return position; - } - - public void setPosition(Vector position) { - this.position = position; - } - - public int getFuseTicks() { - return fuseTicks; - } - - public void setFuseTicks(int fuseTicks) { - this.fuseTicks = fuseTicks; - } - - public int getCount() { - return count; - } - - public void setCount(int count) { - this.count = count; - } - - public int getTickOffset() { - return tickOffset; - } - - public void setTickOffset(int tickOffset) { - this.tickOffset = tickOffset; - } - - public boolean isxVelocity() { - return xVelocity; - } - - public void setxVelocity(boolean xVelocity) { - this.xVelocity = xVelocity; - } - - public boolean isyVelocity() { - return yVelocity; - } - - public void setyVelocity(boolean yVelocity) { - this.yVelocity = yVelocity; - } - - public boolean iszVelocity() { - return zVelocity; - } - - public void setzVelocity(boolean zVelocity) { - this.zVelocity = zVelocity; - } - - public boolean isComparator() { - return comparator; - } - - public void setComparator(boolean comparator) { - this.comparator = comparator; - } - - @Override - public int compareTo(TNTSpawn tntSpawn) { - return -Integer.compare(tickOffset, tntSpawn.tickOffset); - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index 8e86f61..e6fe493 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.cannonsimulator.TNTSimulator; +import de.steamwar.bausystem.world.TNTSimulator; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -32,6 +32,12 @@ import org.bukkit.entity.Player; public class CommandSimulator implements CommandExecutor { + private void help(Player player) { + player.sendMessage("§8/§esimulator §8- §7Öffnet die Simulations GUI"); + player.sendMessage("§8/§esimulator start §8- §7Startet die Simulation"); + player.sendMessage("§8/§esimulator wand §8- §7Legt den Simulator ins Inventar"); + } + private boolean permissionCheck(Player player) { if (Welt.noPermission(player, Permission.world)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Simulator nutzen"); @@ -58,6 +64,9 @@ public class CommandSimulator implements CommandExecutor { case "start": TNTSimulator.get(player).start(); break; + default: + help(player); + break; } return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java similarity index 76% rename from BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java rename to BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index ee7be08..b1e5495 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -19,7 +19,7 @@ * / */ -package de.steamwar.bausystem.cannonsimulator; +package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWAnvilInv; @@ -28,13 +28,14 @@ import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Consumer; import org.bukkit.util.Vector; import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; public class TNTSimulator { @@ -46,19 +47,20 @@ public class TNTSimulator { private static final Vector NZ_VECTOR = new Vector(0, 0, -0.0625); private static final List LORE = Collections.singletonList("§7Zum ändern klicken"); - static Map tntSimulatorMap = new HashMap<>(); + static final Map TNT_SIMULATOR_MAP = new HashMap<>(); + private final Set TNT_SPAWNS = new HashSet<>(); 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()); + return TNT_SIMULATOR_MAP.computeIfAbsent(player, p -> new TNTSimulator()); } public static void openSimulator(Player player) { TNTSimulator tntSimulator = get(player); List> swListEntryList = new ArrayList<>(); - tntSimulator.tntSpawns.forEach(tntSpawn -> { + tntSimulator.TNT_SPAWNS.forEach(tntSpawn -> { List lore = new ArrayList<>(); lore.add("§7Klicken zum einstellen"); lore.add(""); @@ -77,7 +79,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); }); swListInv.setItem(51, new SWItem(Material.BARRIER, "§cLösche alle TNT", clickType -> { - tntSimulator.tntSpawns.clear(); + tntSimulator.TNT_SPAWNS.clear(); openSimulator(player); })); swListInv.setItem(49, new SWItem(Material.TNT, "§aNeues TNT", clickType -> { @@ -88,10 +90,10 @@ public class TNTSimulator { vector.multiply(0.0625); TNTSpawn tntSpawn = new TNTSpawn(vector); - if (tntSimulator.tntSpawns.contains(tntSpawn)) { + if (tntSimulator.TNT_SPAWNS.contains(tntSpawn)) { return; } - tntSimulator.tntSpawns.add(tntSpawn); + tntSimulator.TNT_SPAWNS.add(tntSpawn); editTNT(player, tntSpawn); })); swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation starten", clickType -> { @@ -111,7 +113,7 @@ public class TNTSimulator { // Delete tnt swInventory.setItem(53, new SWItem(Material.BARRIER, "§cEntfernen", clickType -> { - tntSimulator.tntSpawns.remove(tntSpawn); + tntSimulator.TNT_SPAWNS.remove(tntSpawn); openSimulator(player); })); @@ -135,7 +137,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); swInventory.setItem(19, new SWItem(Material.TNT, "§eAnzahl §8- §7" + tntSpawn.getCount(), LORE, false, clickType -> { - changeCount(player, tntSpawn.getCount(), count -> { + changeCount(player, "Anzahl TNT", tntSpawn.getCount(), count -> { if (count < 1) count = 1; if (count > 400) count = 400; tntSpawn.setCount(count); @@ -159,7 +161,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); })); swInventory.setItem(20, new SWItem(Material.CLOCK, "§eTick §8- §7" + tntSpawn.getTickOffset(), LORE, false, clickType -> { - changeCount(player, tntSpawn.getTickOffset(), tick -> { + changeCount(player, "Tick Offset", tntSpawn.getTickOffset(), tick -> { if (tick < 0) tick = 0; if (tick > 8000) tick = 8000; tntSpawn.setTickOffset(tick); @@ -182,8 +184,8 @@ public class TNTSimulator { } editTNT(player, tntSpawn); })); - swInventory.setItem(21, new SWItem(Material.CLOCK, "§eFuseTicks §8- §7" + tntSpawn.getFuseTicks(), LORE, false, clickType -> { - changeCount(player, tntSpawn.getFuseTicks(), tick -> { + swInventory.setItem(21, new SWItem(Material.CLOCK, "§eFuse-Ticks §8- §7" + tntSpawn.getFuseTicks(), LORE, false, clickType -> { + changeCount(player, "Fuse-Ticks", tntSpawn.getFuseTicks(), tick -> { if (tick < 0) tick = 0; if (tick > 80) tick = 80; tntSpawn.setFuseTicks(tick); @@ -269,24 +271,24 @@ public class TNTSimulator { } static void startSimulation(Player player) { - if (tntSimulatorMap.containsKey(player)) { - tntSimulatorMap.get(player).start(); + if (TNT_SIMULATOR_MAP.containsKey(player)) { + TNT_SIMULATOR_MAP.get(player).start(); } } static void addTNT(Player player, TNTSpawn tntSpawn) { - if (!tntSimulatorMap.containsKey(player)) { - tntSimulatorMap.put(player, new TNTSimulator()); + if (!TNT_SIMULATOR_MAP.containsKey(player)) { + TNT_SIMULATOR_MAP.put(player, new TNTSimulator()); } - tntSimulatorMap.get(player).tntSpawns.add(tntSpawn); + TNT_SIMULATOR_MAP.get(player).TNT_SPAWNS.add(tntSpawn); } private static String active(boolean b) { return b ? "§aan" : "§caus"; } - private static void changeCount(Player player, int defaultValue, Consumer result, Runnable failure) { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Zahl", defaultValue + ""); + private static void changeCount(Player player, String name, int defaultValue, Consumer result, Runnable failure) { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, name, defaultValue + ""); swAnvilInv.setItem(Material.PAPER); swAnvilInv.setCallback(s -> { try { @@ -315,8 +317,6 @@ public class TNTSimulator { return (int)(d * 10000) * 0.0001; } - private Set tntSpawns = new HashSet<>(); - private static class TNTSpawnPair { private int countLeft; @@ -336,7 +336,7 @@ public class TNTSimulator { public void start() { Map[]> tntSpawnMap = new HashMap<>(); - tntSpawns.forEach(tntSpawn -> { + TNT_SPAWNS.forEach(tntSpawn -> { tntSpawnMap.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList[]{new ArrayList<>(), new ArrayList<>()})[tntSpawn.isComparator() ? 1 : 0].add(new TNTSpawnPair(tntSpawn.getCount(), tntSpawn)); }); tntSpawnMap.forEach((integer, tntSpawnPairs) -> { @@ -348,15 +348,121 @@ public class TNTSimulator { } private void spawnRandomList(List tntSpawnPairs) { - AtomicInteger index = new AtomicInteger(tntSpawnPairs.size() - 1); + int index = tntSpawnPairs.size() - 1; while (!tntSpawnPairs.isEmpty()) { - TNTSpawnPair tntSpawnPair = tntSpawnPairs.get(index.get()); + TNTSpawnPair tntSpawnPair = tntSpawnPairs.get(index); tntSpawnPair.spawn(); if (tntSpawnPair.countLeft <= 0) { - tntSpawnPairs.remove(index.get()); + tntSpawnPairs.remove(index); } - if (index.decrementAndGet() < 0) index.set(tntSpawnPairs.size() - 1); + if (--index < 0) index = tntSpawnPairs.size() - 1; } } + public static class TNTSpawn implements Comparable { + + private static final World WORLD = Bukkit.getWorlds().get(0); + + private String name = ""; + private Vector position; + private int fuseTicks = 80; + private int count = 1; + private int tickOffset = 0; + private boolean xVelocity = true; + private boolean yVelocity = true; + private boolean zVelocity = true; + private boolean comparator = false; + + public TNTSpawn(Vector position) { + this.position = position; + } + + public void spawn() { + WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { + tntPrimed.setFuseTicks(fuseTicks); + if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); + if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); + if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); + }); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Vector getPosition() { + return position; + } + + public void setPosition(Vector position) { + this.position = position; + } + + public int getFuseTicks() { + return fuseTicks; + } + + public void setFuseTicks(int fuseTicks) { + this.fuseTicks = fuseTicks; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public int getTickOffset() { + return tickOffset; + } + + public void setTickOffset(int tickOffset) { + this.tickOffset = tickOffset; + } + + public boolean isxVelocity() { + return xVelocity; + } + + public void setxVelocity(boolean xVelocity) { + this.xVelocity = xVelocity; + } + + public boolean isyVelocity() { + return yVelocity; + } + + public void setyVelocity(boolean yVelocity) { + this.yVelocity = yVelocity; + } + + public boolean iszVelocity() { + return zVelocity; + } + + public void setzVelocity(boolean zVelocity) { + this.zVelocity = zVelocity; + } + + public boolean isComparator() { + return comparator; + } + + public void setComparator(boolean comparator) { + this.comparator = comparator; + } + + @Override + public int compareTo(TNTSpawn tntSpawn) { + return -Integer.compare(tickOffset, tntSpawn.tickOffset); + } + + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java similarity index 83% rename from BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java rename to BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java index 49dc743..b6e26b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/cannonsimulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java @@ -19,11 +19,10 @@ * / */ -package de.steamwar.bausystem.cannonsimulator; +package de.steamwar.bausystem.world; 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; @@ -32,6 +31,8 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.util.Vector; +import static de.steamwar.bausystem.world.TNTSimulator.*; + public class TNTSimulatorListener implements Listener { private static final Vector HALF = new Vector(0.5, 0, 0.5); @@ -47,29 +48,29 @@ public class TNTSimulatorListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getItem() == null) return; - if (!event.getItem().isSimilar(TNTSimulator.WAND)) return; + if (!event.getItem().isSimilar(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()); + startSimulation(event.getPlayer()); return; } if (event.getClickedBlock() == null) { - TNTSimulator.openSimulator(event.getPlayer()); + openSimulator(event.getPlayer()); return; } Vector location = event.getClickedBlock().getLocation().toVector().add(event.getBlockFace().getDirection()).add(HALF); TNTSpawn tntSpawn = new TNTSpawn(location); - TNTSimulator.addTNT(event.getPlayer(), tntSpawn); - TNTSimulator.editTNT(event.getPlayer(), tntSpawn); + addTNT(event.getPlayer(), tntSpawn); + editTNT(event.getPlayer(), tntSpawn); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - TNTSimulator.tntSimulatorMap.remove(event.getPlayer()); + TNT_SIMULATOR_MAP.remove(event.getPlayer()); } } From 4f1307cc8d7152cad44b61bf3f6b0e2aeb9c5ca5 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 31 Jan 2021 13:29:39 +0100 Subject: [PATCH 17/34] Fix pr stuff --- .../bausystem/world/TNTSimulator.java | 45 +++++-------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index b1e5495..fc2a2d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -50,7 +50,7 @@ public class TNTSimulator { static final Map TNT_SIMULATOR_MAP = new HashMap<>(); private final Set TNT_SPAWNS = new HashSet<>(); - 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 final ItemStack WAND = new SWItem(Material.TRIPWIRE_HOOK, "§eKanonensimulator", 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 TNT_SIMULATOR_MAP.computeIfAbsent(player, p -> new TNTSimulator()); @@ -62,15 +62,15 @@ public class TNTSimulator { List> swListEntryList = new ArrayList<>(); tntSimulator.TNT_SPAWNS.forEach(tntSpawn -> { List lore = new ArrayList<>(); - lore.add("§7Klicken zum einstellen"); + lore.add("§7Klicken zum Konfigurieren"); lore.add(""); - lore.add("§eTNT-Anzahl§8: §7" + tntSpawn.getCount()); - lore.add("§eTick§8: §7" + tntSpawn.getTickOffset()); - lore.add("§eFuse-Tick§8: §7" + tntSpawn.getFuseTicks()); + lore.add("§7TNT-Anzahl§8: §e" + tntSpawn.getCount()); + lore.add("§7Tick§8: §e" + tntSpawn.getTickOffset()); + lore.add("§7Fuse-Tick§8: §e" + tntSpawn.getFuseTicks()); lore.add(""); - lore.add("§eX§8: §7" + tntSpawn.getPosition().getX()); - lore.add("§eY§8: §7" + tntSpawn.getPosition().getY()); - lore.add("§eZ§8: §7" + tntSpawn.getPosition().getZ()); + lore.add("§7X§8: §e" + tntSpawn.getPosition().getX()); + lore.add("§7Y§8: §e" + tntSpawn.getPosition().getY()); + lore.add("§7Z§8: §e" + tntSpawn.getPosition().getZ()); swListEntryList.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT, "§eTNT" + (!tntSpawn.getName().isEmpty() ? " §8- §e" + tntSpawn.getName() : ""), lore, false, null), tntSpawn)); }); swListEntryList.sort(Comparator.comparing(SWListInv.SWListEntry::getObject)); @@ -82,20 +82,6 @@ public class TNTSimulator { tntSimulator.TNT_SPAWNS.clear(); openSimulator(player); })); - swListInv.setItem(49, new SWItem(Material.TNT, "§aNeues TNT", clickType -> { - Vector vector = player.getLocation().toVector().multiply(16); - vector.setX((int) vector.getX()); - vector.setY((int) vector.getY()); - vector.setZ((int) vector.getZ()); - vector.multiply(0.0625); - - TNTSpawn tntSpawn = new TNTSpawn(vector); - if (tntSimulator.TNT_SPAWNS.contains(tntSpawn)) { - return; - } - tntSimulator.TNT_SPAWNS.add(tntSpawn); - editTNT(player, tntSpawn); - })); swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation starten", clickType -> { startSimulation(player); player.closeInventory(); @@ -271,16 +257,11 @@ public class TNTSimulator { } static void startSimulation(Player player) { - if (TNT_SIMULATOR_MAP.containsKey(player)) { - TNT_SIMULATOR_MAP.get(player).start(); - } + TNT_SIMULATOR_MAP.getOrDefault(player, new TNTSimulator()).start(); } static void addTNT(Player player, TNTSpawn tntSpawn) { - if (!TNT_SIMULATOR_MAP.containsKey(player)) { - TNT_SIMULATOR_MAP.put(player, new TNTSimulator()); - } - TNT_SIMULATOR_MAP.get(player).TNT_SPAWNS.add(tntSpawn); + TNT_SIMULATOR_MAP.computeIfAbsent(player, player1 -> new TNTSimulator()).TNT_SPAWNS.add(tntSpawn); } private static String active(boolean b) { @@ -364,7 +345,7 @@ public class TNTSimulator { private static final World WORLD = Bukkit.getWorlds().get(0); private String name = ""; - private Vector position; + private final Vector position; private int fuseTicks = 80; private int count = 1; private int tickOffset = 0; @@ -398,10 +379,6 @@ public class TNTSimulator { return position; } - public void setPosition(Vector position) { - this.position = position; - } - public int getFuseTicks() { return fuseTicks; } From f977837175334d7dab2c8350825cf6c7673d7e03 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 3 Feb 2021 16:53:37 +0100 Subject: [PATCH 18/34] Simplify TNTSimulator.start --- .../bausystem/world/TNTSimulator.java | 52 +++++++------------ 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index fc2a2d4..73130b8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -46,6 +46,7 @@ public class TNTSimulator { 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("§7Zum ändern klicken"); + private static final List EMPTY = new ArrayList<>(); static final Map TNT_SIMULATOR_MAP = new HashMap<>(); private final Set TNT_SPAWNS = new HashSet<>(); @@ -298,45 +299,30 @@ public class TNTSimulator { return (int)(d * 10000) * 0.0001; } - private static class TNTSpawnPair { - - private int countLeft; - private TNTSpawn tntSpawn; - - public TNTSpawnPair(int countLeft, TNTSpawn tntSpawn) { - this.countLeft = countLeft; - this.tntSpawn = tntSpawn; - } - - private void spawn() { - tntSpawn.spawn(); - countLeft--; - } - - } - public void start() { - Map[]> tntSpawnMap = new HashMap<>(); + Map> first = new HashMap<>(); + Map> second = new HashMap<>(); TNT_SPAWNS.forEach(tntSpawn -> { - tntSpawnMap.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList[]{new ArrayList<>(), new ArrayList<>()})[tntSpawn.isComparator() ? 1 : 0].add(new TNTSpawnPair(tntSpawn.getCount(), tntSpawn)); + Map> list = tntSpawn.isComparator() ? second : first; + for (int i = 0; i < tntSpawn.getCount(); i++) { + list.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList<>()).add(tntSpawn); + } }); - tntSpawnMap.forEach((integer, tntSpawnPairs) -> { + Set ticks = new HashSet<>(first.keySet()); + ticks.addAll(second.keySet()); + for (int tick : ticks) { Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - spawnRandomList(tntSpawnPairs[0]); - spawnRandomList(tntSpawnPairs[1]); - }, integer + 1L); - }); + spawnRandomList(first.getOrDefault(tick, EMPTY)); + spawnRandomList(second.getOrDefault(tick, EMPTY)); + }, tick + 1L); + } } - private void spawnRandomList(List tntSpawnPairs) { - int index = tntSpawnPairs.size() - 1; - while (!tntSpawnPairs.isEmpty()) { - TNTSpawnPair tntSpawnPair = tntSpawnPairs.get(index); - tntSpawnPair.spawn(); - if (tntSpawnPair.countLeft <= 0) { - tntSpawnPairs.remove(index); - } - if (--index < 0) index = tntSpawnPairs.size() - 1; + private void spawnRandomList(List tntSpawns) { + if (tntSpawns.isEmpty()) return; + Collections.shuffle(tntSpawns); + for (TNTSpawn tntSpawn : tntSpawns) { + tntSpawn.spawn(); } } From bcb964fdb47357ba04528cfaa104a794ad41b466 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 4 Feb 2021 20:24:51 +0100 Subject: [PATCH 19/34] Change TNTSimulator --- .../src/de/steamwar/bausystem/world/TNTSimulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index 73130b8..82f4812 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -51,7 +51,7 @@ public class TNTSimulator { static final Map TNT_SIMULATOR_MAP = new HashMap<>(); private final Set TNT_SPAWNS = new HashSet<>(); - public static final ItemStack WAND = new SWItem(Material.TRIPWIRE_HOOK, "§eKanonensimulator", 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 final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eKanonensimulator", 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 TNT_SIMULATOR_MAP.computeIfAbsent(player, p -> new TNTSimulator()); From de28cc9c1d9ae297f64760c6126bb436bf8f580d Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 8 Feb 2021 20:48:45 +0100 Subject: [PATCH 20/34] Fix pr stuff --- .../src/de/steamwar/bausystem/world/TNTSimulator.java | 8 +++++--- .../de/steamwar/bausystem/world/TNTSimulatorListener.java | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index 82f4812..98f7cb6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -50,6 +50,7 @@ public class TNTSimulator { static final Map TNT_SIMULATOR_MAP = new HashMap<>(); private final Set TNT_SPAWNS = new HashSet<>(); + private int number = 0; public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eKanonensimulator", 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(); @@ -84,8 +85,8 @@ public class TNTSimulator { openSimulator(player); })); swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation starten", clickType -> { - startSimulation(player); player.closeInventory(); + startSimulation(player); })); swListInv.open(); } @@ -108,7 +109,6 @@ public class TNTSimulator { swInventory.setItem(45, new SWItem(Material.NAME_TAG, "§eName", clickType -> { SWAnvilInv tntSimulatorAnvil = new SWAnvilInv(player, "Name", tntSpawn.getName()); tntSimulatorAnvil.setCallback(s -> { - if (s.startsWith("»")) s = s.substring(1); tntSpawn.setName(s); editTNT(player, tntSpawn); }); @@ -262,7 +262,9 @@ public class TNTSimulator { } static void addTNT(Player player, TNTSpawn tntSpawn) { - TNT_SIMULATOR_MAP.computeIfAbsent(player, player1 -> new TNTSimulator()).TNT_SPAWNS.add(tntSpawn); + TNTSimulator tntSimulator = TNT_SIMULATOR_MAP.computeIfAbsent(player, player1 -> new TNTSimulator()); + if (tntSpawn.name.isEmpty()) tntSpawn.name = (++tntSimulator.number) + ""; + tntSimulator.TNT_SPAWNS.add(tntSpawn); } private static String active(boolean b) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java index b6e26b6..a0210ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java @@ -47,8 +47,12 @@ public class TNTSimulatorListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - if (event.getItem() == null) return; - if (!event.getItem().isSimilar(WAND)) return; + if (event.getItem() == null) { + return; + } + if (!event.getItem().isSimilar(WAND)) { + return; + } event.setCancelled(true); if (!permissionCheck(event.getPlayer())) { return; From a16a2999627f2d875f4602793a2fa849ebbf696b Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 11 Feb 2021 19:47:40 +0100 Subject: [PATCH 21/34] Fix pr stuff --- .../bausystem/commands/CommandSimulator.java | 8 ++++++-- .../CommandSimulatorTabCompleter.java | 1 - .../bausystem/world/TNTSimulator.java | 20 +++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index e6fe493..73771ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -16,7 +16,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * / */ package de.steamwar.bausystem.commands; @@ -25,6 +24,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.TNTSimulator; 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; @@ -58,7 +58,11 @@ public class CommandSimulator implements CommandExecutor { if (args.length == 1) { switch (args[0].toLowerCase()) { case "wand": - player.getInventory().setItemInMainHand(TNTSimulator.WAND); + if (player.getInventory().getItemInMainHand().getType() == Material.AIR) { + player.getInventory().setItemInMainHand(TNTSimulator.WAND); + } else { + player.getInventory().addItem(TNTSimulator.WAND); + } player.updateInventory(); break; case "start": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java index de34b0c..dea9982 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java @@ -16,7 +16,6 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . - * / */ package de.steamwar.bausystem.commands; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index 98f7cb6..f294bbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -36,6 +36,7 @@ import org.bukkit.util.Consumer; import org.bukkit.util.Vector; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; public class TNTSimulator { @@ -304,20 +305,23 @@ public class TNTSimulator { public void start() { Map> first = new HashMap<>(); Map> second = new HashMap<>(); + AtomicInteger lastTick = new AtomicInteger(0); TNT_SPAWNS.forEach(tntSpawn -> { Map> list = tntSpawn.isComparator() ? second : first; for (int i = 0; i < tntSpawn.getCount(); i++) { list.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList<>()).add(tntSpawn); } + if (lastTick.get() < tntSpawn.getTickOffset()) { + lastTick.set(tntSpawn.getTickOffset()); + } }); - Set ticks = new HashSet<>(first.keySet()); - ticks.addAll(second.keySet()); - for (int tick : ticks) { - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - spawnRandomList(first.getOrDefault(tick, EMPTY)); - spawnRandomList(second.getOrDefault(tick, EMPTY)); - }, tick + 1L); - } + AtomicInteger currentTick = new AtomicInteger(0); + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + int tick = currentTick.get(); + spawnRandomList(first.getOrDefault(tick, EMPTY)); + spawnRandomList(second.getOrDefault(tick, EMPTY)); + currentTick.incrementAndGet(); + }, 1, 1); } private void spawnRandomList(List tntSpawns) { From e6417bd57873a696914fcaa870e7fbabaf5646de Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 12 Feb 2021 11:01:58 +0100 Subject: [PATCH 22/34] Fix pr stuff --- .../CommandSimulatorTabCompleter.java | 4 +-- .../bausystem/world/TNTSimulator.java | 30 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java index dea9982..65841e7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java @@ -33,10 +33,10 @@ public class CommandSimulatorTabCompleter implements TabCompleter { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return new ArrayList<>(); - return detonaterTabComplete((Player) sender, args); + return simulatorTabComplete((Player) sender, args); } - private List detonaterTabComplete(Player player, String[] args) { + private List simulatorTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); tabComplete.add("wand"); tabComplete.add("start"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index f294bbd..d537811 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -117,7 +117,7 @@ public class TNTSimulator { })); // Change Count of spawned TNT - swInventory.setItem(10, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { + swInventory.setItem(10, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { tntSpawn.setCount(tntSpawn.getCount() + 1); if (tntSpawn.getCount() > 400) { tntSpawn.setCount(400); @@ -132,7 +132,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); })); - swInventory.setItem(28, new SWItem(SWItem.getDye(1), "§c-1", clickType -> { + swInventory.setItem(28, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { tntSpawn.setCount(tntSpawn.getCount() - 1); if (tntSpawn.getCount() < 1) { tntSpawn.setCount(1); @@ -141,7 +141,7 @@ public class TNTSimulator { })); // Change TickOffset - swInventory.setItem(11, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { + swInventory.setItem(11, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { tntSpawn.setTickOffset(tntSpawn.getTickOffset() + 1); if (tntSpawn.getTickOffset() > 8000) { tntSpawn.setTickOffset(8000); @@ -156,7 +156,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); })); - swInventory.setItem(29, new SWItem(SWItem.getDye(1), "§c-1", clickType -> { + swInventory.setItem(29, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { tntSpawn.setTickOffset(tntSpawn.getTickOffset() - 1); if (tntSpawn.getTickOffset() < 0) { tntSpawn.setTickOffset(0); @@ -165,7 +165,7 @@ public class TNTSimulator { })); // Change FuseTicks - swInventory.setItem(12, new SWItem(SWItem.getDye(10), "§a+1", clickType -> { + swInventory.setItem(12, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { tntSpawn.setFuseTicks(tntSpawn.getFuseTicks() + 1); if (tntSpawn.getFuseTicks() > 80) { tntSpawn.setFuseTicks(80); @@ -180,7 +180,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); })); - swInventory.setItem(30, new SWItem(SWItem.getDye(1), "§c-1", clickType -> { + swInventory.setItem(30, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { tntSpawn.setFuseTicks(tntSpawn.getFuseTicks() - 1); if (tntSpawn.getFuseTicks() < 1) { tntSpawn.setFuseTicks(1); @@ -195,21 +195,21 @@ public class TNTSimulator { })); // Velocity Settings - swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> { + swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> { tntSpawn.setxVelocity(!tntSpawn.isxVelocity()); editTNT(player, tntSpawn); })); - swInventory.setItem(22, new SWItem(tntSpawn.isyVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity Y §8- §7" + active(tntSpawn.isyVelocity()), clickType -> { + swInventory.setItem(22, new SWItem(tntSpawn.isyVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung Y §8- §7" + active(tntSpawn.isyVelocity()), clickType -> { tntSpawn.setyVelocity(!tntSpawn.isyVelocity()); editTNT(player, tntSpawn); })); - swInventory.setItem(31, new SWItem(tntSpawn.iszVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity Z §8- §7" + active(tntSpawn.iszVelocity()), clickType -> { + swInventory.setItem(31, new SWItem(tntSpawn.iszVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung Z §8- §7" + active(tntSpawn.iszVelocity()), clickType -> { tntSpawn.setzVelocity(!tntSpawn.iszVelocity()); editTNT(player, tntSpawn); })); // X Position - swInventory.setItem(14, new SWItem(SWItem.getDye(10), "§a+0,0625", clickType -> { + swInventory.setItem(14, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { tntSpawn.getPosition().add(X_VECTOR); editTNT(player, tntSpawn); })); @@ -219,13 +219,13 @@ public class TNTSimulator { editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); })); - swInventory.setItem(32, new SWItem(SWItem.getDye(1), "§c-0,0625", clickType -> { + swInventory.setItem(32, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { tntSpawn.getPosition().add(NX_VECTOR); editTNT(player, tntSpawn); })); // Y Position - swInventory.setItem(15, new SWItem(SWItem.getDye(10), "§a+0,0625", clickType -> { + swInventory.setItem(15, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { tntSpawn.getPosition().add(Y_VECTOR); editTNT(player, tntSpawn); })); @@ -235,13 +235,13 @@ public class TNTSimulator { editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); })); - swInventory.setItem(33, new SWItem(SWItem.getDye(1), "§c-0,0625", clickType -> { + swInventory.setItem(33, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { tntSpawn.getPosition().add(NY_VECTOR); editTNT(player, tntSpawn); })); // Z Position - swInventory.setItem(16, new SWItem(SWItem.getDye(10), "§a+0,0625", clickType -> { + swInventory.setItem(16, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { tntSpawn.getPosition().add(Z_VECTOR); editTNT(player, tntSpawn); })); @@ -251,7 +251,7 @@ public class TNTSimulator { editTNT(player, tntSpawn); }, () -> editTNT(player, tntSpawn)); })); - swInventory.setItem(34, new SWItem(SWItem.getDye(1), "§c-0,0625", clickType -> { + swInventory.setItem(34, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { tntSpawn.getPosition().add(NZ_VECTOR); editTNT(player, tntSpawn); })); From 3f39066209f91f9f97562332c83e5a8841755a04 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 12 Feb 2021 16:20:22 +0100 Subject: [PATCH 23/34] Fix pr stuff --- .../de/steamwar/bausystem/world/TNTSimulator.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index d537811..b59b814 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -32,11 +32,13 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.Consumer; import org.bukkit.util.Vector; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; public class TNTSimulator { @@ -195,15 +197,15 @@ public class TNTSimulator { })); // Velocity Settings - swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> { + swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung X §8- " + active(tntSpawn.isxVelocity()), clickType -> { tntSpawn.setxVelocity(!tntSpawn.isxVelocity()); editTNT(player, tntSpawn); })); - swInventory.setItem(22, new SWItem(tntSpawn.isyVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung Y §8- §7" + active(tntSpawn.isyVelocity()), clickType -> { + swInventory.setItem(22, new SWItem(tntSpawn.isyVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung Y §8- " + active(tntSpawn.isyVelocity()), clickType -> { tntSpawn.setyVelocity(!tntSpawn.isyVelocity()); editTNT(player, tntSpawn); })); - swInventory.setItem(31, new SWItem(tntSpawn.iszVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung Z §8- §7" + active(tntSpawn.iszVelocity()), clickType -> { + swInventory.setItem(31, new SWItem(tntSpawn.iszVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung Z §8- " + active(tntSpawn.iszVelocity()), clickType -> { tntSpawn.setzVelocity(!tntSpawn.iszVelocity()); editTNT(player, tntSpawn); })); @@ -316,12 +318,15 @@ public class TNTSimulator { } }); AtomicInteger currentTick = new AtomicInteger(0); - Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + AtomicReference taskCanceler = new AtomicReference<>(() -> {}); + BukkitTask bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { int tick = currentTick.get(); spawnRandomList(first.getOrDefault(tick, EMPTY)); spawnRandomList(second.getOrDefault(tick, EMPTY)); + if (tick > lastTick.get()) taskCanceler.get().run(); currentTick.incrementAndGet(); }, 1, 1); + taskCanceler.set(bukkitTask::cancel); } private void spawnRandomList(List tntSpawns) { From b523747394aa60ef176e07f124e3fcf89a515e00 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 12 Feb 2021 17:06:53 +0100 Subject: [PATCH 24/34] Fix pr stuff --- .../bausystem/world/TNTSimulatorListener.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java index a0210ac..80ca456 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java @@ -58,18 +58,23 @@ public class TNTSimulatorListener implements Listener { return; } - if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) { - startSimulation(event.getPlayer()); - return; + switch (event.getAction()) { + case LEFT_CLICK_BLOCK: + case LEFT_CLICK_AIR: + startSimulation(event.getPlayer()); + break; + case RIGHT_CLICK_BLOCK: + Vector location = event.getClickedBlock().getLocation().toVector().add(event.getBlockFace().getDirection()).add(HALF); + TNTSpawn tntSpawn = new TNTSpawn(location); + addTNT(event.getPlayer(), tntSpawn); + editTNT(event.getPlayer(), tntSpawn); + break; + case RIGHT_CLICK_AIR: + openSimulator(event.getPlayer()); + break; + default: + break; } - if (event.getClickedBlock() == null) { - openSimulator(event.getPlayer()); - return; - } - Vector location = event.getClickedBlock().getLocation().toVector().add(event.getBlockFace().getDirection()).add(HALF); - TNTSpawn tntSpawn = new TNTSpawn(location); - addTNT(event.getPlayer(), tntSpawn); - editTNT(event.getPlayer(), tntSpawn); } @EventHandler From dbcadcfa0c729feb0c8008c72f3699e117007e09 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 14 Feb 2021 11:24:06 +0100 Subject: [PATCH 25/34] Fix pr stuff --- .../de/steamwar/bausystem/commands/CommandSimulator.java | 4 ++-- .../src/de/steamwar/bausystem/world/TNTSimulator.java | 8 ++------ .../de/steamwar/bausystem/world/TNTSimulatorListener.java | 1 - 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index 73771ac..8a9f47d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -33,9 +33,9 @@ import org.bukkit.entity.Player; public class CommandSimulator implements CommandExecutor { private void help(Player player) { - player.sendMessage("§8/§esimulator §8- §7Öffnet die Simulations GUI"); + player.sendMessage("§8/§esimulator §8- §7Öffnet das Simulations GUI"); player.sendMessage("§8/§esimulator start §8- §7Startet die Simulation"); - player.sendMessage("§8/§esimulator wand §8- §7Legt den Simulator ins Inventar"); + player.sendMessage("§8/§esimulator wand §8- §7Legt den Simulatorstab ins Inventar"); } private boolean permissionCheck(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index b59b814..5710297 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -32,13 +32,11 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.Consumer; import org.bukkit.util.Vector; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; public class TNTSimulator { @@ -318,15 +316,13 @@ public class TNTSimulator { } }); AtomicInteger currentTick = new AtomicInteger(0); - AtomicReference taskCanceler = new AtomicReference<>(() -> {}); - BukkitTask bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), bukkitTask -> { int tick = currentTick.get(); spawnRandomList(first.getOrDefault(tick, EMPTY)); spawnRandomList(second.getOrDefault(tick, EMPTY)); - if (tick > lastTick.get()) taskCanceler.get().run(); + if (tick > lastTick.get()) bukkitTask.cancel(); currentTick.incrementAndGet(); }, 1, 1); - taskCanceler.set(bukkitTask::cancel); } private void spawnRandomList(List tntSpawns) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java index 80ca456..e0af211 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulatorListener.java @@ -26,7 +26,6 @@ import de.steamwar.bausystem.Permission; 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.event.player.PlayerQuitEvent; import org.bukkit.util.Vector; From 38eef6f0a1b155c4d97b2d4a54d7ee11b796356e Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 14 Feb 2021 14:47:39 +0100 Subject: [PATCH 26/34] Fix pr stuff --- .../de/steamwar/bausystem/world/TNTSimulator.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index 5710297..f0ed328 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -124,7 +124,7 @@ public class TNTSimulator { } editTNT(player, tntSpawn); })); - swInventory.setItem(19, new SWItem(Material.TNT, "§eAnzahl §8- §7" + tntSpawn.getCount(), LORE, false, clickType -> { + swInventory.setItem(19, new SWItem(Material.TNT, "§7Anzahl §8- §e" + tntSpawn.getCount(), LORE, false, clickType -> { changeCount(player, "Anzahl TNT", tntSpawn.getCount(), count -> { if (count < 1) count = 1; if (count > 400) count = 400; @@ -148,7 +148,7 @@ public class TNTSimulator { } editTNT(player, tntSpawn); })); - swInventory.setItem(20, new SWItem(Material.CLOCK, "§eTick §8- §7" + tntSpawn.getTickOffset(), LORE, false, clickType -> { + swInventory.setItem(20, new SWItem(Material.CLOCK, "§7Tick §8- §e" + tntSpawn.getTickOffset(), LORE, false, clickType -> { changeCount(player, "Tick Offset", tntSpawn.getTickOffset(), tick -> { if (tick < 0) tick = 0; if (tick > 8000) tick = 8000; @@ -172,7 +172,7 @@ public class TNTSimulator { } editTNT(player, tntSpawn); })); - swInventory.setItem(21, new SWItem(Material.CLOCK, "§eFuse-Ticks §8- §7" + tntSpawn.getFuseTicks(), LORE, false, clickType -> { + swInventory.setItem(21, new SWItem(Material.CLOCK, "§7Fuse-Ticks §8- §e" + tntSpawn.getFuseTicks(), LORE, false, clickType -> { changeCount(player, "Fuse-Ticks", tntSpawn.getFuseTicks(), tick -> { if (tick < 0) tick = 0; if (tick > 80) tick = 80; @@ -213,7 +213,7 @@ public class TNTSimulator { tntSpawn.getPosition().add(X_VECTOR); editTNT(player, tntSpawn); })); - swInventory.setItem(23, new SWItem(Material.PAPER, "§ex-Position §8- §7" + tntSpawn.getPosition().getX(), LORE, false, clickType -> { + swInventory.setItem(23, new SWItem(Material.PAPER, "§7x-Position §8- §e" + tntSpawn.getPosition().getX(), LORE, false, clickType -> { changePosition(player, tntSpawn.getPosition().getX(), x -> { tntSpawn.getPosition().setX(clamp(x)); editTNT(player, tntSpawn); @@ -229,7 +229,7 @@ public class TNTSimulator { tntSpawn.getPosition().add(Y_VECTOR); editTNT(player, tntSpawn); })); - swInventory.setItem(24, new SWItem(Material.PAPER, "§ey-Position §8- §7" + tntSpawn.getPosition().getY(), LORE, false, clickType -> { + swInventory.setItem(24, new SWItem(Material.PAPER, "§7y-Position §8- §e" + tntSpawn.getPosition().getY(), LORE, false, clickType -> { changePosition(player, tntSpawn.getPosition().getY(), y -> { tntSpawn.getPosition().setY(clamp(y)); editTNT(player, tntSpawn); @@ -245,7 +245,7 @@ public class TNTSimulator { tntSpawn.getPosition().add(Z_VECTOR); editTNT(player, tntSpawn); })); - swInventory.setItem(25, new SWItem(Material.PAPER, "§ez-Position §8- §7" + tntSpawn.getPosition().getZ(), LORE, false, clickType -> { + swInventory.setItem(25, new SWItem(Material.PAPER, "§7z-Position §8- §e" + tntSpawn.getPosition().getZ(), LORE, false, clickType -> { changePosition(player, tntSpawn.getPosition().getZ(), z -> { tntSpawn.getPosition().setZ(clamp(z)); editTNT(player, tntSpawn); From 67b40433d80dfa8e76b96b017bee61ae37fad67a Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 16 Feb 2021 11:47:13 +0100 Subject: [PATCH 27/34] Fix pr stuff --- .../bausystem/world/TNTSimulator_12.java | 42 ++++++++++++++++++ .../bausystem/world/TNTSimulator_15.java | 43 +++++++++++++++++++ .../bausystem/world/TNTSimulator.java | 25 +++++++++-- 3 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java new file mode 100644 index 0000000..abd0ba1 --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java @@ -0,0 +1,42 @@ +/* + * 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.world; + +import org.bukkit.Material; + +public class TNTSimulator_12 { + + public static Material active() { + return Material.CONCRETE; + } + + public static Material notActive() { + return Material.CONCRETE; + } + + public static Material repeater() { + return Material.DIODE; + } + + public static Material comparator() { + return Material.REDSTONE_COMPARATOR; + } + +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java new file mode 100644 index 0000000..7042a86 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java @@ -0,0 +1,43 @@ +/* + * + * 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.world; + +import org.bukkit.Material; + +public class TNTSimulator_15 { + + public static Material active() { + return Material.LIME_CONCRETE; + } + + public static Material notActive() { + return Material.RED_CONCRETE; + } + + public static Material repeater() { + return Material.REPEATER; + } + + public static Material comparator() { + return Material.COMPARATOR; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index f0ed328..dc02da4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.VersionedCallable; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -189,21 +190,21 @@ public class TNTSimulator { })); // Repeater before Comparator - swInventory.setItem(4, new SWItem(tntSpawn.isComparator() ? Material.COMPARATOR : Material.REPEATER, "§7Gezündet durch §8- §e" + (tntSpawn.isComparator() ? "Comparator" : "Repeater"), clickType -> { + swInventory.setItem(4, new SWItem(comparatorOrNot(tntSpawn.isComparator()), "§7Gezündet durch §8- §e" + (tntSpawn.isComparator() ? "Comparator" : "Repeater"), clickType -> { tntSpawn.setComparator(!tntSpawn.isComparator()); editTNT(player, tntSpawn); })); // Velocity Settings - swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung X §8- " + active(tntSpawn.isxVelocity()), clickType -> { + swInventory.setItem(13, new SWItem(activeOrNot(tntSpawn.isxVelocity()), "§7TNT §eSprung X §8- " + active(tntSpawn.isxVelocity()), clickType -> { tntSpawn.setxVelocity(!tntSpawn.isxVelocity()); editTNT(player, tntSpawn); })); - swInventory.setItem(22, new SWItem(tntSpawn.isyVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung Y §8- " + active(tntSpawn.isyVelocity()), clickType -> { + swInventory.setItem(22, new SWItem(activeOrNot(tntSpawn.isyVelocity()), "§7TNT §eSprung Y §8- " + active(tntSpawn.isyVelocity()), clickType -> { tntSpawn.setyVelocity(!tntSpawn.isyVelocity()); editTNT(player, tntSpawn); })); - swInventory.setItem(31, new SWItem(tntSpawn.iszVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7TNT §eSprung Z §8- " + active(tntSpawn.iszVelocity()), clickType -> { + swInventory.setItem(31, new SWItem(activeOrNot(tntSpawn.iszVelocity()), "§7TNT §eSprung Z §8- " + active(tntSpawn.iszVelocity()), clickType -> { tntSpawn.setzVelocity(!tntSpawn.iszVelocity()); editTNT(player, tntSpawn); })); @@ -268,6 +269,22 @@ public class TNTSimulator { tntSimulator.TNT_SPAWNS.add(tntSpawn); } + private static Material comparatorOrNot(boolean b) { + if (b) { + return VersionedCallable.call(new VersionedCallable<>(TNTSimulator_12::comparator, 8), new VersionedCallable<>(TNTSimulator_15::comparator, 14)); + } else { + return VersionedCallable.call(new VersionedCallable<>(TNTSimulator_12::repeater, 8), new VersionedCallable<>(TNTSimulator_15::repeater, 14)); + } + } + + private static Material activeOrNot(boolean b) { + if (b) { + return VersionedCallable.call(new VersionedCallable<>(TNTSimulator_12::active, 8), new VersionedCallable<>(TNTSimulator_15::active, 14)); + } else { + return VersionedCallable.call(new VersionedCallable<>(TNTSimulator_12::notActive, 8), new VersionedCallable<>(TNTSimulator_15::notActive, 14)); + } + } + private static String active(boolean b) { return b ? "§aan" : "§caus"; } From 549efa9801bd3d731b66681982b36c159e6e8beb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 5 Mar 2021 20:13:15 +0100 Subject: [PATCH 28/34] Fix pr stuff --- .../bausystem/world/TNTSimulator_12.java | 8 ------- .../bausystem/world/TNTSimulator_15.java | 8 ------- .../bausystem/commands/CommandSimulator.java | 7 ++++-- .../bausystem/world/TNTSimulator.java | 23 ++++++++++++------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java index abd0ba1..099c96f 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/world/TNTSimulator_12.java @@ -31,12 +31,4 @@ public class TNTSimulator_12 { return Material.CONCRETE; } - public static Material repeater() { - return Material.DIODE; - } - - public static Material comparator() { - return Material.REDSTONE_COMPARATOR; - } - } diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java index 7042a86..8fea70d 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/TNTSimulator_15.java @@ -32,12 +32,4 @@ public class TNTSimulator_15 { return Material.RED_CONCRETE; } - public static Material repeater() { - return Material.REPEATER; - } - - public static Material comparator() { - return Material.COMPARATOR; - } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index 8a9f47d..458504e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -33,9 +33,10 @@ import org.bukkit.entity.Player; public class CommandSimulator implements CommandExecutor { private void help(Player player) { - player.sendMessage("§8/§esimulator §8- §7Öffnet das Simulations GUI"); + player.sendMessage("§8/§esimulator §8- §7Öffnet die Simulations GUI"); player.sendMessage("§8/§esimulator start §8- §7Startet die Simulation"); - player.sendMessage("§8/§esimulator wand §8- §7Legt den Simulatorstab ins Inventar"); + player.sendMessage("§8/§esimulator wand §8- §7Legt dir den Simulatorstab ins Inventar"); + player.sendMessage("§8/§esimulator delete §8- §7Lösche alle TNT"); } private boolean permissionCheck(Player player) { @@ -68,6 +69,8 @@ public class CommandSimulator implements CommandExecutor { case "start": TNTSimulator.get(player).start(); break; + case "delete": + TNTSimulator.get(player).delete(); default: help(player); break; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index dc02da4..4240621 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -271,9 +271,9 @@ public class TNTSimulator { private static Material comparatorOrNot(boolean b) { if (b) { - return VersionedCallable.call(new VersionedCallable<>(TNTSimulator_12::comparator, 8), new VersionedCallable<>(TNTSimulator_15::comparator, 14)); + return SWItem.getMaterial("REDSTONE_COMPARATOR"); } else { - return VersionedCallable.call(new VersionedCallable<>(TNTSimulator_12::repeater, 8), new VersionedCallable<>(TNTSimulator_15::repeater, 14)); + return SWItem.getMaterial("DIODE"); } } @@ -319,25 +319,32 @@ public class TNTSimulator { return (int)(d * 10000) * 0.0001; } + public void delete() { + TNT_SPAWNS.clear(); + } + public void start() { Map> first = new HashMap<>(); Map> second = new HashMap<>(); - AtomicInteger lastTick = new AtomicInteger(0); - TNT_SPAWNS.forEach(tntSpawn -> { + int lastTick = 0; + + for (TNTSpawn tntSpawn : TNT_SPAWNS) { Map> list = tntSpawn.isComparator() ? second : first; for (int i = 0; i < tntSpawn.getCount(); i++) { list.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList<>()).add(tntSpawn); } - if (lastTick.get() < tntSpawn.getTickOffset()) { - lastTick.set(tntSpawn.getTickOffset()); + if (lastTick < tntSpawn.getTickOffset()) { + lastTick = tntSpawn.getTickOffset(); } - }); + } + int finalLastTick = lastTick; + AtomicInteger currentTick = new AtomicInteger(0); Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), bukkitTask -> { int tick = currentTick.get(); spawnRandomList(first.getOrDefault(tick, EMPTY)); spawnRandomList(second.getOrDefault(tick, EMPTY)); - if (tick > lastTick.get()) bukkitTask.cancel(); + if (tick > finalLastTick) bukkitTask.cancel(); currentTick.incrementAndGet(); }, 1, 1); } From 9a1c900a71c72f6ca70004a1fea5cad2280ad1e6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 6 Mar 2021 21:23:35 +0100 Subject: [PATCH 29/34] Add CommandSimulator Add TNTSimulator --- .../bausystem/commands/CommandSimulator.java | 2 +- .../bausystem/world/TNTSimulator.java | 27 +++---------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index 458504e..e73a2e7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -36,7 +36,7 @@ public class CommandSimulator implements CommandExecutor { player.sendMessage("§8/§esimulator §8- §7Öffnet die Simulations GUI"); player.sendMessage("§8/§esimulator start §8- §7Startet die Simulation"); player.sendMessage("§8/§esimulator wand §8- §7Legt dir den Simulatorstab ins Inventar"); - player.sendMessage("§8/§esimulator delete §8- §7Lösche alle TNT"); + player.sendMessage("§8/§esimulator delete §8- §7Löscht alle TNT"); } private boolean permissionCheck(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index 4240621..e451ad6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -47,12 +47,11 @@ 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("§7Zum ändern klicken"); + private static final List LORE = Collections.singletonList("§eZum ändern klicken"); private static final List EMPTY = new ArrayList<>(); static final Map TNT_SIMULATOR_MAP = new HashMap<>(); private final Set TNT_SPAWNS = new HashSet<>(); - private int number = 0; public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eKanonensimulator", 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(); @@ -75,7 +74,7 @@ public class TNTSimulator { lore.add("§7X§8: §e" + tntSpawn.getPosition().getX()); lore.add("§7Y§8: §e" + tntSpawn.getPosition().getY()); lore.add("§7Z§8: §e" + tntSpawn.getPosition().getZ()); - swListEntryList.add(new SWListInv.SWListEntry<>(new SWItem(Material.TNT, "§eTNT" + (!tntSpawn.getName().isEmpty() ? " §8- §e" + tntSpawn.getName() : ""), 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)); @@ -96,7 +95,7 @@ public class TNTSimulator { static void editTNT(Player player, TNTSpawn tntSpawn) { TNTSimulator tntSimulator = get(player); - SWInventory swInventory = new SWInventory(player, 54, "TNT" + (!tntSpawn.getName().isEmpty() ? " - " + tntSpawn.getName() : "")); + SWInventory swInventory = new SWInventory(player, 54, "TNT"); swInventory.setItem(49, new SWItem(Material.REDSTONE_BLOCK, "§cZurück", clickType -> { openSimulator(player); })); @@ -107,16 +106,6 @@ public class TNTSimulator { openSimulator(player); })); - // tnt Name - swInventory.setItem(45, new SWItem(Material.NAME_TAG, "§eName", clickType -> { - SWAnvilInv tntSimulatorAnvil = new SWAnvilInv(player, "Name", tntSpawn.getName()); - tntSimulatorAnvil.setCallback(s -> { - tntSpawn.setName(s); - editTNT(player, tntSpawn); - }); - tntSimulatorAnvil.open(); - })); - // Change Count of spawned TNT swInventory.setItem(10, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { tntSpawn.setCount(tntSpawn.getCount() + 1); @@ -265,7 +254,6 @@ public class TNTSimulator { static void addTNT(Player player, TNTSpawn tntSpawn) { TNTSimulator tntSimulator = TNT_SIMULATOR_MAP.computeIfAbsent(player, player1 -> new TNTSimulator()); - if (tntSpawn.name.isEmpty()) tntSpawn.name = (++tntSimulator.number) + ""; tntSimulator.TNT_SPAWNS.add(tntSpawn); } @@ -361,7 +349,6 @@ public class TNTSimulator { private static final World WORLD = Bukkit.getWorlds().get(0); - private String name = ""; private final Vector position; private int fuseTicks = 80; private int count = 1; @@ -384,14 +371,6 @@ public class TNTSimulator { }); } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public Vector getPosition() { return position; } From bed5a74c1058ece23eb72b9babafe399e92831f0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 6 Mar 2021 21:35:33 +0100 Subject: [PATCH 30/34] Add Simulator Wand to CommandGUI --- .../bausystem/commands/CommandGUI.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index be01a34..00bee35 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -45,6 +45,18 @@ public class CommandGUI implements CommandExecutor, Listener { Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getPlugin(), LAST_F_PLAYER::clear, 0, 20); } + private static ItemStack wand(Player player, ItemStack base, String command, Permission permission, String noPermissionMessage) { + base = base.clone(); + ItemMeta meta = base.getItemMeta(); + List lore = meta.getLore(); + lore.add(command); + if (Welt.noPermission(player, permission)) + lore.add(noPermissionMessage); + meta.setLore(lore); + base.setItemMeta(meta); + return base; + } + 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"); @@ -64,14 +76,7 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("gui item"); }); - 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); + ItemStack dtWand = wand(player, Detonator.WAND, "§8/§7dt wand", Permission.world, "§cDu hast keine Worldrechte"); inv.setItem(39, dtWand, clickType -> { if (Welt.noPermission(player, Permission.world)) return; @@ -79,6 +84,14 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("dt wand"); }); + ItemStack simWand = wand(player, TNTSimulator.WAND, "§8/§7sim wand", Permission.world, "§cDu hast keine Worldrechte"); + inv.setItem(38, simWand, clickType -> { + if (Welt.noPermission(player, Permission.world)) + return; + player.closeInventory(); + player.performCommand("sim 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)) return; From 5b1a1a2f6995aec525320d95d13a6b7233843acc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 6 Mar 2021 21:35:59 +0100 Subject: [PATCH 31/34] Optimize CommandGUI --- .../src/de/steamwar/bausystem/commands/CommandGUI.java | 2 -- 1 file changed, 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 00bee35..a5f0ccb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -67,8 +67,6 @@ public class CommandGUI implements CommandExecutor, Listener { 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 -> { From 801211c57d111caa3e163b81d97044688668d62e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 10:25:05 +0100 Subject: [PATCH 32/34] Update pr stuff --- .../src/de/steamwar/bausystem/BauSystem.java | 1 - .../bausystem/commands/CommandGUI.java | 24 +++++++++---------- .../bausystem/commands/CommandSimulator.java | 8 ++----- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 8cd5112..c388e29 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem; -import de.steamwar.bausystem.world.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/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index a5f0ccb..5576d67 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -45,18 +45,6 @@ public class CommandGUI implements CommandExecutor, Listener { Bukkit.getScheduler().runTaskTimerAsynchronously(BauSystem.getPlugin(), LAST_F_PLAYER::clear, 0, 20); } - private static ItemStack wand(Player player, ItemStack base, String command, Permission permission, String noPermissionMessage) { - base = base.clone(); - ItemMeta meta = base.getItemMeta(); - List lore = meta.getLore(); - lore.add(command); - if (Welt.noPermission(player, permission)) - lore.add(noPermissionMessage); - meta.setLore(lore); - base.setItemMeta(meta); - return base; - } - 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"); @@ -578,6 +566,18 @@ public class CommandGUI implements CommandExecutor, Listener { return null; } + private static ItemStack wand(Player player, ItemStack base, String command, Permission permission, String noPermissionMessage) { + base = base.clone(); + ItemMeta meta = base.getItemMeta(); + List lore = meta.getLore(); + lore.add(command); + if (Welt.noPermission(player, permission)) + lore.add(noPermissionMessage); + meta.setLore(lore); + base.setItemMeta(meta); + return base; + } + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { if (!(commandSender instanceof Player)) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index e73a2e7..a4dfcd8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -22,6 +22,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.TNTSimulator; import de.steamwar.bausystem.world.Welt; import org.bukkit.Material; @@ -59,12 +60,7 @@ public class CommandSimulator implements CommandExecutor { if (args.length == 1) { switch (args[0].toLowerCase()) { case "wand": - if (player.getInventory().getItemInMainHand().getType() == Material.AIR) { - player.getInventory().setItemInMainHand(TNTSimulator.WAND); - } else { - player.getInventory().addItem(TNTSimulator.WAND); - } - player.updateInventory(); + PlayerUtils.giveItemToPlayer(player, TNTSimulator.WAND); break; case "start": TNTSimulator.get(player).start(); From 8b46d6fe6927ff0d816b15943c59866d491662a3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 10:34:58 +0100 Subject: [PATCH 33/34] Update pr stuff --- .../src/de/steamwar/bausystem/commands/CommandSimulator.java | 1 - .../src/de/steamwar/bausystem/world/TNTSimulator.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java index a4dfcd8..325f1a3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -25,7 +25,6 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.PlayerUtils; import de.steamwar.bausystem.world.TNTSimulator; 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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java index e451ad6..7a9fb2d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TNTSimulator.java @@ -81,11 +81,11 @@ public class TNTSimulator { 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 -> { + swListInv.setItem(51, new SWItem(Material.BARRIER, "§cTNT löschen", clickType -> { tntSimulator.TNT_SPAWNS.clear(); openSimulator(player); })); - swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, "§eSimulation starten", clickType -> { + swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, "§eStarten", clickType -> { player.closeInventory(); startSimulation(player); })); From c6791f394c4d1744310568bde184781c011cf604 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 10:38:52 +0100 Subject: [PATCH 34/34] Update pr stuff --- .../bausystem/commands/CommandSimulatorTabCompleter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java index 65841e7..0103d30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java @@ -40,6 +40,7 @@ public class CommandSimulatorTabCompleter implements TabCompleter { List tabComplete = new ArrayList<>(); tabComplete.add("wand"); tabComplete.add("start"); + tabComplete.add("delete"); if (args.length >= 2) { return new ArrayList<>();