From 0c17692fc3a47f332159210e50c3a17325b670d7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 Mar 2021 12:31:36 +0100 Subject: [PATCH 01/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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/46] 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 50decb6a4ada5218461de8551ea800b343dc917f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 13 Mar 2021 14:43:39 +0100 Subject: [PATCH 19/46] Add variable reference support to internal commands Add arithmetic commands Add auto_trace constant --- .../bausystem/commands/CommandScript.java | 8 +- .../bausystem/tracer/record/RecordStatus.java | 16 ++- .../bausystem/world/ScriptListener.java | 106 +++++++++++++----- 3 files changed, 92 insertions(+), 38 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java index e8d0811..12188de 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -39,7 +39,7 @@ public class CommandScript implements CommandExecutor { static { List pages = new ArrayList<>(); - pages.add("§6Script System§8\n\n- Commands\n- Kommentare\n- Scriptausführung\n- Sleep\n- Variablen\n- Konstanten\n- Abfragen\n- Schleifen\n- \"echo\""); + pages.add("§6Script System§8\n\n- Commands\n- Kommentare\n- Scriptausführung\n- Sleep\n- Variablen\n- Konstanten\n- Abfragen\n- Schleifen\n- \"echo\"\n- Arithmetik"); pages.add("§6Commands§8\n\nEin minecraft Befehl wird im Scriptbuch so hingeschrieben. Dabei kann man ein '/' weglassen. Um Befehle zu trennen kommen diese in neue Zeilen.\n\nStatt\n/tnt -> tnt\n//pos1 -> /pos1"); pages.add("§6Kommentare§8\n\nFür ein Kommentar fängt die Zeile mit einem '#' an. Diese Zeilen werden bei dem Ausführen dann ignoriert.\n\nBeispiel:\n§9# TNT an/aus\ntnt§8"); pages.add("§6Scriptausführung§8\n\nWenn du mit dem Buch in der Hand links klickst wird dieses ausgeführt."); @@ -47,12 +47,16 @@ 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 ++§8"); pages.add("§8Variablen kann man referenzieren\ndurch '$' vor dem Variablennamen. Diese kann man in jedem Befehl verwenden.\n\nBeispiel:\n§9# Stacked um 10\nvar stacks 10\n/stack $stacks§8"); - pages.add("§6Konstanten§8\n\nNeben den variablen gibt es noch 4 Konstante Werte, welche nicht mit dem 'var' Befehl verändert werden können.\n\nDiese sind:\n- trace\n- tnt\n- freeze\n- fire"); + pages.add("§6Konstanten§8\n\nNeben den variablen gibt es noch 4 Konstante Werte, welche nicht mit dem 'var' Befehl verändert werden können.\n\nDiese sind:\n- trace/auto_trace\n- tnt\n- freeze\n- fire"); 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."); 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"); pages.add("§6\"echo\"§8\n\nDer echo Befehl ist gut um Ausgaben zu tätigen. Hier drin kann man sowohl Variablen ausgeben, als auch Farbcodes verwenden. Es wird alles nach dem Befehl ausgegeben.\n\nBeispiel:\n§9echo &eSteam&8war &7war hier!§8"); + pages.add("§6Arithmetik§8\n\nEs gibt 4 Arithmetische Befehle:\n- add\n- sub\n- mul\n- div\n\nDer erste Parameter ist die Variable welche den ausgerechneten Wert halten soll. Hiernach muss ein"); + pages.add("§8Wert oder Variable kommen welcher verrechnet wird. Hierbei wird das erste Argument als ersten Operand genommen.\n\nBeispiel:\n§9var i 2\nvar j 3\nadd i j\necho $i§8"); + pages.add("§8Man kann auch 3 Argumente angeben. Dann wird die arithmetische Operation zwischen den letzten beiden Argumenten berechnet und als Variable des ersten Arguments abgespeichert. \n\nBeispiel auf der nächsten Seite -->"); + pages.add("§8Beispiel:\n§9var i 2\nvar j 2\nadd k i j\necho $k"); BookMeta bookMeta = (BookMeta) BOOK.getItemMeta(); bookMeta.setGeneration(BookMeta.Generation.ORIGINAL); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java index e9f69e7..b3d0a94 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java @@ -21,18 +21,20 @@ package de.steamwar.bausystem.tracer.record; public enum RecordStatus { - RECORD("§aan", true,"§cTNT-Tracer muss gestoppt werden"), - RECORD_AUTO("§aan", true, "§cTNT-Tracer darf nicht aufnehmen"), - IDLE("§caus", false, "§cAuto-Tracer gestoppt"), - IDLE_AUTO("§eauto", false, "§aAuto-Tracer gestartet"); + RECORD("§aan", true,false, "§cTNT-Tracer muss gestoppt werden"), + RECORD_AUTO("§aan", true, true, "§cTNT-Tracer darf nicht aufnehmen"), + IDLE("§caus", false, false, "§cAuto-Tracer gestoppt"), + IDLE_AUTO("§eauto", false, true, "§aAuto-Tracer gestartet"); String name; boolean tracing; + boolean autoTrace; String autoMessage; - RecordStatus(String value, boolean tracing, String autoMessage) { + RecordStatus(String value, boolean tracing, boolean autoTrace, String autoMessage) { this.name = value; this.tracing = tracing; + this.autoTrace = autoTrace; this.autoMessage = autoMessage; } @@ -44,6 +46,10 @@ public enum RecordStatus { return tracing; } + public boolean isAutoTrace() { + return autoTrace; + } + public String getAutoMessage() { return autoMessage; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 07cffe3..af29687 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -37,6 +37,8 @@ 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.logging.Level; public class ScriptListener implements Listener { @@ -122,12 +124,12 @@ public class ScriptListener implements Listener { } switch (firstArg.toLowerCase()) { case "sleep": - ScriptListener.sleepCommand(this, generateArgumentArray("sleep", command)); + ScriptListener.sleepCommand(this, generateArgumentArray("sleep", this, command)); return; case "exit": return; case "jump": - int jumpIndex = ScriptListener.jumpCommand(this, generateArgumentArray("jump", command)); + int jumpIndex = ScriptListener.jumpCommand(this, generateArgumentArray("jump", this, command)); if (jumpIndex != -1) { index = jumpIndex; } else { @@ -135,13 +137,25 @@ public class ScriptListener implements Listener { } continue; case "echo": - ScriptListener.echoCommand(this, generateArgumentArray("echo", command)); + ScriptListener.echoCommand(this, generateArgumentArray("echo", this, command)); continue; case "var": - ScriptListener.variableCommand(this, generateArgumentArray("var", command)); + ScriptListener.variableCommand(this, generateArgumentArray("var", this, command)); + continue; + case "add": + ScriptListener.arithmeticCommand(this, generateArgumentArray("add", this, command), (left, right) -> left + right); + continue; + case "sub": + ScriptListener.arithmeticCommand(this, generateArgumentArray("sub", this, command), (left, right) -> left - right); + continue; + case "mul": + ScriptListener.arithmeticCommand(this, generateArgumentArray("mul", this, command), (left, right) -> left * right); + continue; + case "div": + ScriptListener.arithmeticCommand(this, generateArgumentArray("div", this, command), (left, right) -> left / right); continue; case "if": - int ifJumpIndex = ScriptListener.ifCommand(this, generateArgumentArray("if", command)); + int ifJumpIndex = ScriptListener.ifCommand(this, generateArgumentArray("if", this, command)); if (ifJumpIndex != -1) { index = ifJumpIndex; } @@ -157,10 +171,7 @@ public class ScriptListener implements Listener { } // Variable Replaces in commands. - String[] commandArgs = command.split(" "); - String[] args = Arrays.copyOfRange(commandArgs, 1, commandArgs.length); - replaceVariables(this, args); - command = commandArgs[0] + " " + String.join(" ", args); + command = String.join(" ", generateArgumentArray("", this, command)); Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); Bukkit.getServer().dispatchCommand(player, command); @@ -169,8 +180,15 @@ public class ScriptListener implements Listener { } - private static String[] generateArgumentArray(String command, String fullCommand) { - return fullCommand.substring(command.length()).trim().split(" "); + private static String[] generateArgumentArray(String command, ScriptExecutor scriptExecutor, String fullCommand) { + String[] strings; + if (command.isEmpty()) { + strings = fullCommand.split(" "); + } else { + strings = fullCommand.substring(command.length()).trim().split(" "); + } + replaceVariables(scriptExecutor, strings); + return strings; } private static void sleepCommand(ScriptExecutor scriptExecutor, String[] args) { @@ -233,31 +251,20 @@ public class ScriptListener implements Listener { default: break; } - setValue(scriptExecutor, args[0], args[1]); + setValue(scriptExecutor, args[0], parseValue(args[1])); } private static int ifCommand(ScriptExecutor scriptExecutor, String[] args) { if (args.length < 2) { - scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDie ersten beiden Argumente sind Zahlen/Boolsche Wertde oder Variablen."); + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDie ersten beiden Argumente sind Zahlen/Boolsche Werte oder Variablen."); return -1; } int jumpTruePoint = scriptExecutor.jumpPoints.getOrDefault(args[2], -1); int jumpFalsePoint = args.length > 3 ? scriptExecutor.jumpPoints.getOrDefault(args[3], -1) : -1; - int firstValue; - int secondValue; - if (isVariable(scriptExecutor, args[0])) { - firstValue = getValue(scriptExecutor, args[0]); - } else { - firstValue = parseValue(args[0]); - } - if (isVariable(scriptExecutor, args[1])) { - secondValue = getValue(scriptExecutor, args[1]); - } else { - secondValue = parseValue(args[1]); - } - + int firstValue = getValueOrParse(scriptExecutor, args[0]); + int secondValue = getValueOrParse(scriptExecutor, args[1]); if (firstValue == secondValue) { return jumpTruePoint; } else { @@ -265,8 +272,34 @@ public class ScriptListener implements Listener { } } - private static void setValue(ScriptExecutor scriptExecutor, String key, String value) { - scriptExecutor.variables.put(key, parseValue(value)); + private static void arithmeticCommand(ScriptExecutor scriptExecutor, String[] args, IntBinaryOperator operation) { + if (args.length < 1) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDas erste Argument ist eine Variable"); + return; + } + if (args.length < 2) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDas zweite Argument ist eine Zahl oder Variable"); + return; + } + + int firstValue; + int secondValue; + if (args.length < 3) { + if (!isVariable(scriptExecutor, args[0])) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDas erste Argument muss eine Variable sein"); + return; + } + firstValue = getValue(scriptExecutor, args[0]); + secondValue = getValueOrParse(scriptExecutor, args[1]); + } else { + firstValue = getValue(scriptExecutor, args[1]); + secondValue = getValueOrParse(scriptExecutor, args[2]); + } + setValue(scriptExecutor, args[0], operation.applyAsInt(firstValue, secondValue)); + } + + private static void setValue(ScriptExecutor scriptExecutor, String key, int value) { + scriptExecutor.variables.put(key, value); } private static void add(ScriptExecutor scriptExecutor, String key, int value) { @@ -276,17 +309,27 @@ public class ScriptListener implements Listener { scriptExecutor.variables.put(key, scriptExecutor.variables.get(key) + value); } + private static int getValueOrParse(ScriptExecutor scriptExecutor, String key) { + if (isVariable(scriptExecutor, key)) { + return getValue(scriptExecutor, key); + } else { + return parseValue(key); + } + } + 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 "auto_trace": + return RecordStateMachine.getRecordStatus().isAutoTrace() ? 1 : 0; case "tnt": - return region == null || region.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; + return region.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; case "freeze": - return region == null || !region.isFreeze() ? 0 : 1; + return !region.isFreeze() ? 0 : 1; case "fire": - return region == null || !region.isFire() ? 0 : 1; + return !region.isFire() ? 0 : 1; default: return scriptExecutor.variables.getOrDefault(key, 0); } @@ -295,6 +338,7 @@ public class ScriptListener implements Listener { private static boolean isVariable(ScriptExecutor scriptExecutor, String key) { switch (key) { case "trace": + case "auto_trace": case "tnt": case "freeze": case "fire": From a7e45111f57e6b923ac9dfcef165b999b2b3e064 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 13 Mar 2021 15:06:42 +0100 Subject: [PATCH 20/46] Add variable reference support to internal commands Add arithmetic commands Add auto_trace constant --- .../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 12188de..9bae4d5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -47,7 +47,7 @@ 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 ++§8"); pages.add("§8Variablen kann man referenzieren\ndurch '$' vor dem Variablennamen. Diese kann man in jedem Befehl verwenden.\n\nBeispiel:\n§9# Stacked um 10\nvar stacks 10\n/stack $stacks§8"); - pages.add("§6Konstanten§8\n\nNeben den variablen gibt es noch 4 Konstante Werte, welche nicht mit dem 'var' Befehl verändert werden können.\n\nDiese sind:\n- trace/auto_trace\n- tnt\n- freeze\n- fire"); + 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/auto_trace\n- tnt\n- freeze\n- fire"); 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."); From c4564e313a58b31f226a18c185a93f81c55e7802 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 19 Mar 2021 22:27:57 +0100 Subject: [PATCH 21/46] Fix ScriptListener Fix RecordStatus --- .../bausystem/tracer/record/RecordStatus.java | 14 ++++++-------- .../steamwar/bausystem/world/ScriptListener.java | 9 ++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java index b3d0a94..b87e740 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/record/RecordStatus.java @@ -21,20 +21,18 @@ package de.steamwar.bausystem.tracer.record; public enum RecordStatus { - RECORD("§aan", true,false, "§cTNT-Tracer muss gestoppt werden"), - RECORD_AUTO("§aan", true, true, "§cTNT-Tracer darf nicht aufnehmen"), - IDLE("§caus", false, false, "§cAuto-Tracer gestoppt"), - IDLE_AUTO("§eauto", false, true, "§aAuto-Tracer gestartet"); + RECORD("§aan", true, "§cTNT-Tracer muss gestoppt werden"), + RECORD_AUTO("§aan", true, "§cTNT-Tracer darf nicht aufnehmen"), + IDLE("§caus", false, "§cAuto-Tracer gestoppt"), + IDLE_AUTO("§eauto", false, "§aAuto-Tracer gestartet"); String name; boolean tracing; - boolean autoTrace; String autoMessage; - RecordStatus(String value, boolean tracing, boolean autoTrace, String autoMessage) { + RecordStatus(String value, boolean tracing, String autoMessage) { this.name = value; this.tracing = tracing; - this.autoTrace = autoTrace; this.autoMessage = autoMessage; } @@ -47,7 +45,7 @@ public enum RecordStatus { } public boolean isAutoTrace() { - return autoTrace; + return this == RECORD_AUTO || this == IDLE_AUTO; } public String getAutoMessage() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index af29687..31a361b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -37,7 +37,6 @@ 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.logging.Level; @@ -274,11 +273,11 @@ public class ScriptListener implements Listener { private static void arithmeticCommand(ScriptExecutor scriptExecutor, String[] args, IntBinaryOperator operation) { if (args.length < 1) { - scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDas erste Argument ist eine Variable"); + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cAls erstes Argument fehlt eine Variable"); return; } if (args.length < 2) { - scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDas zweite Argument ist eine Zahl oder Variable"); + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cAls zweites Argument fehlt eine Zahl oder Variable"); return; } @@ -322,7 +321,7 @@ public class ScriptListener implements Listener { switch (key) { case "trace": return RecordStateMachine.getRecordStatus().isTracing() ? 1 : 0; - case "auto_trace": + case "autotrace": return RecordStateMachine.getRecordStatus().isAutoTrace() ? 1 : 0; case "tnt": return region.getTntMode() == CommandTNT.TNTMode.OFF ? 0 : 1; @@ -338,7 +337,7 @@ public class ScriptListener implements Listener { private static boolean isVariable(ScriptExecutor scriptExecutor, String key) { switch (key) { case "trace": - case "auto_trace": + case "autotrace": case "tnt": case "freeze": case "fire": From de68dc00f1f3f4a0eb9942104cded8bee77ffdde Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 19 Mar 2021 22:41:30 +0100 Subject: [PATCH 22/46] Fix 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 9bae4d5..e2d0bfa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -47,7 +47,7 @@ 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 ++§8"); pages.add("§8Variablen kann man referenzieren\ndurch '$' vor dem Variablennamen. Diese kann man in jedem Befehl verwenden.\n\nBeispiel:\n§9# Stacked um 10\nvar stacks 10\n/stack $stacks§8"); - 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/auto_trace\n- tnt\n- freeze\n- fire"); + 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("§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."); From 48a60e19b3b4e415722c6190fced952b6e79070a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Mar 2021 12:31:17 +0100 Subject: [PATCH 23/46] Add Logic to ScriptListener Add Input to ScriptListener --- .../bausystem/commands/CommandScript.java | 21 +++-- .../bausystem/world/ScriptListener.java | 82 +++++++++++++++++-- 2 files changed, 91 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java index e2d0bfa..95ddb92 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScript.java @@ -39,24 +39,31 @@ public class CommandScript implements CommandExecutor { static { List pages = new ArrayList<>(); - pages.add("§6Script System§8\n\n- Commands\n- Kommentare\n- Scriptausführung\n- Sleep\n- Variablen\n- Konstanten\n- Abfragen\n- Schleifen\n- \"echo\"\n- Arithmetik"); + pages.add("§6Script System§8\n\n- Commands\n- Kommentare\n- Scriptausführung\n- Sleep\n- Variablen\n- Konstanten\n- Abfragen\n- Schleifen\n- \"echo\"\n- \"input\"\n- Arithmetik\n- Logik"); pages.add("§6Commands§8\n\nEin minecraft Befehl wird im Scriptbuch so hingeschrieben. Dabei kann man ein '/' weglassen. Um Befehle zu trennen kommen diese in neue Zeilen.\n\nStatt\n/tnt -> tnt\n//pos1 -> /pos1"); - pages.add("§6Kommentare§8\n\nFür ein Kommentar fängt die Zeile mit einem '#' an. Diese Zeilen werden bei dem Ausführen dann ignoriert.\n\nBeispiel:\n§9# TNT an/aus\ntnt§8"); + pages.add("§6Kommentare§8\n\nFür ein Kommentar fängt die Zeile mit einem '#' an. Diese Zeilen werden bei dem Ausführen dann ignoriert.\n\nBeispiel:\n§9# TNT an/aus\ntnt"); pages.add("§6Scriptausführung§8\n\nWenn du mit dem Buch in der Hand links klickst wird dieses ausgeführt."); - pages.add("§6Sleep§8\n\nUm Sachen langsamer zu machen kann man ein 'sleep' in sein Script schreiben. Danach kommt eine Zahl mit der Anzahl der GameTicks die zu schlafen sind.\n\nBeispiel:\n§9# 1 Sekunde schlafen\nsleep 20§8"); + pages.add("§6Sleep§8\n\nUm Sachen langsamer zu machen kann man ein 'sleep' in sein Script schreiben. Danach kommt eine Zahl mit der Anzahl der GameTicks die zu schlafen sind.\n\nBeispiel:\n§9# 1 Sekunde schlafen\nsleep 20"); 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 ++§8"); - pages.add("§8Variablen kann man referenzieren\ndurch '$' vor dem Variablennamen. Diese kann man in jedem Befehl verwenden.\n\nBeispiel:\n§9# Stacked um 10\nvar stacks 10\n/stack $stacks§8"); + 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("§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("§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."); 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"); - pages.add("§6\"echo\"§8\n\nDer echo Befehl ist gut um Ausgaben zu tätigen. Hier drin kann man sowohl Variablen ausgeben, als auch Farbcodes verwenden. Es wird alles nach dem Befehl ausgegeben.\n\nBeispiel:\n§9echo &eSteam&8war &7war hier!§8"); + pages.add("§6\"echo\"§8\n\nDer echo Befehl ist da um Ausgaben zu tätigen. Hier drin kann man sowohl Variablen ausgeben, als auch Farbcodes verwenden. Es wird alles nach dem Befehl ausgegeben.\n\nBeispiel:\n§9echo &eSteam&8war &7war hier!"); + pages.add("§6\"input\"§8\n\nDer input Befehl ist eine Aufforderung einer Eingabe des Users. Die Argumente sind eine Variable und ein Text als Nachricht.\n\nBeispiel:\n§9input age &eDein Alter?"); pages.add("§6Arithmetik§8\n\nEs gibt 4 Arithmetische Befehle:\n- add\n- sub\n- mul\n- div\n\nDer erste Parameter ist die Variable welche den ausgerechneten Wert halten soll. Hiernach muss ein"); - pages.add("§8Wert oder Variable kommen welcher verrechnet wird. Hierbei wird das erste Argument als ersten Operand genommen.\n\nBeispiel:\n§9var i 2\nvar j 3\nadd i j\necho $i§8"); + pages.add("§8Wert oder Variable kommen welcher verrechnet wird. Hierbei wird das erste Argument als ersten Operand genommen.\n\nBeispiel:\n§9var i 2\nvar j 3\nadd i j\necho $i"); pages.add("§8Man kann auch 3 Argumente angeben. Dann wird die arithmetische Operation zwischen den letzten beiden Argumenten berechnet und als Variable des ersten Arguments abgespeichert. \n\nBeispiel auf der nächsten Seite -->"); pages.add("§8Beispiel:\n§9var i 2\nvar j 2\nadd k i j\necho $k"); + pages.add("§6Logik§8\n\nEs gibt 3 Vergleichs Befehle:\n- equal\n- less\n- greater\n\nUnd 3 Logik Befehle:\n- and\n- or\n- not"); + pages.add("§8Der erste Parameter ist die Variable welche den ausgerechneten Wert halten soll. Hiernach muss ein Wert oder Variable kommen welcher verrechnet wird. Hierbei wird das erste Argument als ersten Operand genommen. Dies gilt nicht für den 'not' Befehl, welcher"); + pages.add("§8nur 2 Parameter nimmt. Der erste die Variable und der zweite eine optionale Variable oder ein Wert. Equal vergleicht 2 Werte, less gibt zurück ob der erste kleiner als der zweite Wert ist, greater gibt zurück ob der erste größer als der zweite Wert ist."); + pages.add("§8And vergleicht ob 2 Werte true (1) sind. Or vergleicht ob 1 Wert oder 2 Werte true (1) ist/sind. Not invertiert den Wert von true (1) auf false und anders rum."); + pages.add("§8Beispiel:\n§9var i 1\nvar j 1\n#Ist i und j gleich\nequal k i j\nvar j 0\n#Ist i kleiner j\nless k i j\n#Ist i größer j\ngreater k i j\n#Ist i und j true\nand k i j\n#Beispiel weiter auf nächster Seite"); + pages.add("§9#Ist i oder j true\nor k i j\n#Invertiere i\nnot k i"); BookMeta bookMeta = (BookMeta) BOOK.getItemMeta(); bookMeta.setGeneration(BookMeta.Generation.ORIGINAL); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 31a361b..d341db9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.commands.CommandScript; import de.steamwar.bausystem.commands.CommandTNT; import de.steamwar.bausystem.tracer.record.RecordStateMachine; import de.steamwar.core.VersionedCallable; +import de.steamwar.inventory.SWAnvilInv; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -38,6 +39,7 @@ import org.bukkit.inventory.meta.BookMeta; import java.util.*; import java.util.function.IntBinaryOperator; +import java.util.function.IntUnaryOperator; import java.util.logging.Level; public class ScriptListener implements Listener { @@ -138,6 +140,9 @@ public class ScriptListener implements Listener { case "echo": ScriptListener.echoCommand(this, generateArgumentArray("echo", this, command)); continue; + case "input": + ScriptListener.inputCommand(this, generateArgumentArray("input", this, command)); + return; case "var": ScriptListener.variableCommand(this, generateArgumentArray("var", this, command)); continue; @@ -153,6 +158,24 @@ public class ScriptListener implements Listener { case "div": ScriptListener.arithmeticCommand(this, generateArgumentArray("div", this, command), (left, right) -> left / right); continue; + case "equal": + ScriptListener.arithmeticCommand(this, generateArgumentArray("equal", this, command), (left, right) -> left == right ? 1 : 0); + continue; + case "less": + ScriptListener.arithmeticCommand(this, generateArgumentArray("less", this, command), (left, right) -> left < right ? 1 : 0); + continue; + case "greater": + ScriptListener.arithmeticCommand(this, generateArgumentArray("greater", this, command), (left, right) -> left > right ? 1 : 0); + continue; + case "not": + ScriptListener.arithmeticInfixCommand(this, generateArgumentArray("not", this, command), (left) -> left == 1 ? 0 : 1); + continue; + case "and": + ScriptListener.arithmeticCommand(this, generateArgumentArray("and", this, command), (left, right) -> left == 1 && right == 1 ? 1 : 0); + continue; + case "or": + ScriptListener.arithmeticCommand(this, generateArgumentArray("or", this, command), (left, right) -> left == 1 || right == 1 ? 1 : 0); + continue; case "if": int ifJumpIndex = ScriptListener.ifCommand(this, generateArgumentArray("if", this, command)); if (ifJumpIndex != -1) { @@ -186,8 +209,7 @@ public class ScriptListener implements Listener { } else { strings = fullCommand.substring(command.length()).trim().split(" "); } - replaceVariables(scriptExecutor, strings); - return strings; + return replaceVariables(scriptExecutor, strings); } private static void sleepCommand(ScriptExecutor scriptExecutor, String[] args) { @@ -214,17 +236,25 @@ public class ScriptListener implements Listener { return scriptExecutor.jumpPoints.getOrDefault(args[0], -1); } - private static void replaceVariables(ScriptExecutor scriptExecutor, String[] args) { + private static String[] replaceVariables(ScriptExecutor scriptExecutor, String[] args) { + // Legacy '$' notation for variable reference, could be removed later on. for (int i = 0; i < args.length; i++) { if (args[i].startsWith("$") && isVariable(scriptExecutor, args[i].substring(1))) { args[i] = getValue(scriptExecutor, args[i].substring(1)) + ""; } } + + String s = String.join(" ", args); + Set variables = new HashSet<>(scriptExecutor.variables.keySet()); + variables.addAll(Arrays.asList("trace", "autotrace", "tnt", "freeze", "fire")); + for (String variable : variables) { + s = s.replace("<" + variable + ">", getValue(scriptExecutor, variable) + ""); + } + return s.split(" "); } private static void echoCommand(ScriptExecutor scriptExecutor, String[] args) { - replaceVariables(scriptExecutor, args); - scriptExecutor.player.sendMessage("§eInfo§8» §7" + ChatColor.translateAlternateColorCodes('&', String.join(" ", args))); + scriptExecutor.player.sendMessage("§eInfo§8» §7" + ChatColor.translateAlternateColorCodes('&', String.join(" ", replaceVariables(scriptExecutor, args)))); } private static void variableCommand(ScriptExecutor scriptExecutor, String[] args) { @@ -297,6 +327,48 @@ public class ScriptListener implements Listener { setValue(scriptExecutor, args[0], operation.applyAsInt(firstValue, secondValue)); } + private static void arithmeticInfixCommand(ScriptExecutor scriptExecutor, String[] args, IntUnaryOperator operation) { + if (args.length < 1) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cAls erstes Argument fehlt eine Variable"); + return; + } + + int firstValue; + if (args.length < 2) { + if (!isVariable(scriptExecutor, args[0])) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDas erste Argument muss eine Variable sein"); + return; + } + firstValue = getValue(scriptExecutor, args[0]); + } else { + firstValue = getValue(scriptExecutor, args[1]); + } + setValue(scriptExecutor, args[0], operation.applyAsInt(firstValue)); + } + + private static void inputCommand(ScriptExecutor scriptExecutor, String[] args) { + if (args.length < 1) { + scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cAls erstes Argument fehlt eine Variable"); + return; + } + String varName = args[0]; + StringBuilder st = new StringBuilder(); + for (int i = 1; i < args.length; i++) { + if (i != 1) { + st.append(" "); + } + st.append(args[i]); + } + + SWAnvilInv swAnvilInv = new SWAnvilInv(scriptExecutor.player, ChatColor.translateAlternateColorCodes('&', st.toString())); + swAnvilInv.setCallback(s -> { + int value = parseValue(s); + setValue(scriptExecutor, varName, value); + scriptExecutor.resume(); + }); + swAnvilInv.open(); + } + private static void setValue(ScriptExecutor scriptExecutor, String key, int value) { scriptExecutor.variables.put(key, value); } From f75292cbbc1b96a996104a6067d3d5c5367dfde2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Mar 2021 12:34:42 +0100 Subject: [PATCH 24/46] 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 704a50b9b65f7c9ed18b57588e8105f09f42c634 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Mar 2021 12:45:24 +0100 Subject: [PATCH 25/46] Fix ScriptListener --- .../src/de/steamwar/bausystem/world/ScriptListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 341f341..f20994a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -288,7 +288,7 @@ public class ScriptListener implements Listener { scriptExecutor.player.sendMessage(BauSystem.PREFIX + "§cDie ersten beiden Argumente sind Zahlen/Boolsche Werte oder Variablen."); return -1; } - + int jumpTruePoint = scriptExecutor.jumpPoints.getOrDefault(args[2], -1); int jumpFalsePoint = args.length > 3 ? scriptExecutor.jumpPoints.getOrDefault(args[3], -1) : -1; From 6b44f1265950a4a312e516e8fc0f4a68278465da Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 20 Mar 2021 13:09:25 +0100 Subject: [PATCH 26/46] 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 ca7b87f466ecd86892bd6db3854b2a543d81a208 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 24 Mar 2021 21:45:35 +0100 Subject: [PATCH 27/46] Minor DT Rework --- .../steamwar/bausystem/world/Detonator.java | 67 ++++++++++++++++--- .../bausystem/world/DetonatorListener.java | 55 +++++++-------- 2 files changed, 84 insertions(+), 38 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index b3918e8..bc89942 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -28,6 +28,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; @@ -50,7 +51,11 @@ public class Detonator implements Listener { im.setDisplayName("§eFernzünder"); - VersionedRunnable.call(new VersionedRunnable(() -> im.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE, (byte) 1), 15)); + VersionedRunnable.call( + new VersionedRunnable(() -> { + im.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE, (byte) 1); + im.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER, 0); + }, 15)); List lorelist = Arrays.asList("§eLinks Klick §8- §7Setzte einen Punkt zum Aktivieren", "§eLinks Klick + Shift §8- §7Füge einen Punkt hinzu", "§eRechts Klick §8- §7Löse alle Punkte aus"); @@ -65,8 +70,9 @@ public class Detonator implements Listener { }, 12), new VersionedCallable<>(() -> { ItemMeta meta = item.getItemMeta(); PersistentDataContainer container = meta.getPersistentDataContainer(); + player.sendMessage(CraftItemStack.asNMSCopy(item).getTag().toString()); List locs = new ArrayList<>(); - for (int i = 0; i < 128; i++) { + for (int i = 0; i < getDetoLocs(container); i++) { NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i); if (container.has(key, PersistentDataType.INTEGER_ARRAY)) locs.add(container.get(key, PersistentDataType.INTEGER_ARRAY)); @@ -94,7 +100,7 @@ public class Detonator implements Listener { }, 12), new VersionedCallable<>(() -> removeLocation(item, location), 15)); } else { DetonatorListener.print(player, detoloader.addBack ? "§e" + detoloader.getBlock() + " hinzugefügt" : - detoloader.getBlock(), Math.min(Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() + 1, 128)); + detoloader.getBlock(), Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() + 1); if (detoloader.getActivation() == 0) return VersionedCallable.call(new VersionedCallable<>(() -> { PLAYER_LOCS.computeIfAbsent(player, player1 -> new HashSet<>()).add(new Detoloader.DetonatorActivation(location)); @@ -110,11 +116,32 @@ public class Detonator implements Listener { public static void execute(Player player) { VersionedRunnable.call(new VersionedRunnable(() -> execute(player, PLAYER_LOCS.get(player)), 12), new VersionedRunnable(() -> { - Detonator detonator = getDetonator(player, player.getInventory().getItemInMainHand()); + ItemStack item = getNextBestDetonator(player); + if(item == null) + return; + Detonator detonator = getDetonator(player, item); execute(player, detonator.getLocs()); }, 15)); } + private static ItemStack getNextBestDetonator(Player player) { + if(player.getInventory().getItemInMainHand().getItemMeta() != null && player.getInventory().getItemInMainHand().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + return player.getInventory().getItemInMainHand(); + } + + for (ItemStack item : player.getInventory().getContents()) { + if(item == null) + continue; + + if(item.getItemMeta() != null && + item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + return item; + } + } + player.sendMessage(BauSystem.PREFIX + "§cDu hast keinen Detonator im Inventar"); + return null; + } + private static void execute(Player player, Set locs) { for (Detoloader.DetonatorActivation activation : locs) { @@ -141,22 +168,45 @@ public class Detonator implements Listener { private static int getFreeSlot(ItemStack item) { ItemMeta meta = item.getItemMeta(); + if(meta == null) { + throw new SecurityException("Das Item ist kein Detonator"); + } PersistentDataContainer container = meta.getPersistentDataContainer(); - for (int i = 0; i < 128; i++) { + if(!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + throw new SecurityException("Das Item ist kein Detonator"); + } + for (int i = 0; i < getDetoLocs(container) + 1; i++) { if (!container.has(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i), PersistentDataType.INTEGER_ARRAY)) return i; } return -1; } + private static int getDetoLocs(PersistentDataContainer container) { + if(!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + throw new SecurityException("Das Item ist kein Detonator"); + } + return container.get(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER); + } + + private static void increaseLocsSize(PersistentDataContainer container, int to) { + if(!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + throw new SecurityException("Das Item ist kein Detonator"); + } + if(container.get(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER) < to) { + container.set(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER, to); + } + } + public static ItemStack pushLocToDetonator(ItemStack item, Detoloader.DetonatorActivation detoloader) { int slot = getFreeSlot(item); if (slot == -1) - throw new SecurityException("Der Detonator ist auf 128 Positionen Limitiert"); + throw new SecurityException("Ein Fehler ist aufgetreten"); ItemMeta meta = item.getItemMeta(); Location block = detoloader.location; meta.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + slot), PersistentDataType.INTEGER_ARRAY, new int[] {block.getBlockX(), block.getBlockY(), block.getBlockZ(), detoloader.activation}); + increaseLocsSize(meta.getPersistentDataContainer(), slot + 1); item.setItemMeta(meta); return item; } @@ -164,7 +214,8 @@ public class Detonator implements Listener { public static ItemStack clearDetonator(ItemStack item) { ItemMeta meta = item.getItemMeta(); PersistentDataContainer container = meta.getPersistentDataContainer(); - for (int i = 0; i < 128; i++) { + container.set(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER, 0); + for (int i = 0; i < getDetoLocs(container); i++) { NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i); container.remove(key); } @@ -179,7 +230,7 @@ public class Detonator implements Listener { private static int getSlotOfLocation(ItemStack item, Location location) { ItemMeta meta = item.getItemMeta(); PersistentDataContainer container = meta.getPersistentDataContainer(); - for (int i = 0; i < 128; i++) { + for (int i = 0; i < getDetoLocs(container); i++) { NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i); if (container.has(key, PersistentDataType.INTEGER_ARRAY)) { int[] locs = container.get(key, PersistentDataType.INTEGER_ARRAY); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/DetonatorListener.java index fb0b1c6..dced125 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/DetonatorListener.java @@ -27,40 +27,35 @@ public class DetonatorListener implements Listener { } ItemStack item = event.getItem(); event.setCancelled(true); - try { - switch (event.getAction()) { - case LEFT_CLICK_BLOCK: - Detoloader detoloader = VersionedCallable.call( - new VersionedCallable<>(() -> AutoLoader_12.onPlayerInteractLoader(event), 12), - new VersionedCallable<>(() -> AutoLoader_15.onPlayerInteractLoader(event), 15)); + switch (event.getAction()) { + case LEFT_CLICK_BLOCK: + Detoloader detoloader = VersionedCallable.call( + new VersionedCallable<>(() -> AutoLoader_12.onPlayerInteractLoader(event), 12), + new VersionedCallable<>(() -> AutoLoader_15.onPlayerInteractLoader(event), 15)); - if (detoloader == null) { - return; - } else if (detoloader.activation == -1) { - print(player, detoloader.getBlock(), detoloader.addBack ? Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() : 0); - return; - } + if (detoloader == null) { + return; + } else if (detoloader.activation == -1) { + print(player, detoloader.getBlock(), detoloader.addBack ? Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() : 0); + return; + } - if (event.getPlayer().isSneaking()) { - player.getInventory().setItemInMainHand(Detonator.toggleLocation(item, player, detoloader, event.getClickedBlock().getLocation())); + if (event.getPlayer().isSneaking()) { + player.getInventory().setItemInMainHand(Detonator.toggleLocation(item, player, detoloader, event.getClickedBlock().getLocation())); + } else { + if (detoloader.getActivation() == 0) { + player.getInventory().setItemInMainHand(Detonator.setLocation(player, item, new Detoloader.DetonatorActivation(event.getClickedBlock().getLocation()))); } else { - if (detoloader.getActivation() == 0) { - player.getInventory().setItemInMainHand(Detonator.setLocation(player, item, new Detoloader.DetonatorActivation(event.getClickedBlock().getLocation()))); - } else { - player.getInventory().setItemInMainHand(Detonator.setLocation(player, item, new Detoloader.DetonatorActivation(detoloader.activation, event.getClickedBlock().getLocation()))); - } - print(player, detoloader.addBack ? "§e" + detoloader.getBlock() + " gesetzt" : - detoloader.getBlock(), detoloader.addBack ? Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() : 0); + player.getInventory().setItemInMainHand(Detonator.setLocation(player, item, new Detoloader.DetonatorActivation(detoloader.activation, event.getClickedBlock().getLocation()))); } - break; - case RIGHT_CLICK_AIR: - case RIGHT_CLICK_BLOCK: - Detonator.execute(player); - break; - } - } catch (RuntimeException e) { - player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage()); - player.getInventory().setItemInMainHand(item); + print(player, detoloader.addBack ? "§e" + detoloader.getBlock() + " gesetzt" : + detoloader.getBlock(), detoloader.addBack ? Detonator.getDetonator(player, player.getInventory().getItemInMainHand()).getLocs().size() : 0); + } + break; + case RIGHT_CLICK_AIR: + case RIGHT_CLICK_BLOCK: + Detonator.execute(player); + break; } } } From b533e27b854328f7015c0832bf07b3cbb86d6f90 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 25 Mar 2021 07:54:43 +0100 Subject: [PATCH 28/46] Removing Debug Messages --- .../de/steamwar/bausystem/world/Detonator.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index bc89942..fe445c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -28,7 +28,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; @@ -70,7 +69,6 @@ public class Detonator implements Listener { }, 12), new VersionedCallable<>(() -> { ItemMeta meta = item.getItemMeta(); PersistentDataContainer container = meta.getPersistentDataContainer(); - player.sendMessage(CraftItemStack.asNMSCopy(item).getTag().toString()); List locs = new ArrayList<>(); for (int i = 0; i < getDetoLocs(container); i++) { NamespacedKey key = new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i); @@ -116,11 +114,15 @@ public class Detonator implements Listener { public static void execute(Player player) { VersionedRunnable.call(new VersionedRunnable(() -> execute(player, PLAYER_LOCS.get(player)), 12), new VersionedRunnable(() -> { - ItemStack item = getNextBestDetonator(player); - if(item == null) - return; - Detonator detonator = getDetonator(player, item); - execute(player, detonator.getLocs()); + try { + ItemStack item = getNextBestDetonator(player); + if(item == null) + return; + Detonator detonator = getDetonator(player, item); + execute(player, detonator.getLocs()); + }catch (SecurityException e) { + player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage()); + } }, 15)); } From 0f970e3a4926565a83b652d3b105ee7e8cc2383a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 25 Mar 2021 08:47:21 +0100 Subject: [PATCH 29/46] Reformat Detonator --- .../steamwar/bausystem/world/Detonator.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index fe445c3..bc2cd42 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -116,26 +116,26 @@ public class Detonator implements Listener { VersionedRunnable.call(new VersionedRunnable(() -> execute(player, PLAYER_LOCS.get(player)), 12), new VersionedRunnable(() -> { try { ItemStack item = getNextBestDetonator(player); - if(item == null) + if (item == null) return; Detonator detonator = getDetonator(player, item); execute(player, detonator.getLocs()); - }catch (SecurityException e) { + } catch (SecurityException e) { player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage()); } }, 15)); } private static ItemStack getNextBestDetonator(Player player) { - if(player.getInventory().getItemInMainHand().getItemMeta() != null && player.getInventory().getItemInMainHand().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + if (player.getInventory().getItemInMainHand().getItemMeta() != null && player.getInventory().getItemInMainHand().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { return player.getInventory().getItemInMainHand(); } for (ItemStack item : player.getInventory().getContents()) { - if(item == null) + if (item == null) continue; - if(item.getItemMeta() != null && + if (item.getItemMeta() != null && item.getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { return item; } @@ -170,11 +170,11 @@ public class Detonator implements Listener { private static int getFreeSlot(ItemStack item) { ItemMeta meta = item.getItemMeta(); - if(meta == null) { + if (meta == null) { throw new SecurityException("Das Item ist kein Detonator"); } PersistentDataContainer container = meta.getPersistentDataContainer(); - if(!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + if (!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { throw new SecurityException("Das Item ist kein Detonator"); } for (int i = 0; i < getDetoLocs(container) + 1; i++) { @@ -185,17 +185,17 @@ public class Detonator implements Listener { } private static int getDetoLocs(PersistentDataContainer container) { - if(!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + if (!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { throw new SecurityException("Das Item ist kein Detonator"); } return container.get(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER); } private static void increaseLocsSize(PersistentDataContainer container, int to) { - if(!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + if (!container.has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { throw new SecurityException("Das Item ist kein Detonator"); } - if(container.get(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER) < to) { + if (container.get(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER) < to) { container.set(new NamespacedKey(BauSystem.getPlugin(), "deto-locs"), PersistentDataType.INTEGER, to); } } From 31df594797c2f9ae02f5de8e92143442758b57e8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 25 Mar 2021 10:39:52 +0100 Subject: [PATCH 30/46] 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 31/46] 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 32/46] 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 33/46] 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 af87505532cb67d3a2395c67672ee0840f1ed5dd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 25 Mar 2021 13:47:53 +0100 Subject: [PATCH 34/46] Add Offhand --- BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index fe445c3..36dd6e9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -131,6 +131,10 @@ public class Detonator implements Listener { return player.getInventory().getItemInMainHand(); } + if(player.getInventory().getItemInOffHand().getItemMeta() != null && player.getInventory().getItemInOffHand().getItemMeta().getPersistentDataContainer().has(new NamespacedKey(BauSystem.getPlugin(), "deto"), PersistentDataType.BYTE)) { + return player.getInventory().getItemInOffHand(); + } + for (ItemStack item : player.getInventory().getContents()) { if(item == null) continue; From b95ecb93b0a447bbcaa2375b436d4c265ea485bb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 26 Mar 2021 22:11:31 +0100 Subject: [PATCH 35/46] 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 36/46] 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 37/46] 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 139bf287644c76addab5ac96e8d3120571e1435f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 27 Mar 2021 08:23:46 +0100 Subject: [PATCH 38/46] Add TPSLimit to any Entity except Player --- .../src/de/steamwar/bausystem/commands/TPSLimit_12.java | 4 ++-- .../src/de/steamwar/bausystem/commands/TPSLimit_15.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java b/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java index b7e5272..cfe3928 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/commands/TPSLimit_12.java @@ -24,7 +24,7 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import java.util.ArrayList; @@ -36,7 +36,7 @@ class TPSLimit_12 { static void createTickCache(World world) { packets.clear(); - world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> { + world.getEntities().stream().filter(entity -> !(entity instanceof Player)).forEach(entity -> { packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), 0, 0, 0)); packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle())); diff --git a/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java b/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java index 04cd25c..344bcf9 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/commands/TPSLimit_15.java @@ -24,7 +24,7 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import java.util.ArrayList; @@ -37,7 +37,7 @@ class TPSLimit_15 { static void createTickCache(World world) { packets.clear(); - world.getEntitiesByClasses(TNTPrimed.class, FallingBlock.class).forEach(entity -> { + world.getEntities().stream().filter(entity -> !(entity instanceof Player)).forEach(entity -> { packets.add(new PacketPlayOutEntityVelocity(entity.getEntityId(), noMotion)); packets.add(new PacketPlayOutEntityTeleport(((CraftEntity) entity).getHandle())); From 944009a17ab09ee6ab626d3ec891387626ca5c39 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 27 Mar 2021 11:04:39 +0100 Subject: [PATCH 39/46] 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 f3511e784174e988a426c81b6a161772c764d6cd Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Mar 2021 12:54:57 +0100 Subject: [PATCH 40/46] ._. --- .../src/de/steamwar/bausystem/commands/CommandDetonator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 0785385..1528920 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -33,7 +33,7 @@ public class CommandDetonator implements CommandExecutor { private void help(Player player) { player.sendMessage("§8/§edetonator wand §8- §7Legt den Fernzünder ins Inventar"); - player.sendMessage("§8/§edetonator detonate §8- §7Benutzt den Fernzünder"); + player.sendMessage("§8/§edetonator detonate §8- §7Benutzt den nächst besten Fernzünder"); player.sendMessage("§8/§edetonator reset §8- §7Löscht alle markierten Positionen"); player.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder"); } From 59ff3a9529fbbc7cda31cbec2b582b562ccc5302 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 27 Mar 2021 13:39:14 +0100 Subject: [PATCH 41/46] ._. --- BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index ec70b4c..4f98875 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -182,8 +182,9 @@ public class Detonator implements Listener { throw new SecurityException("Das Item ist kein Detonator"); } for (int i = 0; i < getDetoLocs(container) + 1; i++) { - if (!container.has(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i), PersistentDataType.INTEGER_ARRAY)) + if (!container.has(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + i), PersistentDataType.INTEGER_ARRAY)) { return i; + } } return -1; } From db2dc1eab43f0efe76b93180576c156f4b8a7ab5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 30 Mar 2021 12:23:52 +0200 Subject: [PATCH 42/46] Adding Message for old Detonator --- .../steamwar/bausystem/world/Detonator.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 4f98875..9275afa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -84,7 +84,14 @@ public class Detonator implements Listener { PLAYER_LOCS.computeIfAbsent(player, player1 -> new HashSet<>()).clear(); PLAYER_LOCS.get(player).add(detoloader); return item; - }, 12), new VersionedCallable<>(() -> pushLocToDetonator(clearDetonator(item), detoloader), 15)); + }, 12), new VersionedCallable<>(() -> { + try { + return pushLocToDetonator(clearDetonator(item), detoloader); + }catch (SecurityException e){ + player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage()); + return item; + } + }, 15)); } public static ItemStack toggleLocation(ItemStack item, Player player, Detoloader detoloader, Location location) { @@ -103,12 +110,26 @@ public class Detonator implements Listener { return VersionedCallable.call(new VersionedCallable<>(() -> { PLAYER_LOCS.computeIfAbsent(player, player1 -> new HashSet<>()).add(new Detoloader.DetonatorActivation(location)); return item; - }, 12), new VersionedCallable<>(() -> pushLocToDetonator(item, new Detoloader.DetonatorActivation(location)), 15)); + }, 12), new VersionedCallable<>(() -> { + try { + return pushLocToDetonator(item, new Detoloader.DetonatorActivation(location)); + }catch (SecurityException e){ + player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage()); + return item; + } + }, 15)); else return VersionedCallable.call(new VersionedCallable<>(() -> { PLAYER_LOCS.computeIfAbsent(player, player1 -> new HashSet<>()).add(new Detoloader.DetonatorActivation(detoloader.getActivation(), location)); return item; - }, 12), new VersionedCallable<>(() -> pushLocToDetonator(item, new Detoloader.DetonatorActivation(detoloader.getActivation(), location)), 15)); + }, 12), new VersionedCallable<>(() -> { + try { + return pushLocToDetonator(item, new Detoloader.DetonatorActivation(detoloader.getActivation(), location)); + }catch (SecurityException e){ + player.sendMessage(BauSystem.PREFIX + "§c" + e.getMessage()); + return item; + } + }, 15)); } } @@ -208,7 +229,7 @@ public class Detonator implements Listener { public static ItemStack pushLocToDetonator(ItemStack item, Detoloader.DetonatorActivation detoloader) { int slot = getFreeSlot(item); if (slot == -1) - throw new SecurityException("Ein Fehler ist aufgetreten"); + throw new SecurityException("Ein Fehler ist aufgetreten, Hohle dir einen neuen Detonator mit §8/§edt wand"); ItemMeta meta = item.getItemMeta(); Location block = detoloader.location; meta.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + slot), PersistentDataType.INTEGER_ARRAY, new int[] From 0a513317b9808867df4540ff7913f09becafdd2a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 30 Mar 2021 12:25:51 +0200 Subject: [PATCH 43/46] Adjusting Message --- BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index 9275afa..f07279d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -229,7 +229,7 @@ public class Detonator implements Listener { public static ItemStack pushLocToDetonator(ItemStack item, Detoloader.DetonatorActivation detoloader) { int slot = getFreeSlot(item); if (slot == -1) - throw new SecurityException("Ein Fehler ist aufgetreten, Hohle dir einen neuen Detonator mit §8/§edt wand"); + throw new SecurityException("Ein Fehler ist aufgetreten, hohl dir einen neuen Detonator mit §8/§edt wand"); ItemMeta meta = item.getItemMeta(); Location block = detoloader.location; meta.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + slot), PersistentDataType.INTEGER_ARRAY, new int[] From 2c2022ec8f4b003d559c1208b4f55bc82c2ec689 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 30 Mar 2021 21:01:32 +0200 Subject: [PATCH 44/46] 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); From 0e8f3f3e688b05d57ac51d368e78cb95b6248e34 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 1 Apr 2021 19:43:04 +0200 Subject: [PATCH 45/46] Adjusting Message --- BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index f07279d..81d7295 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -229,7 +229,7 @@ public class Detonator implements Listener { public static ItemStack pushLocToDetonator(ItemStack item, Detoloader.DetonatorActivation detoloader) { int slot = getFreeSlot(item); if (slot == -1) - throw new SecurityException("Ein Fehler ist aufgetreten, hohl dir einen neuen Detonator mit §8/§edt wand"); + throw new SecurityException("Mit dem Detonator stimmt etwas nicht. Nimm dir einen neuen mit /dt wand. Wenn es dann immer nicht nicht tut, wende dich an einen Developer"); ItemMeta meta = item.getItemMeta(); Location block = detoloader.location; meta.getPersistentDataContainer().set(new NamespacedKey(BauSystem.getPlugin(), DETO_PREFIX + slot), PersistentDataType.INTEGER_ARRAY, new int[] From 613b5d3f7539eb202a2181afd7bb5a404024c679 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Apr 2021 23:00:00 +0200 Subject: [PATCH 46/46] Improve SWUtils.giveItemToPlayer --- BauSystem_API/src/de/steamwar/bausystem/SWUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java b/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java index e5b2468..693cd1f 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java +++ b/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java @@ -29,6 +29,14 @@ import java.util.List; public class SWUtils { public static void giveItemToPlayer(Player player, ItemStack itemStack) { + for (int i = 0; i < player.getInventory().getSize(); i++) { + ItemStack current = player.getInventory().getItem(i); + if (current != null && current.isSimilar(itemStack)) { + player.getInventory().setItem(i, null); + itemStack = current; + break; + } + } ItemStack current = player.getInventory().getItemInMainHand(); player.getInventory().setItemInMainHand(itemStack); if (current.getType() != Material.AIR) {