165 lines
7.0 KiB
Java
165 lines
7.0 KiB
Java
![]() |
package jesse.keeblarcraft.Commands;
|
||
|
|
||
|
import org.apache.logging.log4j.core.jmx.Server;
|
||
|
|
||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||
|
|
||
|
import jesse.keeblarcraft.Keeblarcraft;
|
||
|
import jesse.keeblarcraft.ConfigMgr.ConfigManager;
|
||
|
import jesse.keeblarcraft.ConfigMgr.GeneralConfig;
|
||
|
import jesse.keeblarcraft.EventMgr.DimensionLoadingEvent;
|
||
|
import jesse.keeblarcraft.Utils.DirectionalVec;
|
||
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||
|
import net.minecraft.block.Block;
|
||
|
import net.minecraft.block.BlockState;
|
||
|
import net.minecraft.block.Blocks;
|
||
|
import net.minecraft.block.ChestBlock;
|
||
|
import net.minecraft.block.entity.BlockEntity;
|
||
|
import net.minecraft.command.argument.EntityArgumentType;
|
||
|
import net.minecraft.inventory.EnderChestInventory;
|
||
|
import net.minecraft.item.ItemPlacementContext;
|
||
|
import net.minecraft.nbt.NbtList;
|
||
|
import net.minecraft.registry.RegistryKey;
|
||
|
import net.minecraft.registry.RegistryKeys;
|
||
|
import net.minecraft.server.command.CommandManager;
|
||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||
|
import net.minecraft.server.world.ServerWorld;
|
||
|
import net.minecraft.text.Text;
|
||
|
import net.minecraft.util.Identifier;
|
||
|
import net.minecraft.util.math.BlockPos;
|
||
|
import net.minecraft.util.math.Vec3d;
|
||
|
import net.minecraft.world.World;
|
||
|
import net.minecraft.world.dimension.DimensionType;
|
||
|
|
||
|
public class MiscCommands {
|
||
|
ConfigManager config = new ConfigManager();
|
||
|
|
||
|
public void RegisterCommands() {
|
||
|
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||
|
|
||
|
// var magicInv = CommandManager.literal("magic-inv").build();
|
||
|
// var claim = CommandManager.literal("claim").executes(context -> ClaimInventory(context.getSource().getPlayer())).build();
|
||
|
|
||
|
// dispatcher.getRoot().addChild(magicInv);
|
||
|
// magicInv.addChild(claim);
|
||
|
// });
|
||
|
|
||
|
// CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||
|
|
||
|
// var eChest = CommandManager.literal("enderchest").build();
|
||
|
// var player = CommandManager.argument("PLAYER", EntityArgumentType.player()).executes(
|
||
|
// context -> GetEnderchestOfPlayer(context.getSource().getPlayer(), EntityArgumentType.getPlayer(context, "PLAYER"))
|
||
|
// ).build();
|
||
|
|
||
|
// dispatcher.getRoot().addChild(eChest);
|
||
|
// eChest.addChild(player);
|
||
|
|
||
|
// // Alias
|
||
|
// dispatcher.register(CommandManager.literal("echest").redirect(eChest));
|
||
|
// });
|
||
|
|
||
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||
|
|
||
|
var forceSpawn = CommandManager.literal("set-global-spawn").executes(context -> ForceGlobalSpawn(context.getSource().getPlayer())).build();
|
||
|
|
||
|
dispatcher.getRoot().addChild(forceSpawn);
|
||
|
});
|
||
|
|
||
|
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
|
||
|
|
||
|
var warp = CommandManager.literal("warp").build();
|
||
|
|
||
|
var warpLoc = CommandManager.argument("LOCATION", StringArgumentType.string())
|
||
|
.executes(context -> Warp(context.getSource().getPlayer(), StringArgumentType.getString(context, "LOCATION"))).build();
|
||
|
|
||
|
dispatcher.getRoot().addChild(warp);
|
||
|
warp.addChild(warpLoc);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public int Warp(ServerPlayerEntity player, String location) {
|
||
|
|
||
|
if (player.hasPermissionLevel(4)) {
|
||
|
// hard coding spawn as only valid warp location. a more robust warp system can come later
|
||
|
DirectionalVec coords = GeneralConfig.GetInstance().GetSpawnCoords();
|
||
|
var server = player.getServer();
|
||
|
|
||
|
System.out.println("Warping! Is server null? " + (server == null ? "YES":"NO"));
|
||
|
System.out.println("Vakye if coords.x: " + coords.x);
|
||
|
System.out.println("Value of coords.world: " + coords.world.toString());
|
||
|
player.teleport(server.getWorld(coords.world), (float)coords.x, (float)coords.y,
|
||
|
(float)coords.z, (float)coords.yaw, (float)coords.pitch);
|
||
|
} else {
|
||
|
player.sendMessage(Text.of("This command is only available to server admins at the moment!"));
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
public int ForceGlobalSpawn(ServerPlayerEntity player) {
|
||
|
if (player.hasPermissionLevel(4)) {
|
||
|
Vec3d coords = player.getPos();
|
||
|
DirectionalVec spawnVec = new DirectionalVec();
|
||
|
spawnVec.x = coords.x;
|
||
|
spawnVec.y = coords.y;
|
||
|
spawnVec.z = coords.z;
|
||
|
spawnVec.pitch = player.getPitch();
|
||
|
spawnVec.yaw = player.getYaw();
|
||
|
spawnVec.world = player.getWorld().getRegistryKey();
|
||
|
player.sendMessage(Text.of("Global spawn has been set to [X, Y, Z]--[YAW, PITCH]: [" +
|
||
|
spawnVec.x + " " + spawnVec.y + " " + spawnVec.z + "]--" + "[" + spawnVec.yaw + " " + spawnVec.pitch + "]" + " IN WORLD " +
|
||
|
player.getWorld().asString()));
|
||
|
|
||
|
GeneralConfig.GetInstance().SetSpawnCoords(spawnVec);
|
||
|
} else {
|
||
|
player.sendMessage(Text.of("You do not have permission to use this command."));
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
public int GetEnderchestOfPlayer(ServerPlayerEntity cmdInitiator, ServerPlayerEntity targetPlayer) {
|
||
|
|
||
|
// if (cmdInitiator.hasPermissionLevel(4)) {
|
||
|
// EnderChestInventory enderInv = targetPlayer.getEnderChestInventory();
|
||
|
// enderInv.
|
||
|
|
||
|
// } else {
|
||
|
|
||
|
// }
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
// public int ClaimInventory(ServerPlayerEntity player) {
|
||
|
// Vec3d playerPosition = player.getPos();
|
||
|
// BlockPos blockPosition = new BlockPos((int) playerPosition.x + 4, (int) playerPosition.y, (int) playerPosition.z).east();
|
||
|
// BlockPos blockPosition2 = new BlockPos((int) playerPosition.x + 3, (int) playerPosition.y, (int) playerPosition.z).east();
|
||
|
|
||
|
|
||
|
// // Verify we can place the blocks before loading cached inventory
|
||
|
// if (player.getWorld().setBlockState(blockPosition, chestState)
|
||
|
// && player.getWorld().setBlockState(blockPosition2, chestState)) {
|
||
|
|
||
|
// // The below code WILL remove the inventory from the dimension cache. Only get
|
||
|
// // it when we succeed in placing chests!
|
||
|
// NbtList nbtInventory = DimensionLoadingEvent.GetInstance().GetInventory(player.getUuidAsString());
|
||
|
// if (nbtInventory != null) {
|
||
|
// BlockEntity block = player.getWorld().getBlockEntity(blockPosition);
|
||
|
// BlockEntity block2 = player.getWorld().getBlockEntity(blockPosition2);
|
||
|
|
||
|
// if (block != null && block2 != null) {
|
||
|
// block.markDirty();
|
||
|
// block2.markDirty();
|
||
|
// }
|
||
|
|
||
|
// player.sendMessage(Text.of("Look around, your magic inventory chest was placed near you!"));
|
||
|
// }
|
||
|
// } else {
|
||
|
// player.sendMessage(Text.of("Well, this is embarassing! Could not place magic inventory chest near you!"));
|
||
|
// }
|
||
|
|
||
|
// return 0;
|
||
|
// }
|
||
|
}
|