mirror of
https://github.com/YouHaveTrouble/BlockEdit.git
synced 2026-06-29 13:36:19 +00:00
allow setting positions via command and fix some errors by returning if selection is null
This commit is contained in:
@@ -8,6 +8,7 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
|
|||||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||||
import io.papermc.paper.command.brigadier.Commands;
|
import io.papermc.paper.command.brigadier.Commands;
|
||||||
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
|
||||||
|
import io.papermc.paper.command.brigadier.argument.resolvers.BlockPositionResolver;
|
||||||
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
||||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||||
import me.youhavetrouble.blockedit.api.BlockEditAPI;
|
import me.youhavetrouble.blockedit.api.BlockEditAPI;
|
||||||
@@ -172,6 +173,16 @@ public class BlockEditCommands {
|
|||||||
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).firstPositionSet.formatted(locationString), NamedTextColor.GRAY));
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).firstPositionSet.formatted(locationString), NamedTextColor.GRAY));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
})
|
})
|
||||||
|
.then(Commands.argument("position", ArgumentTypes.blockPosition())
|
||||||
|
.executes(ctx -> {
|
||||||
|
Player player = (Player) ctx.getSource().getSender();
|
||||||
|
BlockPositionResolver blockPositionResolver = ctx.getArgument("position", BlockPositionResolver.class);
|
||||||
|
Location location = blockPositionResolver.resolve(ctx.getSource()).toLocation(player.getWorld());
|
||||||
|
BEPlayer.getByPlayer(player).setSelectionPoint1(location);
|
||||||
|
String locationString = "X: " + location.blockX() + " Y: " + location.blockY() + " Z: " + location.blockZ();
|
||||||
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).firstPositionSet.formatted(locationString), NamedTextColor.GRAY));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +200,16 @@ public class BlockEditCommands {
|
|||||||
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).secondPositionSet.formatted(locationString), NamedTextColor.GRAY));
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).secondPositionSet.formatted(locationString), NamedTextColor.GRAY));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
})
|
})
|
||||||
|
.then(Commands.argument("position", ArgumentTypes.blockPosition())
|
||||||
|
.executes(ctx -> {
|
||||||
|
Player player = (Player) ctx.getSource().getSender();
|
||||||
|
BlockPositionResolver blockPositionResolver = ctx.getArgument("position", BlockPositionResolver.class);
|
||||||
|
Location location = blockPositionResolver.resolve(ctx.getSource()).toLocation(player.getWorld());
|
||||||
|
BEPlayer.getByPlayer(player).setSelectionPoint2(location);
|
||||||
|
String locationString = "X: " + location.blockX() + " Y: " + location.blockY() + " Z: " + location.blockZ();
|
||||||
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).secondPositionSet.formatted(locationString), NamedTextColor.GRAY));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +296,10 @@ public class BlockEditCommands {
|
|||||||
BEPlayer bePlayer = BEPlayer.getByPlayer(player);
|
BEPlayer bePlayer = BEPlayer.getByPlayer(player);
|
||||||
BlockState blockState = ctx.getArgument("block", BlockState.class);
|
BlockState blockState = ctx.getArgument("block", BlockState.class);
|
||||||
Selection selection = bePlayer.getSelection();
|
Selection selection = bePlayer.getSelection();
|
||||||
|
if (selection == null) {
|
||||||
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).selectArea, NamedTextColor.RED));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
BlockEditAPI.runOperation(selection, 1, new SetOperation(blockState));
|
BlockEditAPI.runOperation(selection, 1, new SetOperation(blockState));
|
||||||
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).settingBlocks, NamedTextColor.GRAY));
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).settingBlocks, NamedTextColor.GRAY));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
@@ -287,6 +312,10 @@ public class BlockEditCommands {
|
|||||||
BlockState blockState = ctx.getArgument("block", BlockState.class);
|
BlockState blockState = ctx.getArgument("block", BlockState.class);
|
||||||
int chunksPerTick = ctx.getArgument("chunks_per_tick", Integer.class);
|
int chunksPerTick = ctx.getArgument("chunks_per_tick", Integer.class);
|
||||||
Selection selection = bePlayer.getSelection();
|
Selection selection = bePlayer.getSelection();
|
||||||
|
if (selection == null) {
|
||||||
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).selectArea, NamedTextColor.RED));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
BlockEditAPI.runOperation(selection, chunksPerTick, new SetOperation(blockState));
|
BlockEditAPI.runOperation(selection, chunksPerTick, new SetOperation(blockState));
|
||||||
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).settingBlocks, NamedTextColor.GRAY));
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).settingBlocks, NamedTextColor.GRAY));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
@@ -313,6 +342,10 @@ public class BlockEditCommands {
|
|||||||
BlockState toReplace = ctx.getArgument("to_replace", BlockState.class);
|
BlockState toReplace = ctx.getArgument("to_replace", BlockState.class);
|
||||||
BlockState replaceWith = ctx.getArgument("replace_with", BlockState.class);
|
BlockState replaceWith = ctx.getArgument("replace_with", BlockState.class);
|
||||||
Selection selection = bePlayer.getSelection();
|
Selection selection = bePlayer.getSelection();
|
||||||
|
if (selection == null) {
|
||||||
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).selectArea, NamedTextColor.RED));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
BlockEditAPI.runOperation(selection, 1, new ReplaceOperation(toReplace, replaceWith));
|
BlockEditAPI.runOperation(selection, 1, new ReplaceOperation(toReplace, replaceWith));
|
||||||
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).replacingBlocks, NamedTextColor.GRAY));
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).replacingBlocks, NamedTextColor.GRAY));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
@@ -326,6 +359,10 @@ public class BlockEditCommands {
|
|||||||
BlockState replaceWith = ctx.getArgument("replace_with", BlockState.class);
|
BlockState replaceWith = ctx.getArgument("replace_with", BlockState.class);
|
||||||
int chunksPerTick = ctx.getArgument("chunks_per_tick", Integer.class);
|
int chunksPerTick = ctx.getArgument("chunks_per_tick", Integer.class);
|
||||||
Selection selection = bePlayer.getSelection();
|
Selection selection = bePlayer.getSelection();
|
||||||
|
if (selection == null) {
|
||||||
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).selectArea, NamedTextColor.RED));
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
BlockEditAPI.runOperation(selection, chunksPerTick, new ReplaceOperation(toReplace, replaceWith));
|
BlockEditAPI.runOperation(selection, chunksPerTick, new ReplaceOperation(toReplace, replaceWith));
|
||||||
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).replacingBlocks, NamedTextColor.GRAY));
|
player.sendMessage(Component.text(BELocale.getLocale(player.locale()).replacingBlocks, NamedTextColor.GRAY));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
|
|||||||
Reference in New Issue
Block a user