From aa989db8f7881e064063fa202d447171e174bbde Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 24 Apr 2013 15:14:15 +0200 Subject: [PATCH] Working on auto claim --- .../factions/cmd/CmdFactionsAutoClaim.java | 8 +-- .../factions/cmd/CmdFactionsMap.java | 6 +-- .../massivecraft/factions/cmd/FCommand.java | 3 ++ .../massivecraft/factions/entity/MPlayer.java | 14 +++-- .../massivecraft/factions/entity/UPlayer.java | 32 +++++------- .../listeners/TodoFactionsPlayerListener.java | 52 +++++++++++++------ 6 files changed, 70 insertions(+), 45 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java index 29eb5deb..441bdc92 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java @@ -24,16 +24,16 @@ public class CmdFactionsAutoClaim extends FCommand public void perform() { Faction forFaction = this.arg(0, ARFaction.get(myFaction), myFaction); - if (forFaction == null || forFaction == fme.getAutoClaimFor()) + if (forFaction == null || forFaction == fme.getAutoClaimFaction()) { - fme.setAutoClaimFor(null); + fme.setAutoClaimFaction(null); msg("Auto-claiming of land disabled."); return; } - if ( ! FPerm.TERRITORY.has(fme, forFaction, true)) return; + if (forFaction.isNormal() && !FPerm.TERRITORY.has(fme, forFaction, true)) return; - fme.setAutoClaimFor(forFaction); + fme.setAutoClaimFaction(forFaction); msg("Now auto-claiming land for %s.", forFaction.describeTo(fme)); fme.tryClaim(forFaction, PS.valueOf(me), true, true); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index 24fdb3cb..9b745b56 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -28,11 +28,11 @@ public class CmdFactionsMap extends FCommand return; } - if (this.arg(0, ARBoolean.get(), !fme.isMapAutoUpdating())) + if (this.arg(0, ARBoolean.get(), !mme.isMapAutoUpdating())) { // Turn on - fme.setMapAutoUpdating(true); + mme.setMapAutoUpdating(true); msg("Map auto update ENABLED."); // And show the map once @@ -41,7 +41,7 @@ public class CmdFactionsMap extends FCommand else { // Turn off - fme.setMapAutoUpdating(false); + mme.setMapAutoUpdating(false); msg("Map auto update DISABLED."); } } diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index 23ac83f7..cb9503c2 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.mcore.cmd.MCommand; @@ -8,12 +9,14 @@ import com.massivecraft.mcore.util.Txt; public abstract class FCommand extends MCommand { + public MPlayer mme; public UPlayer fme; public Faction myFaction; @Override public void fixSenderVars() { + this.mme = MPlayer.get(sender); this.fme = UPlayer.get(this.sender); this.myFaction = this.fme.getFaction(); } diff --git a/src/com/massivecraft/factions/entity/MPlayer.java b/src/com/massivecraft/factions/entity/MPlayer.java index 8cec823f..eb67daa6 100644 --- a/src/com/massivecraft/factions/entity/MPlayer.java +++ b/src/com/massivecraft/factions/entity/MPlayer.java @@ -20,7 +20,8 @@ public class MPlayer extends SenderEntity @Override public MPlayer load(MPlayer that) { - // TODO + this.mapAutoUpdating = that.mapAutoUpdating; + this.usingAdminMode = that.usingAdminMode; return this; } @@ -28,8 +29,8 @@ public class MPlayer extends SenderEntity @Override public boolean isDefault() { - // TODO - //return false; + if (this.isMapAutoUpdating()) return false; + if (this.isUsingAdminMode()) return false; return true; } @@ -38,5 +39,12 @@ public class MPlayer extends SenderEntity // FIELDS // -------------------------------------------- // + private boolean mapAutoUpdating = false; + public boolean isMapAutoUpdating() { return this.mapAutoUpdating; } + public void setMapAutoUpdating(boolean mapAutoUpdating) { this.mapAutoUpdating = mapAutoUpdating; this.changed(); } + + private boolean usingAdminMode = false; + public boolean isUsingAdminMode() { return this.usingAdminMode; } + public void setUsingAdminMode(boolean usingAdminMode) { this.usingAdminMode = usingAdminMode; this.changed(); } } diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index 2ed6b518..917a5eb5 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -93,27 +93,22 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // Null means default for the universe. private Double power = null; + // The id for the faction this uplayer is currently autoclaiming for. + // NOTE: This field will not be saved to the database ever. + // Null means the player isn't auto claiming. + private transient Faction autoClaimFaction = null; + public Faction getAutoClaimFaction() { return this.autoClaimFaction; } + public void setAutoClaimFaction(Faction autoClaimFaction) { this.autoClaimFaction = autoClaimFaction; } + // -------------------------------------------- // - // FIELDS: RAW TRANSIENT + // FIELDS: MULTIVERSE PROXY // -------------------------------------------- // - // FIELD: mapAutoUpdating - // TODO: Move this to the MPlayer - private transient boolean mapAutoUpdating = false; - public void setMapAutoUpdating(boolean mapAutoUpdating) { this.mapAutoUpdating = mapAutoUpdating; } - public boolean isMapAutoUpdating() { return mapAutoUpdating; } + public boolean isMapAutoUpdating() { return MPlayer.get(this).isMapAutoUpdating(); } + public void setMapAutoUpdating(boolean mapAutoUpdating) { MPlayer.get(this).setMapAutoUpdating(mapAutoUpdating); } - // FIELD: autoClaimEnabled - private transient Faction autoClaimFor = null; - public Faction getAutoClaimFor() { return autoClaimFor; } - public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; } - - private transient boolean usingAdminMode = false; - public boolean isUsingAdminMode() { return this.usingAdminMode; } - public void setUsingAdminMode(boolean val) { this.usingAdminMode = val; } - - // FIELD: loginPvpDisabled - //private transient boolean loginPvpDisabled; + public boolean isUsingAdminMode() { return MPlayer.get(this).isUsingAdminMode(); } + public void setUsingAdminMode(boolean usingAdminMode) { MPlayer.get(this).setUsingAdminMode(usingAdminMode); } // -------------------------------------------- // // CORE UTILITIES @@ -125,8 +120,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato this.setFactionId(null); this.setRole(null); this.setTitle(null); - - this.autoClaimFor = null; + this.setAutoClaimFaction(null); } /* diff --git a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java index fd613c15..a2d0f5ef 100644 --- a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java @@ -28,18 +28,18 @@ import com.massivecraft.mcore.util.Txt; public class TodoFactionsPlayerListener implements Listener { // -------------------------------------------- // - // TERRITORY INFO MESSAGES + // CHUNK CHANGE: DETECT // -------------------------------------------- // @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerMove(PlayerMoveEvent event) + public void chunkChangeDetect(PlayerMoveEvent event) { // If the player is moving from one chunk to another ... if (MUtil.isSameChunk(event)) return; // ... gather info on the player and the move ... Player player = event.getPlayer(); - UPlayer uplayerTo = UPlayerColls.get().get(event.getTo()).get(player); + UPlayer uplayer = UPlayerColls.get().get(event.getTo()).get(player); PS chunkFrom = PS.valueOf(event.getFrom()).getChunk(true); PS chunkTo = PS.valueOf(event.getTo()).getChunk(true); @@ -47,14 +47,25 @@ public class TodoFactionsPlayerListener implements Listener Faction factionFrom = BoardColls.get().getFactionAt(chunkFrom); Faction factionTo = BoardColls.get().getFactionAt(chunkTo); - // ... send host faction info updates ... - if (uplayerTo.isMapAutoUpdating()) + // ... and send info onwards. + this.chunkChangeTerritoryInfo(uplayer, player, chunkFrom, chunkTo, factionFrom, factionTo); + this.chunkChangeAutoClaim(uplayer, chunkTo); + } + + // -------------------------------------------- // + // CHUNK CHANGE: TERRITORY INFO + // -------------------------------------------- // + + public void chunkChangeTerritoryInfo(UPlayer uplayer, Player player, PS chunkFrom, PS chunkTo, Faction factionFrom, Faction factionTo) + { + // send host faction info updates + if (uplayer.isMapAutoUpdating()) { - uplayerTo.sendMessage(BoardColls.get().getMap(uplayerTo.getFaction(), chunkTo, player.getLocation().getYaw())); + uplayer.sendMessage(BoardColls.get().getMap(uplayer, chunkTo, player.getLocation().getYaw())); } else if (factionFrom != factionTo) { - String msg = Txt.parse("") + " ~ " + factionTo.getTag(uplayerTo); + String msg = Txt.parse("") + " ~ " + factionTo.getTag(uplayer); if (factionTo.hasDescription()) { msg += " - " + factionTo.getDescription(); @@ -66,20 +77,29 @@ public class TodoFactionsPlayerListener implements Listener TerritoryAccess accessTo = BoardColls.get().getTerritoryAccessAt(chunkTo); if (!accessTo.isDefault()) { - if (accessTo.subjectHasAccess(uplayerTo)) + if (accessTo.subjectHasAccess(uplayer)) { - uplayerTo.msg("You have access to this area."); + uplayer.msg("You have access to this area."); } - else if (accessTo.subjectAccessIsRestricted(uplayerTo)) + else if (accessTo.subjectAccessIsRestricted(uplayer)) { - uplayerTo.msg("This area has restricted access."); + uplayer.msg("This area has restricted access."); } } - - if (uplayerTo.getAutoClaimFor() != null) - { - uplayerTo.tryClaim(uplayerTo.getAutoClaimFor(), PS.valueOf(event.getTo()), true, true); - } + } + + // -------------------------------------------- // + // CHUNK CHANGE: AUTO CLAIM + // -------------------------------------------- // + + public void chunkChangeAutoClaim(UPlayer uplayer, PS chunkTo) + { + // If the player is auto claiming ... + Faction autoClaimFaction = uplayer.getAutoClaimFaction(); + if (autoClaimFaction == null) return; + + // ... try claim. + uplayer.tryClaim(autoClaimFaction, chunkTo, true, true); } // -------------------------------------------- //