Performance overhaul sponsored by rockxz3, using his large server's data for reference to help with testing and tuning. Timing numbers below are based on this data set.
* PlayerMoveEvent performance boost (from 0.047ms to 0.015ms in testing, ~313% as fast): now more thrifty in determining whether player has actually moved between chunks before doing anything else; important since this event triggers extremely quickly * PlayerInteractEvent performance boost (from 0.068ms to 0.034ms in testing, ~200% as fast): now ignores left-clicks for interaction checks, since in CraftBukkit 1.4 left-clicks no longer open doors or activate buttons/levers/etc.; not as important as above, but still triggers quite often as people are digging or interacting with blocks * "/f list" command performance boost (from 234ms to 30ms in testing, ~780% as fast): code was getting information for all factions, narrowed it down to only getting info for displayed page range * "/f show" command performance boost (from 132ms to 28ms in testing, ~470% as fast): tweaked the ally & enemy listing code used
This commit is contained in:
parent
ee6c7c07d2
commit
30d9bbf138
@ -572,7 +572,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Faction factionHere = Board.getFactionAt(new FLocation(this));
|
Faction factionHere = Board.getFactionAt(this.getLastStoodAt());
|
||||||
String msg = P.p.txt.parse("<i>")+" ~ "+factionHere.getTag(this);
|
String msg = P.p.txt.parse("<i>")+" ~ "+factionHere.getTag(this);
|
||||||
if (factionHere.getDescription().length() > 0)
|
if (factionHere.getDescription().length() > 0)
|
||||||
{
|
{
|
||||||
|
@ -71,6 +71,8 @@ public class CmdList extends FCommand
|
|||||||
});
|
});
|
||||||
|
|
||||||
ArrayList<String> lines = new ArrayList<String>();
|
ArrayList<String> lines = new ArrayList<String>();
|
||||||
|
|
||||||
|
/* // this code was really slow on large servers, getting full info for every faction and then only showing 9 of them; rewritten below
|
||||||
lines.add(p.txt.parse("<i>Factionless<i> %d online", Factions.i.getNone().getFPlayersWhereOnline(true).size()));
|
lines.add(p.txt.parse("<i>Factionless<i> %d online", Factions.i.getNone().getFPlayersWhereOnline(true).size()));
|
||||||
for (Faction faction : factionList)
|
for (Faction faction : factionList)
|
||||||
{
|
{
|
||||||
@ -85,6 +87,37 @@ public class CmdList extends FCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(p.txt.getPage(lines, this.argAsInt(0, 1), "Faction List"));
|
sendMessage(p.txt.getPage(lines, this.argAsInt(0, 1), "Faction List"));
|
||||||
}
|
*/
|
||||||
|
|
||||||
|
factionList.add(0, Factions.i.getNone());
|
||||||
|
|
||||||
|
final int pageheight = 9;
|
||||||
|
int pagenumber = this.argAsInt(0, 1);
|
||||||
|
int pagecount = (factionList.size() / pageheight) + 1;
|
||||||
|
int start = (pagenumber - 1) * pageheight;
|
||||||
|
int end = start + pageheight;
|
||||||
|
if (end > factionList.size())
|
||||||
|
end = factionList.size();
|
||||||
|
|
||||||
|
lines.add(p.txt.titleize("Faction List "+pagenumber+"/"+pagecount));
|
||||||
|
|
||||||
|
for (Faction faction : factionList.subList(start, end))
|
||||||
|
{
|
||||||
|
if (faction.isNone())
|
||||||
|
{
|
||||||
|
lines.add(p.txt.parse("<i>Factionless<i> %d online", Factions.i.getNone().getFPlayersWhereOnline(true).size()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lines.add(p.txt.parse("%s<i> %d/%d online, %d/%d/%d",
|
||||||
|
faction.getTag(fme),
|
||||||
|
faction.getFPlayersWhereOnline(true).size(),
|
||||||
|
faction.getFPlayers().size(),
|
||||||
|
faction.getLandRounded(),
|
||||||
|
faction.getPowerRounded(),
|
||||||
|
faction.getPowerMaxRounded())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage(lines);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import com.massivecraft.factions.Faction;
|
|||||||
import com.massivecraft.factions.Factions;
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
import com.massivecraft.factions.struct.Role;
|
import com.massivecraft.factions.struct.Role;
|
||||||
|
import com.massivecraft.factions.struct.Relation;
|
||||||
|
|
||||||
public class CmdShow extends FCommand
|
public class CmdShow extends FCommand
|
||||||
{
|
{
|
||||||
@ -96,28 +97,21 @@ public class CmdShow extends FCommand
|
|||||||
String enemyList = p.txt.parse("<a>Enemies: ");
|
String enemyList = p.txt.parse("<a>Enemies: ");
|
||||||
for (Faction otherFaction : Factions.i.get())
|
for (Faction otherFaction : Factions.i.get())
|
||||||
{
|
{
|
||||||
if (otherFaction == faction)
|
if (otherFaction == faction) continue;
|
||||||
{
|
|
||||||
continue;
|
Relation rel = otherFaction.getRelationTo(faction);
|
||||||
}
|
if ( ! rel.isAlly() && ! rel.isEnemy()) continue; // if not ally or enemy, drop out now so we're not wasting time on it; good performance boost
|
||||||
|
|
||||||
listpart = otherFaction.getTag(fme)+p.txt.parse("<i>")+", ";
|
listpart = otherFaction.getTag(fme)+p.txt.parse("<i>")+", ";
|
||||||
if (otherFaction.getRelationTo(faction).isAlly())
|
if (rel.isAlly())
|
||||||
{
|
|
||||||
allyList += listpart;
|
allyList += listpart;
|
||||||
}
|
else if (rel.isEnemy())
|
||||||
else if (otherFaction.getRelationTo(faction).isEnemy())
|
|
||||||
{
|
|
||||||
enemyList += listpart;
|
enemyList += listpart;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (allyList.endsWith(", "))
|
if (allyList.endsWith(", "))
|
||||||
{
|
|
||||||
allyList = allyList.substring(0, allyList.length()-2);
|
allyList = allyList.substring(0, allyList.length()-2);
|
||||||
}
|
|
||||||
if (enemyList.endsWith(", "))
|
if (enemyList.endsWith(", "))
|
||||||
{
|
|
||||||
enemyList = enemyList.substring(0, enemyList.length()-2);
|
enemyList = enemyList.substring(0, enemyList.length()-2);
|
||||||
}
|
|
||||||
|
|
||||||
sendMessage(allyList);
|
sendMessage(allyList);
|
||||||
sendMessage(enemyList);
|
sendMessage(enemyList);
|
||||||
|
@ -65,7 +65,7 @@ public class SpoutMainListener implements Listener
|
|||||||
if (!sPlayer.isSpoutCraftEnabled() || (Conf.spoutTerritoryDisplaySize <= 0 && ! Conf.spoutTerritoryNoticeShow))
|
if (!sPlayer.isSpoutCraftEnabled() || (Conf.spoutTerritoryDisplaySize <= 0 && ! Conf.spoutTerritoryNoticeShow))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FLocation here = new FLocation(player);
|
FLocation here = player.getLastStoodAt();
|
||||||
Faction factionHere = Board.getFactionAt(here);
|
Faction factionHere = Board.getFactionAt(here);
|
||||||
|
|
||||||
doOwnerList(player, sPlayer, here, factionHere);
|
doOwnerList(player, sPlayer, here, factionHere);
|
||||||
@ -83,7 +83,7 @@ public class SpoutMainListener implements Listener
|
|||||||
|
|
||||||
private void doLabels(FPlayer player, SpoutPlayer sPlayer, boolean notify)
|
private void doLabels(FPlayer player, SpoutPlayer sPlayer, boolean notify)
|
||||||
{
|
{
|
||||||
FLocation here = new FLocation(player);
|
FLocation here = player.getLastStoodAt();
|
||||||
Faction factionHere = Board.getFactionAt(here);
|
Faction factionHere = Board.getFactionAt(here);
|
||||||
String tag = factionHere.getColorTo(player).toString() + factionHere.getTag();
|
String tag = factionHere.getColorTo(player).toString() + factionHere.getTag();
|
||||||
|
|
||||||
|
@ -54,11 +54,10 @@ public class FactionsPlayerListener implements Listener
|
|||||||
// Update the lastLoginTime for this fplayer
|
// Update the lastLoginTime for this fplayer
|
||||||
me.setLastLoginTime(System.currentTimeMillis());
|
me.setLastLoginTime(System.currentTimeMillis());
|
||||||
|
|
||||||
/* This is now done in a separate task which runs every few minutes
|
// Store player's current FLocation and notify them where they are
|
||||||
// Run the member auto kick routine. Twice to get to the admins...
|
me.setLastStoodAt(new FLocation(event.getPlayer().getLocation()));
|
||||||
FPlayers.i.autoLeaveOnInactivityRoutine();
|
if ( ! SpoutFeatures.updateTerritoryDisplay(me))
|
||||||
FPlayers.i.autoLeaveOnInactivityRoutine();
|
me.sendFactionHereMessage();
|
||||||
*/
|
|
||||||
|
|
||||||
SpoutFeatures.updateAppearancesShortly(event.getPlayer());
|
SpoutFeatures.updateAppearancesShortly(event.getPlayer());
|
||||||
}
|
}
|
||||||
@ -81,15 +80,28 @@ public class FactionsPlayerListener implements Listener
|
|||||||
SpoutFeatures.playerDisconnect(me);
|
SpoutFeatures.playerDisconnect(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerMove(PlayerMoveEvent event)
|
public void onPlayerMove(PlayerMoveEvent event)
|
||||||
{
|
{
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
|
||||||
|
// quick check to make sure player is moving between chunks; good performance boost
|
||||||
|
if
|
||||||
|
(
|
||||||
|
event.getFrom().getBlockX() >> 4 == event.getTo().getBlockX() >> 4
|
||||||
|
&&
|
||||||
|
event.getFrom().getBlockZ() >> 4 == event.getTo().getBlockZ() >> 4
|
||||||
|
&&
|
||||||
|
event.getFrom().getWorld() == event.getTo().getWorld()
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
FPlayer me = FPlayers.i.get(player);
|
FPlayer me = FPlayers.i.get(player);
|
||||||
|
|
||||||
// Did we change coord?
|
// Did we change coord?
|
||||||
FLocation from = me.getLastStoodAt();
|
FLocation from = me.getLastStoodAt();
|
||||||
FLocation to = new FLocation(player.getLocation());
|
FLocation to = new FLocation(event.getTo());
|
||||||
|
|
||||||
if (from.equals(to))
|
if (from.equals(to))
|
||||||
{
|
{
|
||||||
@ -172,7 +184,7 @@ public class FactionsPlayerListener implements Listener
|
|||||||
|
|
||||||
if (me.getAutoClaimFor() != null)
|
if (me.getAutoClaimFor() != null)
|
||||||
{
|
{
|
||||||
me.attemptClaim(me.getAutoClaimFor(), player.getLocation(), true);
|
me.attemptClaim(me.getAutoClaimFor(), event.getTo(), true);
|
||||||
}
|
}
|
||||||
else if (me.isAutoSafeClaimEnabled())
|
else if (me.isAutoSafeClaimEnabled())
|
||||||
{
|
{
|
||||||
@ -182,11 +194,9 @@ public class FactionsPlayerListener implements Listener
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FLocation playerFlocation = new FLocation(me);
|
if (!Board.getFactionAt(to).isSafeZone())
|
||||||
|
|
||||||
if (!Board.getFactionAt(playerFlocation).isSafeZone())
|
|
||||||
{
|
{
|
||||||
Board.setFactionAt(Factions.i.getSafeZone(), playerFlocation);
|
Board.setFactionAt(Factions.i.getSafeZone(), to);
|
||||||
me.msg("<i>This land is now a safe zone.");
|
me.msg("<i>This land is now a safe zone.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,11 +209,9 @@ public class FactionsPlayerListener implements Listener
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FLocation playerFlocation = new FLocation(me);
|
if (!Board.getFactionAt(to).isWarZone())
|
||||||
|
|
||||||
if (!Board.getFactionAt(playerFlocation).isWarZone())
|
|
||||||
{
|
{
|
||||||
Board.setFactionAt(Factions.i.getWarZone(), playerFlocation);
|
Board.setFactionAt(Factions.i.getWarZone(), to);
|
||||||
me.msg("<i>This land is now a war zone.");
|
me.msg("<i>This land is now a war zone.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,14 +222,12 @@ public class FactionsPlayerListener implements Listener
|
|||||||
public void onPlayerInteract(PlayerInteractEvent event)
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
if (event.isCancelled()) return;
|
if (event.isCancelled()) return;
|
||||||
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; // only interested in right-clicks as of MC 1.4+; good performance boost
|
||||||
|
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (block == null)
|
if (block == null) return; // clicked in air, apparently
|
||||||
{
|
|
||||||
return; // clicked in air, apparently
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! canPlayerUseBlock(player, block, false))
|
if ( ! canPlayerUseBlock(player, block, false))
|
||||||
{
|
{
|
||||||
@ -246,11 +252,6 @@ public class FactionsPlayerListener implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
||||||
{
|
|
||||||
return; // only interested on right-clicks for below
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false))
|
if ( ! playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user