some commands

This commit is contained in:
YouHaveTrouble
2021-07-27 03:25:25 +02:00
parent 8fb1a36a07
commit c6b2ce2349
9 changed files with 112 additions and 72 deletions
@@ -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;
@@ -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);
}
}
}
@@ -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;
}
}
@@ -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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}
@@ -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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}
@@ -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<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}
@@ -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;
@@ -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
+8 -4
View File
@@ -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