mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 07:53:22 +02:00
added '/sit' to sit on current block
This commit is contained in:
parent
811e2cb89a
commit
08eddf5d62
1 changed files with 24 additions and 2 deletions
|
@ -7,11 +7,15 @@ import com.mojang.brigadier.context.CommandContext;
|
|||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.decoration.DisplayEntity;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.TextColor;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
@ -19,9 +23,10 @@ import java.util.concurrent.CompletableFuture;
|
|||
public class SitCommand {
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
dispatcher.register(CommandManager.literal("sit")
|
||||
.requires((commandSource) -> commandSource.hasPermissionLevel(2))
|
||||
.requires((commandSource) -> commandSource.hasPermissionLevel(0))
|
||||
.executes((context2) -> command(context2.getSource(), context2.getInput()))
|
||||
.then(CommandManager.argument("args", StringArgumentType.string())
|
||||
.requires((commandSource) -> commandSource.hasPermissionLevel(2))
|
||||
.suggests(SitCommand::getSuggestions)
|
||||
.executes((context2) -> command(context2.getSource(), context2.getInput()))));
|
||||
}
|
||||
|
@ -44,7 +49,24 @@ public class SitCommand {
|
|||
String[] args = arg.split(" ");
|
||||
if (args[0].equalsIgnoreCase("sit"))
|
||||
args = arg.replaceFirst("sit ", "").split(" ");
|
||||
|
||||
if (args[0].equalsIgnoreCase("sit")) {
|
||||
BlockPos pos = player.getBlockPos();
|
||||
if (!(player.getY() -((int) player.getY()) > 0.00)) {
|
||||
pos = pos.add(0,-1,0);
|
||||
}
|
||||
World world = player.getWorld();
|
||||
if (Events.checkBlocks(pos,world)) {
|
||||
if (Events.entities.containsKey(player)) {
|
||||
return 1;
|
||||
}
|
||||
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
||||
Events.setEntity(pos,world,entity);
|
||||
player.getServerWorld().spawnEntity(entity);
|
||||
player.startRiding(entity);
|
||||
Events.entities.put(player,entity);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
config.load();
|
||||
player.sendMessage(Sit.lang("key.sit.command.reloaded").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue