Fix back, migrate config to snbt, implement cooldowns
This commit is contained in:
parent
21c349ef3c
commit
ca869f6d2b
43 changed files with 953 additions and 189 deletions
|
@ -3,7 +3,7 @@
|
|||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
libzontreck=1.10.011024.0312
|
||||
libzontreck=1.10.011524.0045
|
||||
|
||||
## Environment Properties
|
||||
|
||||
|
@ -49,7 +49,7 @@ mod_name=Aria's Essentials
|
|||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=GPLv3
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=1.2.011124.0032
|
||||
mod_version=1.2.011524.2032
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
|
|
@ -5,27 +5,29 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
import dev.zontreck.essentials.client.Keybindings;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
||||
import dev.zontreck.essentials.configs.AEClientConfig;
|
||||
import dev.zontreck.essentials.configs.AEServerConfig;
|
||||
import dev.zontreck.essentials.configs.client.AEClientConfig;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.essentials.events.TeleportEvent;
|
||||
import dev.zontreck.essentials.gui.HeartsRenderer;
|
||||
import dev.zontreck.essentials.networking.ModMessages;
|
||||
import dev.zontreck.essentials.rtp.RTPCaches;
|
||||
import dev.zontreck.essentials.rtp.RTPCachesEventHandlers;
|
||||
import dev.zontreck.essentials.util.BackPositionCaches;
|
||||
import dev.zontreck.essentials.util.CommandCooldowns;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
|
@ -40,7 +42,6 @@ import net.minecraftforge.event.server.ServerStartedEvent;
|
|||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
@ -62,11 +63,8 @@ public class AriasEssentials {
|
|||
bus.addListener(this::setup);
|
||||
DelayedExecutorService.setup();
|
||||
|
||||
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, AEServerConfig.SPEC, "arias-essentials-server.toml");
|
||||
|
||||
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, AEClientConfig.SPEC, "arias-essentials-client.toml");
|
||||
AEServerConfig.loadFromFile();
|
||||
AEClientConfig.loadFromFile();
|
||||
|
||||
|
||||
|
||||
|
@ -76,6 +74,7 @@ public class AriasEssentials {
|
|||
MinecraftForge.EVENT_BUS.register(new CommandRegister());
|
||||
MinecraftForge.EVENT_BUS.register(new ForgeEventsHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new RTPCachesEventHandlers());
|
||||
MinecraftForge.EVENT_BUS.register(new CommandCooldowns());
|
||||
MinecraftForge.EVENT_BUS.register(RTPCachesEventHandlers.class);
|
||||
}
|
||||
|
||||
|
@ -86,8 +85,8 @@ public class AriasEssentials {
|
|||
{
|
||||
event.setCanceled(true);
|
||||
} else {
|
||||
if(AEServerConfig.BACK_ALLOWS_LAST_TP.get())
|
||||
BackPositionCaches.Update(event.getContainer().PlayerInst.getUUID(), event.getContainer().world_pos);
|
||||
if(AEServerConfig.getInstance().back.Enabled && AEServerConfig.getInstance().back.EnabledForTp)
|
||||
BackPositionCaches.Update(event.getContainer().PlayerInst.getUUID(), event.getContainer().OldPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,11 +119,17 @@ public class AriasEssentials {
|
|||
@SubscribeEvent (priority = EventPriority.HIGHEST)
|
||||
public void onPlayerDied(final LivingDeathEvent ev)
|
||||
{
|
||||
if(ev.getEntity() instanceof ServerPlayer sp)
|
||||
if(ev.getEntity() instanceof Player p)
|
||||
{
|
||||
// Update player back position!
|
||||
WorldPosition wp = new WorldPosition(sp);
|
||||
BackPositionCaches.Update(sp.getUUID(), wp);
|
||||
if(ServerUtilities.isServer())
|
||||
{
|
||||
ServerPlayer sp = ServerUtilities.getPlayerByID(p.getUUID().toString());
|
||||
// Update player back position!
|
||||
WorldPosition wp = new WorldPosition(sp);
|
||||
BackPositionCaches.Update(sp.getUUID(), wp);
|
||||
|
||||
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.USE_BACK_INTRO), sp.server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@ public class Messages {
|
|||
public static final String TELEPORT_BACK_DISABLED;
|
||||
public static final String TELEPORT_BACK_LAST;
|
||||
public static final String TELEPORT_BACK_NO_LAST;
|
||||
public static final String USE_BACK_INTRO;
|
||||
public static final String COOLDOWN_IN_PROGRESS;
|
||||
public static final String TP_EFFECTS_TOGGLED;
|
||||
|
||||
|
||||
static{
|
||||
|
@ -164,5 +167,10 @@ public class Messages {
|
|||
|
||||
TELEPORT_BACK_LAST = ESSENTIALS_PREFIX + "!Dark_Purple!You are being taken back to your last death or teleport location.";
|
||||
|
||||
USE_BACK_INTRO = ESSENTIALS_PREFIX + "!Dark_Purple!You died! Use the !Dark_Red!/back!Dark_Purple! command to go back to your last death location";
|
||||
|
||||
COOLDOWN_IN_PROGRESS = ESSENTIALS_PREFIX + "!Dark_Red!The command [0] is still on cooldown for another [1]";
|
||||
|
||||
TP_EFFECTS_TOGGLED = ESSENTIALS_PREFIX + "!Dark_Purple!The teleport effects preferences have been toggled to: [0]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,5 +41,7 @@ public class CommandRegister {
|
|||
HeartsCommand.register(ev.getDispatcher());
|
||||
SpawnCommand.register(ev.getDispatcher());
|
||||
BackCommand.register(ev.getDispatcher());
|
||||
|
||||
TPEffectsCommand.register(ev.getDispatcher());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,13 @@ package dev.zontreck.essentials.commands.gui;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.networking.ModMessages;
|
||||
import dev.zontreck.essentials.networking.packets.s2c.S2CUpdateHearts;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class HeartsCommand
|
||||
{
|
||||
|
@ -18,6 +20,11 @@ public class HeartsCommand
|
|||
|
||||
private static int hearts(CommandSourceStack stack, boolean compressHearts)
|
||||
{
|
||||
var exec = new CommandExecutionEvent(stack.getPlayer(), "hearts");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Send the state to the client, then update the config
|
||||
// Send feedback to the user
|
||||
ChatHelpers.broadcastTo(stack.getPlayer().getUUID(), ChatHelpers.macro(Messages.HEARTS_UPDATED), stack.getServer());
|
||||
|
|
|
@ -5,15 +5,27 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
|||
|
||||
import dev.zontreck.essentials.AriasEssentials;
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.homes.HomesSuggestionProvider;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.commands.FunctionCommand;
|
||||
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("rmhome")
|
||||
.executes(c->rmHome(c.getSource(), "default"))
|
||||
.then(Commands.argument("nickname", StringArgumentType.string())
|
||||
.suggests(HomesSuggestionProvider.PROVIDER)
|
||||
.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");
|
||||
|
@ -23,6 +35,12 @@ public class DelHomeCommand {
|
|||
|
||||
private static int rmHome(CommandSourceStack ctx, String homeName)
|
||||
{
|
||||
|
||||
var exec = new CommandExecutionEvent(ctx.getPlayer(), "delhome");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Request homes
|
||||
// String homeName = "";
|
||||
// CommandSourceStack ctx = ctx2.getSource();
|
||||
|
|
|
@ -9,17 +9,21 @@ import dev.zontreck.essentials.Messages;
|
|||
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.homes.Home;
|
||||
import dev.zontreck.essentials.exceptions.NoSuchHomeException;
|
||||
import dev.zontreck.essentials.homes.HomesSuggestionProvider;
|
||||
import dev.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 HomeCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("home").executes(c-> home(c.getSource(), "default")).then(Commands.argument("nickname", StringArgumentType.string()).executes(c -> home(c.getSource(), StringArgumentType.getString(c, "nickname")))));
|
||||
dispatcher.register(Commands.literal("home").executes(c-> home(c.getSource(), "default"))
|
||||
.then(Commands.argument("nickname", StringArgumentType.string()).suggests(HomesSuggestionProvider.PROVIDER).executes(c -> home(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");
|
||||
|
@ -29,6 +33,11 @@ public class HomeCommand {
|
|||
|
||||
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();
|
||||
|
@ -53,7 +62,7 @@ public class HomeCommand {
|
|||
TeleportDestination dest = home.destination;
|
||||
TeleportActioner.ApplyTeleportEffect(p);
|
||||
TeleportContainer cont = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), dest.getActualDimension());
|
||||
TeleportActioner.PerformTeleport(cont);
|
||||
TeleportActioner.PerformTeleport(cont,false);
|
||||
|
||||
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.TELEPORTING_HOME), ctx.getServer());
|
||||
}catch(CommandSyntaxException e)
|
||||
|
|
|
@ -62,12 +62,12 @@ public class HomesCommand {
|
|||
}
|
||||
stack.setHoverName(Component.literal(string.homeName));
|
||||
|
||||
ChestGUIButton button = new ChestGUIButton(stack, ()-> {
|
||||
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);
|
||||
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())
|
||||
|
@ -79,7 +79,7 @@ public class HomesCommand {
|
|||
iconY=0;
|
||||
iconX++;
|
||||
}
|
||||
if(homes.count() > 27)
|
||||
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
|
||||
|
|
|
@ -12,9 +12,10 @@ import dev.zontreck.essentials.AriasEssentials;
|
|||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
|
||||
import dev.zontreck.essentials.configs.AEServerConfig;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.homes.Home;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.Vector2;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
|
@ -25,6 +26,7 @@ import net.minecraft.world.entity.player.Player;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
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)
|
||||
|
@ -39,6 +41,12 @@ public class SetHomeCommand {
|
|||
|
||||
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();
|
||||
|
@ -52,7 +60,7 @@ public class SetHomeCommand {
|
|||
|
||||
if(TeleportActioner.isBlacklistedDimension(p.serverLevel()))
|
||||
{
|
||||
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + AEServerConfig.BLACKLISTED_DIMENSION_ERROR.get()), p.server);
|
||||
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + AEServerConfig.getInstance().messages.BlacklistedDimensionError), p.server);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package dev.zontreck.essentials.commands.teleport;
|
|||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.configs.AEServerConfig;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.util.BackPositionCaches;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class BackCommand
|
||||
{
|
||||
|
@ -18,9 +20,13 @@ public class BackCommand
|
|||
|
||||
public static int back(CommandSourceStack ctx)
|
||||
{
|
||||
var exec = new CommandExecutionEvent(ctx.getPlayer(), "back");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
|
||||
if(!AEServerConfig.ENABLE_BACK.get() && !ctx.hasPermission(ctx.getServer().getOperatorUserPermissionLevel()))
|
||||
if(!AEServerConfig.getInstance().back.Enabled && !ctx.hasPermission(ctx.getServer().getOperatorUserPermissionLevel()))
|
||||
{
|
||||
ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK_DISABLED), ctx.getServer());
|
||||
return 0;
|
||||
|
@ -33,7 +39,7 @@ public class BackCommand
|
|||
TeleportContainer cont = new TeleportContainer(ctx.getPlayer(), wp.Position.asMinecraftVector(), ctx.getRotation(), wp.getActualDimension());
|
||||
|
||||
TeleportActioner.ApplyTeleportEffect(ctx.getPlayer());
|
||||
TeleportActioner.PerformTeleport(cont);
|
||||
TeleportActioner.PerformTeleport(cont, true);
|
||||
} catch (Exception e) {
|
||||
ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.NO_BACK), ctx.getServer());
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package dev.zontreck.essentials.commands.teleport;
|
|||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.rtp.RandomPositionFactory;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class RTPCommand {
|
||||
|
||||
|
@ -25,6 +27,11 @@ public class RTPCommand {
|
|||
|
||||
private static int rtp(CommandSourceStack source) {
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "rtp");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/*if(!CommandRegistry.canUse("rtp")) {
|
||||
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), Component.translatable("dev.zontreck.otemod.msgs.command_cooling_down").append(Component.literal(""+CommandRegistry.getRemaining("rtp"))).append(Component.translatable("dev.zontreck.otemod.msgs.command_cooling_down_seconds")), source.getServer());
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.zontreck.essentials.commands.teleport;
|
|||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
|
@ -10,6 +11,7 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class SpawnCommand {
|
||||
|
||||
|
@ -24,6 +26,12 @@ public class SpawnCommand {
|
|||
}
|
||||
|
||||
private static int respawn(CommandSourceStack source) {
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "spawn");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ServerPlayer p = (ServerPlayer)source.getEntity();
|
||||
|
||||
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.RESPAWNING), p.server);
|
||||
|
@ -32,7 +40,7 @@ public class SpawnCommand {
|
|||
|
||||
TeleportActioner.ApplyTeleportEffect(p);
|
||||
TeleportContainer cont = new TeleportContainer(p, new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()), Vec2.ZERO, p.serverLevel());
|
||||
TeleportActioner.PerformTeleport(cont);
|
||||
TeleportActioner.PerformTeleport(cont, false);
|
||||
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.mojang.brigadier.CommandDispatcher;
|
|||
import dev.zontreck.ariaslib.terminal.Task;
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.chat.Clickable;
|
||||
import dev.zontreck.libzontreck.chat.HoverTip;
|
||||
|
@ -19,6 +20,7 @@ import net.minecraft.network.chat.Component;
|
|||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public class TPACommand {
|
||||
|
@ -34,6 +36,12 @@ public class TPACommand {
|
|||
}
|
||||
|
||||
private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) {
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "tpa");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Send the request to player
|
||||
if(serverPlayer == null){
|
||||
source.sendFailure(ChatHelpers.macro(Messages.PLAYER_NOT_FOUND));
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.mojang.brigadier.CommandDispatcher;
|
|||
import dev.zontreck.ariaslib.terminal.Task;
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.chat.Clickable;
|
||||
import dev.zontreck.libzontreck.chat.HoverTip;
|
||||
|
@ -16,6 +17,7 @@ import net.minecraft.commands.Commands;
|
|||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class TPAHereCommand {
|
||||
|
||||
|
@ -30,6 +32,12 @@ public class TPAHereCommand {
|
|||
}
|
||||
|
||||
private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) {
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "tpahere");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Send the request to player
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
|
|
|
@ -7,28 +7,29 @@ import com.mojang.brigadier.CommandDispatcher;
|
|||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class TPAcceptCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tpaccept").then(Commands.argument("TeleportUUID", StringArgumentType.string()).executes(c->doCancel(c.getSource(), StringArgumentType.getString(c, "TeleportUUID")))));
|
||||
|
||||
//executes(c -> doCancel(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);
|
||||
//}));
|
||||
dispatcher.register(Commands.literal("tpaccept").then(Commands.argument("TeleportUUID", StringArgumentType.string()).executes(c->doAccept(c.getSource(), StringArgumentType.getString(c, "TeleportUUID")))));
|
||||
}
|
||||
|
||||
private static int doCancel(CommandSourceStack source, String TPID) {
|
||||
private static int doAccept(CommandSourceStack source, String TPID) {
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "tpaccept");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
UUID teleporter = UUID.fromString(TPID);
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
|
@ -56,7 +57,7 @@ public class TPAcceptCommand {
|
|||
cont.Dimension = to.serverLevel();
|
||||
|
||||
TeleportActioner.ApplyTeleportEffect(from);
|
||||
TeleportActioner.PerformTeleport(cont);
|
||||
TeleportActioner.PerformTeleport(cont, false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package dev.zontreck.essentials.commands.teleport;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUI;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
/**
|
||||
* This is added because of a petty complaint about the effects being annoying. I've added it so someone can opt out if they are truly just that impatient.
|
||||
*/
|
||||
public class TPEffectsCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tpeffects").then(Commands.argument("enable", BoolArgumentType.bool()).executes(x->tpeffects(x.getSource(), BoolArgumentType.getBool(x, "enable")))));
|
||||
}
|
||||
|
||||
public static int tpeffects(CommandSourceStack source, boolean enabled)
|
||||
{
|
||||
ServerPlayer player = source.getPlayer();
|
||||
|
||||
try {
|
||||
Profile prof = Profile.get_profile_of(player.getStringUUID());
|
||||
prof.NBT.putBoolean("tpeffects", enabled);
|
||||
|
||||
return 0;
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package dev.zontreck.essentials.commands.teleport;
|
|||
|
||||
import dev.zontreck.ariaslib.util.DelayedExecutorService;
|
||||
import dev.zontreck.essentials.AriasEssentials;
|
||||
import dev.zontreck.essentials.configs.AEServerConfig;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.libzontreck.vectors.Vector3;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
|
@ -18,15 +18,15 @@ import net.minecraftforge.registries.RegistryObject;
|
|||
|
||||
public class TeleportActioner
|
||||
{
|
||||
public static void PerformTeleport(TeleportContainer contain){
|
||||
public static void PerformTeleport(TeleportContainer contain, boolean eventless){
|
||||
//sub_runnable run = new sub_runnable(contain);
|
||||
DelayedExecutorService.getInstance().schedule(new TeleportRunnable(contain), 2);
|
||||
DelayedExecutorService.getInstance().schedule(new TeleportRunnable(contain, eventless), 2);
|
||||
}
|
||||
|
||||
public static boolean isBlacklistedDimension(ServerLevel level)
|
||||
{
|
||||
WorldPosition pos = new WorldPosition(Vector3.ZERO, level);
|
||||
if(AEServerConfig.DIMENSION_BLACKLIST.get().contains(pos.Dimension))
|
||||
if(AEServerConfig.getInstance().teleport.Blacklist.contains(pos.Dimension))
|
||||
{
|
||||
return true;
|
||||
} else return false;
|
||||
|
@ -42,7 +42,7 @@ public class TeleportActioner
|
|||
public void run(){
|
||||
|
||||
// 12/18/2023 - Updated to store effects in the config, and make duration and amplifier random!
|
||||
var effects = AEServerConfig.TELEPORT_EFFECTS.get();
|
||||
var effects = AEServerConfig.getInstance().teleport.Effects;
|
||||
for(int i = 0; i < effects.size(); i++) {
|
||||
RegistryObject<MobEffect> effect = RegistryObject.create(new ResourceLocation(effects.get(i)), ForgeRegistries.MOB_EFFECTS);
|
||||
|
||||
|
|
|
@ -9,20 +9,26 @@ import net.minecraftforge.common.MinecraftForge;
|
|||
|
||||
public class TeleportRunnable extends Task
|
||||
{
|
||||
|
||||
|
||||
public final boolean IgnoreEvent;
|
||||
public final TeleportContainer Action;
|
||||
public TeleportRunnable(TeleportContainer cont){
|
||||
public TeleportRunnable(TeleportContainer cont, boolean eventless){
|
||||
super("TP",true);
|
||||
Action = cont;
|
||||
IgnoreEvent=eventless;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Action.OldPosition = new WorldPosition(Action.PlayerInst);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(new TeleportEvent(Action)))
|
||||
if(!IgnoreEvent)
|
||||
{
|
||||
return;
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(new TeleportEvent(Action)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Action.PlayerInst.teleportTo(Action.Dimension, Action.Position.x, Action.Position.y, Action.Position.z, Action.Rotation.y, Action.Rotation.x);
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.mojang.brigadier.CommandDispatcher;
|
|||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.warps.NoSuchWarpException;
|
||||
import dev.zontreck.essentials.warps.Warp;
|
||||
import dev.zontreck.essentials.warps.WarpsProvider;
|
||||
|
@ -12,6 +13,7 @@ import dev.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 DelWarpCommand {
|
||||
|
||||
|
@ -26,7 +28,14 @@ public class DelWarpCommand {
|
|||
}
|
||||
|
||||
private static int setWarp(CommandSourceStack source, String string) {
|
||||
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "delwarp");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ServerPlayer p = (ServerPlayer)source.getEntity();
|
||||
|
||||
Warp warp;
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
|||
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.events.WarpCreatedEvent;
|
||||
import dev.zontreck.essentials.warps.Warp;
|
||||
import dev.zontreck.essentials.warps.WarpsProvider;
|
||||
|
@ -38,7 +39,12 @@ public class RTPWarpCommand {
|
|||
}
|
||||
|
||||
private static int setWarp(CommandSourceStack source, String string) {
|
||||
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "setwarp");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ServerPlayer p = (ServerPlayer)source.getEntity();
|
||||
|
||||
Vec3 position = p.position();
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
|||
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.events.WarpCreatedEvent;
|
||||
import dev.zontreck.essentials.warps.Warp;
|
||||
import dev.zontreck.essentials.warps.WarpsProvider;
|
||||
|
@ -38,7 +39,12 @@ public class SetWarpCommand {
|
|||
}
|
||||
|
||||
private static int setWarp(CommandSourceStack source, String string) {
|
||||
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "setwarp");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ServerPlayer p = (ServerPlayer)source.getEntity();
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import dev.zontreck.essentials.Messages;
|
|||
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
|
||||
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.essentials.rtp.RandomPositionFactory;
|
||||
import dev.zontreck.essentials.warps.NoSuchWarpException;
|
||||
import dev.zontreck.essentials.warps.Warp;
|
||||
|
@ -21,6 +22,7 @@ import net.minecraft.server.level.ServerLevel;
|
|||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class WarpCommand {
|
||||
|
||||
|
@ -62,6 +64,11 @@ public class WarpCommand {
|
|||
|
||||
if(type==1){
|
||||
try {
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "rtp");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return;
|
||||
}
|
||||
dest.Position = Vector3.ZERO;
|
||||
RandomPositionFactory.beginRTP(p, f_dim);
|
||||
return;
|
||||
|
@ -70,10 +77,16 @@ public class WarpCommand {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "warp");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TeleportActioner.ApplyTeleportEffect(p);
|
||||
TeleportContainer tc = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), f_dim);
|
||||
TeleportActioner.PerformTeleport(tc);
|
||||
TeleportActioner.PerformTeleport(tc, false);
|
||||
}
|
||||
});
|
||||
tx.start();
|
||||
|
|
|
@ -114,7 +114,7 @@ public class WarpsCommand {
|
|||
warpMsg = ChatHelpers.applyClickEvent(warpMsg, click);
|
||||
|
||||
|
||||
ChestGUIButton button = new ChestGUIButton(HeadUtilities.get(prof.username, warpName), ()->{
|
||||
ChestGUIButton button = new ChestGUIButton(HeadUtilities.get(prof.username, warpName), (stack, container, lore)->{
|
||||
TeleportDestination dest = warp.destination;
|
||||
if(warpType == 1)
|
||||
{
|
||||
|
@ -126,7 +126,7 @@ public class WarpsCommand {
|
|||
try {
|
||||
TeleportActioner.ApplyTeleportEffect(p);
|
||||
TeleportContainer tc = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), dest.getActualDimension());
|
||||
TeleportActioner.PerformTeleport(tc);
|
||||
TeleportActioner.PerformTeleport(tc, false);
|
||||
|
||||
}catch(Exception e){
|
||||
|
||||
|
@ -140,7 +140,7 @@ public class WarpsCommand {
|
|||
)
|
||||
.withInfo(new LoreEntry.Builder().text(ChatHelpers.macro(appendType, warp.destination.Dimension).getString()).build());
|
||||
|
||||
if(warps.size() > 27)
|
||||
if(warps.size() > (2*9))
|
||||
{
|
||||
// Say to person
|
||||
ChatHelpers.broadcastTo(p, warpMsg, p.server);
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package dev.zontreck.essentials.configs;
|
||||
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
public class AEClientConfig
|
||||
{
|
||||
|
||||
|
||||
public static final ForgeConfigSpec.Builder BUILDER= new ForgeConfigSpec.Builder();
|
||||
public static final ForgeConfigSpec SPEC;
|
||||
|
||||
public static final ForgeConfigSpec.ConfigValue<Boolean> ENABLE_HEARTS_RENDER;
|
||||
|
||||
|
||||
static {
|
||||
BUILDER.push("overlay");
|
||||
ENABLE_HEARTS_RENDER = BUILDER.comment("Enable compressed hearts? This puts all the hearts in a single row").define("enable_hearts", true);
|
||||
|
||||
BUILDER.pop();
|
||||
SPEC = BUILDER.build();
|
||||
}
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
package dev.zontreck.essentials.configs;
|
||||
|
||||
import dev.zontreck.ariaslib.util.Lists;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AEServerConfig {
|
||||
// TODO:
|
||||
/*
|
||||
* 1. Waystone support, Issue #1
|
||||
* 2. Economy support for server owners to charge a fee to use warps and / or homes
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
public static final ForgeConfigSpec.Builder BUILDER= new ForgeConfigSpec.Builder();
|
||||
public static final ForgeConfigSpec SPEC;
|
||||
|
||||
public static final ForgeConfigSpec.ConfigValue<Integer> COST_TO_TP_HOME;
|
||||
public static final ForgeConfigSpec.ConfigValue<Integer> COST_TO_WARP;
|
||||
public static final ForgeConfigSpec.ConfigValue<Integer> COST_TO_MAKE_HOME;
|
||||
public static final ForgeConfigSpec.ConfigValue<Integer> COST_TO_MAKE_WARP;
|
||||
|
||||
public static final ForgeConfigSpec.ConfigValue<Integer> MAX_HOMES;
|
||||
public static final ForgeConfigSpec.ConfigValue<Integer> MAX_WARPS;
|
||||
|
||||
public static final ForgeConfigSpec.ConfigValue<List<String>> DIMENSION_BLACKLIST;
|
||||
public static final ForgeConfigSpec.ConfigValue<String> BLACKLISTED_DIMENSION_ERROR;
|
||||
|
||||
public static final ForgeConfigSpec.ConfigValue<Boolean> BACK_ALLOWS_LAST_TP;
|
||||
public static final ForgeConfigSpec.ConfigValue<Boolean> ENABLE_BACK;
|
||||
|
||||
public static final ForgeConfigSpec.ConfigValue<List<String>> TELEPORT_EFFECTS;
|
||||
|
||||
|
||||
static{
|
||||
|
||||
BUILDER.push("prices").comment("Costs are calculated as follows: A copper coin is 1, while a iron coin is 100. Thus a gold coin is 10000");
|
||||
COST_TO_TP_HOME = BUILDER.comment("The cost to teleport home.").define("home_tp_cost", 100);
|
||||
COST_TO_WARP = BUILDER.comment("The cost to warp.").define("warp_tp_cost", 1000);
|
||||
COST_TO_MAKE_HOME = BUILDER.comment("The cost to set a new home").define("make_home_cost", 1);
|
||||
COST_TO_MAKE_WARP = BUILDER.comment("The cost to make a new warp. (This applies to all non-creative players) (Default: 1 Emerald Coin)").define("make_warp_cost", 1000000);
|
||||
BUILDER.pop();
|
||||
BUILDER.push("permissions").comment("This section defines permissions, such as total number of homes, and who can make warps");
|
||||
|
||||
MAX_HOMES = BUILDER.comment("Maximum number of homes that are allowed per player (-1 disables the limit entirely). 27 is the current default as that is the max that can fit in the current /homes gui").define("max_homes", 27);
|
||||
MAX_WARPS = BUILDER.comment("Maximum number of warps that are allowed to exist. Default is 27, the max number that can fit in the /warps gui").define("max_warps", 27);
|
||||
|
||||
BUILDER.pop();
|
||||
BUILDER.push("teleport");
|
||||
BUILDER.push("blacklist");
|
||||
|
||||
DIMENSION_BLACKLIST = BUILDER.comment("Blacklist the use of teleportation commands from any of the listed dimensions.").define("blacklist", Lists.of("dimdoors:dungeon_pockets", "dimdoors:limbo", "dimdoors:personal_pockets", "dimdoors:public_pockets", "witherstormmod:bowels"));
|
||||
|
||||
BLACKLISTED_DIMENSION_ERROR = BUILDER.comment("The error to say if the user tries to teleport out of a blacklisted dimension").define("error", "!Dark_Red!You appear to be in a place where we cannot find you.");
|
||||
|
||||
BUILDER.pop();
|
||||
|
||||
TELEPORT_EFFECTS = BUILDER.comment("Teleportation effects that get applied when the user attempts a teleport. Teleport effects will always have a random duration between 5 seconds and 15 seconds. The amplifier will also be random, between Lv1 and Lv4").define("effects", Lists.of(
|
||||
"minecraft:darkness",
|
||||
"minecraft:levitation",
|
||||
"minecraft:slow_falling",
|
||||
"minecraft:hunger"
|
||||
|
||||
));
|
||||
|
||||
BUILDER.push("back");
|
||||
BACK_ALLOWS_LAST_TP = BUILDER.comment("Whether to allow going back to the last teleport location in addition to the last death (If back is enabled for non-op). The history for the back command goes back only to the very last teleport or death").define("allow_last_tp", true);
|
||||
|
||||
ENABLE_BACK = BUILDER.comment("Enable the use of the back command for non-op?").define("enabled", true);
|
||||
|
||||
BUILDER.pop();
|
||||
|
||||
|
||||
|
||||
BUILDER.pop();
|
||||
SPEC=BUILDER.build();
|
||||
}
|
||||
static class TeleportEffect
|
||||
{
|
||||
String Effect;
|
||||
int Duration;
|
||||
int Amplifier;
|
||||
boolean Ambient;
|
||||
|
||||
public TeleportEffect(String name, int Duration, int Amplifier, boolean Ambient)
|
||||
{
|
||||
this.Effect = name;
|
||||
this.Duration = Duration;
|
||||
this.Amplifier = Amplifier;
|
||||
this.Ambient = Ambient;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package dev.zontreck.essentials.configs.client;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import dev.zontreck.essentials.util.EssentialsDatastore;
|
||||
import dev.zontreck.essentials.util.FileHandler;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class AEClientConfig
|
||||
{
|
||||
public static final String TAG_HEARTS = "enable_hearts";
|
||||
|
||||
private static AEClientConfig inst;
|
||||
public boolean EnableHearts = true;
|
||||
|
||||
|
||||
|
||||
public static AEClientConfig deserialize(CompoundTag tag)
|
||||
{
|
||||
AEClientConfig config = new AEClientConfig();
|
||||
config.EnableHearts = tag.getBoolean(TAG_HEARTS);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void loadFromFile()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("client.snbt");
|
||||
if(serverConfig.toFile().exists())
|
||||
{
|
||||
|
||||
try {
|
||||
String snbt = FileHandler.readFile(serverConfig.toFile().getAbsolutePath());
|
||||
|
||||
inst = deserialize(NbtUtils.snbtToStructure(snbt));
|
||||
|
||||
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else {
|
||||
initNewConfig();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void initNewConfig()
|
||||
{
|
||||
inst = new AEClientConfig();
|
||||
inst.reset();
|
||||
}
|
||||
|
||||
private void reset()
|
||||
{
|
||||
EnableHearts = true;
|
||||
|
||||
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
public static void save()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("client.snbt", false);
|
||||
|
||||
CompoundTag tag = inst.serialize();
|
||||
|
||||
var snbt = NbtUtils.structureToSnbt(tag);
|
||||
|
||||
FileHandler.writeFile(serverConfig.toFile().getAbsolutePath(), snbt);
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putBoolean(TAG_HEARTS, EnableHearts);
|
||||
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static AEClientConfig getInstance()
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package dev.zontreck.essentials.configs.client.sections;
|
||||
|
||||
public class Messages
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
package dev.zontreck.essentials.configs.server;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import dev.zontreck.ariaslib.util.Lists;
|
||||
import dev.zontreck.essentials.configs.server.sections.*;
|
||||
import dev.zontreck.essentials.util.EssentialsDatastore;
|
||||
import dev.zontreck.essentials.util.FileHandler;
|
||||
import dev.zontreck.essentials.util.Maps;
|
||||
import net.minecraft.nbt.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AEServerConfig
|
||||
{
|
||||
private static AEServerConfig inst;
|
||||
public Costs costs;
|
||||
public Limitations limits;
|
||||
public Map<String, Cooldown> cooldowns;
|
||||
public Back back;
|
||||
public Teleportation teleport;
|
||||
public Messages messages;
|
||||
|
||||
|
||||
|
||||
public static AEServerConfig deserialize(CompoundTag tag)
|
||||
{
|
||||
AEServerConfig config = new AEServerConfig();
|
||||
config.costs = Costs.deserialize(tag.getCompound(Costs.TAG_NAME));
|
||||
config.limits = Limitations.deserialize(tag.getCompound(Limitations.TAG_NAME));
|
||||
config.cooldowns = new HashMap<>();
|
||||
ListTag cools = tag.getList(Cooldown.TAG_NAME, ListTag.TAG_COMPOUND);
|
||||
for(Tag cooldown : cools)
|
||||
{
|
||||
Cooldown cd = Cooldown.deserialize((CompoundTag) cooldown);
|
||||
config.cooldowns.put(cd.Command, cd);
|
||||
}
|
||||
config.back = Back.deserialize(tag.getCompound(Back.TAG_NAME));
|
||||
config.teleport = Teleportation.deserialize(tag.getCompound(Teleportation.TAG_NAME));
|
||||
config.messages = Messages.deserialize(tag.getCompound(Messages.TAG_NAME));
|
||||
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void loadFromFile()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("server.snbt");
|
||||
if(serverConfig.toFile().exists())
|
||||
{
|
||||
|
||||
try {
|
||||
String snbt = FileHandler.readFile(serverConfig.toFile().getAbsolutePath());
|
||||
|
||||
inst = deserialize(NbtUtils.snbtToStructure(snbt));
|
||||
|
||||
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}else {
|
||||
initNewConfig();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void initNewConfig()
|
||||
{
|
||||
inst = new AEServerConfig();
|
||||
inst.reset();
|
||||
}
|
||||
|
||||
private void reset()
|
||||
{
|
||||
costs = new Costs();
|
||||
limits = new Limitations();
|
||||
cooldowns = Maps.builder("", new Cooldown())
|
||||
.with("rtp", new Cooldown("rtp", 30L))
|
||||
.with("warp", new Cooldown("warp", 10L))
|
||||
.with("home", new Cooldown("home", 5L))
|
||||
.with("tpaccept", new Cooldown("tpaccept", 5L))
|
||||
.build();
|
||||
back = new Back();
|
||||
teleport = new Teleportation();
|
||||
teleport.Effects = Lists.of(
|
||||
"minecraft:darkness",
|
||||
"minecraft:levitation",
|
||||
"minecraft:slow_falling",
|
||||
"minecraft:hunger"
|
||||
);
|
||||
teleport.Blacklist = Lists.of(
|
||||
"dimdoors:dungeon_pockets",
|
||||
"dimdoors:limbo",
|
||||
"dimdoors:personal_pockets",
|
||||
"dimdoors:public_pockets",
|
||||
"witherstormmod:bowels"
|
||||
);
|
||||
messages = new Messages();
|
||||
|
||||
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
public static void save()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("server.snbt", false);
|
||||
|
||||
CompoundTag tag = inst.serialize();
|
||||
|
||||
var snbt = NbtUtils.structureToSnbt(tag);
|
||||
|
||||
FileHandler.writeFile(serverConfig.toFile().getAbsolutePath(), snbt);
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put(Costs.TAG_NAME, costs.serialize());
|
||||
tag.put(Limitations.TAG_NAME, limits.serialize());
|
||||
ListTag cools = new ListTag();
|
||||
for(Map.Entry<String,Cooldown> entries : cooldowns.entrySet())
|
||||
{
|
||||
cools.add(entries.getValue().serialize());
|
||||
}
|
||||
tag.put(Cooldown.TAG_NAME, cools);
|
||||
tag.put(Back.TAG_NAME, back.serialize());
|
||||
tag.put(Teleportation.TAG_NAME, teleport.serialize());
|
||||
tag.put(Messages.TAG_NAME, messages.serialize());
|
||||
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static AEServerConfig getInstance()
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package dev.zontreck.essentials.configs.server.sections;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Back
|
||||
{
|
||||
public static final String TAG_NAME = "back";
|
||||
public static final String TAG_ENABLE = "enabled";
|
||||
public static final String TAG_ALLOW_BACK_FOR_TP = "back_for_tp";
|
||||
|
||||
|
||||
public boolean Enabled = true;
|
||||
public boolean EnabledForTp = false;
|
||||
|
||||
public static Back deserialize(CompoundTag tag)
|
||||
{
|
||||
Back back = new Back();
|
||||
back.Enabled = tag.getBoolean(TAG_ENABLE);
|
||||
back.EnabledForTp = tag.getBoolean(TAG_ALLOW_BACK_FOR_TP);
|
||||
|
||||
return back;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putBoolean(TAG_ENABLE, Enabled);
|
||||
tag.putBoolean(TAG_ALLOW_BACK_FOR_TP, EnabledForTp);
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package dev.zontreck.essentials.configs.server.sections;
|
||||
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Cooldown
|
||||
{
|
||||
public static final String TAG_NAME = "cooldowns";
|
||||
public static final String TAG_COMMAND = "command";
|
||||
public static final String TAG_SECONDS = "seconds";
|
||||
|
||||
public Cooldown(){
|
||||
|
||||
}
|
||||
|
||||
public Cooldown(String name, long sec)
|
||||
{
|
||||
Command = name;
|
||||
Seconds = sec;
|
||||
}
|
||||
|
||||
public String Command;
|
||||
public long Seconds;
|
||||
|
||||
public static Cooldown deserialize(CompoundTag tag)
|
||||
{
|
||||
Cooldown cd = new Cooldown();
|
||||
cd.Command = tag.getString(TAG_COMMAND);
|
||||
cd.Seconds = tag.getLong(TAG_SECONDS);
|
||||
|
||||
return cd;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putString(TAG_COMMAND, Command);
|
||||
tag.putLong(TAG_SECONDS, Seconds);
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package dev.zontreck.essentials.configs.server.sections;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Costs
|
||||
{
|
||||
public static final String TAG_NAME = "costs";
|
||||
public static final String TAG_COST_TP_HOME = "tp_home";
|
||||
public static final String TAG_COST_WARP = "warp";
|
||||
public static final String TAG_COST_MAKE_WARP = "setwarp";
|
||||
public static final String TAG_COST_MAKE_HOME = "sethome";
|
||||
|
||||
|
||||
public String CostToTPHome = "1i"; // 1 iron coin
|
||||
public String CostToWarp = "5i"; // 5 iron coins
|
||||
public String CostToMakeWarp = "5e"; // 5 emerald coin
|
||||
public String CostToSetHome = "1d"; // 1 diamond coin
|
||||
|
||||
|
||||
public static Costs deserialize(CompoundTag tag)
|
||||
{
|
||||
Costs costs = new Costs();
|
||||
costs.CostToTPHome = tag.getString(TAG_COST_TP_HOME);
|
||||
costs.CostToWarp = tag.getString(TAG_COST_WARP);
|
||||
costs.CostToMakeWarp = tag.getString(TAG_COST_MAKE_WARP);
|
||||
costs.CostToSetHome = tag.getString(TAG_COST_MAKE_HOME);
|
||||
|
||||
|
||||
return costs;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putString(TAG_COST_TP_HOME, CostToTPHome);
|
||||
tag.putString(TAG_COST_WARP, CostToWarp);
|
||||
tag.putString(TAG_COST_MAKE_WARP, CostToMakeWarp);
|
||||
tag.putString(TAG_COST_MAKE_HOME, CostToSetHome);
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package dev.zontreck.essentials.configs.server.sections;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Limitations {
|
||||
public static final String TAG_NAME = "limits";
|
||||
|
||||
public static final String TAG_MAX_HOMES = "max_homes";
|
||||
public static final String TAG_MAX_WARPS = "max_warps";
|
||||
|
||||
|
||||
public int MaxHomes = 27;
|
||||
public int MaxWarps = 27;
|
||||
|
||||
|
||||
public static Limitations deserialize(CompoundTag tag)
|
||||
{
|
||||
Limitations limits = new Limitations();
|
||||
limits.MaxHomes = tag.getInt(TAG_MAX_HOMES);
|
||||
limits.MaxWarps = tag.getInt(TAG_MAX_WARPS);
|
||||
|
||||
return limits;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt(TAG_MAX_HOMES, MaxHomes);
|
||||
tag.putInt(TAG_MAX_WARPS, MaxWarps);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package dev.zontreck.essentials.configs.server.sections;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Messages
|
||||
{
|
||||
public static final String TAG_NAME = "messages";
|
||||
public static final String TAG_BL_DIM_ERROR = "blacklisted_dimension_error";
|
||||
|
||||
|
||||
public String BlacklistedDimensionError = "!Dark_Red!You appear to be in a place where we cannot find you.";
|
||||
|
||||
public static Messages deserialize(CompoundTag tag)
|
||||
{
|
||||
Messages msgs = new Messages();
|
||||
msgs.BlacklistedDimensionError = tag.getString(TAG_BL_DIM_ERROR);
|
||||
|
||||
return msgs;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putString(TAG_BL_DIM_ERROR, BlacklistedDimensionError);
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package dev.zontreck.essentials.configs.server.sections;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Teleportation
|
||||
{
|
||||
public static final String TAG_NAME = "teleport";
|
||||
public static final String TAG_EFFECTS = "effects";
|
||||
public static final String TAG_BLACKLIST = "blacklist";
|
||||
|
||||
public List<String> Effects;
|
||||
public List<String> Blacklist;
|
||||
|
||||
public static Teleportation deserialize(CompoundTag tag)
|
||||
{
|
||||
Teleportation teleport = new Teleportation();
|
||||
teleport.Effects = new ArrayList<>();
|
||||
teleport.Blacklist = new ArrayList<>();
|
||||
ListTag effects = tag.getList(TAG_EFFECTS, Tag.TAG_STRING);
|
||||
for(Tag str : effects)
|
||||
{
|
||||
teleport.Effects.add(str.getAsString());
|
||||
}
|
||||
|
||||
ListTag dims = tag.getList(TAG_BLACKLIST, Tag.TAG_STRING);
|
||||
for(Tag dim : dims)
|
||||
{
|
||||
teleport.Blacklist.add(dim.getAsString());
|
||||
}
|
||||
|
||||
return teleport;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
ListTag eff = new ListTag();
|
||||
for(String str : Effects)
|
||||
{
|
||||
eff.add(StringTag.valueOf(str));
|
||||
}
|
||||
|
||||
tag.put(TAG_EFFECTS, eff);
|
||||
|
||||
ListTag dims = new ListTag();
|
||||
for(String str : Blacklist)
|
||||
{
|
||||
dims.add(StringTag.valueOf(str));
|
||||
}
|
||||
|
||||
tag.put(TAG_BLACKLIST, dims);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
static class TeleportEffect
|
||||
{
|
||||
String Effect;
|
||||
int Duration;
|
||||
int Amplifier;
|
||||
boolean Ambient;
|
||||
|
||||
public TeleportEffect(String name, int Duration, int Amplifier, boolean Ambient)
|
||||
{
|
||||
this.Effect = name;
|
||||
this.Duration = Duration;
|
||||
this.Amplifier = Amplifier;
|
||||
this.Ambient = Ambient;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package dev.zontreck.essentials.events;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Cancelable
|
||||
public class CommandExecutionEvent extends Event
|
||||
{
|
||||
public UUID playerID;
|
||||
public String command;
|
||||
|
||||
public CommandExecutionEvent(Player player, String cmd)
|
||||
{
|
||||
playerID=player.getUUID();
|
||||
command=cmd;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import dev.zontreck.essentials.AriasEssentials;
|
||||
import dev.zontreck.essentials.configs.AEClientConfig;
|
||||
import dev.zontreck.essentials.configs.client.AEClientConfig;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
@ -96,7 +96,7 @@ public class HeartsRenderer {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (event.isCanceled() || !AEClientConfig.ENABLE_HEARTS_RENDER.get() || event.getOverlay() != ActualOverlay) {
|
||||
if (event.isCanceled() || !AEClientConfig.getInstance().EnableHearts || event.getOverlay() != ActualOverlay) {
|
||||
return;
|
||||
}
|
||||
// ensure its visible
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package dev.zontreck.essentials.homes;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class HomesSuggestionProvider {
|
||||
public static SuggestionProvider<CommandSourceStack> PROVIDER = (ctx,suggestionsBuilder)->{
|
||||
Homes homes = HomesProvider.getHomesForPlayer(ctx.getSource().getPlayer().getUUID().toString());
|
||||
|
||||
List<String> homesList = new ArrayList<>();
|
||||
|
||||
for(Home home : homes.getList())
|
||||
{
|
||||
homesList.add(home.homeName);
|
||||
}
|
||||
|
||||
|
||||
return SharedSuggestionProvider.suggest((String[]) homesList.toArray(), suggestionsBuilder);
|
||||
};
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package dev.zontreck.essentials.networking.packets.s2c;
|
||||
|
||||
import dev.zontreck.essentials.configs.AEClientConfig;
|
||||
import dev.zontreck.essentials.configs.client.AEClientConfig;
|
||||
import dev.zontreck.libzontreck.networking.packets.IPacket;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -35,8 +35,8 @@ public class S2CUpdateHearts
|
|||
NetworkEvent.Context ctx=supplier.get();
|
||||
|
||||
ctx.enqueueWork(()->{
|
||||
AEClientConfig.ENABLE_HEARTS_RENDER.set(current);
|
||||
AEClientConfig.ENABLE_HEARTS_RENDER.save();
|
||||
AEClientConfig.getInstance().EnableHearts = current;
|
||||
AEClientConfig.save();
|
||||
});
|
||||
|
||||
return true;
|
||||
|
|
|
@ -39,6 +39,6 @@ public class RandomPositionFactory {
|
|||
TeleportActioner.ApplyTeleportEffect(player);
|
||||
TeleportContainer cont = new TeleportContainer(player, tmp.position.Position.asMinecraftVector(), player.getRotationVector(), level);
|
||||
|
||||
TeleportActioner.PerformTeleport(cont);
|
||||
TeleportActioner.PerformTeleport(cont, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package dev.zontreck.essentials.util;
|
||||
|
||||
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.vectors.WorldPosition;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -10,18 +15,46 @@ import java.util.UUID;
|
|||
|
||||
public class BackPositionCaches
|
||||
{
|
||||
private static final Map<UUID, WorldPosition> backCaches = new HashMap<>();
|
||||
public static void Update(UUID ID, WorldPosition pos)
|
||||
{
|
||||
backCaches.put(ID, pos);
|
||||
try {
|
||||
Profile prof = Profile.get_profile_of(ID.toString());
|
||||
if(prof.NBT.contains("back_positions"))
|
||||
{
|
||||
|
||||
ListTag backCaches = prof.NBT.getList("back_positions", CompoundTag.TAG_COMPOUND);
|
||||
backCaches.add(pos.serialize());
|
||||
|
||||
prof.commit();
|
||||
} else {
|
||||
ListTag backCaches = new ListTag();
|
||||
backCaches.add(pos.serialize());
|
||||
|
||||
prof.NBT.put("back_positions", backCaches);
|
||||
|
||||
prof.commit();
|
||||
}
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldPosition Pop(UUID ID) throws Exception {
|
||||
if(backCaches.containsKey(ID)) {
|
||||
WorldPosition pos = backCaches.get(ID);
|
||||
backCaches.remove(ID);
|
||||
return pos;
|
||||
}else throw new Exception("No such back cache");
|
||||
Profile prof = Profile.get_profile_of(ID.toString());
|
||||
if(prof.NBT.contains("back_positions"))
|
||||
{
|
||||
ListTag lst = prof.NBT.getList("back_positions", Tag.TAG_COMPOUND);
|
||||
if(lst.size()>0)
|
||||
{
|
||||
WorldPosition pos = new WorldPosition(lst.getCompound(0), false);
|
||||
lst.remove(0);
|
||||
|
||||
prof.commit();
|
||||
return pos;
|
||||
}else {
|
||||
throw new Exception("No back cache");
|
||||
}
|
||||
} else throw new Exception("No back cache");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package dev.zontreck.essentials.util;
|
||||
|
||||
import dev.zontreck.essentials.Messages;
|
||||
import dev.zontreck.essentials.configs.server.AEServerConfig;
|
||||
import dev.zontreck.essentials.events.CommandExecutionEvent;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandCooldowns
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void onCommand(CommandExecutionEvent ev)
|
||||
{
|
||||
if(isOnCooldown(ev.playerID, ev.command))
|
||||
{
|
||||
ev.setCanceled(true);
|
||||
ChatHelpers.broadcastTo(ev.playerID, ChatHelpers.macro(Messages.COOLDOWN_IN_PROGRESS, ev.command, getCooldownSeconds(ev.playerID, ev.command) + " seconds"), ServerUtilities.getPlayerByID(ev.playerID.toString()).server);
|
||||
}
|
||||
}
|
||||
|
||||
public long getCooldownSeconds(UUID ID, String command)
|
||||
{
|
||||
try{
|
||||
Profile prof = Profile.get_profile_of(ID.toString());
|
||||
CompoundTag commands = prof.NBT.getCompound("commands");
|
||||
return Instant.now().getEpochSecond() - (commands.getLong(command) + getConfigCooldown(command));
|
||||
}catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public long getConfigCooldown(String command)
|
||||
{
|
||||
if(AEServerConfig.getInstance().cooldowns.containsKey(command))
|
||||
{
|
||||
return AEServerConfig.getInstance().cooldowns.get(command).Seconds;
|
||||
}else return 0;
|
||||
}
|
||||
|
||||
public boolean isOnCooldown(UUID ID, String command)
|
||||
{
|
||||
try {
|
||||
Profile prof = Profile.get_profile_of(ID.toString());
|
||||
CompoundTag commands = prof.NBT.getCompound("commands");
|
||||
if(commands.contains(command))
|
||||
{
|
||||
long cfg = getConfigCooldown(command);
|
||||
if(Instant.now().getEpochSecond() > (commands.getLong(command) + cfg))
|
||||
{
|
||||
commands.putLong(command, Instant.now().getEpochSecond());
|
||||
prof.commit();
|
||||
return false;
|
||||
}else return true;
|
||||
}else {
|
||||
commands = new CompoundTag();
|
||||
prof.NBT.put("commands", commands);
|
||||
commands.putLong(command, Instant.now().getEpochSecond());
|
||||
prof.commit();
|
||||
|
||||
return false;
|
||||
}
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
25
src/main/java/dev/zontreck/essentials/util/FileHandler.java
Normal file
25
src/main/java/dev/zontreck/essentials/util/FileHandler.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package dev.zontreck.essentials.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileHandler
|
||||
{
|
||||
|
||||
public static String readFile(String filePath) {
|
||||
try {
|
||||
byte[] fileBytes = Files.readAllBytes(Paths.get(filePath));
|
||||
return new String(fileBytes);
|
||||
} catch (IOException e) {
|
||||
return "An error occurred: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
public static void writeFile(String filePath, String newContent) {
|
||||
try {
|
||||
Files.write(Paths.get(filePath), newContent.getBytes());
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
27
src/main/java/dev/zontreck/essentials/util/Maps.java
Normal file
27
src/main/java/dev/zontreck/essentials/util/Maps.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package dev.zontreck.essentials.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Maps <K,V>
|
||||
{
|
||||
public Map<K,V> map = new HashMap<>();
|
||||
|
||||
public static <K,V> Maps<K,V> builder(K k, V v)
|
||||
{
|
||||
return new Maps<K,V>();
|
||||
}
|
||||
|
||||
public Maps<K,V> with(K k, V v)
|
||||
{
|
||||
map.put(k,v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<K,V> build()
|
||||
{
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue