From 595225895648776548f39e4c51199e29ae18ff60 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Sep 2020 01:52:19 +0200 Subject: [PATCH 1/3] Initial Detonator Commit --- .../src/de/steamwar/bausystem/BauSystem.java | 8 +- .../bausystem/commands/CommandDetonator.java | 82 ++++++ .../CommandDetonatorTabCompleter.java | 40 +++ .../steamwar/bausystem/world/Detonator.java | 254 ++++++++++++++++++ BauSystem_Main/src/plugin.yml | 3 +- 5 files changed, 382 insertions(+), 5 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 21aa520..b1201c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -23,10 +23,7 @@ import de.steamwar.bausystem.commands.*; import de.steamwar.bausystem.tracer.TraceListener; import de.steamwar.bausystem.tracer.TNTTracer; import de.steamwar.bausystem.tracer.ShowManager; -import de.steamwar.bausystem.world.AFKStopper; -import de.steamwar.bausystem.world.ArenaSection; -import de.steamwar.bausystem.world.BauScoreboard; -import de.steamwar.bausystem.world.RegionListener; +import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; import de.steamwar.core.Core; import de.steamwar.scoreboard.SWScoreboard; @@ -117,11 +114,14 @@ public class BauSystem extends JavaPlugin implements Listener { getCommand("lockschem").setExecutor(new CommandLockschem()); getCommand("debugstick").setExecutor(new CommandDebugStick()); getCommand("watervision").setExecutor(new CommandGills()); + getCommand("detonator").setExecutor(new CommandDetonator()); + getCommand("detonator").setTabCompleter(new CommandDetonatorTabCompleter()); Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new BauScoreboard(), this); Bukkit.getPluginManager().registerEvents(new TraceListener(), this); + Bukkit.getPluginManager().registerEvents(new Detonator(), this); new AFKStopper(); TNTTracer.init(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java new file mode 100644 index 0000000..62744c1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -0,0 +1,82 @@ +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Detonator; +import de.steamwar.bausystem.world.Welt; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +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 reset §8- §7Löscht alle markierten Positionen"); + player.sendMessage("§8/§edetonator add [Z] [Y] [Z] §8- §7Fügt den Block an der Coordinate hinzu"); + player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); + } + + private boolean permissionCheck(Player player) { + if(Welt.noPermission(player, Permission.world)){ + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Detonator nutzen"); + return false; + } + return true; + } + + @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){ + help(player); + return false; + } + + if (!permissionCheck(player)) return false; + + switch (args[0].toLowerCase()) { + case "wand": + case "detonator": + player.getInventory().setItemInMainHand(Detonator.WAND); + player.updateInventory(); + break; + case "delete": + case "reset": + case "remove": + Detonator.INSTANCE.deleteLocations(player); + break; + case "detonate": + case "click": + case "use": + Detonator.INSTANCE.execute(player); + break; + case "add": + case "location": + case "loc": + if (args.length >= 4) { + try { + int x = Integer.parseInt(args[1]); + int y = Integer.parseInt(args[2]); + int z = Integer.parseInt(args[3]); + Detonator.INSTANCE.addLocation(player, new Location(player.getWorld(), x, y, z), true); + }catch (NumberFormatException e){ + player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Coordinate an!"); + } + }else { + player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Coordinate an!"); + } + break; + default: + help(player); + } + + return false; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java new file mode 100644 index 0000000..d190d92 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java @@ -0,0 +1,40 @@ +package de.steamwar.bausystem.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class CommandDetonatorTabCompleter implements TabCompleter { + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) return new ArrayList<>(); + return detonaterTabComplete((Player) sender, args); + } + + private List detonaterTabComplete(Player player, String[] args) { + List tabComplete = new ArrayList<>(); + tabComplete.add("wand"); + tabComplete.add("detonate"); + tabComplete.add("delete"); + tabComplete.add("add"); + + 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; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java new file mode 100644 index 0000000..d79a646 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -0,0 +1,254 @@ +package de.steamwar.bausystem.world; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.commands.CommandDetonator; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Openable; +import org.bukkit.block.data.Powerable; +import org.bukkit.block.data.type.*; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.*; +import java.util.stream.Collectors; + +public class Detonator implements Listener { + + private final Map> locs; + + public static Detonator INSTANCE; + public static ItemStack WAND; + + public Detonator() { + locs = new HashMap<>(); + WAND = new ItemStack(Material.TRIPWIRE_HOOK, 1); + ItemMeta im = WAND.getItemMeta(); + + im.setDisplayName("§6Fernzünder"); + im.addItemFlags(ItemFlag.HIDE_ENCHANTS); + + 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"); + im.setLore(lorelist); + + WAND.setItemMeta(im); + INSTANCE = this; + } + + public void addLocation(Player player, Location location, boolean shift) { + if(!shift) locs.get(player).clear(); + locs.get(player).add(new Loc(location.getBlockX(), + location.getBlockY(), + location.getBlockZ())); + } + + public void deleteLocations(Player player) { + if(locs.containsKey(player)) locs.remove(player); + } + + public void deleteLocation(Player player, Location location) { + if(locs.get(player).stream().filter(loc -> loc.equals(Loc.getFromLocation(location))).count() >= 1) + locs.get(player).remove(locs.get(player).stream().filter(loc -> Loc.getFromLocation(location) + .equals(loc)).limit(1).collect(Collectors.toList()).get(0)); + } + + public void execute(Player player) { + for (Loc loc: locs.get(player)) { + handleSwitch(loc.getLocation()); + } + } + + private void handleSwitch(Location location) { + Block block = location.getBlock(); + switch (block.getType()) { + case OAK_BUTTON: + case BIRCH_BUTTON: + case ACACIA_BUTTON: + case DARK_OAK_BUTTON: + case JUNGLE_BUTTON: + case SPRUCE_BUTTON: + case LEGACY_WOOD_BUTTON: + Switch btn = (Switch) block.getBlockData(); + Powerable btnpow = (Powerable) block.getBlockData(); + btnpow.setPowered(true); + block.setBlockData(btnpow); + updateBlockface(block); + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + btnpow.setPowered(false); + block.setBlockData(btnpow); + updateBlockface(block); + }, 30); + break; + case STONE_BUTTON: + case LEGACY_STONE_BUTTON: + Switch sbtn = (Switch) block.getBlockData(); + Powerable sbtnpow = (Powerable) block.getBlockData(); + sbtnpow.setPowered(true); + block.setBlockData(sbtnpow); + updateBlockface(block); + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + sbtnpow.setPowered(false); + block.setBlockData(sbtnpow); + updateBlockface(block); + }, 20); + break; + case NOTE_BLOCK: + case LEGACY_NOTE_BLOCK: + NoteBlock noteBlock = (NoteBlock) block.getBlockData(); + if(noteBlock.getNote().isSharped()) noteBlock.setNote(noteBlock.getNote().flattened()); + else noteBlock.setNote(noteBlock.getNote().sharped()); + block.setBlockData(noteBlock); + break; + case TRIPWIRE: + Tripwire tripwire = (Tripwire) block.getBlockData(); + if(tripwire.isAttached()) { + tripwire.setPowered(!tripwire.isPowered()); + block.setBlockData(tripwire); + updateBlock(block); + } else { + tripwire.setPowered(!tripwire.isPowered()); + block.setBlockData(tripwire); + } + break; + case ACACIA_PRESSURE_PLATE: + case BIRCH_PRESSURE_PLATE: + case DARK_OAK_PRESSURE_PLATE: + case HEAVY_WEIGHTED_PRESSURE_PLATE: + case JUNGLE_PRESSURE_PLATE: + case LIGHT_WEIGHTED_PRESSURE_PLATE: + case OAK_PRESSURE_PLATE: + case SPRUCE_PRESSURE_PLATE: + case STONE_PRESSURE_PLATE: + Powerable pressureSensor = (Powerable) block.getBlockData(); + pressureSensor.setPowered(true); + block.setBlockData(pressureSensor); + updateBlock(block.getRelative(BlockFace.DOWN)); + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + pressureSensor.setPowered(false); + block.setBlockData(pressureSensor); + updateBlock(block.getRelative(BlockFace.DOWN)); + }, 20); + break; + default: + if(block.getBlockData() instanceof Openable) { + Openable openable = (Openable) block.getBlockData(); + openable.setOpen(!openable.isOpen()); + block.setBlockData(openable); + } else if(block.getBlockData() instanceof Powerable) { + Powerable powerable = (Powerable) block.getBlockData(); + powerable.setPowered(!powerable.isPowered()); + block.setBlockData(powerable); + updateBlockface(block); + } + } + } + + static void updateBlock(Block block) { + BlockData data = block.getBlockData(); + block.setType(Material.BARRIER, true); + block.setBlockData(data, true); + } + + static void updateBlockface(Block block) { + Block relativebtn; + if(!(block.getBlockData() instanceof Switch)) return; + switch(((Switch)block.getBlockData()).getFace()){ + case FLOOR: + relativebtn = block.getRelative(BlockFace.DOWN); + break; + case CEILING: + relativebtn = block.getRelative(BlockFace.UP); + break; + default: + relativebtn = block.getRelative(((Switch)block.getBlockData()).getFacing()); + break; + } + updateBlock(relativebtn); + } + + private static class Loc { + + private final int x; + private final int y; + private final int z; + + public Loc(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int[] getCords() { + return new int[] {x, y, z}; + } + + public Location getLocation() { + return new Location(Bukkit.getWorlds().get(0), x, y, z); + } + + public static Loc getFromLocation(Location location) { + return new Loc(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + + @Override + public boolean equals(Object o) { + if(!(o instanceof Loc)) return false; + Loc loc = (Loc) o; + return loc.getCords()[0] == x && loc.getCords()[1] == y && loc.getCords()[2] == z; + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getItem() == null) return; + if (event.getItem().isSimilar(WAND)) { + event.setCancelled(true); + if(!locs.containsKey(event.getPlayer())) locs.put(event.getPlayer(), new HashSet<>()); + switch (event.getAction()) { + case LEFT_CLICK_BLOCK: + Location location = event.getClickedBlock().getLocation(); + if (event.getPlayer().isSneaking()){ + if(locs.get(event.getPlayer()).stream().filter(loc -> loc.equals(Loc.getFromLocation(location))) + .count() >= 1) { + deleteLocation(event.getPlayer(), location); + event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent + .fromLegacyText("§cPunkt entfernt!")); + }else { + addLocation(event.getPlayer(), location, true); + event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent + .fromLegacyText("§aPunkt hinzugefügt!")); + } + } else { + addLocation(event.getPlayer(), location, false); + event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent + .fromLegacyText("§aPunkt gesetzt!")); + } + break; + case RIGHT_CLICK_AIR: + case RIGHT_CLICK_BLOCK: + execute(event.getPlayer()); + break; + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerQuit(PlayerQuitEvent event) { + if(locs.containsKey(event.getPlayer())) { + locs.remove(event.getPlayer()); + } + } +} diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 6eac2b7..11f81ae 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -29,4 +29,5 @@ commands: aliases: nv watervision: aliases: wv - lockschem: \ No newline at end of file + lockschem: + detonator: \ No newline at end of file -- 2.39.2 From ba2d321109e751c9faefd6a2e6bbb4cd8efe9931 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Sep 2020 14:01:30 +0200 Subject: [PATCH 2/3] Added 12.2 Support --- .../bausystem/world/Detonator_12.java | 75 +++++++ .../bausystem/world/Detonator_15.java | 135 ++++++++++++ .../bausystem/commands/CommandDetonator.java | 70 ++++++- .../CommandDetonatorTabCompleter.java | 4 +- .../steamwar/bausystem/world/Detonator.java | 198 +++++------------- BauSystem_Main/src/plugin.yml | 3 +- 6 files changed, 332 insertions(+), 153 deletions(-) create mode 100644 BauSystem_12/src/de/steamwar/bausystem/world/Detonator_12.java create mode 100644 BauSystem_15/src/de/steamwar/bausystem/world/Detonator_15.java diff --git a/BauSystem_12/src/de/steamwar/bausystem/world/Detonator_12.java b/BauSystem_12/src/de/steamwar/bausystem/world/Detonator_12.java new file mode 100644 index 0000000..0d5bd29 --- /dev/null +++ b/BauSystem_12/src/de/steamwar/bausystem/world/Detonator_12.java @@ -0,0 +1,75 @@ +package de.steamwar.bausystem.world; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.NoteBlock; +import org.bukkit.craftbukkit.v1_12_R1.block.CraftNoteBlock; +import org.bukkit.material.*; +import org.bukkit.plugin.Plugin; + +public class Detonator_12 { + + public static void handleSwitch(Location location) { + Block block = location.getBlock(); + switch (block.getType()) { + case WOOD_BUTTON: + handleButton(block, 30); + break; + case STONE_BUTTON: + handleButton(block, 20); + break; + case LEVER: + handleLever(block); + break; + case NOTE_BLOCK: + handleNoteBlock(block); + break; + case TRIPWIRE: + handleTripWire(block); + break; + } + } + + private static void handleButton(Block block, int delay) { + Button btnpow = new Button(block.getType(), block.getData()); + btnpow.setPowered(true); + block.setData(btnpow.getData()); + updateBlock(block); + Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { + btnpow.setPowered(false); + block.setData(btnpow.getData()); + updateBlock(block); + }, delay); + } + + private static void handleNoteBlock(Block block) { + NoteBlock noteBlock = new CraftNoteBlock(block); + if(!noteBlock.getNote().isSharped()) noteBlock.setNote(noteBlock.getNote().sharped()); + else noteBlock.setNote(noteBlock.getNote().flattened()); + block.setData(noteBlock.getRawData()); + updateBlock(block); + } + + private static void handleLever(Block block) { + Lever lever = new Lever(block.getType(), block.getData()); + lever.setPowered(!lever.isPowered()); + block.setData(lever.getData()); + updateBlock(block); + } + + private static void handleTripWire(Block block) { + Tripwire tripwire = new Tripwire(block.getType().getId(), block.getData()); + tripwire.setActivated(!tripwire.isActivated()); + block.setData(tripwire.getData()); + updateBlock(block); + } + + static void updateBlock(Block block) { + block.getState().update(true); + } + + private static Plugin getPlugin() { + return Bukkit.getPluginManager().getPlugin("BauSystem"); + } +} diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/Detonator_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/Detonator_15.java new file mode 100644 index 0000000..8a01274 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Detonator_15.java @@ -0,0 +1,135 @@ +package de.steamwar.bausystem.world; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Openable; +import org.bukkit.block.data.Powerable; +import org.bukkit.block.data.type.NoteBlock; +import org.bukkit.block.data.type.Switch; +import org.bukkit.block.data.type.Tripwire; +import org.bukkit.plugin.Plugin; + +public class Detonator_15 { + + public static void handleSwitch(Location location) { + Block block = location.getBlock(); + switch (block.getType()) { + case OAK_BUTTON: + case BIRCH_BUTTON: + case ACACIA_BUTTON: + case DARK_OAK_BUTTON: + case JUNGLE_BUTTON: + case SPRUCE_BUTTON: + case LEGACY_WOOD_BUTTON: + handleButton(block, 30); + break; + case STONE_BUTTON: + case LEGACY_STONE_BUTTON: + handleButton(block, 20); + break; + case NOTE_BLOCK: + case LEGACY_NOTE_BLOCK: + handleNoteBlock(block); + break; + case TRIPWIRE: + handleTripWire(block); + break; + case ACACIA_PRESSURE_PLATE: + case BIRCH_PRESSURE_PLATE: + case DARK_OAK_PRESSURE_PLATE: + case HEAVY_WEIGHTED_PRESSURE_PLATE: + case JUNGLE_PRESSURE_PLATE: + case LIGHT_WEIGHTED_PRESSURE_PLATE: + case OAK_PRESSURE_PLATE: + case SPRUCE_PRESSURE_PLATE: + case STONE_PRESSURE_PLATE: + handlePressurePlate(block); + break; + default: + if(block.getBlockData() instanceof Openable) { + Openable openable = (Openable) block.getBlockData(); + openable.setOpen(!openable.isOpen()); + block.setBlockData(openable); + } else if(block.getBlockData() instanceof Powerable) { + Powerable powerable = (Powerable) block.getBlockData(); + powerable.setPowered(!powerable.isPowered()); + block.setBlockData(powerable); + updateBlockface(block); + } + } + } + + private static void handleButton(Block block, int delay) { + Powerable btnpow = (Powerable) block.getBlockData(); + btnpow.setPowered(true); + block.setBlockData(btnpow); + updateBlockface(block); + Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { + btnpow.setPowered(false); + block.setBlockData(btnpow); + updateBlockface(block); + }, delay); + } + + private static void handleNoteBlock(Block block) { + NoteBlock noteBlock = (NoteBlock) block.getBlockData(); + if(!noteBlock.getNote().isSharped()) noteBlock.setNote(noteBlock.getNote().sharped()); + else noteBlock.setNote(noteBlock.getNote().flattened()); + block.setBlockData(noteBlock); + } + + private static void handleTripWire(Block block) { + Tripwire tripwire = (Tripwire) block.getBlockData(); + if(tripwire.isAttached()) { + tripwire.setPowered(!tripwire.isPowered()); + block.setBlockData(tripwire); + updateBlock(block); + } else { + tripwire.setPowered(!tripwire.isPowered()); + block.setBlockData(tripwire); + } + } + + private static void handlePressurePlate(Block block) { + Powerable pressureSensor = (Powerable) block.getBlockData(); + pressureSensor.setPowered(true); + block.setBlockData(pressureSensor); + updateBlock(block.getRelative(BlockFace.DOWN)); + Bukkit.getScheduler().runTaskLater(getPlugin(), () -> { + pressureSensor.setPowered(false); + block.setBlockData(pressureSensor); + updateBlock(block.getRelative(BlockFace.DOWN)); + }, 20); + } + + static void updateBlock(Block block) { + BlockData data = block.getBlockData(); + block.setType(Material.BARRIER, true); + block.setBlockData(data, true); + } + + static void updateBlockface(Block block) { + Block relativebtn; + if (!(block.getBlockData() instanceof Switch)) return; + switch (((Switch) block.getBlockData()).getFace()) { + case FLOOR: + relativebtn = block.getRelative(BlockFace.DOWN); + break; + case CEILING: + relativebtn = block.getRelative(BlockFace.UP); + break; + default: + relativebtn = block.getRelative(((Switch) block.getBlockData()).getFacing()); + break; + } + updateBlock(relativebtn); + } + + private static Plugin getPlugin() { + return Bukkit.getPluginManager().getPlugin("BauSystem"); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 62744c1..139eec7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -4,19 +4,26 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Detonator; import de.steamwar.bausystem.world.Welt; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.ArrayList; + 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 reset §8- §7Löscht alle markierten Positionen"); - player.sendMessage("§8/§edetonator add [Z] [Y] [Z] §8- §7Fügt den Block an der Coordinate hinzu"); + player.sendMessage("§8/§edetonator add [X] [Y] [Z] §8- §7Fügt den Block an der Coordinate hinzu"); + player.sendMessage("§8/§edetonator list §8- §7Zeigt dir alle Punkte an"); + player.sendMessage("§8/§edetonator tp [Punkt] §8- §7Teleportiert dich zu dem Punkt"); player.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); } @@ -44,6 +51,7 @@ public class CommandDetonator implements CommandExecutor { switch (args[0].toLowerCase()) { case "wand": case "detonator": + case "item": player.getInventory().setItemInMainHand(Detonator.WAND); player.updateInventory(); break; @@ -73,10 +81,68 @@ public class CommandDetonator implements CommandExecutor { player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Coordinate an!"); } break; + case "list": + case "show": + if(!Detonator.INSTANCE.containsPlayer(player) || + Detonator.INSTANCE.getLocations(player).isEmpty()) { + player.sendMessage(BauSystem.PREFIX + "§cDu hast keine Punkte!"); + }else { + player.sendMessage(BauSystem.PREFIX + "§7Deine Punkte:"); + int i = 0; + for (Detonator.Loc loc: Detonator.INSTANCE.getLocations(player)) { + i++; + sendTxtCmd(player, ChatMessageType.SYSTEM, newTxtCmd("§ePunkt " + i + "§8: §7[" + loc.getCords()[0]+ ", " + loc.getCords()[1] + + ", " + loc.getCords()[2] + "]", "/detonator tp " + i)); + } + } + break; + case "tp": + case "teleport": + if(!Detonator.INSTANCE.containsPlayer(player) || + Detonator.INSTANCE.getLocations(player).isEmpty()) { + player.sendMessage(BauSystem.PREFIX + "§cDu hast keine Punkte!"); + return true; + } + if(args.length <= 1) { + player.sendMessage(BauSystem.PREFIX + "§cNicht genug Argumente!"); + return true; + } + + try { + int i = Integer.parseInt(args[1]); + if(Detonator.INSTANCE.getLocations(player).size() <= i || i > 0) { + player.teleport(player.getLocation().zero().add(new ArrayList<>(Detonator.INSTANCE.getLocations(player)).get(i-1).getLocation() + .add(0.5, 0, 0.5))); + TextComponent.fromLegacyText("§aTeleportiert zu Punkt: " + args[1]); + }else { + player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Punkt ein!"); + } + }catch (NumberFormatException e) { + player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Zahl ein!"); + } + break; default: help(player); } - return false; + return true; + } + + public static TextComponent newTxtCmd(String txt, String cmd) { + TextComponent tc = new TextComponent(); + tc.setText(txt); + tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, cmd)); + return tc; + } + + public static void sendTxtCmd(Player p, ChatMessageType chatMessageType ,TextComponent... tcs) { + TextComponent[] var5 = tcs; + int var4 = tcs.length; + + for(int var3 = 0; var3 < var4; ++var3) { + TextComponent textComponent = var5[var3]; + p.spigot().sendMessage(chatMessageType, textComponent); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java index d190d92..afddb42 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonatorTabCompleter.java @@ -19,9 +19,11 @@ public class CommandDetonatorTabCompleter implements TabCompleter { private List detonaterTabComplete(Player player, String[] args) { List tabComplete = new ArrayList<>(); tabComplete.add("wand"); - tabComplete.add("detonate"); + tabComplete.add("reset"); tabComplete.add("delete"); tabComplete.add("add"); + tabComplete.add("list"); + tabComplete.add("tp"); if (args.length >= 2) { return new ArrayList<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java index d79a646..5f410a1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Detonator.java @@ -1,18 +1,11 @@ package de.steamwar.bausystem.world; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.commands.CommandDetonator; +import de.steamwar.core.Core; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Openable; -import org.bukkit.block.data.Powerable; -import org.bukkit.block.data.type.*; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -65,149 +58,24 @@ public class Detonator implements Listener { .equals(loc)).limit(1).collect(Collectors.toList()).get(0)); } + public Set getLocations(Player player) { + return locs.get(player); + } + + public boolean containsPlayer(Player player) { + return locs.containsKey(player); + } + public void execute(Player player) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§a" + locs.get(player).size() + " Punkt(e) ausgelöst!")); for (Loc loc: locs.get(player)) { - handleSwitch(loc.getLocation()); - } - } - - private void handleSwitch(Location location) { - Block block = location.getBlock(); - switch (block.getType()) { - case OAK_BUTTON: - case BIRCH_BUTTON: - case ACACIA_BUTTON: - case DARK_OAK_BUTTON: - case JUNGLE_BUTTON: - case SPRUCE_BUTTON: - case LEGACY_WOOD_BUTTON: - Switch btn = (Switch) block.getBlockData(); - Powerable btnpow = (Powerable) block.getBlockData(); - btnpow.setPowered(true); - block.setBlockData(btnpow); - updateBlockface(block); - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - btnpow.setPowered(false); - block.setBlockData(btnpow); - updateBlockface(block); - }, 30); - break; - case STONE_BUTTON: - case LEGACY_STONE_BUTTON: - Switch sbtn = (Switch) block.getBlockData(); - Powerable sbtnpow = (Powerable) block.getBlockData(); - sbtnpow.setPowered(true); - block.setBlockData(sbtnpow); - updateBlockface(block); - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - sbtnpow.setPowered(false); - block.setBlockData(sbtnpow); - updateBlockface(block); - }, 20); - break; - case NOTE_BLOCK: - case LEGACY_NOTE_BLOCK: - NoteBlock noteBlock = (NoteBlock) block.getBlockData(); - if(noteBlock.getNote().isSharped()) noteBlock.setNote(noteBlock.getNote().flattened()); - else noteBlock.setNote(noteBlock.getNote().sharped()); - block.setBlockData(noteBlock); - break; - case TRIPWIRE: - Tripwire tripwire = (Tripwire) block.getBlockData(); - if(tripwire.isAttached()) { - tripwire.setPowered(!tripwire.isPowered()); - block.setBlockData(tripwire); - updateBlock(block); - } else { - tripwire.setPowered(!tripwire.isPowered()); - block.setBlockData(tripwire); - } - break; - case ACACIA_PRESSURE_PLATE: - case BIRCH_PRESSURE_PLATE: - case DARK_OAK_PRESSURE_PLATE: - case HEAVY_WEIGHTED_PRESSURE_PLATE: - case JUNGLE_PRESSURE_PLATE: - case LIGHT_WEIGHTED_PRESSURE_PLATE: - case OAK_PRESSURE_PLATE: - case SPRUCE_PRESSURE_PLATE: - case STONE_PRESSURE_PLATE: - Powerable pressureSensor = (Powerable) block.getBlockData(); - pressureSensor.setPowered(true); - block.setBlockData(pressureSensor); - updateBlock(block.getRelative(BlockFace.DOWN)); - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { - pressureSensor.setPowered(false); - block.setBlockData(pressureSensor); - updateBlock(block.getRelative(BlockFace.DOWN)); - }, 20); - break; - default: - if(block.getBlockData() instanceof Openable) { - Openable openable = (Openable) block.getBlockData(); - openable.setOpen(!openable.isOpen()); - block.setBlockData(openable); - } else if(block.getBlockData() instanceof Powerable) { - Powerable powerable = (Powerable) block.getBlockData(); - powerable.setPowered(!powerable.isPowered()); - block.setBlockData(powerable); - updateBlockface(block); - } - } - } - - static void updateBlock(Block block) { - BlockData data = block.getBlockData(); - block.setType(Material.BARRIER, true); - block.setBlockData(data, true); - } - - static void updateBlockface(Block block) { - Block relativebtn; - if(!(block.getBlockData() instanceof Switch)) return; - switch(((Switch)block.getBlockData()).getFace()){ - case FLOOR: - relativebtn = block.getRelative(BlockFace.DOWN); - break; - case CEILING: - relativebtn = block.getRelative(BlockFace.UP); - break; - default: - relativebtn = block.getRelative(((Switch)block.getBlockData()).getFacing()); - break; - } - updateBlock(relativebtn); - } - - private static class Loc { - - private final int x; - private final int y; - private final int z; - - public Loc(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public int[] getCords() { - return new int[] {x, y, z}; - } - - public Location getLocation() { - return new Location(Bukkit.getWorlds().get(0), x, y, z); - } - - public static Loc getFromLocation(Location location) { - return new Loc(location.getBlockX(), location.getBlockY(), location.getBlockZ()); - } - - @Override - public boolean equals(Object o) { - if(!(o instanceof Loc)) return false; - Loc loc = (Loc) o; - return loc.getCords()[0] == x && loc.getCords()[1] == y && loc.getCords()[2] == z; + switch(Core.getVersion()){ + case 15: + Detonator_15.handleSwitch(loc.getLocation()); + break; + default: + Detonator_12.handleSwitch(loc.getLocation()); + } } } @@ -251,4 +119,36 @@ public class Detonator implements Listener { locs.remove(event.getPlayer()); } } + + public static class Loc { + + private final int x; + private final int y; + private final int z; + + public Loc(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + public int[] getCords() { + return new int[] {x, y, z}; + } + + public Location getLocation() { + return new Location(Bukkit.getWorlds().get(0), x, y, z); + } + + public static Loc getFromLocation(Location location) { + return new Loc(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + + @Override + public boolean equals(Object o) { + if(!(o instanceof Loc)) return false; + Loc loc = (Loc) o; + return loc.getCords()[0] == x && loc.getCords()[1] == y && loc.getCords()[2] == z; + } + } } diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 11f81ae..4a21d05 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -30,4 +30,5 @@ commands: watervision: aliases: wv lockschem: - detonator: \ No newline at end of file + detonator: + aliases: dt \ No newline at end of file -- 2.39.2 From 55e5b6534516513eb9d42398905ed548e349110b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 6 Sep 2020 14:27:29 +0200 Subject: [PATCH 3/3] Improved Language --- .../de/steamwar/bausystem/commands/CommandDetonator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java index 139eec7..749ef9c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandDetonator.java @@ -75,10 +75,10 @@ public class CommandDetonator implements CommandExecutor { int z = Integer.parseInt(args[3]); Detonator.INSTANCE.addLocation(player, new Location(player.getWorld(), x, y, z), true); }catch (NumberFormatException e){ - player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Coordinate an!"); + player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine valide Coordinate an!"); } }else { - player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Coordinate an!"); + player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine valide Coordinate an!"); } break; case "list": @@ -115,10 +115,10 @@ public class CommandDetonator implements CommandExecutor { .add(0.5, 0, 0.5))); TextComponent.fromLegacyText("§aTeleportiert zu Punkt: " + args[1]); }else { - player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Punkt ein!"); + player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine valide Punkt ein!"); } }catch (NumberFormatException e) { - player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine Valide Zahl ein!"); + player.sendMessage(BauSystem.PREFIX + "§cBitte gebe eine valide Zahl ein!"); } break; default: -- 2.39.2