Moves the Bungee Queue to BungeeHelper
This commit is contained in:
		@@ -42,7 +42,6 @@ import org.bukkit.scheduler.BukkitScheduler;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
@@ -78,8 +77,6 @@ public class Stargate extends JavaPlugin {
 | 
			
		||||
    public static boolean debuggingEnabled = false;
 | 
			
		||||
    public static boolean permissionDebuggingEnabled = false;
 | 
			
		||||
 | 
			
		||||
    //HashMap of player names for Bungee support
 | 
			
		||||
    public static final Map<String, String> bungeeQueue = new HashMap<>();
 | 
			
		||||
    //World names that contain stargates
 | 
			
		||||
    public static final HashSet<String> managedWorlds = new HashSet<>();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -48,7 +48,7 @@ public class PlayerEventListener implements Listener {
 | 
			
		||||
 | 
			
		||||
        Player player = event.getPlayer();
 | 
			
		||||
        //Check if the player is waiting to be teleported to a stargate
 | 
			
		||||
        String destination = Stargate.bungeeQueue.remove(player.getName().toLowerCase());
 | 
			
		||||
        String destination = BungeeHelper.removeFromQueue(player.getName());
 | 
			
		||||
        if (destination == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,8 @@ import java.io.ByteArrayOutputStream;
 | 
			
		||||
import java.io.DataInputStream;
 | 
			
		||||
import java.io.DataOutputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class contains helpful functions to help with sending and receiving BungeeCord plugin messages
 | 
			
		||||
@@ -20,11 +22,26 @@ public final class BungeeHelper {
 | 
			
		||||
    private final static String bungeeSubChannel = "SGBungee";
 | 
			
		||||
    private final static String bungeeChannel = "BungeeCord";
 | 
			
		||||
    private final static String teleportMessageDelimiter = "#@#";
 | 
			
		||||
    private final static Map<String, String> bungeeQueue = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    private BungeeHelper() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Removes a player from the queue of players teleporting through BungeeCord
 | 
			
		||||
     *
 | 
			
		||||
     * <p>Whenever a BungeeCord teleportation message is received and the player is not currently connected to this
 | 
			
		||||
     * server, it'll be added to this queue. Once the player joins this server, the player should be removed from the
 | 
			
		||||
     * queue and teleported to the destination.</p>
 | 
			
		||||
     *
 | 
			
		||||
     * @param playerName <p>The name of the player to remove</p>
 | 
			
		||||
     * @return <p>The name of the destination portal the player should be teleported to</p>
 | 
			
		||||
     */
 | 
			
		||||
    public static String removeFromQueue(String playerName) {
 | 
			
		||||
        return bungeeQueue.remove(playerName.toLowerCase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sends a plugin message to BungeeCord allowing the target server to catch it
 | 
			
		||||
     *
 | 
			
		||||
@@ -123,7 +140,7 @@ public final class BungeeHelper {
 | 
			
		||||
        // Check if the player is online, if so, teleport, otherwise, queue
 | 
			
		||||
        Player player = Stargate.server.getPlayer(playerName);
 | 
			
		||||
        if (player == null) {
 | 
			
		||||
            Stargate.bungeeQueue.put(playerName.toLowerCase(), destination);
 | 
			
		||||
            bungeeQueue.put(playerName.toLowerCase(), destination);
 | 
			
		||||
        } else {
 | 
			
		||||
            Portal destinationPortal = PortalHandler.getBungeePortal(destination);
 | 
			
		||||
            // Specified an invalid gate. For now, we'll just let them connect at their current location
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user