diff --git a/src/main/java/me/youhavetrouble/blockedit/BlockEdit.java b/src/main/java/me/youhavetrouble/blockedit/BlockEdit.java index e95c42c..c42bbe9 100644 --- a/src/main/java/me/youhavetrouble/blockedit/BlockEdit.java +++ b/src/main/java/me/youhavetrouble/blockedit/BlockEdit.java @@ -4,8 +4,6 @@ import me.youhavetrouble.blockedit.api.BlockEditWands; import me.youhavetrouble.blockedit.commands.*; import me.youhavetrouble.blockedit.wands.SelectionWand; import org.bukkit.command.Command; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.TabExecutor; import org.bukkit.plugin.java.JavaPlugin; public final class BlockEdit extends JavaPlugin { @@ -30,6 +28,7 @@ public final class BlockEdit extends JavaPlugin { registerCommand(new Pos2Command()); registerCommand(new CopyCommand()); registerCommand(new PasteCommand()); + registerCommand(new RotateCommand()); } diff --git a/src/main/java/me/youhavetrouble/blockedit/commands/RotateCommand.java b/src/main/java/me/youhavetrouble/blockedit/commands/RotateCommand.java new file mode 100644 index 0000000..bb8463c --- /dev/null +++ b/src/main/java/me/youhavetrouble/blockedit/commands/RotateCommand.java @@ -0,0 +1,51 @@ +package me.youhavetrouble.blockedit.commands; + +import me.youhavetrouble.blockedit.BEPlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class RotateCommand extends Command { + + public RotateCommand() { + super("rotate"); + setPermission("blockedit.command.rotate"); + } + + @Override + public boolean execute(@NotNull CommandSender sender, @NotNull String s, @NotNull String[] args) { + + if (!(sender instanceof Player player)) { + sender.sendMessage("You need to be a player to use this command"); + return true; + } + + if (args.length == 0) { + player.sendMessage("You need to provide an angle"); + return true; + } + + double angle; + + try { + angle = Double.parseDouble(args[0]); + } catch (NumberFormatException e) { + player.sendMessage("Angle must be a number"); + return true; + } + + if (angle > 360 || angle < -360) { + player.sendMessage("Angle must be between -360 and 360"); + return true; + } + + BEPlayer bePlayer = BEPlayer.getByPlayer(player); + + bePlayer.getClipboard().rotate(angle); + + player.sendMessage("Rotated clipboard by " + angle + " degrees"); + + return false; + } +} diff --git a/src/main/java/me/youhavetrouble/blockedit/util/Clipboard.java b/src/main/java/me/youhavetrouble/blockedit/util/Clipboard.java index f74e717..ced6163 100644 --- a/src/main/java/me/youhavetrouble/blockedit/util/Clipboard.java +++ b/src/main/java/me/youhavetrouble/blockedit/util/Clipboard.java @@ -57,7 +57,9 @@ public class Clipboard { public void rotate(double angle) { for (Map.Entry entry : this.blocks.entrySet()) { Vector relativeLocation = entry.getKey(); - relativeLocation.rotateAroundAxis(baseLocationVector, angle); + relativeLocation.rotateAroundY(angle); + relativeLocation.setX((int)relativeLocation.getX()); + relativeLocation.setZ((int)relativeLocation.getZ()); } }