Move the old stuff out of the way, begin fixing one by one

This commit is contained in:
zontreck 2025-02-23 01:27:27 -07:00
parent abfaa02ace
commit 6ccef8275c
1579 changed files with 252390 additions and 76 deletions

View file

@ -0,0 +1,95 @@
package com.zontreck.commands.homes;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.zontreck.Messages;
import com.zontreck.configs.server.AEServerConfig;
import com.zontreck.events.CommandExecutionEvent;
import com.zontreck.homes.Home;
import com.zontreck.libzontreck.profiles.Profile;
import com.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import com.zontreck.libzontreck.util.ChatHelpers;
import com.zontreck.libzontreck.vectors.Vector2f;
import com.zontreck.libzontreck.vectors.Vector3d;
import com.zontreck.util.TeleportActioner;
import com.zontreck.util.TeleportDestination;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
public class SetHomeCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(
Commands.literal("sethome")
.executes(c->setHome(c.getSource(), "default"))
.then(Commands.argument("nickname", StringArgumentType.string())
.executes(c -> setHome(c.getSource(), StringArgumentType.getString(c, "nickname")))
)
);
//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 setHome(CommandSourceStack ctx, String homeName)
{
var exec = new CommandExecutionEvent(ctx.getPlayer(), "sethome");
if(MinecraftForge.EVENT_BUS.post(exec))
{
return 0;
}
// Request homes
// String homeName = "";
// CommandSourceStack ctx = ctx2.getSource();
// homeName = StringArgumentType.getString(ctx2, "nickname");
// if(homeName==null)return 0;
ServerPlayer p;
try {
p = ctx.getPlayerOrException();
if(TeleportActioner.isBlacklistedDimension(p.getLevel()))
{
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + AEServerConfig.getInstance().messages.BlacklistedDimensionError), p.server);
return 0;
}
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3d(position), new Vector2f(rot), p.getLevel());
BlockState bs = p.getLevel().getBlockState(dest.Position.moveDown().asBlockPos());
Home newhome = new Home(p, homeName, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem()));
Profile prof = Profile.factory(p);
prof.homes.add(newhome);
prof.commit();
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.HOME_CREATE_SUCCESS), ctx.getServer());
} catch (CommandSyntaxException e) {
ChatHelpers.broadcastTo(ctx.getEntity().getUUID(), ChatHelpers.macro(Messages.HOME_CREATE_FAIL), ctx.getServer());
e.printStackTrace();
}
return 0;
}
}