Fix clients getting kicked from too many allies/enemies.

This commit is contained in:
Tibo 2014-11-17 20:16:58 +01:00
parent b970755cb1
commit 356842ab41

View File

@ -11,6 +11,7 @@ import com.massivecraft.factions.struct.Role;
import mkremins.fanciful.FancyMessage; import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
public class CmdShow extends FCommand { public class CmdShow extends FCommand {
@ -87,32 +88,46 @@ public class CmdShow extends FCommand {
} }
} }
FancyMessage allies = new FancyMessage("Allies: ").color(ChatColor.GOLD); ArrayList<FancyMessage> allies = new ArrayList<FancyMessage>();
FancyMessage enemies = new FancyMessage("Enemies: ").color(ChatColor.GOLD); ArrayList<FancyMessage> enemies = new ArrayList<FancyMessage>();
boolean firstAlly = true; FancyMessage currentAllies = new FancyMessage("Allies: ").color(ChatColor.GOLD);
boolean firstEnemy = true; FancyMessage currentEnemies = new FancyMessage("Enemies: ").color(ChatColor.GOLD);
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
if (otherFaction == faction) {
continue;
}
Relation rel = otherFaction.getRelationTo(faction); boolean firstAlly = true;
String s = otherFaction.getTag(fme); boolean firstEnemy = true;
if (rel.isAlly()) { for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
if (firstAlly) if (otherFaction == faction) {
allies.then(s).tooltip(getToolTips(otherFaction)); continue;
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;
}
}
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 online = new FancyMessage("Members online: ").color(ChatColor.GOLD);
FancyMessage offline = new FancyMessage("Members offline: ").color(ChatColor.GOLD); FancyMessage offline = new FancyMessage("Members offline: ").color(ChatColor.GOLD);