diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/BackCommand.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/BackCommand.java index 9d5795789..5e0c9c411 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/BackCommand.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/BackCommand.java @@ -3,8 +3,13 @@ package mineplex.mapparser.command.teleport; import java.util.LinkedList; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; +import mineplex.core.common.Pair; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.mapparser.command.BaseCommand; public class BackCommand extends BaseCommand @@ -21,7 +26,7 @@ public class BackCommand extends BaseCommand @Override public boolean execute(Player player, String alias, String[] args) { - LinkedList teleportHistory = _teleportManager.getTeleportHistory(player); + LinkedList> teleportHistory = _teleportManager.getTeleportHistory(player); if (teleportHistory == null || teleportHistory.isEmpty()) { @@ -49,39 +54,38 @@ public class BackCommand extends BaseCommand } } - Location location = null; + Pair locationPair = null; if (steps == 1) { - location = teleportHistory.removeFirst(); + locationPair = teleportHistory.removeFirst(); } else { for (int i = 0; i < steps; i++) { - location = teleportHistory.remove(i); + locationPair = teleportHistory.remove(i); } } - if (location == null) + if (locationPair == null) { message(player, "Something went wrong. Couldn't teleport you back."); return true; } + World locationWorld =_teleportManager.getPlugin().getWorldFromName(locationPair.getRight()); + Vector locationVec = locationPair.getLeft(); + Location location = new Location(locationWorld, locationVec.getX(), locationVec.getY(), locationVec.getZ()); + if (!_teleportManager.canTeleportTo(player, location)) { message(player, "You don't have access to teleport back to that location."); return true; } - // If the world doesn't already exist, load it - if (location.getWorld() == null || (!location.getWorld().equals(player.getWorld()) && location.getWorld().getPlayers().size() == 0)) - { - _teleportManager.getPlugin().getWorldFromName(location.getWorld().getName()); - } - player.teleport(location); + message(player, "You undid your last " + ((steps == 1) ? "teleport." : F.count(steps) + C.mBody + " teleports.")); return true; } } diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportManager.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportManager.java index 6997404f4..52b330cb5 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportManager.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/command/teleport/TeleportManager.java @@ -6,14 +6,16 @@ import java.util.Map; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; +import mineplex.core.common.Pair; import mineplex.mapparser.MapData; import mineplex.mapparser.MapParser; public class TeleportManager { private MapParser _plugin; - private Map> _teleportHistory; + private Map>> _teleportHistory; public TeleportManager(MapParser plugin) { @@ -23,10 +25,10 @@ public class TeleportManager private void addToHistory(Player player, Location location) { - _teleportHistory.computeIfAbsent(player, key -> new LinkedList<>()).addFirst(location); + _teleportHistory.computeIfAbsent(player, key -> new LinkedList<>()).addFirst(Pair.create(new Vector(location.getX(), location.getY(), location.getZ()), location.getWorld().getName())); } - public LinkedList getTeleportHistory(Player player) + public LinkedList> getTeleportHistory(Player player) { return _teleportHistory.get(player); }