diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index f3c7d7e..4f80b77 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -4,7 +4,7 @@ us.ajg0702 ajQueue ajQueue - 1.3.0 + 1.3.4 diff --git a/pom.xml b/pom.xml index 01b8ec0..9cdc8af 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 us.ajg0702 ajQueue - 1.3.0 + 1.3.4 ajQueue @@ -39,7 +39,7 @@ javadoc provided - + us.ajg0702.premium ajQueuePlus 1.0.0 diff --git a/src/main/java/us/ajg0702/queue/Main.java b/src/main/java/us/ajg0702/queue/Main.java index f5723ac..bde347a 100644 --- a/src/main/java/us/ajg0702/queue/Main.java +++ b/src/main/java/us/ajg0702/queue/Main.java @@ -1,10 +1,14 @@ package us.ajg0702.queue; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; import java.util.List; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; +import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; @@ -48,6 +52,7 @@ public class Main extends Plugin implements Listener { this.getProxy().getPluginManager().registerListener(this, this); getProxy().registerChannel("ajqueue:tospigot"); + getProxy().registerChannel("ajqueue:tobungee"); timeBetweenPlayers = config.getInt("wait-time"); @@ -121,4 +126,26 @@ public class Main extends Plugin implements Listener { } } + + @EventHandler + public void onMessage(PluginMessageEvent e) { + //getLogger().info("Recieved message of "+e.getTag()); + if(!e.getTag().equals("ajqueue:tobungee")) return; + DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData())); + try { + String subchannel = in.readUTF(); + + + if(subchannel.equals("queue")) { + String data = in.readUTF(); + ProxiedPlayer player = (ProxiedPlayer) e.getReceiver(); + man.addToQueue(player, data); + } + + } catch (IOException e1) { + getLogger().warning("An error occured while reading data from spigot side:"); + e1.printStackTrace(); + } + } + } diff --git a/src/main/java/us/ajg0702/queue/Manager.java b/src/main/java/us/ajg0702/queue/Manager.java index 39529b9..edcbea3 100644 --- a/src/main/java/us/ajg0702/queue/Manager.java +++ b/src/main/java/us/ajg0702/queue/Manager.java @@ -122,7 +122,7 @@ public class Manager { continue; } int len = plys.size(); - if(!s.isOnline()) { + if(!s.isOnline() || s.isFull()) { String or = msgs.get("status.offline.restarting"); if(ot > pl.config.getInt("offline-time")) { or = msgs.get("status.offline.offline"); @@ -169,11 +169,14 @@ public class Manager { continue; } int len = plys.size(); - if(!s.isOnline()) { + if(!s.isOnline() || s.isFull()) { String or = msgs.get("status.offline.restarting"); if(ot > pl.config.getInt("offline-time")) { or = msgs.get("status.offline.offline"); } + if(s.isFull() && s.isOnline()) { + or = msgs.get("status.offline.full"); + } ply.sendMessage(Main.formatMessage( msgs.get("status.offline.base") .replaceAll("\\{STATUS\\}", or) @@ -246,7 +249,17 @@ public class Manager { if(!s.isOnline()) continue; if(s.getQueue().size() <= 0) continue; - s.getQueue().get(0).connect(s.getInfo()); + ProxiedPlayer nextplayer = s.getQueue().get(0); + + while(nextplayer.getServer().getInfo().getName().equals(s.getName())) { + s.getQueue().remove(nextplayer); + if(s.getQueue().size() <= 0) break; + nextplayer = s.getQueue().get(0); + } + if(s.getQueue().size() <= 0) continue; + if(s.isFull() && !nextplayer.hasPermission("ajqueue.joinfull")) continue; + + nextplayer.connect(s.getInfo()); } } @@ -262,6 +275,11 @@ public class Manager { return; } + if(p.getServer().getInfo().getName().equals(s)) { + p.sendMessage(msgs.getBC("errors.already-connected")); + return; + } + Server beforeQueue = findPlayerInQueue(p); if(beforeQueue != null) { if(beforeQueue.equals(server)) { diff --git a/src/main/java/us/ajg0702/queue/spigot/Commands.java b/src/main/java/us/ajg0702/queue/spigot/Commands.java new file mode 100644 index 0000000..469c97d --- /dev/null +++ b/src/main/java/us/ajg0702/queue/spigot/Commands.java @@ -0,0 +1,24 @@ +package us.ajg0702.queue.spigot; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commands implements CommandExecutor { + + Main pl; + public Commands(Main pl) { + this.pl = pl; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) return true; + Player player = (Player) sender; + if(args.length < 1) return false; + this.pl.sendMessage(player, "queue", args[0]); + return true; + } + +} diff --git a/src/main/java/us/ajg0702/queue/spigot/Main.java b/src/main/java/us/ajg0702/queue/spigot/Main.java index 279d96d..bd7ab87 100644 --- a/src/main/java/us/ajg0702/queue/spigot/Main.java +++ b/src/main/java/us/ajg0702/queue/spigot/Main.java @@ -6,6 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.messaging.PluginMessageListener; import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import us.ajg0702.queue.spigot.utils.VersionSupport; @@ -13,6 +14,10 @@ import us.ajg0702.queue.spigot.utils.VersionSupport; public class Main extends JavaPlugin implements PluginMessageListener { public void onEnable() { getServer().getMessenger().registerIncomingPluginChannel(this, "ajqueue:tospigot", this); + getServer().getMessenger().registerOutgoingPluginChannel(this, "ajqueue:tobungee"); + + this.getCommand("move").setExecutor(new Commands(this)); + getLogger().info("Spigot side enabled! v"+getDescription().getVersion()); } @@ -33,6 +38,17 @@ public class Main extends JavaPlugin implements PluginMessageListener { final String text = data.split(";time=")[0]; //getLogger().info("recieved actionbar for "+player.getName()+": "+text); VersionSupport.sendActionBar(p, text); + return; } } + + + public void sendMessage(Player player, String subchannel, String data) { + //getLogger().info("Sending message. "+subchannel+" "+data); + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF(subchannel); + out.writeUTF(data); + + player.sendPluginMessage(this, "ajqueue:tobungee", out.toByteArray()); + } } diff --git a/src/main/java/us/ajg0702/queue/utils/BungeeMessages.java b/src/main/java/us/ajg0702/queue/utils/BungeeMessages.java index 442d750..19f9eb5 100644 --- a/src/main/java/us/ajg0702/queue/utils/BungeeMessages.java +++ b/src/main/java/us/ajg0702/queue/utils/BungeeMessages.java @@ -56,6 +56,7 @@ public class BungeeMessages { d.put("status.offline.base", "&cThe server you are queued for is {STATUS}. &7You are in position &f{POS}&7 of &f{LEN}&7."); d.put("status.offline.offline", "offline"); d.put("status.offline.restarting", "restarting"); + d.put("status.offline.full", "full"); d.put("status.online.base", "&7You are in position &f{POS}&7 of &f{LEN}&7. Estimated time: {TIME}"); d.put("status.left-last-queue", "&aYou left the last queue you were in."); d.put("status.now-in-queue", "&aYou are now queued! &7You are in position &f{POS}&7 of &f{LEN}&7.\n&7Type &f/leavequeue&7 to leave the queue!"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2cc6ebb..5b70f3a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,9 +14,9 @@ offline-time: 120 message-time: 10 # If a player is in a server, you can have the plugin make them automatically join a queue for another server -# Example with the default values: Player joins survivalfallback server, they will auto-join the queue for survival +# Example with the default values: Player joins survivalqueue server, they will auto-join the queue for survival queue-servers: -- 'survivalfallback:survival' +- 'survivalqueue:survival' # Should the plugin send an actionbar to the player? # Requires this plugin to be installed on the server the player is on for it to work diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 20348ff..f031858 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,8 @@ main: us.ajg0702.queue.spigot.Main version: ${project.version} author: ajgeiss0702 -name: ajQueue \ No newline at end of file +name: ajQueue +commands: + move: + aliases: [server, queue] + description: Queue for a server \ No newline at end of file