mirror of
https://github.com/YouHaveTrouble/BlockEdit.git
synced 2026-06-29 13:36:19 +00:00
rotate command
This commit is contained in:
@@ -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());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,9 @@ public class Clipboard {
|
||||
public void rotate(double angle) {
|
||||
for (Map.Entry<Vector, BlockState> 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user