Add latest revisions after getting it functional

This commit is contained in:
zontreck 2024-10-31 17:18:14 -07:00
parent 9653e273e4
commit ffcecb8e8e
1443 changed files with 258988 additions and 6046 deletions

View file

@ -0,0 +1,65 @@
package com.zontreck.commands.homes;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.zontreck.Messages;
import com.zontreck.events.CommandExecutionEvent;
import com.zontreck.libzontreck.profiles.Profile;
import com.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge;
public class DelHomeCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(
Commands.literal("rmhome")
.executes(c->rmHome(c.getSource(), "default"))
.then(Commands.argument("nickname", StringArgumentType.string())
.executes(c->rmHome(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 rmHome(CommandSourceStack ctx, String homeName)
{
var exec = new CommandExecutionEvent(ctx.getPlayer(), "rmhome");
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;
try{
ServerPlayer p = ctx.getPlayerOrException();
Profile prof = Profile.factory(p);
prof.homes.delete(homeName);
prof.commit();
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.HOME_DELETE_SUCCESS), ctx.getServer());
}catch(Exception e)
{
e.printStackTrace();
ChatHelpers.broadcastTo(ctx.getEntity().getUUID(), ChatHelpers.macro(Messages.HOME_DELETE_FAIL), ctx.getServer());
}
return 0;
}
}

View file

@ -0,0 +1,81 @@
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.events.CommandExecutionEvent;
import com.zontreck.exceptions.NoSuchHomeException;
import com.zontreck.homes.Home;
import com.zontreck.libzontreck.profiles.Profile;
import com.zontreck.libzontreck.util.ChatHelpers;
import com.zontreck.util.TeleportActioner;
import com.zontreck.util.TeleportContainer;
import com.zontreck.util.TeleportDestination;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge;
public class HomeCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("home").executes(c-> home(c.getSource(), "default")).then(Commands.argument("name", StringArgumentType.string()).executes(c->home(c.getSource(), StringArgumentType.getString(c, "name")))));
//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 home(CommandSourceStack ctx, String homeName)
{
var exec = new CommandExecutionEvent(ctx.getPlayer(), "home");
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;
try{
ServerPlayer p = ctx.getPlayerOrException();
Profile prof = Profile.factory(p);
Home home = prof.homes.get(homeName);
//Transaction tx = new Transaction(Bank.getAccount(p.getUUID()), Bank.SYSTEM, AEServerConfig.COST_TO_TP_HOME.get(), Instant.now().getEpochSecond());
//ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.PAYMENT_ATTEMPTING,
// "$" + String.valueOf(AEServerConfig.COST_TO_TP_HOME.get()), "SYSTEM"), p.server);
/*if(true)
{
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.PAYMENT_SUCCESS), p.server);
}else {
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.PAYMENT_FAILED), p.server);
return 0;
}*/
TeleportDestination dest = home.destination;
TeleportActioner.ApplyTeleportEffect(p);
TeleportContainer cont = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), dest.getActualDimension());
TeleportActioner.PerformTeleport(cont,false);
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.TELEPORTING_HOME), ctx.getServer());
}catch(CommandSyntaxException e)
{
e.printStackTrace();
return 1;
}catch(NoSuchHomeException e)
{
ChatHelpers.broadcastTo(ctx.getEntity().getUUID(), ChatHelpers.macro(Messages.TELEPORT_HOME_FAIL), ctx.getServer());
return 0;
}
return 0;
}
}

View file

@ -0,0 +1,106 @@
package com.zontreck.commands.homes;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.zontreck.Messages;
import com.zontreck.events.CommandExecutionEvent;
import com.zontreck.exceptions.NoSuchHomeException;
import com.zontreck.homes.Home;
import com.zontreck.homes.Homes;
import com.zontreck.libzontreck.chat.ChatColor;
import com.zontreck.libzontreck.chat.Clickable;
import com.zontreck.libzontreck.chat.HoverTip;
import com.zontreck.libzontreck.chestgui.ChestGUI;
import com.zontreck.libzontreck.chestgui.ChestGUIButton;
import com.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
import com.zontreck.libzontreck.lore.LoreEntry;
import com.zontreck.libzontreck.profiles.Profile;
import com.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import com.zontreck.libzontreck.util.ChatHelpers;
import com.zontreck.libzontreck.vectors.Vector2i;
import com.zontreck.util.TeleportActioner;
import com.zontreck.util.TeleportContainer;
import com.zontreck.util.TeleportDestination;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraftforge.common.MinecraftForge;
public class HomesCommand {
private static final ChestGUIIdentifier HOMES_GUI_ID = new ChestGUIIdentifier("homes-gui");
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("homes").executes(HomesCommand::getHomes));
}
private static int getHomes(CommandContext<CommandSourceStack> ctx)
{
// Request homes
try{
ServerPlayer player = ctx.getSource().getPlayerOrException();
Profile prof = Profile.factory(player);
Homes homes = prof.homes;
ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.HOME_COUNT, String.valueOf(homes.count())), player.server);
ChestGUI gui = ChestGUI.builder().withGUIId(HOMES_GUI_ID).withTitle("Homes").withPlayer(player.getUUID());
int iconX = 0;
int iconY = 0;
for (Home string : homes.getList()) {
Style st = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatHelpers.macroize(Messages.HOME_HOVER_TEXT))).withClickEvent(Clickable.command("/home "+string.homeName));
ItemStack stack = string.homeIcon.copy();
if(stack.is(Items.AIR))
{
stack = new ItemStack(Items.GRASS_BLOCK, 1);
}
stack.setHoverName(Component.literal(string.homeName));
ChestGUIButton button = new ChestGUIButton(stack, (stackx, container, lore)-> {
TeleportDestination dest = string.destination;
TeleportActioner.ApplyTeleportEffect(player);
TeleportContainer cont = new TeleportContainer(player, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), dest.getActualDimension());
TeleportActioner.PerformTeleport(cont, false);
gui.close();
}, new Vector2i(iconX, iconY))
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Click here to go to this home")).build())
.withInfo(new LoreEntry.Builder().text(ChatHelpers.macro("!Dark_Purple!This home is in the dimension [0]", string.destination.Dimension).getString()).bold(true).build());
iconY++;
if(iconY>=9)
{
iconY=0;
iconX++;
}
if(homes.count() > (2*9))
ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.HOME_FORMAT, string.homeName).setStyle(st), ctx.getSource().getServer());
else
gui.withButton(button); // Put this in the else case, to prevent a error when exceeding inventory slots
}
if(homes.count()<=27)
gui.open();
}catch(CommandSyntaxException ex)
{
ex.printStackTrace();
}
return 0;
}
}

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;
}
}