send queue plugin messages in batches
This commit is contained in:
@@ -5,6 +5,8 @@ import java.io.DataInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
@@ -239,6 +241,19 @@ public class Main extends Plugin implements Listener {
|
|||||||
//man.addToQueue(player, data);
|
//man.addToQueue(player, data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if(subchannel.equals("massqueue")) {
|
||||||
|
String data = in.readUTF();
|
||||||
|
String[] parts = data.split(",");
|
||||||
|
for(String part : parts) {
|
||||||
|
String[] pparts = part.split(":");
|
||||||
|
String pname = pparts[0];
|
||||||
|
String pserver = pparts[1];
|
||||||
|
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(pname);
|
||||||
|
String[] args = new String[1];
|
||||||
|
args[0] = pserver;
|
||||||
|
moveCommand.execute(p, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(subchannel.equals("queuename")) {
|
if(subchannel.equals("queuename")) {
|
||||||
BungeeUtils.sendCustomData(player, "queuename", aliases.getAlias(man.getQueuedName(player)));
|
BungeeUtils.sendCustomData(player, "queuename", aliases.getAlias(man.getQueuedName(player)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
@@ -20,6 +21,9 @@ public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|||||||
|
|
||||||
boolean papi = false;
|
boolean papi = false;
|
||||||
Placeholders placeholders;
|
Placeholders placeholders;
|
||||||
|
|
||||||
|
Config config;
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, "ajqueue:tospigot", this);
|
getServer().getMessenger().registerIncomingPluginChannel(this, "ajqueue:tospigot", this);
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "ajqueue:tobungee");
|
getServer().getMessenger().registerOutgoingPluginChannel(this, "ajqueue:tobungee");
|
||||||
@@ -36,13 +40,27 @@ public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|||||||
getLogger().info("Registered PlaceholderAPI placeholders");
|
getLogger().info("Registered PlaceholderAPI placeholders");
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().info("Spigot side enabled! v"+getDescription().getVersion());
|
Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
|
||||||
/*Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
|
|
||||||
public void run() {
|
public void run() {
|
||||||
sendMessage
|
if(Bukkit.getOnlinePlayers().size() <= 0) return;
|
||||||
|
String msg = "";
|
||||||
|
for(Player p : queuebatch.keySet()) {
|
||||||
|
msg += p.getName()+":"+queuebatch.get(p)+",";
|
||||||
}
|
}
|
||||||
}, 0, 2*20);*/
|
if(msg.length() > 1) {
|
||||||
|
msg = msg.substring(0, msg.length()-1);
|
||||||
}
|
}
|
||||||
|
queuebatch.clear();
|
||||||
|
sendMessage("massqueue", msg);
|
||||||
|
}
|
||||||
|
}, 2*20, 20);
|
||||||
|
|
||||||
|
config = new Config(this);
|
||||||
|
|
||||||
|
getLogger().info("Spigot side enabled! v"+getDescription().getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<Player, String> queuebatch = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
@@ -140,6 +158,15 @@ public class Main extends JavaPlugin implements PluginMessageListener,Listener {
|
|||||||
player.sendPluginMessage(this, "ajqueue:tobungee", out.toByteArray());
|
player.sendPluginMessage(this, "ajqueue:tobungee", out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String subchannel, String data) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF(subchannel);
|
||||||
|
out.writeUTF(data);
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers().iterator().next()
|
||||||
|
.sendPluginMessage(this, "ajqueue:tobungee", out.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onLeave(PlayerQuitEvent e) {
|
public void onLeave(PlayerQuitEvent e) {
|
||||||
if(!papi) return;
|
if(!papi) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user