From 0c17692fc3a47f332159210e50c3a17325b670d7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 12:31:36 +0100 Subject: [PATCH 01/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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/29] 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 31df594797c2f9ae02f5de8e92143442758b57e8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 25 Mar 2021 10:39:52 +0100 Subject: [PATCH 21/29] Update CommandScript Add ScriptListener.CONSTANTS Add ScriptListener.GLOBAL_VARIABLES Add ScriptListener unvar command Add ScriptListener global command Add ScriptListener unglobal command Add CommandScriptVars Add CommandScriptVarsTabCompleter --- .../src/de/steamwar/bausystem/BauSystem.java | 2 + .../bausystem/commands/CommandScript.java | 3 + .../bausystem/commands/CommandScriptVars.java | 67 ++++++++++ .../CommandScriptVarsTabCompleter.java | 34 +++++ .../bausystem/world/ScriptListener.java | 118 ++++++++++++++---- BauSystem_Main/src/plugin.yml | 1 + 6 files changed, 200 insertions(+), 25 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVarsTabCompleter.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index dd1817f..d7920a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -97,6 +97,8 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("detonator").setExecutor(new CommandDetonator()); getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter()); getCommand("script").setExecutor(new CommandScript()); + getCommand("scriptvars").setExecutor(new CommandScriptVars()); + getCommand("scriptvars").setTabCompleter(new CommandScriptVarsTabCompleter()); getCommand("simulator").setExecutor(new CommandSimulator()); getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter()); getCommand("gui").setExecutor(new CommandGUI()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java index 95ddb92..e4db45b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -47,7 +47,10 @@ public class CommandScript implements CommandExecutor { pages.add("§6Variablen§8\n\nMit Variablen kann man sich Zahlen speichern. Man definiert diese mit 'var '.\n\nBeispiel:\n§9# Setze i zu 0\nvar i 0§8\n\nEs gibt einige spezial values. Dazu zählen"); pages.add("§8'true', 'yes', 'false' und 'no', welche für 1, 1, 0 und 0 stehen.\n\nMan kann eine Variable auch um einen erhöhen oder verkleinern. Hierfür schreibt man statt einer Zahl '++', 'inc' oder '--', 'dec'.\n\nBeispiel:\n§9var i ++"); pages.add("§8Variablen kann man referenzieren\ndurch '<' vor dem Variablennamen und '>' nach diesem. Diese kann man in jedem Befehl verwenden.\n\nBeispiel:\n§9# Stacked um 10\nvar stacks 10\n/stack "); + pages.add("§8Um Variablen über das Script ausführen zu speichern gibt es 'global' und 'unglobal' als Befehle. Der erste speichert eine locale Variable global und das zweite löscht eine globale wieder."); + pages.add("§8Des weiteren kann man Lokale Variablen mit 'unvar' löschen. Nach dem verlassen einer Welt werden alle Globalen Variablen gelöscht. Globale Variablen kann man mit '/scriptvars' einsehen"); pages.add("§6Konstanten§8\n\nNeben den variablen gibt es noch 5 Konstante Werte, welche nicht mit dem 'var' Befehl verändert werden können.\n\nDiese sind:\n- trace/autotrace\n- tnt\n- freeze\n- fire"); + pages.add("§8Des weiteren gibt es 3 weitere Variablen, welche explizit Spieler gebunden sind\n\nDiese sind:\n- x\n- y\n- z"); pages.add("§6Abfragen§8\n\nMit Abfragen kann man nur Gleichheit von 2 Werten überprüft werden. Hierfür verwendet man\n'if '.\nNach den zwei Werten kann man ein oder 2 Jump-Points schreiben\n'if [...] (JP)'."); pages.add("§8Ein Jump-Point ist eine Zeile Script, wohin man springen kann. Dieser wird mit einem '.' am Anfang der Zeile beschrieben und direkt danach der Jump-Point Namen ohne Leerzeichen.\n\nBeispiel:\n§9# Jump-Point X\n.X§8"); pages.add("§8Um zu einem Jump-Point ohne Abfrage zu springen kann man den\n'jump ' Befehl verwenden."); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java new file mode 100644 index 0000000..7c32e91 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java @@ -0,0 +1,67 @@ +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.world.ScriptListener; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +public class CommandScriptVars implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String s, String[] args) { + if (!(sender instanceof Player)) { + return false; + } + Player player = (Player) sender; + if (args.length == 0) { + Map globalVariables = ScriptListener.GLOBAL_VARIABLES.get(player); + if (globalVariables == null) { + player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert"); + return false; + } + int i = 0; + player.sendMessage(BauSystem.PREFIX + globalVariables.size() + " Variable(n)"); + for (Map.Entry var : globalVariables.entrySet()) { + if (i++ >= 40) break; + player.sendMessage("- " + var.getKey() + "=" + var.getValue()); + } + return false; + } + String varName = args[0]; + if (args.length == 1) { + Map globalVariables = ScriptListener.GLOBAL_VARIABLES.get(player); + if (globalVariables == null) { + player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert"); + return false; + } + if (!globalVariables.containsKey(varName)) { + player.sendMessage(BauSystem.PREFIX + "§cUnbekannte Variable"); + return false; + } + player.sendMessage(BauSystem.PREFIX + varName + "=" + globalVariables.get(varName)); + } + switch (args[2].toLowerCase()) { + case "delete": + case "clear": + case "remove": + if (!ScriptListener.GLOBAL_VARIABLES.containsKey(player)) { + player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert"); + break; + } + ScriptListener.GLOBAL_VARIABLES.get(player).remove(varName); + player.sendMessage(BauSystem.PREFIX + "Variable " + varName + " gelöscht"); + break; + default: + int value = ScriptListener.parseValue(args[2]); + ScriptListener.GLOBAL_VARIABLES.computeIfAbsent(player, p -> new HashMap<>()).put(varName, value); + player.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt"); + } + return false; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVarsTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVarsTabCompleter.java new file mode 100644 index 0000000..f9fa6ef --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVarsTabCompleter.java @@ -0,0 +1,34 @@ +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.world.ScriptListener; +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.Arrays; +import java.util.HashMap; +import java.util.List; + +public class CommandScriptVarsTabCompleter implements TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command command, String s, String[] args) { + if (!(sender instanceof Player)) { + return new ArrayList<>(); + } + Player player = (Player) sender; + if (args.length == 1) { + List variables = new ArrayList<>(ScriptListener.GLOBAL_VARIABLES.getOrDefault(player, new HashMap<>()).keySet()); + return SWUtils.manageList(variables, args); + } + if (args.length != 2) { + return new ArrayList<>(); + } + int value = ScriptListener.GLOBAL_VARIABLES.getOrDefault(player, new HashMap<>()).getOrDefault(args[0], 0); + return SWUtils.manageList(Arrays.asList(value + "", "true", "false", "yes", "no", "delete", "clear", "remove"), args); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index f20994a..1f229dc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -34,16 +34,32 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; import java.util.*; +import java.util.function.Function; import java.util.function.IntBinaryOperator; import java.util.function.IntUnaryOperator; import java.util.logging.Level; public class ScriptListener implements Listener { + public static final Map> GLOBAL_VARIABLES = new HashMap<>(); + private static final Map> CONSTANTS = new HashMap<>(); + + static { + CONSTANTS.put("trace", player -> RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0); + CONSTANTS.put("autotrace", player -> RecordStateMachine.getRecordStatus().isAutoTrace() ? 1 : 0); + CONSTANTS.put("tnt", player -> Region.getRegion(player.getLocation()).getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1); + CONSTANTS.put("freeze", player -> Region.getRegion(player.getLocation()).isFreeze() ? 1 : 0); + CONSTANTS.put("fire", player -> Region.getRegion(player.getLocation()).isFire() ? 1 : 0); + CONSTANTS.put("x", player -> player.getLocation().getBlockX()); + CONSTANTS.put("y", player -> player.getLocation().getBlockY()); + CONSTANTS.put("z", player -> player.getLocation().getBlockZ()); + } + private Set playerSet = new HashSet<>(); public ScriptListener() { @@ -74,6 +90,11 @@ public class ScriptListener implements Listener { new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer()); } + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + GLOBAL_VARIABLES.remove(event.getPlayer()); + } + private boolean isNoBook(ItemStack item) { return VersionedCallable.call(new VersionedCallable<>(() -> ScriptListener_12.isNoBook(item), 8), new VersionedCallable<>(() -> ScriptListener_15.isNoBook(item), 15)); @@ -146,6 +167,15 @@ public class ScriptListener implements Listener { case "var": ScriptListener.variableCommand(this, generateArgumentArray("var", this, command)); continue; + case "unvar": + ScriptListener.unvariableCommand(this, generateArgumentArray("unvar", this, command)); + continue; + case "global": + ScriptListener.globalCommand(this, generateArgumentArray("global", this, command)); + continue; + case "unglobal": + ScriptListener.unglobalCommand(this, generateArgumentArray("unglobal", this, command)); + continue; case "add": ScriptListener.arithmeticCommand(this, generateArgumentArray("add", this, command), (left, right) -> left + right); continue; @@ -246,7 +276,7 @@ public class ScriptListener implements Listener { String s = String.join(" ", args); Set variables = new HashSet<>(scriptExecutor.variables.keySet()); - variables.addAll(Arrays.asList("trace", "autotrace", "tnt", "freeze", "fire")); + variables.addAll(CONSTANTS.keySet()); for (String variable : variables) { s = s.replace("<" + variable + ">", getValue(scriptExecutor, variable) + ""); } @@ -283,6 +313,44 @@ public class ScriptListener implements Listener { setValue(scriptExecutor, args[0], parseValue(args[1])); } + private static void unvariableCommand(ScriptExecutor scriptExecutor, String[] args) { + if (args.length < 1) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cVariablen Namen fehlt."); + return; + } + if (!isLocalVariable(scriptExecutor, args[0])) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cVariable is nicht definiert"); + return; + } + scriptExecutor.variables.remove(args[0]); + } + + private static void globalCommand(ScriptExecutor scriptExecutor, String[] args) { + if (args.length < 1) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cVariablen Namen fehlt."); + return; + } + if (!isLocalVariable(scriptExecutor, args[0])) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cVariable is nicht definiert"); + return; + } + GLOBAL_VARIABLES.computeIfAbsent(scriptExecutor.player, player -> new HashMap<>()).put(args[0], scriptExecutor.variables.getOrDefault(args[0], 0)); + } + + private static void unglobalCommand(ScriptExecutor scriptExecutor, String[] args) { + if (args.length < 1) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cVariablen Namen fehlt."); + return; + } + if (!isGlobalVariable(scriptExecutor, args[0])) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cVariable is nicht definiert"); + return; + } + if (GLOBAL_VARIABLES.containsKey(scriptExecutor.player)) { + GLOBAL_VARIABLES.get(scriptExecutor.player).remove(args[0]); + } + } + private static int ifCommand(ScriptExecutor scriptExecutor, String[] args) { if (args.length < 2) { scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDie ersten beiden Argumente sind Zahlen/Boolsche Werte oder Variablen."); @@ -389,37 +457,37 @@ public class ScriptListener implements Listener { } private static int getValue(ScriptExecutor scriptExecutor, String key) { - Region region = Region.getRegion(scriptExecutor.player.getLocation()); - switch (key) { - case "trace": - return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; - case "autotrace": - return RecordStateMachine.getRecordStatus().isAutoTrace() ? 1 : 0; - case "tnt": - return region.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; - case "freeze": - return !region.isFreeze() ? 0 : 1; - case "fire": - return !region.isFire() ? 0 : 1; - default: - return scriptExecutor.variables.getOrDefault(key, 0); + if (CONSTANTS.containsKey(key)) { + return CONSTANTS.get(key).apply(scriptExecutor.player); } + if (GLOBAL_VARIABLES.containsKey(scriptExecutor.player) && GLOBAL_VARIABLES.get(scriptExecutor.player).containsKey(key)) { + return GLOBAL_VARIABLES.get(scriptExecutor.player).get(key); + } + return scriptExecutor.variables.getOrDefault(key, 0); } private static boolean isVariable(ScriptExecutor scriptExecutor, String key) { - switch (key) { - case "trace": - case "autotrace": - case "tnt": - case "freeze": - case "fire": - return true; - default: - return scriptExecutor.variables.containsKey(key); + if (CONSTANTS.containsKey(key)) { + return true; } + if (GLOBAL_VARIABLES.containsKey(scriptExecutor.player) && GLOBAL_VARIABLES.get(scriptExecutor.player).containsKey(key)) { + return true; + } + return scriptExecutor.variables.containsKey(key); } - private static int parseValue(String value) { + private static boolean isLocalVariable(ScriptExecutor scriptExecutor, String key) { + return isVariable(scriptExecutor, key) && !isGlobalVariable(scriptExecutor, key); + } + + private static boolean isGlobalVariable(ScriptExecutor scriptExecutor, String key) { + if (!GLOBAL_VARIABLES.containsKey(scriptExecutor.player)) { + return false; + } + return GLOBAL_VARIABLES.get(scriptExecutor.player).containsKey(key); + } + + public static int parseValue(String value) { if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes")) { return 1; } else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no")) { diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 113cb9a..7020039 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -36,6 +36,7 @@ commands: detonator: aliases: dt script: + scriptvars: simulator: aliases: sim gui: \ No newline at end of file From 0b326387793f65b4077f448ebd53276eed643717 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 25 Mar 2021 10:44:48 +0100 Subject: [PATCH 22/29] 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 23/29] 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 24/29] 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)"); } } From b95ecb93b0a447bbcaa2375b436d4c265ea485bb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 26 Mar 2021 22:11:31 +0100 Subject: [PATCH 25/29] Add replace multi space to single --- .../src/de/steamwar/bausystem/world/ScriptListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 1f229dc..4a87884 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -114,6 +114,7 @@ public class ScriptListener implements Listener { for (String page : bookMeta.getPages()) { for (String command : page.split("\n")) { + command = command.replaceAll(" +", " "); if (command.startsWith("#") || command.trim().isEmpty()) continue; if (command.startsWith(".")) { jumpPoints.put(command.substring(1), commands.size()); From fd2f073520520657b9a8f6efdea25e7c48388321 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 26 Mar 2021 22:25:49 +0100 Subject: [PATCH 26/29] Fix CommandScriptVars Fix ScriptListener.generateArgumentArray --- .../de/steamwar/bausystem/commands/CommandScriptVars.java | 5 +++-- .../src/de/steamwar/bausystem/world/ScriptListener.java | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java index 7c32e91..946e07b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java @@ -44,8 +44,9 @@ public class CommandScriptVars implements CommandExecutor { return false; } player.sendMessage(BauSystem.PREFIX + varName + "=" + globalVariables.get(varName)); + return false; } - switch (args[2].toLowerCase()) { + switch (args[1].toLowerCase()) { case "delete": case "clear": case "remove": @@ -57,7 +58,7 @@ public class CommandScriptVars implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "Variable " + varName + " gelöscht"); break; default: - int value = ScriptListener.parseValue(args[2]); + int value = ScriptListener.parseValue(args[1]); ScriptListener.GLOBAL_VARIABLES.computeIfAbsent(player, p -> new HashMap<>()).put(varName, value); player.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt"); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 4a87884..6b897a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -278,6 +278,9 @@ public class ScriptListener implements Listener { String s = String.join(" ", args); Set variables = new HashSet<>(scriptExecutor.variables.keySet()); variables.addAll(CONSTANTS.keySet()); + if (GLOBAL_VARIABLES.containsKey(scriptExecutor.player)) { + variables.addAll(GLOBAL_VARIABLES.get(scriptExecutor.player).keySet()); + } for (String variable : variables) { s = s.replace("<" + variable + ">", getValue(scriptExecutor, variable) + ""); } From 01b456f804b09614a16adcf0df736e47cdbb56d9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 26 Mar 2021 22:30:57 +0100 Subject: [PATCH 27/29] Fix Typo in CommandScript --- .../src/de/steamwar/bausystem/commands/CommandScript.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java index e4db45b..52045b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -48,7 +48,7 @@ public class CommandScript implements CommandExecutor { pages.add("§8'true', 'yes', 'false' und 'no', welche für 1, 1, 0 und 0 stehen.\n\nMan kann eine Variable auch um einen erhöhen oder verkleinern. Hierfür schreibt man statt einer Zahl '++', 'inc' oder '--', 'dec'.\n\nBeispiel:\n§9var i ++"); pages.add("§8Variablen kann man referenzieren\ndurch '<' vor dem Variablennamen und '>' nach diesem. Diese kann man in jedem Befehl verwenden.\n\nBeispiel:\n§9# Stacked um 10\nvar stacks 10\n/stack "); pages.add("§8Um Variablen über das Script ausführen zu speichern gibt es 'global' und 'unglobal' als Befehle. Der erste speichert eine locale Variable global und das zweite löscht eine globale wieder."); - pages.add("§8Des weiteren kann man Lokale Variablen mit 'unvar' löschen. Nach dem verlassen einer Welt werden alle Globalen Variablen gelöscht. Globale Variablen kann man mit '/scriptvars' einsehen"); + pages.add("§8Des weiteren kann man Lokale Variablen mit 'unvar' löschen. Nach dem verlassen einer Welt werden alle Globalen Variablen gelöscht. Globale Variablen kann man mit '/scriptvars' einsehen."); pages.add("§6Konstanten§8\n\nNeben den variablen gibt es noch 5 Konstante Werte, welche nicht mit dem 'var' Befehl verändert werden können.\n\nDiese sind:\n- trace/autotrace\n- tnt\n- freeze\n- fire"); pages.add("§8Des weiteren gibt es 3 weitere Variablen, welche explizit Spieler gebunden sind\n\nDiese sind:\n- x\n- y\n- z"); pages.add("§6Abfragen§8\n\nMit Abfragen kann man nur Gleichheit von 2 Werten überprüft werden. Hierfür verwendet man\n'if '.\nNach den zwei Werten kann man ein oder 2 Jump-Points schreiben\n'if [...] (JP)'."); From 944009a17ab09ee6ab626d3ec891387626ca5c39 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 27 Mar 2021 11:04:39 +0100 Subject: [PATCH 28/29] Add CommandScript Add ScriptListener --- .../bausystem/commands/CommandScript.java | 2 ++ .../bausystem/world/ScriptListener.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java index 52045b6..1af6767 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -47,11 +47,13 @@ public class CommandScript implements CommandExecutor { pages.add("§6Variablen§8\n\nMit Variablen kann man sich Zahlen speichern. Man definiert diese mit 'var '.\n\nBeispiel:\n§9# Setze i zu 0\nvar i 0§8\n\nEs gibt einige spezial values. Dazu zählen"); pages.add("§8'true', 'yes', 'false' und 'no', welche für 1, 1, 0 und 0 stehen.\n\nMan kann eine Variable auch um einen erhöhen oder verkleinern. Hierfür schreibt man statt einer Zahl '++', 'inc' oder '--', 'dec'.\n\nBeispiel:\n§9var i ++"); pages.add("§8Variablen kann man referenzieren\ndurch '<' vor dem Variablennamen und '>' nach diesem. Diese kann man in jedem Befehl verwenden.\n\nBeispiel:\n§9# Stacked um 10\nvar stacks 10\n/stack "); + pages.add("§8Man kann auch explizit eine globale, locale, oder konstante variable referenzieren, indem 'global.', 'local.' oder 'const.' vor den Namen in die Klammern zu schreiben."); pages.add("§8Um Variablen über das Script ausführen zu speichern gibt es 'global' und 'unglobal' als Befehle. Der erste speichert eine locale Variable global und das zweite löscht eine globale wieder."); pages.add("§8Des weiteren kann man Lokale Variablen mit 'unvar' löschen. Nach dem verlassen einer Welt werden alle Globalen Variablen gelöscht. Globale Variablen kann man mit '/scriptvars' einsehen."); pages.add("§6Konstanten§8\n\nNeben den variablen gibt es noch 5 Konstante Werte, welche nicht mit dem 'var' Befehl verändert werden können.\n\nDiese sind:\n- trace/autotrace\n- tnt\n- freeze\n- fire"); pages.add("§8Des weiteren gibt es 3 weitere Variablen, welche explizit Spieler gebunden sind\n\nDiese sind:\n- x\n- y\n- z"); pages.add("§6Abfragen§8\n\nMit Abfragen kann man nur Gleichheit von 2 Werten überprüft werden. Hierfür verwendet man\n'if '.\nNach den zwei Werten kann man ein oder 2 Jump-Points schreiben\n'if [...] (JP)'."); + pages.add("§8Des weiteren kann man überprüfen, ob eine Variable existiert mit 'if exists' wonach dann wieder 1 oder 2 Jump-Points sein müssen."); pages.add("§8Ein Jump-Point ist eine Zeile Script, wohin man springen kann. Dieser wird mit einem '.' am Anfang der Zeile beschrieben und direkt danach der Jump-Point Namen ohne Leerzeichen.\n\nBeispiel:\n§9# Jump-Point X\n.X§8"); pages.add("§8Um zu einem Jump-Point ohne Abfrage zu springen kann man den\n'jump ' Befehl verwenden."); pages.add("§6Schleifen§8\n\nSchleifen werden mit Jump-Points, if Abfragen und Jumps gebaut.\n\nBeispiel:\n§9var i 0\n.JUMP\nvar i ++\nif i 10 END JUMP\n.END§8"); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 6b897a0..cf084e2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -284,6 +284,15 @@ public class ScriptListener implements Listener { for (String variable : variables) { s = s.replace("<" + variable + ">", getValue(scriptExecutor, variable) + ""); } + for (String constVariable : CONSTANTS.keySet()) { + s = s.replace("", getConstantValue(scriptExecutor, constVariable) + ""); + } + for (String localVariable : scriptExecutor.variables.keySet()) { + s = s.replace("", getLocalValue(scriptExecutor, localVariable) + ""); + } + for (String globalVariable : GLOBAL_VARIABLES.getOrDefault(scriptExecutor.player, new HashMap<>()).keySet()) { + s = s.replace("", getGlobalValue(scriptExecutor, globalVariable) + ""); + } return s.split(" "); } @@ -364,6 +373,13 @@ public class ScriptListener implements Listener { int jumpTruePoint = scriptExecutor.jumpPoints.getOrDefault(args[2], -1); int jumpFalsePoint = args.length > 3 ? scriptExecutor.jumpPoints.getOrDefault(args[3], -1) : -1; + if (args[1].equals("exists")) { + if (isVariable(scriptExecutor, args[0])) { + return jumpTruePoint; + } else { + return jumpFalsePoint; + } + } int firstValue = getValueOrParse(scriptExecutor, args[0]); int secondValue = getValueOrParse(scriptExecutor, args[1]); if (firstValue == secondValue) { @@ -470,6 +486,21 @@ public class ScriptListener implements Listener { return scriptExecutor.variables.getOrDefault(key, 0); } + private static int getConstantValue(ScriptExecutor scriptExecutor, String key) { + return CONSTANTS.getOrDefault(key, player -> 0).apply(scriptExecutor.player); + } + + private static int getGlobalValue(ScriptExecutor scriptExecutor, String key) { + if (!GLOBAL_VARIABLES.containsKey(scriptExecutor.player)) { + return 0; + } + return GLOBAL_VARIABLES.get(scriptExecutor.player).getOrDefault(key, 0); + } + + private static int getLocalValue(ScriptExecutor scriptExecutor, String key) { + return scriptExecutor.variables.getOrDefault(key, 0); + } + private static boolean isVariable(ScriptExecutor scriptExecutor, String key) { if (CONSTANTS.containsKey(key)) { return true; From 2c2022ec8f4b003d559c1208b4f55bc82c2ec689 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 30 Mar 2021 21:01:32 +0200 Subject: [PATCH 29/29] Fix 1.12 tracer you idiot --- .../src/de/steamwar/bausystem/tracer/TraceEntity_12.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index c42cf23..d39c62f 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -49,7 +49,7 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { } else if (references++ > 0) return; - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0, 0); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 70, Block.getCombinedId(getBlock())); PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; playerConnection.sendPacket(packetPlayOutSpawnEntity);