Return player to previous location
This commit is contained in:
1 parent
9020f85e3d
commit
f345e5163a
6 files changed
+76
-15
No files matched your search
@@ -20,6 +20,10 @@
|
||||
|
||||
package plugily.projects.buildbattle;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import plugily.projects.buildbattle.arena.ArenaEvents;
|
||||
import plugily.projects.buildbattle.arena.ArenaManager;
|
||||
@@ -50,6 +54,8 @@ import plugily.projects.minigamesbox.classic.handlers.setup.categories.PluginSet
|
||||
*/
|
||||
public class Main extends PluginMain {
|
||||
|
||||
private final ConcurrentHashMap<UUID, Location> preJoinLocations = new ConcurrentHashMap<>();
|
||||
|
||||
private VoteItems voteItems;
|
||||
private HeadDatabaseManager headDatabaseManager;
|
||||
private ThemeManager themeManager;
|
||||
@@ -160,6 +166,18 @@ public class Main extends PluginMain {
|
||||
|
||||
}
|
||||
|
||||
public void savePreJoinLocation(Player player) {
|
||||
|
||||
preJoinLocations.put(player.getUniqueId(), player.getLocation().clone());
|
||||
|
||||
}
|
||||
|
||||
public Location getAndRemovePreJoinLocation(UUID playerId) {
|
||||
|
||||
return preJoinLocations.remove(playerId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArenaRegistry getArenaRegistry() {
|
||||
|
||||
|
||||
@@ -49,6 +49,19 @@ public class ArenaManager extends PluginArenaManager {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinAttempt(@NotNull Player player, @NotNull IPluginArena arena) {
|
||||
|
||||
if (!plugin.getArenaRegistry().isInArena(player)) {
|
||||
|
||||
plugin.savePreJoinLocation(player);
|
||||
|
||||
}
|
||||
|
||||
super.joinAttempt(player, arena);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void additionalPartyJoin(Player player, IPluginArena arena, Player partyLeader) {
|
||||
|
||||
|
||||
@@ -33,6 +33,34 @@ public class HubCommand implements CommandExecutor {
|
||||
|
||||
}
|
||||
|
||||
BaseArena arena = plugin.getArenaRegistry().getArena(player);
|
||||
if (arena != null) {
|
||||
|
||||
plugin.getArenaManager().hubLeaveAttempt(player, arena);
|
||||
|
||||
}
|
||||
|
||||
Location savedLoc = plugin.getAndRemovePreJoinLocation(player.getUniqueId());
|
||||
if (savedLoc != null && savedLoc.getWorld() != null) {
|
||||
|
||||
if (!player.teleport(savedLoc)) {
|
||||
|
||||
send(player, "&cUnable to return you to your previous location.");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if (arena != null) {
|
||||
|
||||
InventorySerializer.loadInventory(plugin, player);
|
||||
|
||||
}
|
||||
|
||||
send(player, "&aReturned to your previous location.");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
World mainWorld = findMainWorld();
|
||||
if (mainWorld == null) {
|
||||
|
||||
@@ -41,13 +69,6 @@ public class HubCommand implements CommandExecutor {
|
||||
|
||||
}
|
||||
|
||||
BaseArena arena = plugin.getArenaRegistry().getArena(player);
|
||||
if (arena != null) {
|
||||
|
||||
plugin.getArenaManager().hubLeaveAttempt(player, arena);
|
||||
|
||||
}
|
||||
|
||||
Location destination = mainWorld.getSpawnLocation();
|
||||
if (!player.teleport(destination)) {
|
||||
|
||||
|
||||
+9
@@ -1,6 +1,7 @@
|
||||
package plugily.projects.buildbattle.handlers.misc;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -67,6 +68,14 @@ public class ReconnectToMainWorldListener implements Listener {
|
||||
|
||||
}
|
||||
|
||||
Location savedLoc = plugin.getAndRemovePreJoinLocation(player.getUniqueId());
|
||||
if (savedLoc != null && savedLoc.getWorld() != null) {
|
||||
|
||||
player.teleport(savedLoc);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
World mainWorld = findMainWorld();
|
||||
if (mainWorld == null) {
|
||||
|
||||
|
||||
@@ -502,18 +502,18 @@ Validator:
|
||||
Placeholders:
|
||||
Game-States:
|
||||
Waiting: "&lWaiting for players..."
|
||||
Starting: "&e&lStarting"
|
||||
Starting: "&6&lStarting"
|
||||
Full-Game: "&4&lFULL"
|
||||
In-Game: "&lIn-game"
|
||||
Ending: "&lEnding"
|
||||
Restarting: "&c&lRestarting"
|
||||
Restarting: "&4&lRestarting"
|
||||
Motd:
|
||||
Waiting: "&lYou can join this game..."
|
||||
Starting: "&e&lStarting"
|
||||
Starting: "&6&lStarting"
|
||||
Full-Game: "&4&lFULL | Use another Server"
|
||||
In-Game: "&lIn-game | Click to spectate"
|
||||
Ending: "&lEnding | Server is closing"
|
||||
Restarting: "&c&lRestarting"
|
||||
Restarting: "&4&lRestarting"
|
||||
|
||||
|
||||
#
|
||||
|
||||
@@ -499,18 +499,18 @@ Validator:
|
||||
Placeholders:
|
||||
Game-States:
|
||||
Waiting: "&lWaiting for players..."
|
||||
Starting: "&e&lStarting"
|
||||
Starting: "&6&lStarting"
|
||||
Full-Game: "&4&lFULL"
|
||||
In-Game: "&lIn-game"
|
||||
Ending: "&lEnding"
|
||||
Restarting: "&c&lRestarting"
|
||||
Restarting: "&4&lRestarting"
|
||||
Motd:
|
||||
Waiting: "&lYou can join this game..."
|
||||
Starting: "&e&lStarting"
|
||||
Starting: "&6&lStarting"
|
||||
Full-Game: "&4&lFULL | Use another Server"
|
||||
In-Game: "&lIn-game | Click to spectate"
|
||||
Ending: "&lEnding | Server is closing"
|
||||
Restarting: "&c&lRestarting"
|
||||
Restarting: "&4&lRestarting"
|
||||
|
||||
|
||||
#
|
||||
|
||||
Reference in new issue
Block a user