From 0c17692fc3a47f332159210e50c3a17325b670d7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 12:31:36 +0100 Subject: [PATCH 01/23] Add CommandRedstoneTester Add RedstoneListener --- .../src/de/steamwar/bausystem/BauSystem.java | 2 + .../commands/CommandRedstoneTester.java | 40 +++++ .../bausystem/world/RedstoneListener.java | 165 ++++++++++++++++++ BauSystem_Main/src/plugin.yml | 3 +- 4 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index dd1817f..60b7709 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -99,6 +99,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("script").setExecutor(new CommandScript()); getCommand("simulator").setExecutor(new CommandSimulator()); getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter()); + getCommand("redstonetester").setExecutor(new CommandRedstoneTester()); getCommand("gui").setExecutor(new CommandGUI()); Bukkit.getPluginManager().registerEvents(this, this); @@ -109,6 +110,7 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new TNTSimulatorListener(), this); Bukkit.getPluginManager().registerEvents(new CommandGUI(), this); Bukkit.getPluginManager().registerEvents(new DetonatorListener(), this); + Bukkit.getPluginManager().registerEvents(new RedstoneListener(), this); new AFKStopper(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java new file mode 100644 index 0000000..5723b53 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -0,0 +1,40 @@ +/* + * 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.PlayerUtils; +import de.steamwar.bausystem.world.RedstoneListener; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandRedstoneTester implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + if (!(commandSender instanceof Player)) + return false; + Player player = (Player) commandSender; + PlayerUtils.giveItemToPlayer(player, RedstoneListener.WAND); + return false; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java new file mode 100644 index 0000000..b951b19 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -0,0 +1,165 @@ +/* + * 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 de.steamwar.bausystem.BauSystem; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Powerable; +import org.bukkit.block.data.type.Piston; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.*; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class RedstoneListener implements Listener { + + private static long currentTick = 0; + + static { + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + currentTick++; + }, 1, 1); + } + + private static class RedstoneTester { + + private final Player player; + private Location loc1 = null; + private Location loc2 = null; + + private Location activated = null; + private long tick = 0; + + public RedstoneTester(Player player) { + this.player = player; + } + + private void activate(Location location) { + if (loc1 != null && loc1.equals(location)) { + if (activated != null && !activated.equals(location)) { + player.sendMessage("§7Aktivierungsdifferenz§8: §e" + (currentTick - tick) + " §8(§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); + activated = null; + return; + } + activated = loc1; + tick = currentTick; + } else if (loc2 != null && loc2.equals(location)) { + if (activated != null && !activated.equals(location)) { + player.sendMessage("§7Aktivierungsdifferenz§8: §e" + (currentTick - tick) + " §8(§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); + activated = null; + return; + } + activated = loc2; + tick = currentTick; + } + } + + } + + private Map playerMap = new HashMap<>(); + public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eRedstonetester", Arrays.asList("§eRechtsklick Block §8- §7Setzt die 1. Position", "§eShift-Rechtsklick Luft §8- §7Zurücksetzten", "§eLinksklick Block §8- §7Setzt die 2. Position"), false, null).getItemStack(); + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (!WAND.isSimilar(event.getItem())) return; + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + event.setCancelled(true); + + switch (event.getAction()) { + case RIGHT_CLICK_AIR: + if (player.isSneaking()) { + playerMap.remove(event.getPlayer()); + player.sendMessage("§7Positionen gelöscht§8."); + } + break; + case RIGHT_CLICK_BLOCK: + if (!validBlock(event.getPlayer(), block.getBlockData())) return; + playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc1 = block.getLocation(); + sendLocation(event.getPlayer(), "§7POS1", block.getLocation()); + break; + case LEFT_CLICK_BLOCK: + if (!validBlock(event.getPlayer(), block.getBlockData())) return; + playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc2 = block.getLocation(); + sendLocation(event.getPlayer(), "§7POS2", block.getLocation()); + break; + } + } + + private void sendLocation(Player player, String prefix, Location location) { + player.sendMessage(prefix + "§8: §e" + locationToString(location)); + } + + private static String locationToString(Location location) { + return location.getBlockX() + " " + location.getBlockY() + " " + location.getBlockZ(); + } + + private boolean validBlock(Player player, BlockData block) { + if (block instanceof Powerable) return true; + if (block instanceof Piston) return true; + player.sendMessage("§7Unbekannte Position"); + return false; + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + playerMap.remove(event.getPlayer()); + } + + @EventHandler + public void onPistonExtend(BlockPistonExtendEvent e) { + playerMap.forEach((player, redstoneTester) -> { + redstoneTester.activate(e.getBlock().getLocation()); + }); + } + + @EventHandler + public void onPistonRetract(BlockPistonRetractEvent e) { + playerMap.forEach((player, redstoneTester) -> { + redstoneTester.activate(e.getBlock().getLocation()); + }); + } + + @EventHandler + public void onRedstoneEvent(BlockRedstoneEvent e) { + playerMap.forEach((player, redstoneTester) -> { + redstoneTester.activate(e.getBlock().getLocation()); + }); + } + + @EventHandler + public void onBlockDispense(BlockDispenseEvent e) { + playerMap.forEach((player, redstoneTester) -> { + redstoneTester.activate(e.getBlock().getLocation()); + }); + } +} diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 113cb9a..4ab7a2c 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -38,4 +38,5 @@ commands: script: simulator: aliases: sim - gui: \ No newline at end of file + gui: + redstonetester: \ No newline at end of file From ab374ea7dd6edfab32f079e092eb3d24af9958ce Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 12:32:54 +0100 Subject: [PATCH 02/23] Add RedstoneListener messages --- .../steamwar/bausystem/world/RedstoneListener.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index b951b19..2cd5948 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -66,7 +66,7 @@ public class RedstoneListener implements Listener { private void activate(Location location) { if (loc1 != null && loc1.equals(location)) { if (activated != null && !activated.equals(location)) { - player.sendMessage("§7Aktivierungsdifferenz§8: §e" + (currentTick - tick) + " §8(§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); + player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick) + " §8(§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); activated = null; return; } @@ -74,7 +74,7 @@ public class RedstoneListener implements Listener { tick = currentTick; } else if (loc2 != null && loc2.equals(location)) { if (activated != null && !activated.equals(location)) { - player.sendMessage("§7Aktivierungsdifferenz§8: §e" + (currentTick - tick) + " §8(§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); + player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick) + " §8(§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); activated = null; return; } @@ -99,24 +99,24 @@ public class RedstoneListener implements Listener { case RIGHT_CLICK_AIR: if (player.isSneaking()) { playerMap.remove(event.getPlayer()); - player.sendMessage("§7Positionen gelöscht§8."); + player.sendMessage(BauSystem.PREFIX + "Positionen gelöscht§8."); } break; case RIGHT_CLICK_BLOCK: if (!validBlock(event.getPlayer(), block.getBlockData())) return; playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc1 = block.getLocation(); - sendLocation(event.getPlayer(), "§7POS1", block.getLocation()); + sendLocation(event.getPlayer(), "POS1", block.getLocation()); break; case LEFT_CLICK_BLOCK: if (!validBlock(event.getPlayer(), block.getBlockData())) return; playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc2 = block.getLocation(); - sendLocation(event.getPlayer(), "§7POS2", block.getLocation()); + sendLocation(event.getPlayer(), "POS2", block.getLocation()); break; } } private void sendLocation(Player player, String prefix, Location location) { - player.sendMessage(prefix + "§8: §e" + locationToString(location)); + player.sendMessage(BauSystem.PREFIX + prefix + "§8: §e" + locationToString(location)); } private static String locationToString(Location location) { @@ -126,7 +126,7 @@ public class RedstoneListener implements Listener { private boolean validBlock(Player player, BlockData block) { if (block instanceof Powerable) return true; if (block instanceof Piston) return true; - player.sendMessage("§7Unbekannte Position"); + player.sendMessage(BauSystem.PREFIX + "Unbekannte Position"); return false; } From 3e184dfefb28068ec7737111eea9473a58e17888 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 12:36:19 +0100 Subject: [PATCH 03/23] Add RedstoneListener messages --- .../src/de/steamwar/bausystem/world/RedstoneListener.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index 2cd5948..b7fa402 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -66,7 +66,8 @@ public class RedstoneListener implements Listener { private void activate(Location location) { if (loc1 != null && loc1.equals(location)) { if (activated != null && !activated.equals(location)) { - player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick) + " §8(§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); + player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick)); + player.sendMessage(BauSystem.PREFIX + "Reihenfolge§8: (§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); activated = null; return; } @@ -74,7 +75,8 @@ public class RedstoneListener implements Listener { tick = currentTick; } else if (loc2 != null && loc2.equals(location)) { if (activated != null && !activated.equals(location)) { - player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick) + " §8(§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); + player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick)); + player.sendMessage(BauSystem.PREFIX + "Reihenfolge§8: (§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); activated = null; return; } From ec1e557cb79c3066bd991d06a37abe1dd311a2e3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 12:37:07 +0100 Subject: [PATCH 04/23] Add RedstoneListener messages --- .../src/de/steamwar/bausystem/world/RedstoneListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index b7fa402..7333dc5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -67,7 +67,7 @@ public class RedstoneListener implements Listener { if (loc1 != null && loc1.equals(location)) { if (activated != null && !activated.equals(location)) { player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick)); - player.sendMessage(BauSystem.PREFIX + "Reihenfolge§8: (§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); + player.sendMessage(BauSystem.PREFIX + "Reihenfolge§8: §7" + locationToString(activated) + " §8->§7 " + locationToString(location)); activated = null; return; } @@ -76,7 +76,7 @@ public class RedstoneListener implements Listener { } else if (loc2 != null && loc2.equals(location)) { if (activated != null && !activated.equals(location)) { player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick)); - player.sendMessage(BauSystem.PREFIX + "Reihenfolge§8: (§7" + locationToString(activated) + " §8->§7 " + locationToString(location) + "§8)"); + player.sendMessage(BauSystem.PREFIX + "Reihenfolge§8: §7" + locationToString(activated) + " §8->§7 " + locationToString(location)); activated = null; return; } From dd54a99fb400cd9370e8c0a422775df4ed67c6ee Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 12:37:52 +0100 Subject: [PATCH 05/23] Optimize Imports --- .../src/de/steamwar/bausystem/world/RedstoneListener.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index 7333dc5..8c87368 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -31,7 +31,10 @@ import org.bukkit.block.data.type.Piston; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.*; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; From 6d8faea32eac581cf63babfdec70e1eb00c3276a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 12:48:32 +0100 Subject: [PATCH 06/23] Add CommandGUI redstoneListener Wand --- .../src/de/steamwar/bausystem/commands/CommandGUI.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 5576d67..7ffa977 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -53,8 +53,6 @@ public class CommandGUI implements CommandExecutor, Listener { OPEN_INVS.remove(player); }); - inv.setItem(37, 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 -> { @@ -78,6 +76,12 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("sim wand"); }); + ItemStack redstoneWand = wand(player, RedstoneListener.WAND, "§8/§7redstonetester", null, ""); + inv.setItem(37, redstoneWand, clickType -> { + player.closeInventory(); + player.performCommand("redstonetester"); + }); + 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; @@ -571,7 +575,7 @@ public class CommandGUI implements CommandExecutor, Listener { ItemMeta meta = base.getItemMeta(); List lore = meta.getLore(); lore.add(command); - if (Welt.noPermission(player, permission)) + if (permission != null && Welt.noPermission(player, permission)) lore.add(noPermissionMessage); meta.setLore(lore); base.setItemMeta(meta); From 4faede4abf7d6465bcf1efa848c49fe197ec0804 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 16:19:46 +0100 Subject: [PATCH 07/23] Update RedstoneListener core feature Add plugin.yml redstonetester -> rt --- .../bausystem/world/RedstoneListener.java | 38 +++++++++---------- BauSystem_Main/src/plugin.yml | 3 +- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index 8c87368..43a7fb0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -59,32 +59,30 @@ public class RedstoneListener implements Listener { private Location loc1 = null; private Location loc2 = null; - private Location activated = null; - private long tick = 0; + private long lastTick = 0; + private Long tick = null; public RedstoneTester(Player player) { this.player = player; } private void activate(Location location) { - if (loc1 != null && loc1.equals(location)) { - if (activated != null && !activated.equals(location)) { - player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick)); - player.sendMessage(BauSystem.PREFIX + "Reihenfolge§8: §7" + locationToString(activated) + " §8->§7 " + locationToString(location)); - activated = null; - return; + if (loc1 == null || loc2 == null) { + tick = null; + return; + } + if (loc1.equals(location)) { + if (currentTick - lastTick > 100) { + tick = null; } - activated = loc1; - tick = currentTick; - } else if (loc2 != null && loc2.equals(location)) { - if (activated != null && !activated.equals(location)) { - player.sendMessage(BauSystem.PREFIX + "Aktivierungsdifferenz§8: §e" + (currentTick - tick)); - player.sendMessage(BauSystem.PREFIX + "Reihenfolge§8: §7" + locationToString(activated) + " §8->§7 " + locationToString(location)); - activated = null; - return; + lastTick = currentTick; + if (tick == null) { + tick = currentTick; } - activated = loc2; - tick = currentTick; + return; + } + if (tick != null && loc2.equals(location)) { + player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (currentTick - tick) + "§8 - §7in GameTicks"); } } @@ -107,12 +105,12 @@ public class RedstoneListener implements Listener { player.sendMessage(BauSystem.PREFIX + "Positionen gelöscht§8."); } break; - case RIGHT_CLICK_BLOCK: + case LEFT_CLICK_BLOCK: if (!validBlock(event.getPlayer(), block.getBlockData())) return; playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc1 = block.getLocation(); sendLocation(event.getPlayer(), "POS1", block.getLocation()); break; - case LEFT_CLICK_BLOCK: + case RIGHT_CLICK_BLOCK: if (!validBlock(event.getPlayer(), block.getBlockData())) return; playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc2 = block.getLocation(); sendLocation(event.getPlayer(), "POS2", block.getLocation()); diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 4ab7a2c..5bb49e5 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -39,4 +39,5 @@ commands: simulator: aliases: sim gui: - redstonetester: \ No newline at end of file + redstonetester: + aliases: rt \ No newline at end of file From d30a8ff4aac2610537e6fd1a762754986d981de4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 16:30:15 +0100 Subject: [PATCH 08/23] Add CommandRedstoneTester help message --- .../steamwar/bausystem/commands/CommandRedstoneTester.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index 5723b53..83d8e09 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.PlayerUtils; import de.steamwar.bausystem.world.RedstoneListener; import org.bukkit.command.Command; @@ -29,10 +30,14 @@ import org.bukkit.entity.Player; public class CommandRedstoneTester implements CommandExecutor { @Override - public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { if (!(commandSender instanceof Player)) return false; Player player = (Player) commandSender; + if (args.length != 0 && args[0].equalsIgnoreCase("help")) { + player.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); + return false; + } PlayerUtils.giveItemToPlayer(player, RedstoneListener.WAND); return false; } From 6c91c965246cec5e3e32b1d06fe2103bea75eeca Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 16:37:19 +0100 Subject: [PATCH 09/23] Add CommandRedstoneTesterTabCompleter Optimize CommandSimulatorTabCompleter Optimize CommandTNTTabComplete Add TabCompleteUtils.manageList --- .../steamwar/bausystem/TabCompleteUtils.java | 35 +++++++++++++ .../src/de/steamwar/bausystem/BauSystem.java | 1 + .../commands/CommandRedstoneTester.java | 19 +++++-- .../CommandRedstoneTesterTabCompleter.java | 50 +++++++++++++++++++ .../CommandSimulatorTabCompleter.java | 12 +---- .../commands/CommandTNTTabComplete.java | 12 +---- 6 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 BauSystem_API/src/de/steamwar/bausystem/TabCompleteUtils.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java diff --git a/BauSystem_API/src/de/steamwar/bausystem/TabCompleteUtils.java b/BauSystem_API/src/de/steamwar/bausystem/TabCompleteUtils.java new file mode 100644 index 0000000..b6be8a8 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/TabCompleteUtils.java @@ -0,0 +1,35 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem; + +import java.util.List; + +public class TabCompleteUtils { + + public static 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; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 60b7709..3b3db15 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -100,6 +100,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("simulator").setExecutor(new CommandSimulator()); getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter()); getCommand("redstonetester").setExecutor(new CommandRedstoneTester()); + getCommand("redstonetester").setTabCompleter(new CommandRedstoneTesterTabCompleter()); getCommand("gui").setExecutor(new CommandGUI()); Bukkit.getPluginManager().registerEvents(this, this); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index 83d8e09..5dd1d6c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -29,16 +29,29 @@ import org.bukkit.entity.Player; public class CommandRedstoneTester implements CommandExecutor { + private void help(Player player) { + player.sendMessage("§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); + player.sendMessage("§8/§eredstonetester help §8- §7Zeigt diese Nachricht"); + player.sendMessage("§8/§eredstonetester wand §8- §7Legt dir den Testerstab ins Inventar"); + } + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { if (!(commandSender instanceof Player)) return false; Player player = (Player) commandSender; - if (args.length != 0 && args[0].equalsIgnoreCase("help")) { - player.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); + if (args.length == 0) { + help(player); return false; } - PlayerUtils.giveItemToPlayer(player, RedstoneListener.WAND); + switch (args[0].toLowerCase()) { + case "help": + help(player); + break; + case "wand": + PlayerUtils.giveItemToPlayer(player, RedstoneListener.WAND); + break; + } return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java new file mode 100644 index 0000000..98922b3 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java @@ -0,0 +1,50 @@ +/* + * 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.TabCompleteUtils; +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 CommandRedstoneTesterTabCompleter implements TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) return new ArrayList<>(); + return commandTabComplete((Player) sender, args); + } + + private List commandTabComplete(Player player, String[] args) { + List tabComplete = new ArrayList<>(); + tabComplete.add("help"); + tabComplete.add("wand"); + + if (args.length >= 2) { + return new ArrayList<>(); + } + return TabCompleteUtils.manageList(tabComplete, args, 0); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java index 0103d30..488fe4e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.TabCompleteUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -45,16 +46,7 @@ public class CommandSimulatorTabCompleter implements TabCompleter { 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; + return TabCompleteUtils.manageList(tabComplete, args, 0); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index dbc18b1..7b34983 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.TabCompleteUtils; import de.steamwar.bausystem.world.Region; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -52,16 +53,7 @@ public class CommandTNTTabComplete implements TabCompleter { 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; + return TabCompleteUtils.manageList(tabComplete, args, 0); } } From 7fa6c2cb09cc2edd3bcf9971a7a7cbe7a3d3050e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 16:48:00 +0100 Subject: [PATCH 10/23] Fix RedstoneListener.WAND lore --- .../src/de/steamwar/bausystem/world/RedstoneListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index 43a7fb0..e905f35 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -89,7 +89,7 @@ public class RedstoneListener implements Listener { } private Map playerMap = new HashMap<>(); - public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eRedstonetester", Arrays.asList("§eRechtsklick Block §8- §7Setzt die 1. Position", "§eShift-Rechtsklick Luft §8- §7Zurücksetzten", "§eLinksklick Block §8- §7Setzt die 2. Position"), false, null).getItemStack(); + public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eRedstonetester", Arrays.asList("§eLinksklick Block §8- §7Setzt die 1. Position", "§eRechtsklick Block §8- §7Setzt die 2. Position", "§eShift-Rechtsklick Luft §8- §7Zurücksetzten"), false, null).getItemStack(); @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { From 0e74158941ef5df9970d95182eeb7ccaeeae0bfd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Mar 2021 01:24:39 +0100 Subject: [PATCH 11/23] Rename PlayerUtils to SWUtils --- .../commands/CommandDebugStick_15.java | 4 +-- .../{PlayerUtils.java => SWUtils.java} | 18 +++++++++- .../steamwar/bausystem/TabCompleteUtils.java | 35 ------------------- .../bausystem/commands/CommandDetonator.java | 4 +-- .../CommandDetonatorTabCompleter.java | 12 ++----- .../bausystem/commands/CommandGUI.java | 4 +-- .../commands/CommandRedstoneTester.java | 5 ++- .../CommandRedstoneTesterTabCompleter.java | 1 - .../bausystem/commands/CommandScript.java | 4 +-- .../bausystem/commands/CommandSimulator.java | 4 +-- .../CommandSimulatorTabCompleter.java | 1 - .../bausystem/commands/CommandSkull.java | 4 +-- .../commands/CommandTNTTabComplete.java | 1 - .../commands/CommandTraceTabCompleter.java | 10 ++---- 14 files changed, 35 insertions(+), 72 deletions(-) rename BauSystem_API/src/de/steamwar/bausystem/{PlayerUtils.java => SWUtils.java} (71%) delete mode 100644 BauSystem_API/src/de/steamwar/bausystem/TabCompleteUtils.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java index 8bbf9dd..104da37 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/CommandDebugStick_15.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.PlayerUtils; +import de.steamwar.bausystem.SWUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -28,6 +28,6 @@ class CommandDebugStick_15 { private CommandDebugStick_15(){} static void giveStick(Player player){ - PlayerUtils.giveItemToPlayer(player, new ItemStack(Material.DEBUG_STICK)); + SWUtils.giveItemToPlayer(player, new ItemStack(Material.DEBUG_STICK)); } } diff --git a/BauSystem_API/src/de/steamwar/bausystem/PlayerUtils.java b/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java similarity index 71% rename from BauSystem_API/src/de/steamwar/bausystem/PlayerUtils.java rename to BauSystem_API/src/de/steamwar/bausystem/SWUtils.java index 8dd1181..0d76a75 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/PlayerUtils.java +++ b/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java @@ -23,7 +23,9 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -public class PlayerUtils { +import java.util.List; + +public class SWUtils { public static void giveItemToPlayer(Player player, ItemStack itemStack) { ItemStack current = player.getInventory().getItemInMainHand(); @@ -33,4 +35,18 @@ public class PlayerUtils { } } + public static 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; + } + + public static List manageList(List strings, String[] args) { + return manageList(strings, args, args.length - 1); + } + + } diff --git a/BauSystem_API/src/de/steamwar/bausystem/TabCompleteUtils.java b/BauSystem_API/src/de/steamwar/bausystem/TabCompleteUtils.java deleted file mode 100644 index b6be8a8..0000000 --- a/BauSystem_API/src/de/steamwar/bausystem/TabCompleteUtils.java +++ /dev/null @@ -1,35 +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; - -import java.util.List; - -public class TabCompleteUtils { - - public static 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; - } - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index e45e53b..866bc47 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.PlayerUtils; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; @@ -63,7 +63,7 @@ public class CommandDetonator implements CommandExecutor { case "wand": case "detonator": case "item": - PlayerUtils.giveItemToPlayer(player, Detonator.WAND); + SWUtils.giveItemToPlayer(player, Detonator.WAND); player.updateInventory(); break; case "remove": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java index 4a20f89..a2cf22d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.SWUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -45,15 +46,6 @@ public class CommandDetonatorTabCompleter implements TabCompleter { 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; + return SWUtils.manageList(tabComplete, args, 0); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 7ffa977..761242b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -2,7 +2,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.PlayerUtils; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.world.*; @@ -591,7 +591,7 @@ public class CommandGUI implements CommandExecutor, Listener { openBauGui(player); OPEN_INVS.add(player); } else if ("item".equalsIgnoreCase(strings[0])) { - PlayerUtils.giveItemToPlayer(player, new ItemStack(Material.NETHER_STAR)); + SWUtils.giveItemToPlayer(player, new ItemStack(Material.NETHER_STAR)); } return true; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index 5dd1d6c..92eb5f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -19,8 +19,7 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.PlayerUtils; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.world.RedstoneListener; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -49,7 +48,7 @@ public class CommandRedstoneTester implements CommandExecutor { help(player); break; case "wand": - PlayerUtils.giveItemToPlayer(player, RedstoneListener.WAND); + SWUtils.giveItemToPlayer(player, RedstoneListener.WAND); break; } return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java index 98922b3..96ed7c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.TabCompleteUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java index 6f03dbe..e8d0811 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -21,7 +21,7 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.PlayerUtils; +import de.steamwar.bausystem.SWUtils; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -68,7 +68,7 @@ public class CommandScript implements CommandExecutor { if (!(sender instanceof Player)) { return false; } - PlayerUtils.giveItemToPlayer((Player) sender, BOOK); + SWUtils.giveItemToPlayer((Player) sender, BOOK); 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 325f1a3..ad876df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulator.java @@ -22,7 +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.SWUtils; import de.steamwar.bausystem.world.TNTSimulator; import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; @@ -59,7 +59,7 @@ public class CommandSimulator implements CommandExecutor { if (args.length == 1) { switch (args[0].toLowerCase()) { case "wand": - PlayerUtils.giveItemToPlayer(player, TNTSimulator.WAND); + SWUtils.giveItemToPlayer(player, TNTSimulator.WAND); break; case "start": TNTSimulator.get(player).start(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java index 488fe4e..c248913 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.TabCompleteUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java index bd8d121..da00ae6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSkull.java @@ -20,7 +20,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.PlayerUtils; +import de.steamwar.bausystem.SWUtils; import de.steamwar.inventory.SWItem; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -47,7 +47,7 @@ public class CommandSkull implements CommandExecutor { assert sm != null; sm.setDisplayName("§e" + args[0] + "§8s Kopf"); is.setItemMeta(sm); - PlayerUtils.giveItemToPlayer(p, is); + SWUtils.giveItemToPlayer(p, is); return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index 7b34983..37794ee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.commands; -import de.steamwar.bausystem.TabCompleteUtils; import de.steamwar.bausystem.world.Region; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java index 47e9912..b626255 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTraceTabCompleter.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.bausystem.tracer.record.RecordStatus; import org.bukkit.command.Command; @@ -54,14 +55,7 @@ public class CommandTraceTabCompleter implements TabCompleter { for (TabComplete tab : tabCompletes) { if (tab.test(player, args)) tabComplete.addAll(Arrays.asList(tab.getTabCompletes())); } - return manageList(tabComplete, args); - } - - private List manageList(List strings, String[] args) { - for (int i = strings.size() - 1; i >= 0; i--) { - if (!strings.get(i).startsWith(args[args.length - 1])) strings.remove(i); - } - return strings; + return SWUtils.manageList(tabComplete, args); } private static class TabComplete { From 3a2a5f6cd30cd75553b5378dd51d03adfe12c7f7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Mar 2021 08:40:40 +0100 Subject: [PATCH 12/23] Remove CommandRedstoneTester help message in help message --- .../steamwar/bausystem/commands/CommandRedstoneTester.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index 92eb5f7..22b1837 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -30,7 +30,6 @@ public class CommandRedstoneTester implements CommandExecutor { private void help(Player player) { player.sendMessage("§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); - player.sendMessage("§8/§eredstonetester help §8- §7Zeigt diese Nachricht"); player.sendMessage("§8/§eredstonetester wand §8- §7Legt dir den Testerstab ins Inventar"); } @@ -44,12 +43,12 @@ public class CommandRedstoneTester implements CommandExecutor { return false; } switch (args[0].toLowerCase()) { - case "help": - help(player); - break; case "wand": SWUtils.giveItemToPlayer(player, RedstoneListener.WAND); break; + default: + help(player); + break; } return false; } From 40de54580e9aa876cbf3279438551150ab1871af Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Mar 2021 08:47:33 +0100 Subject: [PATCH 13/23] Fix TabCompleter --- .../bausystem/commands/CommandRedstoneTesterTabCompleter.java | 3 ++- .../bausystem/commands/CommandSimulatorTabCompleter.java | 3 ++- .../de/steamwar/bausystem/commands/CommandTNTTabComplete.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java index 96ed7c4..9a01d39 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.SWUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -43,7 +44,7 @@ public class CommandRedstoneTesterTabCompleter implements TabCompleter { if (args.length >= 2) { return new ArrayList<>(); } - return TabCompleteUtils.manageList(tabComplete, args, 0); + return SWUtils.manageList(tabComplete, args, 0); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java index c248913..50c494e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandSimulatorTabCompleter.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.SWUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -45,7 +46,7 @@ public class CommandSimulatorTabCompleter implements TabCompleter { if (args.length >= 2) { return new ArrayList<>(); } - return TabCompleteUtils.manageList(tabComplete, args, 0); + return SWUtils.manageList(tabComplete, args, 0); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java index 37794ee..02e430e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTNTTabComplete.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.world.Region; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -52,7 +53,7 @@ public class CommandTNTTabComplete implements TabCompleter { if (args.length >= 2) { return new ArrayList<>(); } - return TabCompleteUtils.manageList(tabComplete, args, 0); + return SWUtils.manageList(tabComplete, args, 0); } } From 8922dd440c6fe64b68d5be39f6568f1724552c35 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Mar 2021 10:14:37 +0100 Subject: [PATCH 14/23] Fix CommandGUI --- .../src/de/steamwar/bausystem/commands/CommandGUI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 761242b..1d91de9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -76,10 +76,10 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("sim wand"); }); - ItemStack redstoneWand = wand(player, RedstoneListener.WAND, "§8/§7redstonetester", null, ""); + ItemStack redstoneWand = wand(player, RedstoneListener.WAND, "§8/§7redstonetester wand", null, ""); inv.setItem(37, redstoneWand, clickType -> { player.closeInventory(); - player.performCommand("redstonetester"); + player.performCommand("redstonetester 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 -> { From 7b7e10d6cc91fbe28e85115e346bf0fa1f084d74 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Mar 2021 10:56:22 +0100 Subject: [PATCH 15/23] Move RedstoneListener.tick to TPSUtils for AutostartTime --- .../bausystem/world/RedstoneListener.java | 19 ++++++------------- .../de/steamwar/bausystem/world/TPSUtils.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index e905f35..db8dca1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -45,14 +44,6 @@ import java.util.Map; public class RedstoneListener implements Listener { - private static long currentTick = 0; - - static { - Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { - currentTick++; - }, 1, 1); - } - private static class RedstoneTester { private final Player player; @@ -72,17 +63,17 @@ public class RedstoneListener implements Listener { return; } if (loc1.equals(location)) { - if (currentTick - lastTick > 100) { + if (TPSUtils.currentTick.get() - lastTick > 100) { tick = null; } - lastTick = currentTick; + lastTick = TPSUtils.currentTick.get(); if (tick == null) { - tick = currentTick; + tick = TPSUtils.currentTick.get(); } return; } if (tick != null && loc2.equals(location)) { - player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (currentTick - tick) + "§8 - §7in GameTicks"); + player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (TPSUtils.currentTick.get() - tick) + "§8 - §7in GameTicks"); } } @@ -115,6 +106,8 @@ public class RedstoneListener implements Listener { playerMap.computeIfAbsent(event.getPlayer(), RedstoneTester::new).loc2 = block.getLocation(); sendLocation(event.getPlayer(), "POS2", block.getLocation()); break; + default: + break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java index 563e01a..aca15f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java @@ -26,6 +26,8 @@ import de.steamwar.core.TPSWatcher; import de.steamwar.core.VersionedRunnable; import org.bukkit.Bukkit; +import java.util.function.Supplier; + public class TPSUtils { private TPSUtils() { @@ -36,12 +38,20 @@ public class TPSUtils { private static long nanoOffset = 0; private static long nanoDOffset = 0; + private static long ticksSinceServerStart = 0; + @SuppressWarnings("java:S4276") + public static final Supplier currentTick = () -> ticksSinceServerStart; + public static void init() { VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), new VersionedRunnable(() -> { Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1); TPSUtils_15.init(() -> nanoOffset); }, 15)); + + Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { + ticksSinceServerStart++; + }, 1, 1); } public static void setTPS(double tps) { From e1cdd4f1b7b8932b9f7d16ab31e55fa21c92109d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Mar 2021 11:01:01 +0100 Subject: [PATCH 16/23] Add buildPermission to CommandRedstoneTester --- .../steamwar/bausystem/commands/CommandGUI.java | 4 +++- .../commands/CommandRedstoneTester.java | 16 ++++++++++++++++ .../bausystem/world/RedstoneListener.java | 13 +++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 1d91de9..92dbe31 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -76,8 +76,10 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("sim wand"); }); - ItemStack redstoneWand = wand(player, RedstoneListener.WAND, "§8/§7redstonetester wand", null, ""); + ItemStack redstoneWand = wand(player, RedstoneListener.WAND, "§8/§7redstonetester wand", Permission.build, "Du hast keine Buildrechte"); inv.setItem(37, redstoneWand, clickType -> { + if (Welt.noPermission(player, Permission.build)) + return; player.closeInventory(); player.performCommand("redstonetester wand"); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index 22b1837..1f46938 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -19,8 +19,11 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.world.RedstoneListener; +import de.steamwar.bausystem.world.Welt; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -33,6 +36,14 @@ public class CommandRedstoneTester implements CommandExecutor { player.sendMessage("§8/§eredstonetester wand §8- §7Legt dir den Testerstab ins Inventar"); } + private boolean permissionCheck(Player player) { + if (Welt.noPermission(player, Permission.build)) { + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Redstonetester nutzen"); + return false; + } + return true; + } + @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { if (!(commandSender instanceof Player)) @@ -42,6 +53,11 @@ public class CommandRedstoneTester implements CommandExecutor { help(player); return false; } + + if (!permissionCheck(player)) { + return false; + } + switch (args[0].toLowerCase()) { case "wand": SWUtils.giveItemToPlayer(player, RedstoneListener.WAND); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index db8dca1..a988510 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.inventory.SWItem; import org.bukkit.Location; import org.bukkit.Material; @@ -82,6 +83,14 @@ public class RedstoneListener implements Listener { private Map playerMap = new HashMap<>(); public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eRedstonetester", Arrays.asList("§eLinksklick Block §8- §7Setzt die 1. Position", "§eRechtsklick Block §8- §7Setzt die 2. Position", "§eShift-Rechtsklick Luft §8- §7Zurücksetzten"), false, null).getItemStack(); + private boolean permissionCheck(Player player) { + if (Welt.noPermission(player, Permission.build)) { + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Redstonetester nutzen"); + return false; + } + return true; + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (!WAND.isSimilar(event.getItem())) return; @@ -89,6 +98,10 @@ public class RedstoneListener implements Listener { Block block = event.getClickedBlock(); event.setCancelled(true); + if (!permissionCheck(event.getPlayer())) { + return; + } + switch (event.getAction()) { case RIGHT_CLICK_AIR: if (player.isSneaking()) { From 6e18ba218ff2d3435d91e10e5ae712f63f77d0c7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 8 Mar 2021 20:21:10 +0100 Subject: [PATCH 17/23] Remove CommandRedstoneTesterTabCompleter.java --- .../src/de/steamwar/bausystem/BauSystem.java | 1 - .../bausystem/commands/CommandGUI.java | 4 +- .../commands/CommandRedstoneTester.java | 19 +------ .../CommandRedstoneTesterTabCompleter.java | 50 ------------------- 4 files changed, 4 insertions(+), 70 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 3b3db15..60b7709 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -100,7 +100,6 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("simulator").setExecutor(new CommandSimulator()); getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter()); getCommand("redstonetester").setExecutor(new CommandRedstoneTester()); - getCommand("redstonetester").setTabCompleter(new CommandRedstoneTesterTabCompleter()); getCommand("gui").setExecutor(new CommandGUI()); Bukkit.getPluginManager().registerEvents(this, this); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 92dbe31..5038659 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -76,12 +76,12 @@ public class CommandGUI implements CommandExecutor, Listener { player.performCommand("sim wand"); }); - ItemStack redstoneWand = wand(player, RedstoneListener.WAND, "§8/§7redstonetester wand", Permission.build, "Du hast keine Buildrechte"); + ItemStack redstoneWand = wand(player, RedstoneListener.WAND, "§8/§7redstonetester", Permission.build, "Du hast keine Buildrechte"); inv.setItem(37, redstoneWand, clickType -> { if (Welt.noPermission(player, Permission.build)) return; player.closeInventory(); - player.performCommand("redstonetester wand"); + player.performCommand("redstonetester"); }); inv.setItem(40, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", getNoPermsLore(Arrays.asList("§8//§7wand"), player, "§cDu hast keine Worldeditrechte", Permission.worldedit), false, clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index 1f46938..2ee1fc2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -31,11 +31,6 @@ import org.bukkit.entity.Player; public class CommandRedstoneTester implements CommandExecutor { - private void help(Player player) { - player.sendMessage("§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); - player.sendMessage("§8/§eredstonetester wand §8- §7Legt dir den Testerstab ins Inventar"); - } - private boolean permissionCheck(Player player) { if (Welt.noPermission(player, Permission.build)) { player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Redstonetester nutzen"); @@ -49,23 +44,13 @@ public class CommandRedstoneTester implements CommandExecutor { if (!(commandSender instanceof Player)) return false; Player player = (Player) commandSender; - if (args.length == 0) { - help(player); - return false; - } if (!permissionCheck(player)) { return false; } - switch (args[0].toLowerCase()) { - case "wand": - SWUtils.giveItemToPlayer(player, RedstoneListener.WAND); - break; - default: - help(player); - break; - } + player.sendMessage("§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); + SWUtils.giveItemToPlayer(player, RedstoneListener.WAND); return false; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java deleted file mode 100644 index 9a01d39..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTesterTabCompleter.java +++ /dev/null @@ -1,50 +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.commands; - -import de.steamwar.bausystem.SWUtils; -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 CommandRedstoneTesterTabCompleter implements TabCompleter { - - @Override - public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) return new ArrayList<>(); - return commandTabComplete((Player) sender, args); - } - - private List commandTabComplete(Player player, String[] args) { - List tabComplete = new ArrayList<>(); - tabComplete.add("help"); - tabComplete.add("wand"); - - if (args.length >= 2) { - return new ArrayList<>(); - } - return SWUtils.manageList(tabComplete, args, 0); - } - -} From b836f3c6d27402cef8cd8d88f429c72f6996a242 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 12 Mar 2021 09:22:37 +0100 Subject: [PATCH 18/23] Fix Help message --- .../de/steamwar/bausystem/commands/CommandRedstoneTester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index 2ee1fc2..fd78ee8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -49,7 +49,7 @@ public class CommandRedstoneTester implements CommandExecutor { return false; } - player.sendMessage("§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); + player.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); SWUtils.giveItemToPlayer(player, RedstoneListener.WAND); return false; } From f75292cbbc1b96a996104a6067d3d5c5367dfde2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Mar 2021 12:34:42 +0100 Subject: [PATCH 19/23] Fix BauSystem RedstoneTester loading Fix CommandGUI RedstoneTester loading --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 8 ++++++-- .../src/de/steamwar/bausystem/commands/CommandGUI.java | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 60b7709..427072b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -99,7 +99,9 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("script").setExecutor(new CommandScript()); getCommand("simulator").setExecutor(new CommandSimulator()); getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter()); - getCommand("redstonetester").setExecutor(new CommandRedstoneTester()); + if (Core.getVersion() >= 15) { + getCommand("redstonetester").setExecutor(new CommandRedstoneTester()); + } getCommand("gui").setExecutor(new CommandGUI()); Bukkit.getPluginManager().registerEvents(this, this); @@ -110,7 +112,9 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new TNTSimulatorListener(), this); Bukkit.getPluginManager().registerEvents(new CommandGUI(), this); Bukkit.getPluginManager().registerEvents(new DetonatorListener(), this); - Bukkit.getPluginManager().registerEvents(new RedstoneListener(), this); + if (Core.getVersion() >= 15) { + Bukkit.getPluginManager().registerEvents(new RedstoneListener(), this); + } new AFKStopper(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index 5038659..c9d948a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -81,7 +81,11 @@ public class CommandGUI implements CommandExecutor, Listener { if (Welt.noPermission(player, Permission.build)) return; player.closeInventory(); - player.performCommand("redstonetester"); + if (Core.getVersion() >= 15) { + player.performCommand("redstonetester"); + } else { + player.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar"); + } }); inv.setItem(40, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", getNoPermsLore(Arrays.asList("§8//§7wand"), player, "§cDu hast keine Worldeditrechte", Permission.worldedit), false, clickType -> { From 6b44f1265950a4a312e516e8fc0f4a68278465da Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Mar 2021 13:09:25 +0100 Subject: [PATCH 20/23] Fix pr stuff --- .../bausystem/world/RedstoneListener.java | 73 ++++++++++--------- .../de/steamwar/bausystem/world/TPSUtils.java | 1 - 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index a988510..7179592 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -45,43 +45,8 @@ import java.util.Map; public class RedstoneListener implements Listener { - private static class RedstoneTester { - - private final Player player; - private Location loc1 = null; - private Location loc2 = null; - - private long lastTick = 0; - private Long tick = null; - - public RedstoneTester(Player player) { - this.player = player; - } - - private void activate(Location location) { - if (loc1 == null || loc2 == null) { - tick = null; - return; - } - if (loc1.equals(location)) { - if (TPSUtils.currentTick.get() - lastTick > 100) { - tick = null; - } - lastTick = TPSUtils.currentTick.get(); - if (tick == null) { - tick = TPSUtils.currentTick.get(); - } - return; - } - if (tick != null && loc2.equals(location)) { - player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (TPSUtils.currentTick.get() - tick) + "§8 - §7in GameTicks"); - } - } - - } - - private Map playerMap = new HashMap<>(); public static final ItemStack WAND = new SWItem(Material.BLAZE_ROD, "§eRedstonetester", Arrays.asList("§eLinksklick Block §8- §7Setzt die 1. Position", "§eRechtsklick Block §8- §7Setzt die 2. Position", "§eShift-Rechtsklick Luft §8- §7Zurücksetzten"), false, null).getItemStack(); + private static Map playerMap = new HashMap<>(); private boolean permissionCheck(Player player) { if (Welt.noPermission(player, Permission.build)) { @@ -171,4 +136,40 @@ public class RedstoneListener implements Listener { redstoneTester.activate(e.getBlock().getLocation()); }); } + + private static class RedstoneTester { + + private final Player player; + private Location loc1 = null; + private Location loc2 = null; + + private long lastTick = 0; + private Long tick = null; + + public RedstoneTester(Player player) { + this.player = player; + } + + private void activate(Location location) { + if (loc1 == null || loc2 == null) { + tick = null; + return; + } + if (loc1.equals(location)) { + if (TPSUtils.currentTick.get() - lastTick > 100) { + tick = null; + } + lastTick = TPSUtils.currentTick.get(); + if (tick == null) { + tick = TPSUtils.currentTick.get(); + } + return; + } + if (tick != null && loc2.equals(location)) { + player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (TPSUtils.currentTick.get() - tick) + "§8 - §7in GameTicks"); + } + } + + } + } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java index 6915dcf..6ec2518 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/TPSUtils.java @@ -39,7 +39,6 @@ public class TPSUtils { private static long nanoDOffset = 0; private static long ticksSinceServerStart = 0; - @SuppressWarnings("java:S4276") public static final Supplier currentTick = () -> ticksSinceServerStart; public static void init() { From 0b326387793f65b4077f448ebd53276eed643717 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 25 Mar 2021 10:44:48 +0100 Subject: [PATCH 21/23] Fix pr stuff --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 9 +++------ .../src/de/steamwar/bausystem/commands/CommandGUI.java | 6 +----- .../bausystem/commands/CommandRedstoneTester.java | 5 +++++ .../de/steamwar/bausystem/world/RedstoneListener.java | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 427072b..9e26020 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.commands.*; import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; import de.steamwar.core.Core; +import de.steamwar.core.VersionedRunnable; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; @@ -99,9 +100,7 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("script").setExecutor(new CommandScript()); getCommand("simulator").setExecutor(new CommandSimulator()); getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter()); - if (Core.getVersion() >= 15) { - getCommand("redstonetester").setExecutor(new CommandRedstoneTester()); - } + getCommand("redstonetester").setExecutor(new CommandRedstoneTester()); getCommand("gui").setExecutor(new CommandGUI()); Bukkit.getPluginManager().registerEvents(this, this); @@ -112,9 +111,7 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new TNTSimulatorListener(), this); Bukkit.getPluginManager().registerEvents(new CommandGUI(), this); Bukkit.getPluginManager().registerEvents(new DetonatorListener(), this); - if (Core.getVersion() >= 15) { - Bukkit.getPluginManager().registerEvents(new RedstoneListener(), this); - } + VersionedRunnable.call(new VersionedRunnable(() -> Bukkit.getPluginManager().registerEvents(new RedstoneListener(), this), 15)); new AFKStopper(); autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 1200); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java index c9d948a..5038659 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandGUI.java @@ -81,11 +81,7 @@ public class CommandGUI implements CommandExecutor, Listener { if (Welt.noPermission(player, Permission.build)) return; player.closeInventory(); - if (Core.getVersion() >= 15) { - player.performCommand("redstonetester"); - } else { - player.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar"); - } + player.performCommand("redstonetester"); }); inv.setItem(40, getMaterial("WOODEN_AXE", "WOOD_AXE"), "§eWorldedit Axt", getNoPermsLore(Arrays.asList("§8//§7wand"), player, "§cDu hast keine Worldeditrechte", Permission.worldedit), false, clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index fd78ee8..356e70f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.world.RedstoneListener; import de.steamwar.bausystem.world.Welt; +import de.steamwar.core.Core; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -44,6 +45,10 @@ public class CommandRedstoneTester implements CommandExecutor { if (!(commandSender instanceof Player)) return false; Player player = (Player) commandSender; + if (Core.getVersion() >= 15) { + player.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar"); + return false; + } if (!permissionCheck(player)) { return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index 7179592..a04d188 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -100,7 +100,7 @@ public class RedstoneListener implements Listener { private boolean validBlock(Player player, BlockData block) { if (block instanceof Powerable) return true; if (block instanceof Piston) return true; - player.sendMessage(BauSystem.PREFIX + "Unbekannte Position"); + player.sendMessage(BauSystem.PREFIX + "§cUnbekannte Position"); return false; } From 689ae7562e87f05ad09239e225495454b08dfccb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 25 Mar 2021 12:33:53 +0100 Subject: [PATCH 22/23] Fix pr stuff --- .../commands/CommandRedstoneTester.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java index 356e70f..08c794a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandRedstoneTester.java @@ -24,7 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.world.RedstoneListener; import de.steamwar.bausystem.world.Welt; -import de.steamwar.core.Core; +import de.steamwar.core.VersionedRunnable; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -45,17 +45,15 @@ public class CommandRedstoneTester implements CommandExecutor { if (!(commandSender instanceof Player)) return false; Player player = (Player) commandSender; - if (Core.getVersion() >= 15) { + VersionedRunnable.call(new VersionedRunnable(() -> { player.sendMessage(BauSystem.PREFIX + "Der RedstoneTester ist nicht in der 1.12 verfügbar"); - return false; - } - - if (!permissionCheck(player)) { - return false; - } - - player.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); - SWUtils.giveItemToPlayer(player, RedstoneListener.WAND); + }, 8), new VersionedRunnable(() -> { + if (!permissionCheck(player)) { + return; + } + player.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); + SWUtils.giveItemToPlayer(player, RedstoneListener.WAND); + }, 15)); return false; } From e65722a8848c8c561c124c060fcfd78bbf081e1d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 25 Mar 2021 12:34:47 +0100 Subject: [PATCH 23/23] Fix pr stuff --- .../src/de/steamwar/bausystem/world/RedstoneListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java index a04d188..1fd82b3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RedstoneListener.java @@ -166,7 +166,7 @@ public class RedstoneListener implements Listener { return; } if (tick != null && loc2.equals(location)) { - player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (TPSUtils.currentTick.get() - tick) + "§8 - §7in GameTicks"); + player.sendMessage(BauSystem.PREFIX + "Differenz§8: §e" + (TPSUtils.currentTick.get() - tick) + "§8 - §7in Ticks §8(§7Ticks/2 -> Redstoneticks§8)"); } }