From 356842ab41fceaee5a73a64d21c21993e9f74dfa Mon Sep 17 00:00:00 2001 From: Tibo Date: Mon, 17 Nov 2014 20:16:58 +0100 Subject: [PATCH] Fix clients getting kicked from too many allies/enemies. --- .../massivecraft/factions/cmd/CmdShow.java | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java index 185cdee2..5ebac12f 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java @@ -11,6 +11,7 @@ import com.massivecraft.factions.struct.Role; import mkremins.fanciful.FancyMessage; import org.bukkit.ChatColor; +import java.util.ArrayList; import java.util.Collection; public class CmdShow extends FCommand { @@ -87,32 +88,46 @@ public class CmdShow extends FCommand { } } - FancyMessage allies = new FancyMessage("Allies: ").color(ChatColor.GOLD); - FancyMessage enemies = new FancyMessage("Enemies: ").color(ChatColor.GOLD); - boolean firstAlly = true; - boolean firstEnemy = true; - for (Faction otherFaction : Factions.getInstance().getAllFactions()) { - if (otherFaction == faction) { - continue; - } + ArrayList allies = new ArrayList(); + ArrayList enemies = new ArrayList(); + FancyMessage currentAllies = new FancyMessage("Allies: ").color(ChatColor.GOLD); + FancyMessage currentEnemies = new FancyMessage("Enemies: ").color(ChatColor.GOLD); - Relation rel = otherFaction.getRelationTo(faction); - String s = otherFaction.getTag(fme); - if (rel.isAlly()) { - if (firstAlly) - allies.then(s).tooltip(getToolTips(otherFaction)); - else - alies.then(", " + s).tooltip(getToolTips(otherFaction)); - firstAlly = false; - } else if (rel.isEnemy()) { - if (firstEnemy) - enemies.then(s).tooltip(getToolTips(otherFaction)); - else - enemies.then(", " + s).tooltip(getToolTips(otherFaction)); - firstEnemy = false; - } - } + boolean firstAlly = true; + boolean firstEnemy = true; + for (Faction otherFaction : Factions.getInstance().getAllFactions()) { + if (otherFaction == faction) { + continue; + } + Relation rel = otherFaction.getRelationTo(faction); + String s = otherFaction.getTag(fme); + if (rel.isAlly()) { + if (firstAlly) + currentAllies.then(s).tooltip(getToolTips(otherFaction)); + else + currentAllies.then(", " + s).tooltip(getToolTips(otherFaction)); + firstAlly = false; + + if (currentAllies.toJSONString().length() >= 32700) { // Client gets kicked at 32767, some leniency + allies.add(currentAllies); + currentAllies = new FancyMessage(); + } + } else if (rel.isEnemy()) { + if (firstEnemy) + currentEnemies.then(s).tooltip(getToolTips(otherFaction)); + else + currentEnemies.then(", " + s).tooltip(getToolTips(otherFaction)); + firstEnemy = false; + + if (currentEnemies.toJSONString().length() >= 32700) { // Client gets kicked at 32767, some leniency + enemies.add(currentEnemies); + currentEnemies = new FancyMessage(); + } + } + } + allies.add(currentAllies); + enemies.add(currentEnemies); FancyMessage online = new FancyMessage("Members online: ").color(ChatColor.GOLD); FancyMessage offline = new FancyMessage("Members offline: ").color(ChatColor.GOLD);