Add max-retries option to config

This commit is contained in:
ajgeiss0702
2020-11-14 09:30:52 -07:00
parent 7917f0d4e0
commit 41625f535a
3 changed files with 21 additions and 1 deletions
+3
View File
@@ -110,6 +110,8 @@ public class Main extends Plugin implements Listener {
d.put("commands.pause.paused.true", "&epaused"); d.put("commands.pause.paused.true", "&epaused");
d.put("commands.pause.paused.false", "&aun-paused"); d.put("commands.pause.paused.false", "&aun-paused");
d.put("max-tries-reached", "&cUnable to connect to {SERVER}. Max retries reached.");
msgs = BungeeMessages.getInstance(this, d); msgs = BungeeMessages.getInstance(this, d);
aliases = new AliasManager(this); aliases = new AliasManager(this);
@@ -173,6 +175,7 @@ public class Main extends Plugin implements Listener {
int pos = queue.indexOf(p); int pos = queue.indexOf(p);
if((pos == 0 && ser.getInfos().contains(p.getServer().getInfo())) || config.getBoolean("remove-player-on-server-switch")) { if((pos == 0 && ser.getInfos().contains(p.getServer().getInfo())) || config.getBoolean("remove-player-on-server-switch")) {
queue.remove(p); queue.remove(p);
Manager.getInstance().sendingAttempts.remove(p);
} }
} }
@@ -460,6 +460,7 @@ public class Manager {
} }
HashMap<ProxiedPlayer, Long> sendingNowAntiSpam = new HashMap<>(); HashMap<ProxiedPlayer, Long> sendingNowAntiSpam = new HashMap<>();
HashMap<ProxiedPlayer, Integer> sendingAttempts = new HashMap<>();
/** /**
* Attempts to send the first player in this queue * Attempts to send the first player in this queue
@@ -537,6 +538,17 @@ public class Manager {
if(s.getQueue().size() <= 0) continue; if(s.getQueue().size() <= 0) continue;
if(s.isFull() && !nextplayer.hasPermission("ajqueue.joinfull")) continue; if(s.isFull() && !nextplayer.hasPermission("ajqueue.joinfull")) continue;
int tries = sendingAttempts.get(nextplayer) == null ? 0 : sendingAttempts.get(nextplayer);
int maxTries = pl.config.getInt("max-tries");
if(tries >= maxTries && maxTries > 0) {
s.getQueue().remove(nextplayer);
sendingAttempts.remove(nextplayer);
nextplayer.sendMessage(msgs.getBC("max-tries-reached", "SERVER:"+pl.aliases.getAlias(s.getName())));
continue;
}
tries++;
pl.getLogger().info(tries+" tries");
sendingAttempts.put(nextplayer, tries);
if(!sendingNowAntiSpam.containsKey(nextplayer)) { if(!sendingNowAntiSpam.containsKey(nextplayer)) {
sendingNowAntiSpam.put(nextplayer, (long) 0); sendingNowAntiSpam.put(nextplayer, (long) 0);
+6 -1
View File
@@ -1,5 +1,5 @@
# Dont touch this number please # Dont touch this number please
config-version: 16 config-version: 17
# The time the server will wait between sending people in the queue # The time the server will wait between sending people in the queue
# Default: 5 # Default: 5
@@ -137,3 +137,8 @@ send-instantly:
# Default: false # Default: false
send-fail-debug: false send-fail-debug: false
# After how many (unsuccessfull) attempts of sending the player should we remove them from the queue?
# Set to -1 to disable
# Default: -1
max-tries: -1