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()
{
this.updatePower();
this.recalculatePower();
return this.power;
}
@ -385,14 +385,13 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
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;
public void updatePower(boolean online)
public void recalculatePower(boolean online)
{
// Is the player really on this server?
// 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
@Deprecated
public void setLastLoginTime(long lastLoginTime)
{
losePowerFromBeingOffline();
//this.lastLoginTime = lastLoginTime;
this.lastPowerUpdateTime = lastLoginTime;
if (ConfServer.noPVPDamageToOthersForXSecondsAfterLogin > 0)
{
this.loginPvpDisabled = true;
}
}
public boolean hasLoginPvpDisabled()
{
if (!loginPvpDisabled)

View File

@ -81,7 +81,7 @@ public class FactionsEntityListener implements Listener
// Call player onDeath if the event is not cancelled
if ( ! powerLossEvent.isCancelled())
{
fplayer.onDeath();
fplayer.setPower(fplayer.getPower() + ConfServer.powerPerDeath);
}
// 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.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.util.NumberConversions;
import com.massivecraft.factions.BoardColl;
@ -34,7 +33,9 @@ import com.massivecraft.factions.Rel;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.mcore.event.MCorePlayerLeaveEvent;
import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.MUtil;
public class FactionsPlayerListener implements Listener
@ -42,91 +43,89 @@ public class FactionsPlayerListener implements Listener
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event)
{
// Make sure that all online players do have a fplayer.
final FPlayer me = FPlayerColl.get().get(event.getPlayer());
// If a player is joining the server ...
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
me.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();
}
fplayer.setLastLoginTime(System.currentTimeMillis());
}
@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.
me.getPower();
// Recalculate the power before the player leaves.
// 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
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)
{
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;
// If the player is moving from one chunk to another ...
if (MUtil.isSameChunk(event)) return;
// ... update the stored current chunk ...
Player player = event.getPlayer();
FPlayer me = FPlayerColl.get().get(player);
FPlayer fplayer = FPlayerColl.get().get(player);
// Did we change coord?
PS chunkFrom = me.getCurrentChunk();
PS chunkFrom = fplayer.getCurrentChunk();
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);
// Did we change "host"(faction)?
boolean changedFaction = (BoardColl.get().getFactionAt(chunkFrom) != access.getHostFaction());
// 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)
{
me.sendFactionHereMessage();
fplayer.sendFactionHereMessage();
}
// show access info message if needed
if ( ! handledBySpout && ! SpoutFeatures.updateAccessInfo(me) && ! access.isDefault())
if ( ! handledBySpout && ! SpoutFeatures.updateAccessInfo(fplayer) && ! access.isDefault())
{
if (access.subjectHasAccess(me))
me.msg("<g>You have access to this area.");
else if (access.subjectAccessIsRestricted(me))
me.msg("<b>This area has restricted access.");
if (access.subjectHasAccess(fplayer))
fplayer.msg("<g>You have access to this area.");
else if (access.subjectAccessIsRestricted(fplayer))
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);
}
}