From c6b2ce23493144bf627b6f3fe7f0c574bd08666d Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Tue, 27 Jul 2021 03:25:25 +0200 Subject: [PATCH] some commands --- .../me/youhavetrouble/blockedit/BEPlayer.java | 4 ++ .../youhavetrouble/blockedit/BlockEdit.java | 39 +++++++---------- .../youhavetrouble/blockedit/TestCommand.java | 42 ------------------- .../blockedit/commands/DeselCommand.java | 28 +++++++++++++ .../blockedit/commands/Pos1Command.java | 28 +++++++++++++ .../blockedit/commands/Pos2Command.java | 28 +++++++++++++ .../blockedit/commands/ReplaceCommand.java | 1 - .../blockedit/operations/SetOperation.java | 2 - src/main/resources/plugin.yml | 12 ++++-- 9 files changed, 112 insertions(+), 72 deletions(-) delete mode 100644 src/main/java/me/youhavetrouble/blockedit/TestCommand.java create mode 100644 src/main/java/me/youhavetrouble/blockedit/commands/DeselCommand.java create mode 100644 src/main/java/me/youhavetrouble/blockedit/commands/Pos1Command.java create mode 100644 src/main/java/me/youhavetrouble/blockedit/commands/Pos2Command.java diff --git a/src/main/java/me/youhavetrouble/blockedit/BEPlayer.java b/src/main/java/me/youhavetrouble/blockedit/BEPlayer.java index 9e46408..c230d0f 100644 --- a/src/main/java/me/youhavetrouble/blockedit/BEPlayer.java +++ b/src/main/java/me/youhavetrouble/blockedit/BEPlayer.java @@ -17,6 +17,10 @@ public class BEPlayer { return selection; } + public void resetSelection() { + this.selection = null; + } + private void updateSelection() { if (selectionPoint1 == null || selectionPoint2 == null) { selection = null; diff --git a/src/main/java/me/youhavetrouble/blockedit/BlockEdit.java b/src/main/java/me/youhavetrouble/blockedit/BlockEdit.java index 7240f45..b842a75 100644 --- a/src/main/java/me/youhavetrouble/blockedit/BlockEdit.java +++ b/src/main/java/me/youhavetrouble/blockedit/BlockEdit.java @@ -1,11 +1,10 @@ package me.youhavetrouble.blockedit; import me.youhavetrouble.blockedit.api.BlockEditWands; -import me.youhavetrouble.blockedit.commands.ReplaceCommand; -import me.youhavetrouble.blockedit.commands.SetCommand; -import me.youhavetrouble.blockedit.commands.WandCommand; +import me.youhavetrouble.blockedit.commands.*; import me.youhavetrouble.blockedit.wands.SelectionWand; import org.bukkit.command.PluginCommand; +import org.bukkit.command.TabExecutor; import org.bukkit.plugin.java.JavaPlugin; public final class BlockEdit extends JavaPlugin { @@ -22,26 +21,12 @@ public final class BlockEdit extends JavaPlugin { BlockEditWands.registerWand(selectionWand); getServer().getPluginManager().registerEvents(selectionWand, this); - //getCommand("test").setExecutor(new TestCommand()); - - WandCommand wandCommand = new WandCommand(); - PluginCommand bukkitWandCommand = getCommand("/wand"); - if (bukkitWandCommand != null) { - bukkitWandCommand.setExecutor(wandCommand); - bukkitWandCommand.setTabCompleter(wandCommand); - } - SetCommand setCommand = new SetCommand(); - PluginCommand bukkitSetCommand = getCommand("/set"); - if (bukkitSetCommand != null) { - bukkitSetCommand.setExecutor(setCommand); - bukkitSetCommand.setTabCompleter(setCommand); - } - ReplaceCommand replaceCommand = new ReplaceCommand(); - PluginCommand bukkitReplaceCommand = getCommand("/replace"); - if (bukkitReplaceCommand != null) { - bukkitReplaceCommand.setExecutor(replaceCommand); - bukkitReplaceCommand.setTabCompleter(replaceCommand); - } + registerCommand("/wand", new WandCommand()); + registerCommand("/set", new SetCommand()); + registerCommand("/replace", new ReplaceCommand()); + registerCommand("/pos1", new Pos1Command()); + registerCommand("/pos2", new Pos2Command()); + registerCommand("/desel", new DeselCommand()); } @@ -49,4 +34,12 @@ public final class BlockEdit extends JavaPlugin { public static BlockEdit getPlugin() { return plugin; } + + private void registerCommand(String command, TabExecutor executor) { + PluginCommand bukkitReplaceCommand = getCommand(command); + if (bukkitReplaceCommand != null) { + bukkitReplaceCommand.setExecutor(executor); + bukkitReplaceCommand.setTabCompleter(executor); + } + } } diff --git a/src/main/java/me/youhavetrouble/blockedit/TestCommand.java b/src/main/java/me/youhavetrouble/blockedit/TestCommand.java deleted file mode 100644 index ef5cff2..0000000 --- a/src/main/java/me/youhavetrouble/blockedit/TestCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -package me.youhavetrouble.blockedit; - -import me.youhavetrouble.blockedit.util.ChunkWork; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Particle; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitTask; -import org.bukkit.util.BoundingBox; -import org.jetbrains.annotations.NotNull; - -public class TestCommand implements CommandExecutor { - - BukkitTask task; - - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (sender instanceof Player player) { - - Location location = player.getLocation(); - if (task != null) { - task.cancel(); - } - // That's how manually checking if selection is valid looks like. - task = Bukkit.getScheduler().runTaskTimerAsynchronously(BlockEdit.getPlugin(),() -> { - BoundingBox box = BEPlayer.getByPlayer(player).getSelection(); - if (box == null) return; - for (int y = 0; y< 255; y++) { - location.getWorld().spawnParticle(Particle.END_ROD, box.getMaxX(), y, box.getMaxZ(), 0, 0.01, 0.01, 0.01); - location.getWorld().spawnParticle(Particle.END_ROD, box.getMinX(), y, box.getMinZ(), 0, 0.01, 0.01, 0.01); - } - }, 0, 4); - - - - } - return true; - } -} diff --git a/src/main/java/me/youhavetrouble/blockedit/commands/DeselCommand.java b/src/main/java/me/youhavetrouble/blockedit/commands/DeselCommand.java new file mode 100644 index 0000000..c4292cd --- /dev/null +++ b/src/main/java/me/youhavetrouble/blockedit/commands/DeselCommand.java @@ -0,0 +1,28 @@ +package me.youhavetrouble.blockedit.commands; + +import me.youhavetrouble.blockedit.BEPlayer; +import net.kyori.adventure.text.Component; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class DeselCommand implements TabExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!(sender instanceof Player player)) return true; + BEPlayer bePlayer = BEPlayer.getByPlayer(player); + bePlayer.resetSelection(); + player.sendMessage(Component.text("You have reset your selection")); + return true; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { + return null; + } +} diff --git a/src/main/java/me/youhavetrouble/blockedit/commands/Pos1Command.java b/src/main/java/me/youhavetrouble/blockedit/commands/Pos1Command.java new file mode 100644 index 0000000..1a163d6 --- /dev/null +++ b/src/main/java/me/youhavetrouble/blockedit/commands/Pos1Command.java @@ -0,0 +1,28 @@ +package me.youhavetrouble.blockedit.commands; + +import me.youhavetrouble.blockedit.BEPlayer; +import net.kyori.adventure.text.Component; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class Pos1Command implements TabExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!(sender instanceof Player player)) return true; + BEPlayer bePlayer = BEPlayer.getByPlayer(player); + bePlayer.setSelectionPoint1(player.getLocation().toBlockLocation()); + player.sendMessage(Component.text("First point set at your location")); + return true; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { + return null; + } +} diff --git a/src/main/java/me/youhavetrouble/blockedit/commands/Pos2Command.java b/src/main/java/me/youhavetrouble/blockedit/commands/Pos2Command.java new file mode 100644 index 0000000..a785639 --- /dev/null +++ b/src/main/java/me/youhavetrouble/blockedit/commands/Pos2Command.java @@ -0,0 +1,28 @@ +package me.youhavetrouble.blockedit.commands; + +import me.youhavetrouble.blockedit.BEPlayer; +import net.kyori.adventure.text.Component; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class Pos2Command implements TabExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!(sender instanceof Player player)) return true; + BEPlayer bePlayer = BEPlayer.getByPlayer(player); + bePlayer.setSelectionPoint2(player.getLocation().toBlockLocation()); + player.sendMessage(Component.text("Second point set at your location")); + return true; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { + return null; + } +} diff --git a/src/main/java/me/youhavetrouble/blockedit/commands/ReplaceCommand.java b/src/main/java/me/youhavetrouble/blockedit/commands/ReplaceCommand.java index 491e3e5..dcb0d89 100644 --- a/src/main/java/me/youhavetrouble/blockedit/commands/ReplaceCommand.java +++ b/src/main/java/me/youhavetrouble/blockedit/commands/ReplaceCommand.java @@ -1,7 +1,6 @@ package me.youhavetrouble.blockedit.commands; import me.youhavetrouble.blockedit.BEPlayer; -import me.youhavetrouble.blockedit.WorkSplitter; import me.youhavetrouble.blockedit.api.BlockEditAPI; import me.youhavetrouble.blockedit.operations.ReplaceOperation; import me.youhavetrouble.blockedit.util.Selection; diff --git a/src/main/java/me/youhavetrouble/blockedit/operations/SetOperation.java b/src/main/java/me/youhavetrouble/blockedit/operations/SetOperation.java index a85e617..ccee905 100644 --- a/src/main/java/me/youhavetrouble/blockedit/operations/SetOperation.java +++ b/src/main/java/me/youhavetrouble/blockedit/operations/SetOperation.java @@ -1,11 +1,9 @@ package me.youhavetrouble.blockedit.operations; - import me.youhavetrouble.blockedit.api.BlockEditOperation; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; - public record SetOperation(BlockData blockData) implements BlockEditOperation { @Override diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9825f02..9687e17 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,14 +6,18 @@ authors: [ YouHaveTrouble ] description: Modern WorldEdit alternative website: youhavetrouble.me commands: - test: - description: test /wand: permission: blockedit.wand description: Gives you a blockedit wand /set: - permission: blockedit.set + permission: blockedit.command.set description: Set selection area to chosen block /replace: - permission: blockedit.replace + permission: blockedit.command.replace description: Replace selected blocks in selection area + /pos1: + permission: blockedit.command.pos + /pos2: + permission: blockedit.command.pos + /desel: + permission: blockedit.command.desel