2024-07-11 13:43:54 -05:00
|
|
|
package one.oth3r.sit.command;
|
2023-07-20 20:17:52 -05:00
|
|
|
|
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
|
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
|
|
import com.mojang.brigadier.context.CommandContext;
|
|
|
|
import com.mojang.brigadier.suggestion.Suggestions;
|
|
|
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
|
|
|
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;
|
2023-08-02 23:04:36 -05:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2024-07-23 13:49:43 -05:00
|
|
|
import one.oth3r.sit.utl.Data;
|
2024-07-11 13:43:54 -05:00
|
|
|
import one.oth3r.sit.utl.Logic;
|
|
|
|
import one.oth3r.sit.utl.Utl;
|
2024-07-23 12:27:01 -05:00
|
|
|
import one.oth3r.sit.file.FileData;
|
2023-07-20 20:17:52 -05:00
|
|
|
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
public class SitCommand {
|
|
|
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
|
|
|
dispatcher.register(CommandManager.literal("sit")
|
2023-08-02 23:04:36 -05:00
|
|
|
.requires((commandSource) -> commandSource.hasPermissionLevel(0))
|
2023-07-20 20:17:52 -05:00
|
|
|
.executes((context2) -> command(context2.getSource(), context2.getInput()))
|
|
|
|
.then(CommandManager.argument("args", StringArgumentType.string())
|
2023-08-02 23:04:36 -05:00
|
|
|
.requires((commandSource) -> commandSource.hasPermissionLevel(2))
|
2023-07-20 20:17:52 -05:00
|
|
|
.suggests(SitCommand::getSuggestions)
|
|
|
|
.executes((context2) -> command(context2.getSource(), context2.getInput()))));
|
|
|
|
}
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2023-07-20 20:17:52 -05:00
|
|
|
public static CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
|
|
|
|
builder.suggest("reload");
|
|
|
|
builder.suggest("purgeChairEntities");
|
|
|
|
return builder.buildFuture();
|
|
|
|
}
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2023-07-20 20:17:52 -05:00
|
|
|
private static int command(ServerCommandSource source, String arg) {
|
|
|
|
ServerPlayerEntity player = source.getPlayer();
|
2024-08-06 11:09:15 -05:00
|
|
|
// trim all the arguments before the command (for commands like /execute)
|
|
|
|
int index = arg.indexOf("sit");
|
|
|
|
// trims the words before the text
|
|
|
|
if (index != -1) arg = arg.substring(index).trim();
|
|
|
|
|
2023-07-20 20:17:52 -05:00
|
|
|
String[] args = arg.split(" ");
|
2024-08-06 11:09:15 -05:00
|
|
|
// if command string starts with sit, remove it
|
2023-07-20 20:17:52 -05:00
|
|
|
if (args[0].equalsIgnoreCase("sit"))
|
|
|
|
args = arg.replaceFirst("sit ", "").split(" ");
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2023-11-25 10:35:51 -06:00
|
|
|
// if console
|
|
|
|
if (player == null) {
|
|
|
|
if (args[0].equalsIgnoreCase("reload")) {
|
2024-07-11 13:43:54 -05:00
|
|
|
Logic.reload();
|
2024-07-23 13:49:43 -05:00
|
|
|
Data.LOGGER.info(Utl.lang("msg.reloaded").getString());
|
2023-11-25 10:35:51 -06:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2024-08-06 11:08:48 -05:00
|
|
|
// player
|
|
|
|
|
2023-08-02 23:04:36 -05:00
|
|
|
if (args[0].equalsIgnoreCase("sit")) {
|
2024-08-06 11:08:48 -05:00
|
|
|
// if the player can't sit where they're looking, try to sit below
|
|
|
|
if (!Logic.sitLooking(player)) {
|
|
|
|
BlockPos pos = player.getBlockPos();
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2024-08-06 11:08:48 -05:00
|
|
|
if (!(player.getY() - ((int) player.getY()) > 0.00)) {
|
|
|
|
pos = pos.add(0, -1, 0);
|
|
|
|
}
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2024-08-06 11:08:48 -05:00
|
|
|
// if already sitting, ignore
|
|
|
|
if (FileData.getSitEntity(player) != null) return 1;
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2024-08-06 11:08:48 -05:00
|
|
|
// try to make the player sit
|
|
|
|
Logic.sit(player, pos, null);
|
|
|
|
}
|
2023-08-02 23:04:36 -05:00
|
|
|
}
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2023-07-20 20:17:52 -05:00
|
|
|
if (args[0].equalsIgnoreCase("reload")) {
|
2024-07-11 13:43:54 -05:00
|
|
|
Logic.reload();
|
2024-06-18 23:13:07 -05:00
|
|
|
player.sendMessage(Utl.lang("msg.reloaded").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))));
|
2023-07-20 20:17:52 -05:00
|
|
|
}
|
2024-07-11 13:43:54 -05:00
|
|
|
|
|
|
|
if (args[0].equalsIgnoreCase("purgeChairEntities")) Utl.Entity.purge(player,true);
|
2023-07-20 20:17:52 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|