Working on the player listener slightly and trying to figure out how to handle the lastLoginMillis through Mixin instead of locally stored.

This commit is contained in:
Olof Larsson 2013-04-18 11:02:58 +02:00
parent 2ddef9f499
commit 2b11bc1042
3 changed files with 54 additions and 57 deletions

View File

@ -353,7 +353,7 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
public double getPower() public double getPower()
{ {
this.updatePower(); this.recalculatePower();
return this.power; return this.power;
} }
@ -385,14 +385,13 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
return ConfServer.powerMin + this.powerBoost; return ConfServer.powerMin + this.powerBoost;
} }
public void updatePower() public void recalculatePower()
{ {
this.updatePower(this.isOnline()); this.recalculatePower(this.isOnline());
} }
private static final transient long POWER_RECALCULATION_MINIMUM_WAIT_MILLIS = 10 * TimeUnit.MILLIS_PER_SECOND; private static final transient long POWER_RECALCULATION_MINIMUM_WAIT_MILLIS = 10 * TimeUnit.MILLIS_PER_SECOND;
public void recalculatePower(boolean online)
public void updatePower(boolean online)
{ {
// Is the player really on this server? // Is the player really on this server?
// We use the sender ps mixin to fetch the current player location. // We use the sender ps mixin to fetch the current player location.
@ -498,17 +497,16 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
// -------------------------------------------- // // -------------------------------------------- //
// TODO // TODO
@Deprecated
public void setLastLoginTime(long lastLoginTime) public void setLastLoginTime(long lastLoginTime)
{ {
losePowerFromBeingOffline();
//this.lastLoginTime = lastLoginTime;
this.lastPowerUpdateTime = lastLoginTime; this.lastPowerUpdateTime = lastLoginTime;
if (ConfServer.noPVPDamageToOthersForXSecondsAfterLogin > 0) if (ConfServer.noPVPDamageToOthersForXSecondsAfterLogin > 0)
{ {
this.loginPvpDisabled = true; this.loginPvpDisabled = true;
} }
} }
public boolean hasLoginPvpDisabled() public boolean hasLoginPvpDisabled()
{ {
if (!loginPvpDisabled) if (!loginPvpDisabled)

View File

@ -81,7 +81,7 @@ public class FactionsEntityListener implements Listener
// Call player onDeath if the event is not cancelled // Call player onDeath if the event is not cancelled
if ( ! powerLossEvent.isCancelled()) if ( ! powerLossEvent.isCancelled())
{ {
fplayer.onDeath(); fplayer.setPower(fplayer.getPower() + ConfServer.powerPerDeath);
} }
// Send the message from the powerLossEvent // Send the message from the powerLossEvent

View File

@ -20,7 +20,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.util.NumberConversions; import org.bukkit.util.NumberConversions;
import com.massivecraft.factions.BoardColl; import com.massivecraft.factions.BoardColl;
@ -34,7 +33,9 @@ import com.massivecraft.factions.Rel;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.mcore.event.MCorePlayerLeaveEvent;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.MUtil;
public class FactionsPlayerListener implements Listener public class FactionsPlayerListener implements Listener
@ -42,91 +43,89 @@ public class FactionsPlayerListener implements Listener
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) public void onPlayerJoin(PlayerJoinEvent event)
{ {
// Make sure that all online players do have a fplayer. // If a player is joining the server ...
final FPlayer me = FPlayerColl.get().get(event.getPlayer()); Player player = event.getPlayer();
FPlayer fplayer = FPlayerColl.get().get(player);
// ... recalculate their power as if they were offline since last recalculation ...
fplayer.recalculatePower(false);
// ... update the current chunk ...
fplayer.setCurrentChunk(PS.valueOf(event.getPlayer()));
// ... notify the player about where they are ...
if ( ! SpoutFeatures.updateTerritoryDisplay(fplayer))
{
fplayer.sendFactionHereMessage();
}
// Update the lastLoginTime for this fplayer // Update the lastLoginTime for this fplayer
me.setLastLoginTime(System.currentTimeMillis()); fplayer.setLastLoginTime(System.currentTimeMillis());
// Store player's current Chunk and notify them where they are
me.setCurrentChunk(PS.valueOf(event.getPlayer()));
if ( ! SpoutFeatures.updateTerritoryDisplay(me))
{
me.sendFactionHereMessage();
}
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuit(PlayerQuitEvent event) public void onPlayerLeave(MCorePlayerLeaveEvent event)
{ {
FPlayer me = FPlayerColl.get().get(event.getPlayer()); Player player = event.getPlayer();
FPlayer fplayer = FPlayerColl.get().get(player);
// Make sure player's power is up to date when they log off. // Recalculate the power before the player leaves.
me.getPower(); // This is required since we recalculate as if the player were offline when they log back in.
// TODO: When I setup universes I must do this for all universe instance of the player that logs off!
fplayer.recalculatePower(true);
// and update their last login time to point to when the logged off, for auto-remove routine // and update their last login time to point to when the logged off, for auto-remove routine
me.setLastLoginTime(System.currentTimeMillis()); fplayer.setLastLoginTime(System.currentTimeMillis());
SpoutFeatures.playerDisconnect(me); SpoutFeatures.playerDisconnect(fplayer);
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) public void onPlayerMove(PlayerMoveEvent event)
{ {
if (event.isCancelled()) return; // If the player is moving from one chunk to another ...
if (MUtil.isSameChunk(event)) 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;
// ... update the stored current chunk ...
Player player = event.getPlayer(); Player player = event.getPlayer();
FPlayer me = FPlayerColl.get().get(player); FPlayer fplayer = FPlayerColl.get().get(player);
// Did we change coord? PS chunkFrom = fplayer.getCurrentChunk();
PS chunkFrom = me.getCurrentChunk();
PS chunkTo = PS.valueOf(event.getTo()).getChunk(true); PS chunkTo = PS.valueOf(event.getTo()).getChunk(true);
if (chunkFrom.equals(chunkTo)) return; fplayer.setCurrentChunk(chunkTo);
// Yes we did change coord (: // ... TODO: assorted and uncleaned code below ...
me.setCurrentChunk(chunkTo);
TerritoryAccess access = BoardColl.get().getTerritoryAccessAt(chunkTo); TerritoryAccess access = BoardColl.get().getTerritoryAccessAt(chunkTo);
// Did we change "host"(faction)? // Did we change "host"(faction)?
boolean changedFaction = (BoardColl.get().getFactionAt(chunkFrom) != access.getHostFaction()); boolean changedFaction = (BoardColl.get().getFactionAt(chunkFrom) != access.getHostFaction());
// let Spout handle most of this if it's available // let Spout handle most of this if it's available
boolean handledBySpout = changedFaction && SpoutFeatures.updateTerritoryDisplay(me); boolean handledBySpout = changedFaction && SpoutFeatures.updateTerritoryDisplay(fplayer);
if (me.isMapAutoUpdating()) if (fplayer.isMapAutoUpdating())
{ {
me.sendMessage(BoardColl.get().getMap(me.getFaction(), chunkTo, player.getLocation().getYaw())); fplayer.sendMessage(BoardColl.get().getMap(fplayer.getFaction(), chunkTo, player.getLocation().getYaw()));
} }
else if (changedFaction && ! handledBySpout) else if (changedFaction && ! handledBySpout)
{ {
me.sendFactionHereMessage(); fplayer.sendFactionHereMessage();
} }
// show access info message if needed // show access info message if needed
if ( ! handledBySpout && ! SpoutFeatures.updateAccessInfo(me) && ! access.isDefault()) if ( ! handledBySpout && ! SpoutFeatures.updateAccessInfo(fplayer) && ! access.isDefault())
{ {
if (access.subjectHasAccess(me)) if (access.subjectHasAccess(fplayer))
me.msg("<g>You have access to this area."); fplayer.msg("<g>You have access to this area.");
else if (access.subjectAccessIsRestricted(me)) else if (access.subjectAccessIsRestricted(fplayer))
me.msg("<b>This area has restricted access."); fplayer.msg("<b>This area has restricted access.");
} }
if (me.getAutoClaimFor() != null) if (fplayer.getAutoClaimFor() != null)
{ {
me.attemptClaim(me.getAutoClaimFor(), event.getTo(), true); fplayer.attemptClaim(fplayer.getAutoClaimFor(), event.getTo(), true);
} }
} }