Added Spigot-side API
This commit is contained in:
@@ -5,20 +5,16 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import us.ajg0702.queue.api.EventHandler;
|
||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.api.server.AdaptedServer;
|
||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||
import us.ajg0702.queue.commands.commands.manage.PauseQueueServer;
|
||||
import us.ajg0702.queue.commands.commands.queue.QueueCommand;
|
||||
import us.ajg0702.queue.common.communication.CommunicationManager;
|
||||
import us.ajg0702.queue.common.players.QueuePlayerImpl;
|
||||
import us.ajg0702.queue.common.utils.Debug;
|
||||
import us.ajg0702.utils.common.TimeUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -26,121 +22,20 @@ import java.util.concurrent.TimeUnit;
|
||||
public class EventHandlerImpl implements EventHandler {
|
||||
|
||||
final QueueMain main;
|
||||
CommunicationManager communicationManager;
|
||||
public EventHandlerImpl(QueueMain main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(AdaptedPlayer recievingPlayer, byte[] data) {
|
||||
IBaseCommand moveCommand = main.getPlatformMethods().getCommands().get(0);
|
||||
IBaseCommand leaveCommand = main.getPlatformMethods().getCommands().get(1);
|
||||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
|
||||
public void handleMessage(AdaptedPlayer receivingPlayer, byte[] data) {
|
||||
if(communicationManager == null) {
|
||||
communicationManager = new CommunicationManager(main);
|
||||
}
|
||||
try {
|
||||
String subchannel = in.readUTF();
|
||||
|
||||
if(subchannel.equals("ack")) {
|
||||
main.getPlatformMethods().sendPluginMessage(recievingPlayer, "ack", "yes, im here");
|
||||
}
|
||||
|
||||
if(subchannel.equals("queue")) {
|
||||
String rawData = in.readUTF();
|
||||
String[] args = new String[1];
|
||||
args[0] = rawData;
|
||||
moveCommand.execute(new PlayerSender(recievingPlayer), args);
|
||||
}
|
||||
if(subchannel.equals("massqueue")) {
|
||||
String inData = in.readUTF();
|
||||
String[] parts = inData.split(",");
|
||||
for(String part : parts) {
|
||||
String[] pparts = part.split(":");
|
||||
if(pparts.length < 2) continue;
|
||||
String pname = pparts[0];
|
||||
String pserver = pparts[1];
|
||||
AdaptedPlayer p = main.getPlatformMethods().getPlayer(pname);
|
||||
String[] args = new String[1];
|
||||
args[0] = pserver;
|
||||
moveCommand.execute(new PlayerSender(p), args);
|
||||
}
|
||||
}
|
||||
if(subchannel.equals("queuename")) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(recievingPlayer);
|
||||
String name = main.getMessages().getString("placeholders.position.none");
|
||||
if(server != null) {
|
||||
name = server.getAlias();
|
||||
}
|
||||
main.getPlatformMethods().sendPluginMessage(recievingPlayer, "queuename", name);
|
||||
}
|
||||
if(subchannel.equals("position")) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(recievingPlayer);
|
||||
String pos = main.getMessages().getString("placeholders.position.none");
|
||||
if(server != null) {
|
||||
pos = server.getQueue().indexOf(server.findPlayer(recievingPlayer))+1+"";
|
||||
}
|
||||
main.getPlatformMethods().sendPluginMessage(recievingPlayer, "position", pos);
|
||||
}
|
||||
if(subchannel.equals("positionof")) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(recievingPlayer);
|
||||
String pos = main.getMessages().getString("placeholders.position.none");
|
||||
if(server != null) {
|
||||
pos = server.getQueue().size()+"";
|
||||
}
|
||||
main.getPlatformMethods().sendPluginMessage(recievingPlayer, "positionof", pos);
|
||||
}
|
||||
if(subchannel.equals("estimated_time")) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(recievingPlayer);
|
||||
|
||||
int time;
|
||||
String timeString;
|
||||
if(server != null) {
|
||||
QueuePlayer queuePlayer = server.findPlayer(recievingPlayer);
|
||||
time = (int) Math.round(queuePlayer.getPosition() * main.getTimeBetweenPlayers());
|
||||
timeString = TimeUtils.timeString(
|
||||
time,
|
||||
main.getMessages().getString("format.time.mins"),
|
||||
main.getMessages().getString("format.time.secs")
|
||||
);
|
||||
} else {
|
||||
timeString = main.getMessages().getString("placeholders.estimated_time.none");
|
||||
}
|
||||
main.getPlatformMethods().sendPluginMessage(
|
||||
recievingPlayer,
|
||||
"estimated_time",
|
||||
timeString
|
||||
);
|
||||
}
|
||||
if(subchannel.equals("inqueue")) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(recievingPlayer);
|
||||
main.getPlatformMethods().sendPluginMessage(recievingPlayer, "inqueue", (server != null)+"");
|
||||
}
|
||||
if(subchannel.equals("queuedfor")) {
|
||||
String srv = in.readUTF();
|
||||
QueueServer server = main.getQueueManager().findServer(srv);
|
||||
if(server == null) return;
|
||||
main.getPlatformMethods().sendPluginMessage(recievingPlayer, "queuedfor", srv, server.getQueue().size()+"");
|
||||
}
|
||||
if(subchannel.equals("status")) {
|
||||
String srv = in.readUTF();
|
||||
QueueServer server = main.getQueueManager().findServer(srv);
|
||||
if(server == null) return;
|
||||
if(!recievingPlayer.isConnected() || recievingPlayer.getServerName() == null) return;
|
||||
main.getPlatformMethods().sendPluginMessage(
|
||||
recievingPlayer,
|
||||
"status",
|
||||
srv,
|
||||
main.getMessages().getRawString("placeholders.status."+server.getStatus(recievingPlayer))
|
||||
);
|
||||
}
|
||||
if(subchannel.equals("leavequeue")) {
|
||||
String[] args = new String[1];
|
||||
try {
|
||||
args[0] = in.readUTF();
|
||||
} catch(Exception ignored) {}
|
||||
leaveCommand.execute(new PlayerSender(recievingPlayer), args);
|
||||
}
|
||||
|
||||
} catch (IOException e1) {
|
||||
main.getLogger().warning("An error occured while reading data from spigot side:");
|
||||
e1.printStackTrace();
|
||||
communicationManager.handle(receivingPlayer, data);
|
||||
} catch (IOException e) {
|
||||
main.getLogger().warning("An error occurred while reading data from spigot side:", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package us.ajg0702.queue.common.communication;
|
||||
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.common.communication.handlers.*;
|
||||
import us.ajg0702.queue.common.utils.Debug;
|
||||
import us.ajg0702.queue.common.utils.MapBuilder;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommunicationManager {
|
||||
private final QueueMain main;
|
||||
Map<String, MessageHandler> handlers;
|
||||
|
||||
public CommunicationManager(QueueMain main) {
|
||||
this.main = main;
|
||||
|
||||
handlers = new MapBuilder<>(
|
||||
"ack", new AckHandler(main),
|
||||
|
||||
"queue", new QueueHandler(main),
|
||||
"massqueue", new MassQueueHandler(main),
|
||||
"leavequeue", new LeaveQueueHandler(main),
|
||||
|
||||
"queuename", new QueueNameHandler(main),
|
||||
"position", new PositionHandler(main),
|
||||
"positionof", new PositionOfHandler(main),
|
||||
"estimated_time", new EstimatedTimeHandler(main),
|
||||
"inqueue", new InQueueHandler(main),
|
||||
"queuedfor", new QueuedForHandler(main),
|
||||
"status", new StatusHandler(main),
|
||||
"playerstatus", new PlayerStatusHandler(main)
|
||||
);
|
||||
}
|
||||
|
||||
public void handle(AdaptedPlayer receivingPlayer, byte[] data) throws IOException {
|
||||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
|
||||
String subChannel = in.readUTF();
|
||||
|
||||
MessageHandler handler = handlers.get(subChannel);
|
||||
|
||||
if(handler == null) {
|
||||
main.getLogger().warn("Invalid sub-channel " + subChannel);
|
||||
return;
|
||||
}
|
||||
|
||||
ComResponse response = handler.handleMessage(receivingPlayer, in.readUTF());
|
||||
|
||||
if(response == null) return;
|
||||
|
||||
Debug.info("Responding with " + response);
|
||||
|
||||
main.getPlatformMethods().sendPluginMessage(
|
||||
receivingPlayer,
|
||||
s(response.getFrom()),
|
||||
s(response.getIdentifier()),
|
||||
s(response.getResponse()),
|
||||
s(response.getNoneMessage())
|
||||
);
|
||||
}
|
||||
|
||||
private String s(String s) {
|
||||
return s + "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package us.ajg0702.queue.common.communication;
|
||||
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
|
||||
public abstract class MessageHandler {
|
||||
protected final QueueMain main;
|
||||
|
||||
public MessageHandler(QueueMain main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public abstract ComResponse handleMessage(AdaptedPlayer player, String data);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class AckHandler extends MessageHandler {
|
||||
public AckHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
return ComResponse
|
||||
.from("ack")
|
||||
.with("yes, im here");
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.players.QueuePlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
import us.ajg0702.utils.common.TimeUtils;
|
||||
|
||||
public class EstimatedTimeHandler extends MessageHandler {
|
||||
|
||||
public EstimatedTimeHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(player);
|
||||
|
||||
int time;
|
||||
String timeString;
|
||||
if(server != null) {
|
||||
QueuePlayer queuePlayer = server.findPlayer(player);
|
||||
time = (int) Math.round(queuePlayer.getPosition() * main.getTimeBetweenPlayers());
|
||||
timeString = TimeUtils.timeString(
|
||||
time,
|
||||
main.getMessages().getString("format.time.mins"),
|
||||
main.getMessages().getString("format.time.secs")
|
||||
);
|
||||
} else {
|
||||
timeString = main.getMessages().getString("placeholders.estimated_time.none");
|
||||
}
|
||||
return ComResponse
|
||||
.from("estimated_time")
|
||||
.id(player.getUniqueId())
|
||||
.with(timeString);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class InQueueHandler extends MessageHandler {
|
||||
|
||||
public InQueueHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(player);
|
||||
return ComResponse
|
||||
.from("inqueue")
|
||||
.id(player.getUniqueId())
|
||||
.with(server != null);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class LeaveQueueHandler extends MessageHandler {
|
||||
IBaseCommand leaveCommand;
|
||||
|
||||
public LeaveQueueHandler(QueueMain main) {
|
||||
super(main);
|
||||
leaveCommand = main.getPlatformMethods().getCommands().get(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
String[] args = new String[1];
|
||||
args[0] = data;
|
||||
leaveCommand.execute(new PlayerSender(player), args);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class MassQueueHandler extends MessageHandler {
|
||||
private final IBaseCommand moveCommand;
|
||||
|
||||
public MassQueueHandler(QueueMain main) {
|
||||
super(main);
|
||||
moveCommand = main.getPlatformMethods().getCommands().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
String[] parts = data.split(",");
|
||||
for(String part : parts) {
|
||||
String[] playerParts = part.split(":");
|
||||
if(playerParts.length < 2) continue;
|
||||
String playerName = playerParts[0];
|
||||
String targetServer = playerParts[1];
|
||||
AdaptedPlayer p = main.getPlatformMethods().getPlayer(playerName);
|
||||
String[] args = new String[1];
|
||||
args[0] = targetServer;
|
||||
moveCommand.execute(new PlayerSender(p), args);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class PlayerStatusHandler extends MessageHandler {
|
||||
public PlayerStatusHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().findServer(data);
|
||||
if(server == null) {
|
||||
return ComResponse
|
||||
.from("playerstatus")
|
||||
.id(data)
|
||||
.with("invalid_server");
|
||||
}
|
||||
if(!player.isConnected() || player.getServerName() == null) return null;
|
||||
return ComResponse
|
||||
.from("playerstatus")
|
||||
.id(player.getUniqueId() + data)
|
||||
.with(
|
||||
main.getMessages().getRawString(
|
||||
"placeholders.status." + server.getStatus(player)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class PositionHandler extends MessageHandler {
|
||||
|
||||
public PositionHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(player);
|
||||
Integer pos = null;
|
||||
String noneMessage = null;
|
||||
if(server != null) {
|
||||
pos = server.getQueue().indexOf(server.findPlayer(player)) + 1;
|
||||
} else {
|
||||
noneMessage = main.getMessages().getString("placeholders.position.none");
|
||||
}
|
||||
return ComResponse
|
||||
.from("position")
|
||||
.id(player.getUniqueId())
|
||||
.with(pos)
|
||||
.noneMessage(noneMessage);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class PositionOfHandler extends MessageHandler {
|
||||
|
||||
|
||||
public PositionOfHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(player);
|
||||
Integer size = null;
|
||||
String noneMessage = null;
|
||||
if(server != null) {
|
||||
size = server.getQueue().size();
|
||||
} else {
|
||||
noneMessage = main.getMessages().getString("placeholders.position.none");
|
||||
}
|
||||
return ComResponse
|
||||
.from("positionof")
|
||||
.id(player.getUniqueId())
|
||||
.with(size)
|
||||
.noneMessage(noneMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.commands.IBaseCommand;
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.commands.commands.PlayerSender;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class QueueHandler extends MessageHandler {
|
||||
private final IBaseCommand moveCommand;
|
||||
|
||||
public QueueHandler(QueueMain main) {
|
||||
super(main);
|
||||
moveCommand = main.getPlatformMethods().getCommands().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
String[] args = new String[1];
|
||||
args[0] = data;
|
||||
moveCommand.execute(new PlayerSender(player), args);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class QueueNameHandler extends MessageHandler {
|
||||
|
||||
public QueueNameHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().getSingleServer(player);
|
||||
String name = null;
|
||||
String none = null;
|
||||
if(server != null) {
|
||||
name = server.getAlias();
|
||||
} else {
|
||||
none = main.getMessages().getString("placeholders.position.none");
|
||||
}
|
||||
return ComResponse
|
||||
.from("queuename")
|
||||
.id(player.getUniqueId())
|
||||
.with(name)
|
||||
.noneMessage(none);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class QueuedForHandler extends MessageHandler {
|
||||
|
||||
public QueuedForHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().findServer(data);
|
||||
if(server == null) {
|
||||
return ComResponse
|
||||
.from("queuedfor")
|
||||
.id(data)
|
||||
.with("invalid_server");
|
||||
}
|
||||
return ComResponse
|
||||
.from("queuedfor")
|
||||
.id(data)
|
||||
.with(server.getQueue().size());
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package us.ajg0702.queue.common.communication.handlers;
|
||||
|
||||
import us.ajg0702.queue.api.players.AdaptedPlayer;
|
||||
import us.ajg0702.queue.api.queues.QueueServer;
|
||||
import us.ajg0702.queue.common.QueueMain;
|
||||
import us.ajg0702.queue.api.communication.ComResponse;
|
||||
import us.ajg0702.queue.common.communication.MessageHandler;
|
||||
|
||||
public class StatusHandler extends MessageHandler {
|
||||
public StatusHandler(QueueMain main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComResponse handleMessage(AdaptedPlayer player, String data) {
|
||||
QueueServer server = main.getQueueManager().findServer(data);
|
||||
if(server == null) {
|
||||
return ComResponse
|
||||
.from("status")
|
||||
.id(data)
|
||||
.with("invalid_server");
|
||||
}
|
||||
return ComResponse
|
||||
.from("status")
|
||||
.id(data)
|
||||
.with(
|
||||
main.getMessages().getRawString(
|
||||
"placeholders.status." + server.getStatus()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package us.ajg0702.queue.common.utils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class MapBuilder<K, V> extends LinkedHashMap<K, V> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public MapBuilder(Object... entries) {
|
||||
for (int i = 0; i < entries.length; i += 2) {
|
||||
put((K) entries[i], (V) entries[i+1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user