Add config toggle to back command; add last tp to back command

This commit is contained in:
zontreck 2023-12-23 23:49:31 -07:00
parent a57d06d20a
commit 9fe614fde9
6 changed files with 33 additions and 0 deletions

View file

@ -79,6 +79,9 @@ public class AriasEssentials {
if(TeleportActioner.isBlacklistedDimension(event.getContainer().Dimension)) if(TeleportActioner.isBlacklistedDimension(event.getContainer().Dimension))
{ {
event.setCanceled(true); event.setCanceled(true);
} else {
if(AEServerConfig.BACK_ALLOWS_LAST_TP.get())
BackPositionCaches.Update(event.getContainer().PlayerInst.getUUID(), event.getContainer().world_pos);
} }
} }

View file

@ -72,6 +72,9 @@ public class Messages {
public static final String RTP_CACHED; public static final String RTP_CACHED;
public static final String NO_BACK; public static final String NO_BACK;
public static final String TELEPORT_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{ 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"; 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 = 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.";
} }
} }

View file

@ -2,6 +2,7 @@ package dev.zontreck.essentials.commands.teleport;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.essentials.Messages; import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.configs.AEServerConfig;
import dev.zontreck.essentials.util.BackPositionCaches; import dev.zontreck.essentials.util.BackPositionCaches;
import dev.zontreck.libzontreck.util.ChatHelpers; import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.WorldPosition; import dev.zontreck.libzontreck.vectors.WorldPosition;
@ -18,6 +19,13 @@ public class BackCommand
public static int back(CommandSourceStack ctx) public static int back(CommandSourceStack ctx)
{ {
try { 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()); WorldPosition wp = BackPositionCaches.Pop(ctx.getPlayer().getUUID());
ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK), ctx.getServer()); ChatHelpers.broadcastTo(ctx.getPlayer(), ChatHelpers.macro(Messages.TELEPORT_BACK), ctx.getServer());

View file

@ -24,6 +24,7 @@ public class TeleportContainer implements Comparable{
public Vec3 Position; public Vec3 Position;
public Vec2 Rotation; public Vec2 Rotation;
public ServerLevel Dimension; public ServerLevel Dimension;
public WorldPosition OldPosition; // Populated in a teleport event
public boolean has_expired(){ public boolean has_expired(){

View file

@ -4,6 +4,7 @@ package dev.zontreck.essentials.commands.teleport;
import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.ariaslib.terminal.Task;
import dev.zontreck.ariaslib.util.DelayedExecutorService; import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.essentials.events.TeleportEvent; import dev.zontreck.essentials.events.TeleportEvent;
import dev.zontreck.libzontreck.vectors.WorldPosition;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
public class TeleportRunnable extends Task public class TeleportRunnable extends Task
@ -17,6 +18,7 @@ public class TeleportRunnable extends Task
@Override @Override
public void run() { public void run() {
Action.OldPosition = new WorldPosition(Action.PlayerInst);
if(MinecraftForge.EVENT_BUS.post(new TeleportEvent(Action))) if(MinecraftForge.EVENT_BUS.post(new TeleportEvent(Action)))
{ {

View file

@ -28,6 +28,9 @@ public class AEServerConfig {
public static final ForgeConfigSpec.ConfigValue<List<String>> DIMENSION_BLACKLIST; public static final ForgeConfigSpec.ConfigValue<List<String>> DIMENSION_BLACKLIST;
public static final ForgeConfigSpec.ConfigValue<String> BLACKLISTED_DIMENSION_ERROR; 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; public static final ForgeConfigSpec.ConfigValue<List<String>> 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(); BUILDER.pop();