Add spawn/setspawn commands

This commit is contained in:
zontreck 2024-11-22 05:32:05 -07:00
parent 0cb0352062
commit 1c63a59566
8 changed files with 101 additions and 24 deletions

View file

@ -6,6 +6,8 @@ import com.zontreck.commands.homes.HomesCommand;
import com.zontreck.commands.homes.SetHomeCommand;
import com.zontreck.commands.items.ShareItemInChatCommand;
import com.zontreck.commands.items.TIABDebug;
import com.zontreck.commands.spawn.SetSpawnCommand;
import com.zontreck.commands.spawn.SpawnCommand;
import com.zontreck.commands.teleport.*;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -27,5 +29,7 @@ public class CommandRegistry
HomeCommand.register(ev.getDispatcher());
ShareItemInChatCommand.register(ev.getDispatcher());
//TIABDebug.register(ev.getDispatcher());
SetSpawnCommand.register(ev.getDispatcher());
SpawnCommand.register(ev.getDispatcher());
}
}

View file

@ -0,0 +1,40 @@
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;
}
}

View file

@ -0,0 +1,31 @@
package com.zontreck.commands.spawn;
import com.mojang.brigadier.CommandDispatcher;
import com.zontreck.configs.server.AEServerConfig;
import com.zontreck.util.TeleportActioner;
import com.zontreck.util.TeleportContainer;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.world.phys.Vec2;
public class SpawnCommand
{
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("shareitem").executes(c->spawn(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 spawn(CommandSourceStack ctx) {
TeleportContainer cont = new TeleportContainer(ctx.getPlayer(), AEServerConfig.getInstance().worldSpawn.Position.asMinecraftVector(), new Vec2(0,0), AEServerConfig.getInstance().worldSpawn.getActualDimension());
TeleportActioner.PerformTeleport(cont, false);
return 0;
}
}

View file

@ -7,6 +7,7 @@ import com.zontreck.configs.server.sections.Drops;
import com.zontreck.configs.server.sections.Messages;
import com.zontreck.configs.server.sections.Teleportation;
import com.zontreck.libzontreck.util.SNbtIo;
import com.zontreck.libzontreck.vectors.WorldPosition;
import com.zontreck.util.EssentialsDatastore;
import net.minecraft.nbt.*;
@ -22,6 +23,7 @@ public class AEServerConfig
public Messages messages;
public Drops drops;
public boolean enable_debug = false;
public WorldPosition worldSpawn;
@ -56,6 +58,12 @@ public class AEServerConfig
config.resetDrops();
}
if(tag.contains("spawn")) {
config.worldSpawn = new WorldPosition(tag.getCompound("spawn"), true);
}else {
config.worldSpawn = null;
}
AriasEssentials.LOGGER.info("Aria's Essentials Server Configuration Loaded");
} catch(Exception e){
e.printStackTrace();
@ -135,6 +143,7 @@ public class AEServerConfig
tag.put(Messages.TAG_NAME, messages.serialize());
tag.putBoolean("use_debug", enable_debug);
tag.put(Drops.TAG_NAME, drops.save());
if(worldSpawn != null) tag.put("spawn", worldSpawn.serializePretty());

View file

@ -5,7 +5,6 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Unique;
@Mixin(ChunkAccess.class)
public class BlockGetterMixin {
}

View file

@ -32,7 +32,8 @@ public class TeleportActioner {
// 10/05/2022 - Thinking ahead here to future proof it so i can do things in threads safely
// By adding this task onto the main server thread, any thread can call the TeleportActioner and it will be actioned on the main thread without needing to repeat the process of sending this to the server thread.
player.server.execute(new Runnable(){
// 11/22/24 - Deactivated teleport effects
/*player.server.execute(new Runnable(){
public void run(){
// 12/18/2023 - Updated to store effects in the config, and make duration and amplifier random!
@ -54,6 +55,6 @@ public class TeleportActioner {
}
}
});
});*/
}
}

View file

@ -28,27 +28,21 @@ public class TeleportRunnable implements Runnable {
}
}
Action.PlayerInst.teleportTo(Action.Dimension, Action.Position.x, Action.Position.y, Action.Position.z, Action.Rotation.y, Action.Rotation.x);
if(Action.world_pos.Dimension.equalsIgnoreCase((new WorldPosition(Action.PlayerInst).Dimension))) {
Action.PlayerInst.setPos(Action.Position);
}else {
Action.PlayerInst.changeDimension(Action.Dimension);
Action.PlayerInst.onUpdateAbilities();
Thread tx = new Thread(new Runnable(){
public final TeleportContainer container=Action;
@Override
public void run()
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
container.PlayerInst.onUpdateAbilities();
container.PlayerInst.setPos(container.Position);
container.PlayerInst.giveExperiencePoints(1);
}
});
tx.start();
Action.PlayerInst.setPos(Action.Position);
}
Action.PlayerInst.onUpdateAbilities();
Action.PlayerInst.giveExperiencePoints(1);
}
}

View file

@ -6,7 +6,6 @@
"client": [
],
"mixins": [
"BlockGetterMixin"
],
"injectors": {
"defaultRequire": 1