40 lines
1.5 KiB
Java
40 lines
1.5 KiB
Java
package com.zontreck.commands.spawn;
|
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
import com.zontreck.configs.server.AEServerConfig;
|
|
import com.zontreck.libzontreck.vectors.WorldPosition;
|
|
import net.minecraft.commands.CommandSourceStack;
|
|
import net.minecraft.commands.Commands;
|
|
import net.minecraft.server.commands.OpCommand;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.server.players.PlayerList;
|
|
import net.minecraftforge.server.ServerLifecycleHooks;
|
|
|
|
public class SetSpawnCommand {
|
|
|
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
|
{
|
|
dispatcher.register(Commands.literal("shareitem").executes(c->setspawn(c.getSource())));
|
|
|
|
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
|
//String arg = StringArgumentType.getString(command, "nickname");
|
|
//return setHome(command.getSource(), arg);
|
|
//}));
|
|
}
|
|
|
|
private static int setspawn(CommandSourceStack ctx) {
|
|
ServerPlayer player = ctx.getPlayer();
|
|
|
|
PlayerList playerList = ServerLifecycleHooks.getCurrentServer().getPlayerList();
|
|
if(playerList.isOp(player.getGameProfile())) {
|
|
// Player is op, spawn can now be set
|
|
WorldPosition WP = new WorldPosition(player);
|
|
ServerLevel level = player.getLevel();
|
|
AEServerConfig.getInstance().worldSpawn = WP;
|
|
AEServerConfig.save();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|