Skip to content

Commit

Permalink
fix /back sending you to the void
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyfts committed Nov 4, 2023
1 parent ba99e3e commit 02dc2ca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/main/java/serverutils/command/tp/CmdBack.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import serverutils.lib.command.CmdBase;
import serverutils.lib.command.CommandUtils;
import serverutils.lib.data.ForgePlayer;
import serverutils.lib.math.BlockDimPos;
import serverutils.lib.util.permission.PermissionAPI;

public class CmdBack extends CmdBase {
Expand All @@ -33,6 +34,11 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
throw ServerUtilities.error(sender, "serverutilities.lang.warps.no_dp");
}

BlockDimPos noPosFound = new BlockDimPos(0, 0, 0, 0);
if (lastTeleportLog.getBlockDimPos().equalsPos(noPosFound)) {
throw ServerUtilities.error(sender, "serverutilities.lang.warps.no_pos_found");
}

data.checkTeleportCooldown(sender, ServerUtilitiesPlayerData.Timer.BACK);

ServerUtilitiesPlayerData.Timer.BACK.teleport(player, playerMP -> lastTeleportLog.teleporter(), universe -> {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/serverutils/data/ServerUtilitiesPlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static ServerUtilitiesPlayerData get(ForgePlayer player) {
private BlockDimPos lastSafePos;
private final long[] lastTeleport;
public final BlockDimPosStorage homes;
private TeleportTracker teleportTracker;
private final TeleportTracker teleportTracker;

public ServerUtilitiesPlayerData(ForgePlayer player) {
super(player);
Expand All @@ -186,7 +186,7 @@ public NBTTagCompound serializeNBT() {
nbt.setBoolean("DisableGlobalBadges", disableGlobalBadge);
nbt.setBoolean("EnablePVP", enablePVP);
nbt.setTag("Homes", homes.serializeNBT());

nbt.setTag("TeleportTracker", teleportTracker.serializeNBT());
nbt.setString("Nickname", nickname);
nbt.setString("AFK", EnumMessageLocation.NAME_MAP.getName(afkMesageLocation));
return nbt;
Expand All @@ -198,8 +198,7 @@ public void deserializeNBT(NBTTagCompound nbt) {
disableGlobalBadge = nbt.getBoolean("DisableGlobalBadges");
enablePVP = !nbt.hasKey("EnablePVP") || nbt.getBoolean("EnablePVP");
homes.deserializeNBT(nbt.getCompoundTag("Homes"));
teleportTracker = new TeleportTracker();
teleportTracker.deserializeNBT(nbt.getCompoundTag("teleportTracker"));
teleportTracker.deserializeNBT(nbt.getCompoundTag("TeleportTracker"));
setLastDeath(BlockDimPos.fromIntArray(nbt.getIntArray("LastDeath")), 0);
nickname = nbt.getString("Nickname");
afkMesageLocation = EnumMessageLocation.NAME_MAP.get(nbt.getString("AFK"));
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/serverutils/data/TeleportTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

public class TeleportTracker implements INBTSerializable<NBTTagCompound> {

private TeleportLog[] logs;
private IPermissionHandler permissionHandler;
private final TeleportLog[] logs;
private final IPermissionHandler permissionHandler;

public TeleportTracker() {
this(PermissionAPI.getPermissionHandler());
Expand Down Expand Up @@ -63,6 +63,7 @@ public void clearLog(TeleportType teleportType) {
public NBTTagCompound serializeNBT() {
NBTTagCompound nbt = new NBTTagCompound();
for (int i = 0; i < logs.length; i++) {
if (logs[i] == null) continue;
nbt.setTag(String.valueOf(i), logs[i].serializeNBT());
}
return nbt;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/serverutilities/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ serverutilities.lang.warps.not_set=Unknown Warp: '%s'!
serverutilities.lang.warps.cooldown=You can only use warp in %s!
serverutilities.lang.warps.tp=Teleported to '%s'!
serverutilities.lang.warps.no_dp=You can only go back once!
serverutilities.lang.warps.no_pos_found=No position to go back to!

# Homes
serverutilities.lang.homes.set=Home '%s' set!
Expand Down

0 comments on commit 02dc2ca

Please sign in to comment.