should finish full minimessage support
This commit is contained in:
@@ -22,13 +22,19 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation("junit:junit:4.12")
|
||||
testImplementation("net.kyori:adventure-text-serializer-bungeecord:4.0.0-SNAPSHOT")
|
||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
||||
|
||||
compileOnly("com.github.MyzelYam:PremiumVanishAPI:2.0.3")
|
||||
compileOnly("net.md-5:bungeecord-api:1.14-SNAPSHOT")
|
||||
compileOnly(group = "org.spigotmc", name = "spigot", version = "1.16.5-R0.1-SNAPSHOT")
|
||||
compileOnly("me.clip:placeholderapi:2.10.4")
|
||||
compileOnly("net.kyori:adventure-text-serializer-bungeecord:4.0.0-SNAPSHOT")
|
||||
|
||||
implementation("us.ajg0702:ajUtils:1.0.4")
|
||||
implementation("org.bstats:bstats-bungeecord:2.2.1")
|
||||
implementation("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ public class Main extends Plugin implements Listener {
|
||||
List<String> svs = config.getStringList("queue-servers");
|
||||
for(String s : svs) {
|
||||
if(!s.contains(":")) continue;
|
||||
String[] parts = s.split("\\:");
|
||||
String[] parts = s.split(":");
|
||||
String from = parts[0];
|
||||
String to = parts[1];
|
||||
if(from.equalsIgnoreCase(servername)) {
|
||||
@@ -219,15 +219,15 @@ public class Main extends Plugin implements Listener {
|
||||
|
||||
if(!queuedServers.contains(man.getServer(e.getKickedFrom().getName())) && config.getBoolean("auto-add-to-queue-on-kick")) {
|
||||
|
||||
String plainReason = "";
|
||||
StringBuilder plainReason = new StringBuilder();
|
||||
for(BaseComponent b : e.getKickReasonComponent()) {
|
||||
plainReason += b.toPlainText();
|
||||
plainReason.append(b.toPlainText());
|
||||
}
|
||||
|
||||
List<String> reasons = config.getStringList("auto-add-kick-reasons");
|
||||
boolean shouldqueue = false;
|
||||
for(String reason : reasons) {
|
||||
if(plainReason.toLowerCase().contains(reason.toLowerCase())) {
|
||||
if(plainReason.toString().toLowerCase().contains(reason.toLowerCase())) {
|
||||
shouldqueue = true;
|
||||
break;
|
||||
}
|
||||
@@ -251,31 +251,22 @@ public class Main extends Plugin implements Listener {
|
||||
if(server.getQueue().indexOf(p) != 0) continue;
|
||||
List<String> kickreasons = config.getStringList("kick-reasons");
|
||||
//getLogger().info(e.getKickReasonComponent());
|
||||
String plainReason = "";
|
||||
StringBuilder plainReason = new StringBuilder();
|
||||
for(BaseComponent b : e.getKickReasonComponent()) {
|
||||
plainReason += b.toPlainText();
|
||||
plainReason.append(b.toPlainText());
|
||||
}
|
||||
for(String reason : kickreasons) {
|
||||
if(plainReason.toLowerCase().contains(reason.toLowerCase())) {
|
||||
if(plainReason.toString().toLowerCase().contains(reason.toLowerCase())) {
|
||||
server.getQueue().remove(p);
|
||||
}
|
||||
}
|
||||
if(config.getBoolean("send-fail-debug")) {
|
||||
String r = "";
|
||||
StringBuilder r = new StringBuilder();
|
||||
for(BaseComponent b : e.getKickReasonComponent()) {
|
||||
r += b.toPlainText();
|
||||
r.append(b.toPlainText());
|
||||
}
|
||||
getLogger().warning("Failed to send "+p.getName()+" to "+e.getKickedFrom().getName()+" because "+r);
|
||||
}
|
||||
|
||||
if(plainReason.toLowerCase().contains("whitelist") && plainReason.contains("&ajq;")) {
|
||||
String rawlist = plainReason.split("&ajq;")[1];
|
||||
List<String> list = new ArrayList<>();
|
||||
for(String s : rawlist.split(",")) {
|
||||
list.add(s);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +314,7 @@ public class Main extends Plugin implements Listener {
|
||||
}
|
||||
if(subchannel.equals("position")) {
|
||||
QueueServer server = man.getSingleServer(player);
|
||||
String pos = msgs.get("placeholders.position.none");
|
||||
String pos = msgs.getString("placeholders.position.none");
|
||||
if(server != null) {
|
||||
pos = server.getQueue().indexOf(player)+1+"";
|
||||
}
|
||||
@@ -331,7 +322,7 @@ public class Main extends Plugin implements Listener {
|
||||
}
|
||||
if(subchannel.equals("positionof")) {
|
||||
QueueServer server = man.getSingleServer(player);
|
||||
String pos = msgs.get("placeholders.position.none");
|
||||
String pos = msgs.getString("placeholders.position.none");
|
||||
if(server != null) {
|
||||
pos = server.getQueue().size()+"";
|
||||
}
|
||||
|
||||
@@ -40,17 +40,9 @@ public class Manager {
|
||||
msgs = BungeeMessages.getInstance();
|
||||
reloadIntervals();
|
||||
if(!pl.config.getBoolean("wait-to-load-servers")) {
|
||||
pl.getProxy().getScheduler().schedule(pl, new Runnable() {
|
||||
public void run() {
|
||||
reloadServers();
|
||||
}
|
||||
}, 0, TimeUnit.MILLISECONDS);
|
||||
pl.getProxy().getScheduler().schedule(pl, this::reloadServers, 0, TimeUnit.MILLISECONDS);
|
||||
} else {
|
||||
pl.getProxy().getScheduler().schedule(pl, new Runnable() {
|
||||
public void run() {
|
||||
reloadServers();
|
||||
}
|
||||
}, pl.config.getInt("wait-to-load-servers-delay"), TimeUnit.MILLISECONDS);
|
||||
pl.getProxy().getScheduler().schedule(pl, this::reloadServers, pl.config.getInt("wait-to-load-servers-delay"), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,76 +80,52 @@ public class Manager {
|
||||
if(sendId != -1) {
|
||||
try {
|
||||
pl.getProxy().getScheduler().cancel(sendId);
|
||||
} catch(IllegalArgumentException e) {}
|
||||
} catch(IllegalArgumentException ignored) {}
|
||||
sendId = -1;
|
||||
}
|
||||
if(updateId != -1) {
|
||||
try {
|
||||
pl.getProxy().getScheduler().cancel(updateId);
|
||||
} catch(IllegalArgumentException e) {}
|
||||
} catch(IllegalArgumentException ignored) {}
|
||||
updateId = -1;
|
||||
}
|
||||
if(messagerId != -1) {
|
||||
try {
|
||||
pl.getProxy().getScheduler().cancel(messagerId);
|
||||
} catch(IllegalArgumentException e) {}
|
||||
} catch(IllegalArgumentException ignored) {}
|
||||
messagerId = -1;
|
||||
}
|
||||
if(actionbarId != -1) {
|
||||
try {
|
||||
pl.getProxy().getScheduler().cancel(actionbarId);
|
||||
} catch(IllegalArgumentException e) {}
|
||||
} catch(IllegalArgumentException ignored) {}
|
||||
actionbarId = -1;
|
||||
}
|
||||
if(srvRefId != -1) {
|
||||
try {
|
||||
pl.getProxy().getScheduler().cancel(srvRefId);
|
||||
} catch(IllegalArgumentException e) {}
|
||||
} catch(IllegalArgumentException ignored) {}
|
||||
srvRefId = -1;
|
||||
}
|
||||
if(queueEventId != -1) {
|
||||
try {
|
||||
pl.getProxy().getScheduler().cancel(queueEventId);
|
||||
} catch(IllegalArgumentException e) {}
|
||||
} catch(IllegalArgumentException ignored) {}
|
||||
queueEventId = -1;
|
||||
}
|
||||
|
||||
queueEventId = pl.getProxy().getScheduler().schedule(pl, new Runnable() {
|
||||
public void run() {
|
||||
sendQueueEvents();
|
||||
}
|
||||
}, 2, 2, TimeUnit.SECONDS).getId();
|
||||
queueEventId = pl.getProxy().getScheduler().schedule(pl, this::sendQueueEvents, 2, 2, TimeUnit.SECONDS).getId();
|
||||
|
||||
sendId = pl.getProxy().getScheduler().schedule(pl, new Runnable() {
|
||||
public void run() {
|
||||
sendPlayers();
|
||||
}
|
||||
}, 2, Math.round(pl.timeBetweenPlayers*1000), TimeUnit.MILLISECONDS).getId();
|
||||
sendId = pl.getProxy().getScheduler().schedule(pl, this::sendPlayers, 2, Math.round(pl.timeBetweenPlayers*1000), TimeUnit.MILLISECONDS).getId();
|
||||
|
||||
updateId = pl.getProxy().getScheduler().schedule(pl, new Runnable() {
|
||||
public void run() {
|
||||
updateServers();
|
||||
}
|
||||
}, 0, Math.max(Math.round(pl.timeBetweenPlayers), 2), TimeUnit.SECONDS).getId();
|
||||
updateId = pl.getProxy().getScheduler().schedule(pl, this::updateServers, 0, Math.max(Math.round(pl.timeBetweenPlayers), 2), TimeUnit.SECONDS).getId();
|
||||
//pl.getLogger().info("Time: "+pl.timeBetweenPlayers);
|
||||
|
||||
messagerId = pl.getProxy().getScheduler().schedule(pl, new Runnable() {
|
||||
public void run() {
|
||||
sendMessages();
|
||||
}
|
||||
}, 0, pl.getConfig().getInt("message-time"), TimeUnit.SECONDS).getId();
|
||||
actionbarId = pl.getProxy().getScheduler().schedule(pl, new Runnable() {
|
||||
public void run() {
|
||||
sendActionBars();
|
||||
}
|
||||
}, 0, 2, TimeUnit.SECONDS).getId();
|
||||
messagerId = pl.getProxy().getScheduler().schedule(pl, this::sendMessages, 0, pl.getConfig().getInt("message-time"), TimeUnit.SECONDS).getId();
|
||||
actionbarId = pl.getProxy().getScheduler().schedule(pl, this::sendActionBars, 0, 2, TimeUnit.SECONDS).getId();
|
||||
|
||||
if(pl.config.getInt("reload-servers-interval") > 0) {
|
||||
srvRefId = pl.getProxy().getScheduler().schedule(pl, new Runnable() {
|
||||
public void run() {
|
||||
updateServers();
|
||||
}
|
||||
}, pl.config.getInt("reload-servers-interval"), pl.config.getInt("reload-servers-interval"), TimeUnit.SECONDS).getId();
|
||||
srvRefId = pl.getProxy().getScheduler().schedule(pl, this::updateServers, pl.config.getInt("reload-servers-interval"), pl.config.getInt("reload-servers-interval"), TimeUnit.SECONDS).getId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,12 +260,12 @@ public class Manager {
|
||||
String timeStr;
|
||||
if(min <= 0) {
|
||||
timeStr = msgs.getString("format.time.secs")
|
||||
.replaceAll("\\{m\\}", "0")
|
||||
.replaceAll("\\{s\\}", sec+"");
|
||||
.replaceAll("\\{m}", "0")
|
||||
.replaceAll("\\{s}", sec+"");
|
||||
} else {
|
||||
timeStr = msgs.getString("format.time.mins")
|
||||
.replaceAll("\\{m\\}", min+"")
|
||||
.replaceAll("\\{s\\}", sec+"");
|
||||
.replaceAll("\\{m}", min+"")
|
||||
.replaceAll("\\{s}", sec+"");
|
||||
}
|
||||
p.sendMessage(ChatMessageType.ACTION_BAR, msgs.getBC("spigot.actionbar.online",
|
||||
"POS:"+pos,
|
||||
@@ -311,12 +279,10 @@ public class Manager {
|
||||
|
||||
|
||||
public synchronized void sendQueueEvents() {
|
||||
for(Iterator<QueueServer> it = servers.iterator(); it.hasNext();) {
|
||||
QueueServer s = it.next();
|
||||
for(Iterator<ProxiedPlayer> pit = s.getQueue().iterator(); pit.hasNext();) {
|
||||
ProxiedPlayer player = pit.next();
|
||||
if(player == null) continue;
|
||||
if(!player.isConnected()) continue;
|
||||
for (QueueServer s : servers) {
|
||||
for (ProxiedPlayer player : s.getQueue()) {
|
||||
if (player == null) continue;
|
||||
if (!player.isConnected()) continue;
|
||||
BungeeUtils.sendCustomData(player, "inqueueevent", "true");
|
||||
}
|
||||
}
|
||||
@@ -351,7 +317,6 @@ public class Manager {
|
||||
int pos = plys.indexOf(ply)+1;
|
||||
if(pos == 0) return;
|
||||
int len = plys.size();
|
||||
int ot = s.getOfflineTime();
|
||||
if(!s.isJoinable(ply)) {
|
||||
|
||||
String status = s.getStatusString(ply);
|
||||
@@ -367,17 +332,17 @@ public class Manager {
|
||||
} else {
|
||||
if(msgs.getString("spigot.actionbar.offline").isEmpty()) return;
|
||||
int time = (int) Math.round(pos*pl.timeBetweenPlayers);
|
||||
int min = (int) Math.floor((time) / (60));
|
||||
int sec = (int) Math.floor((time % (60)));
|
||||
int min = (int) Math.floor((time) / (60.0));
|
||||
int sec = (int) Math.floor((time % (60.0)));
|
||||
String timeStr;
|
||||
if(min <= 0) {
|
||||
timeStr = msgs.getString("format.time.secs")
|
||||
.replaceAll("\\{m\\}", "0")
|
||||
.replaceAll("\\{s\\}", sec+"");
|
||||
.replaceAll("\\{m}", "0")
|
||||
.replaceAll("\\{s}", sec+"");
|
||||
} else {
|
||||
timeStr = msgs.getString("format.time.mins")
|
||||
.replaceAll("\\{m\\}", min+"")
|
||||
.replaceAll("\\{s\\}", sec+"");
|
||||
.replaceAll("\\{m}", min+"")
|
||||
.replaceAll("\\{s}", sec+"");
|
||||
}
|
||||
ply.sendMessage(msgs.getBC("status.online.base",
|
||||
"TIME:"+timeStr,
|
||||
@@ -407,9 +372,8 @@ public class Manager {
|
||||
* Updates info about servers.
|
||||
*/
|
||||
public synchronized void updateServers() {
|
||||
Iterator<QueueServer> it = servers.iterator();
|
||||
while(it.hasNext()) {
|
||||
it.next().update();
|
||||
for (QueueServer server : servers) {
|
||||
server.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,7 +403,6 @@ public class Manager {
|
||||
if(selectednum > online && findServer(si.getName()).isJoinable(p)) {
|
||||
selected = si;
|
||||
selectednum = online;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -505,25 +468,6 @@ public class Manager {
|
||||
if(!s.canAccess(nextplayer)) continue;
|
||||
|
||||
|
||||
/*if(nextplayer == null) {
|
||||
pl.getLogger().info("nextplayer is null");
|
||||
}
|
||||
if(nextplayer.getServer() == null) {
|
||||
pl.getLogger().info("getServer is null");
|
||||
}
|
||||
if(nextplayer.getServer().getInfo() == null) {
|
||||
pl.getLogger().info("getInfo is null");
|
||||
}
|
||||
if(nextplayer.getServer().getInfo().getName() == null) {
|
||||
pl.getLogger().info("getName is null");
|
||||
}
|
||||
if(s == null) {
|
||||
pl.getLogger().info("s is null");
|
||||
}
|
||||
if(s.getName() == null) {
|
||||
pl.getLogger().info("s.getName() is null");
|
||||
}*/
|
||||
|
||||
if(s.getQueue().size() <= 0) continue;
|
||||
while(!nextplayer.isConnected()) {
|
||||
s.getQueue().remove(nextplayer);
|
||||
@@ -617,7 +561,7 @@ public class Manager {
|
||||
}
|
||||
|
||||
List<ProxiedPlayer> list = server.getQueue();
|
||||
if(list.indexOf(p) != -1) {
|
||||
if(list.contains(p)) {
|
||||
int pos = list.indexOf(p)+1;
|
||||
int len = list.size();
|
||||
p.sendMessage(msgs.getBC("errors.already-queued",
|
||||
@@ -655,11 +599,9 @@ public class Manager {
|
||||
int len = list.size();
|
||||
|
||||
|
||||
boolean sendInstant = pl.config.getStringList("send-instantly").indexOf(server.getName()) != -1 || server.isJoinable(p);
|
||||
boolean sendInstant = pl.config.getStringList("send-instantly").contains(server.getName()) || server.isJoinable(p);
|
||||
boolean sendInstantp = list.size() <= 1 && server.canAccess(p);
|
||||
boolean timeGood = pl.config.getBoolean("check-last-player-sent-time") ?
|
||||
System.currentTimeMillis() - server.getLastSentTime() > Math.floor(pl.getConfig().getDouble("wait-time")*1000)
|
||||
: true;
|
||||
boolean timeGood = !pl.config.getBoolean("check-last-player-sent-time") || System.currentTimeMillis() - server.getLastSentTime() > Math.floor(pl.getConfig().getDouble("wait-time") * 1000);
|
||||
|
||||
if((sendInstant && (sendInstantp && timeGood))) {
|
||||
sendPlayers(s);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package us.ajg0702.queue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@@ -19,7 +16,7 @@ public class QueueServer {
|
||||
List<ServerInfo> servers;
|
||||
|
||||
public QueueServer(String name, ServerInfo info) {
|
||||
init(name, Arrays.asList(info));
|
||||
init(name, Collections.singletonList(info));
|
||||
}
|
||||
public QueueServer(String name, List<ServerInfo> infos) {
|
||||
init(name, infos);
|
||||
@@ -57,9 +54,7 @@ public class QueueServer {
|
||||
if(Main.plugin.getConfig().getBoolean("pinger-debug")) {
|
||||
Main.plugin.getLogger().info("[pinger] ["+info.getName()+"] sending ping");
|
||||
}
|
||||
info.ping(new Callback<ServerPing>() {
|
||||
@Override
|
||||
public void done(ServerPing result, Throwable error) {
|
||||
info.ping((result, error) -> {
|
||||
if(Manager.getInstance() == null || Main.plugin.getConfig() == null) {
|
||||
ProxyServer.getInstance().getLogger()
|
||||
.warning("[ajQueue] Something used update() too early! The plugin hasnt fully loaded yet!");
|
||||
@@ -70,10 +65,10 @@ public class QueueServer {
|
||||
|
||||
if(config.getBoolean("pinger-debug")) {
|
||||
if(error != null) {
|
||||
ProxyServer.getInstance().getLogger().info("[ajQueue] [pinger] ["+name+"] Status: "+online+". Error: ");
|
||||
ProxyServer.getInstance().getLogger().info("[ajQueue] [pinger] ["+name+"] Status: offline. Error: ");
|
||||
error.printStackTrace();
|
||||
} else {
|
||||
ProxyServer.getInstance().getLogger().info("[ajQueue] [pinger] ["+name+"] Status: "+online+". motd: "
|
||||
ProxyServer.getInstance().getLogger().info("[ajQueue] [pinger] ["+name+"] Status: online. motd: "
|
||||
+result.getDescriptionComponent()+" players:"+result.getPlayers());
|
||||
}
|
||||
}
|
||||
@@ -81,7 +76,6 @@ public class QueueServer {
|
||||
|
||||
pings.put(info, online ? result : null);
|
||||
if(pings.size() == servers.size()) allDonePing();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -136,7 +130,7 @@ public class QueueServer {
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
offlineTime = 0;
|
||||
} else {
|
||||
int timesincelast = Math.round((System.currentTimeMillis() - lastUpdate)/1000);
|
||||
int timesincelast = (int) Math.round((System.currentTimeMillis() - lastUpdate*1.0)/1000);
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
if(!online) {
|
||||
offlineTime += timesincelast;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package us.ajg0702.queue.commands;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.PatternReplacementResult;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
@@ -13,6 +18,7 @@ import us.ajg0702.utils.bungee.BungeeMessages;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ManageCommand extends Command implements TabExecutor {
|
||||
|
||||
@@ -53,24 +59,42 @@ public class ManageCommand extends Command implements TabExecutor {
|
||||
int total = 0;
|
||||
for(QueueServer server : Manager.getInstance().getServers()) {
|
||||
|
||||
String msg = msgs.get("list.format").replaceAll("\\{SERVER\\}", server.getName());
|
||||
String playerlist = "";
|
||||
Component msg = msgs.getComponent("list.format",
|
||||
"SERVER:"+server.getName()
|
||||
);
|
||||
Component playerList = Component.empty();
|
||||
List<ProxiedPlayer> players = server.getQueue();
|
||||
if(msg.contains("{LIST}")) {
|
||||
boolean none = true;
|
||||
for(ProxiedPlayer p : players) {
|
||||
playerlist += msgs.get("list.playerlist").replaceAll("\\{NAME\\}", p.getDisplayName());
|
||||
playerList = playerList.append(msgs.getComponent("list.playerlist",
|
||||
"NAME:" + p.getDisplayName()
|
||||
));
|
||||
none = false;
|
||||
}
|
||||
if(playerlist.equalsIgnoreCase("")) {
|
||||
playerlist = msgs.get("list.none")+", ";
|
||||
if(none) {
|
||||
playerList = playerList.append(msgs.getComponent("list.none"));
|
||||
playerList = playerList.append(Component.text(", "));
|
||||
}
|
||||
playerlist = playerlist.substring(0, playerlist.length()-2);
|
||||
msg = msg.replaceAll("\\{LIST\\}", playerlist);
|
||||
Component finalPlayerList = playerList;
|
||||
msg = msg.replaceText(b -> b.match(Pattern.compile("\\{LIST}")).replacement(finalPlayerList));
|
||||
char[] commaCountString = PlainTextComponentSerializer.plainText().serialize(msg).toCharArray();
|
||||
int commas = 0;
|
||||
for(Character fChar : commaCountString) {
|
||||
if(fChar == ',') commas++;
|
||||
}
|
||||
|
||||
int finalCommas = commas;
|
||||
msg = msg.replaceText(b -> b.match(",(?!.*,)").replacement("").condition((r, c, re) -> {
|
||||
if(c == finalCommas) {
|
||||
return PatternReplacementResult.REPLACE;
|
||||
}
|
||||
return PatternReplacementResult.CONTINUE;
|
||||
}));
|
||||
total += players.size();
|
||||
msg = msg.replaceAll("\\{COUNT\\}", players.size()+"");
|
||||
sender.sendMessage(Main.formatMessage(msg));
|
||||
msg = msg.replaceText(b -> b.match(Pattern.compile("\\{COUNT}")).replacement(players.size()+""));
|
||||
sender.sendMessage(msgs.getBC(msg));
|
||||
}
|
||||
sender.sendMessage(Main.formatMessage(msgs.get("list.total").replaceAll("\\{TOTAL\\}", total+"")));
|
||||
sender.sendMessage(msgs.getBC("list.total", "TOTAL:"+total));
|
||||
return;
|
||||
}
|
||||
if(args[0].equalsIgnoreCase("p")) {
|
||||
@@ -121,7 +145,7 @@ public class ManageCommand extends Command implements TabExecutor {
|
||||
srv.setPaused(!srv.isPaused());
|
||||
sender.sendMessage(msgs.getBC("commands.pause.success",
|
||||
"SERVER:"+srv.getName(),
|
||||
"PAUSED:"+msgs.get("commands.pause.paused."+srv.isPaused())
|
||||
"PAUSED:"+msgs.getString("commands.pause.paused."+srv.isPaused())
|
||||
));
|
||||
return;
|
||||
}
|
||||
@@ -152,7 +176,7 @@ public class ManageCommand extends Command implements TabExecutor {
|
||||
srv.setPaused(args[2].equalsIgnoreCase("on") || args[2].equalsIgnoreCase("true"));
|
||||
sender.sendMessage(msgs.getBC("commands.pause.success",
|
||||
"SERVER:"+srv.getName(),
|
||||
"PAUSED:"+msgs.get("commands.pause.paused."+srv.isPaused())
|
||||
"PAUSED:"+msgs.getString("commands.pause.paused."+srv.isPaused())
|
||||
));
|
||||
return;
|
||||
}
|
||||
@@ -172,13 +196,12 @@ public class ManageCommand extends Command implements TabExecutor {
|
||||
|
||||
ProxiedPlayer ply = pl.getProxy().getPlayer(args[1]);
|
||||
Manager.getInstance().addToQueue(ply, args[2]);
|
||||
sender.sendMessage(Main.formatMessage(
|
||||
msgs.get("send")
|
||||
.replaceAll("\\{PLAYER\\}", ply.getDisplayName())
|
||||
.replaceAll("\\{SERVER\\}", args[2]))
|
||||
sender.sendMessage(msgs.getBC("send",
|
||||
"PLAYER:"+ply.getDisplayName(),
|
||||
"SERVER:"+args[2])
|
||||
);
|
||||
return;
|
||||
} else if(pl.getProxy().getServers().keySet().contains(args[1])) {
|
||||
} else if(pl.getProxy().getServers().containsKey(args[1])) {
|
||||
|
||||
ServerInfo from = pl.getProxy().getServerInfo(args[1]);
|
||||
if(from == null) {
|
||||
|
||||
@@ -33,13 +33,8 @@ public class MoveCommand extends Command implements TabExecutor {
|
||||
return;
|
||||
}
|
||||
Manager.getInstance().addToQueue(p, args[0]);
|
||||
} else if(args.length == 0) {
|
||||
} else {
|
||||
sender.sendMessage(msgs.getBC("commands.joinqueue.usage"));
|
||||
/*Server server = Manager.getInstance().findPlayerInQueue((ProxiedPlayer) sender);
|
||||
if(server != null) {
|
||||
server.getQueue().remove(p);
|
||||
p.sendMessage(msgs.getBC("commands.leave-queue"));
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.PatternReplacementResult;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegexTest {
|
||||
@Test
|
||||
public void regex() throws Exception {
|
||||
Component msg = Component.text("&b{SERVER} &7({COUNT}): {LIST}");
|
||||
Component playerList = Component.empty();
|
||||
List<String> players = Arrays.asList("bot01", "bot02", "bot03", "bot04", "bot05", "bot06");
|
||||
for(String p : players) {
|
||||
playerList = playerList.append(Component.text("&9"+p+"&7, "));
|
||||
}
|
||||
Component finalPlayerList = playerList;
|
||||
msg = msg.replaceText(b -> b.match(Pattern.compile("\\{LIST}")).replacement(finalPlayerList));
|
||||
char[] commaCountString = PlainTextComponentSerializer.plainText().serialize(msg).toCharArray();
|
||||
int commas = 0;
|
||||
for(Character fChar : commaCountString) {
|
||||
if(fChar == ',') commas++;
|
||||
}
|
||||
|
||||
int finalCommas = commas;
|
||||
msg = msg.replaceText(b -> b.match(",(?!.*,)").replacement("").condition((r, c, re) -> {
|
||||
if(c == finalCommas) {
|
||||
return PatternReplacementResult.REPLACE;
|
||||
}
|
||||
return PatternReplacementResult.CONTINUE;
|
||||
}));
|
||||
msg = msg.replaceText(b -> b.match(Pattern.compile("\\{COUNT}")).replacement(players.size()+""));
|
||||
|
||||
|
||||
String f = PlainTextComponentSerializer.plainText().serialize(msg);
|
||||
System.out.println(f);
|
||||
int c = 0;
|
||||
for(Character fChar : f.toCharArray()) {
|
||||
if(fChar == ',') c++;
|
||||
}
|
||||
if(c != 5) {
|
||||
throw new Exception("Wrong comma count! Had "+c+" when expected 5");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user