From 9fe614fde928e22dbb04a4a065829231e92620d5 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 23 Dec 2023 23:49:31 -0700 Subject: [PATCH] Add config toggle to back command; add last tp to back command --- .../java/dev/zontreck/essentials/AriasEssentials.java | 3 +++ src/main/java/dev/zontreck/essentials/Messages.java | 9 +++++++++ .../essentials/commands/teleport/BackCommand.java | 8 ++++++++ .../commands/teleport/TeleportContainer.java | 1 + .../essentials/commands/teleport/TeleportRunnable.java | 2 ++ .../zontreck/essentials/configs/AEServerConfig.java | 10 ++++++++++ 6 files changed, 33 insertions(+) diff --git a/src/main/java/dev/zontreck/essentials/AriasEssentials.java b/src/main/java/dev/zontreck/essentials/AriasEssentials.java index 29fb0b5..18fb9b4 100644 --- a/src/main/java/dev/zontreck/essentials/AriasEssentials.java +++ b/src/main/java/dev/zontreck/essentials/AriasEssentials.java @@ -79,6 +79,9 @@ public class AriasEssentials { if(TeleportActioner.isBlacklistedDimension(event.getContainer().Dimension)) { event.setCanceled(true); + } else { + if(AEServerConfig.BACK_ALLOWS_LAST_TP.get()) + BackPositionCaches.Update(event.getContainer().PlayerInst.getUUID(), event.getContainer().world_pos); } } diff --git a/src/main/java/dev/zontreck/essentials/Messages.java b/src/main/java/dev/zontreck/essentials/Messages.java index 96660a5..6ac6962 100644 --- a/src/main/java/dev/zontreck/essentials/Messages.java +++ b/src/main/java/dev/zontreck/essentials/Messages.java @@ -72,6 +72,9 @@ public class Messages { public static final String RTP_CACHED; public static final String NO_BACK; public static final String TELEPORT_BACK; + public static final String TELEPORT_BACK_DISABLED; + public static final String TELEPORT_BACK_LAST; + public static final String TELEPORT_BACK_NO_LAST; static{ @@ -155,5 +158,11 @@ public class Messages { NO_BACK = ESSENTIALS_PREFIX + "!Dark_Green!Good news! You have not died recently, there is no saved back position"; TELEPORT_BACK = ESSENTIALS_PREFIX + "!Dark_Purple!You are being taken back to your last death location now."; + TELEPORT_BACK_DISABLED = ESSENTIALS_PREFIX + "!Dark_Red!You are not an op, and the back command is disabled on this server."; + + TELEPORT_BACK_NO_LAST = ESSENTIALS_PREFIX + "!Dark_Red!You have not teleported recently, nor died. There is nothing to go back to."; + + TELEPORT_BACK_LAST = ESSENTIALS_PREFIX + "!Dark_Purple!You are being taken back to your last death or teleport location."; + } } diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/BackCommand.java b/src/main/java/dev/zontreck/essentials/commands/teleport/BackCommand.java index 02df6e2..9693e67 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/BackCommand.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/BackCommand.java @@ -2,6 +2,7 @@ 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.util.BackPositionCaches; import dev.zontreck.libzontreck.util.ChatHelpers; import dev.zontreck.libzontreck.vectors.WorldPosition; @@ -18,6 +19,13 @@ public class BackCommand public static int back(CommandSourceStack ctx) { try { + + if(!AEServerConfig.ENABLE_BACK.get() && !ctx.hasPermission(ctx.getServer().getOperatorUserPermissionLevel())) + { + ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK_DISABLED), ctx.getServer()); + return 0; + } + WorldPosition wp = BackPositionCaches.Pop(ctx.getPlayer().getUUID()); ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK), ctx.getServer()); diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportContainer.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportContainer.java index adb211e..9aed23d 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportContainer.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportContainer.java @@ -24,6 +24,7 @@ public class TeleportContainer implements Comparable{ public Vec3 Position; public Vec2 Rotation; public ServerLevel Dimension; + public WorldPosition OldPosition; // Populated in a teleport event public boolean has_expired(){ diff --git a/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportRunnable.java b/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportRunnable.java index ba066ef..f953765 100644 --- a/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportRunnable.java +++ b/src/main/java/dev/zontreck/essentials/commands/teleport/TeleportRunnable.java @@ -4,6 +4,7 @@ package dev.zontreck.essentials.commands.teleport; import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.essentials.events.TeleportEvent; +import dev.zontreck.libzontreck.vectors.WorldPosition; import net.minecraftforge.common.MinecraftForge; public class TeleportRunnable extends Task @@ -17,6 +18,7 @@ public class TeleportRunnable extends Task @Override public void run() { + Action.OldPosition = new WorldPosition(Action.PlayerInst); if(MinecraftForge.EVENT_BUS.post(new TeleportEvent(Action))) { diff --git a/src/main/java/dev/zontreck/essentials/configs/AEServerConfig.java b/src/main/java/dev/zontreck/essentials/configs/AEServerConfig.java index 4901453..3337849 100644 --- a/src/main/java/dev/zontreck/essentials/configs/AEServerConfig.java +++ b/src/main/java/dev/zontreck/essentials/configs/AEServerConfig.java @@ -28,6 +28,9 @@ public class AEServerConfig { public static final ForgeConfigSpec.ConfigValue> DIMENSION_BLACKLIST; public static final ForgeConfigSpec.ConfigValue BLACKLISTED_DIMENSION_ERROR; + public static final ForgeConfigSpec.ConfigValue BACK_ALLOWS_LAST_TP; + public static final ForgeConfigSpec.ConfigValue ENABLE_BACK; + public static final ForgeConfigSpec.ConfigValue> TELEPORT_EFFECTS; @@ -61,6 +64,13 @@ public class AEServerConfig { )); + 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();