Working on auto claim

This commit is contained in:
Olof Larsson 2013-04-24 15:14:15 +02:00
parent f6da2d397b
commit aa989db8f7
6 changed files with 70 additions and 45 deletions

View File

@ -24,16 +24,16 @@ public class CmdFactionsAutoClaim extends FCommand
public void perform() public void perform()
{ {
Faction forFaction = this.arg(0, ARFaction.get(myFaction), myFaction); 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("<i>Auto-claiming of land disabled."); msg("<i>Auto-claiming of land disabled.");
return; 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("<i>Now auto-claiming land for <h>%s<i>.", forFaction.describeTo(fme)); msg("<i>Now auto-claiming land for <h>%s<i>.", forFaction.describeTo(fme));
fme.tryClaim(forFaction, PS.valueOf(me), true, true); fme.tryClaim(forFaction, PS.valueOf(me), true, true);

View File

@ -28,11 +28,11 @@ public class CmdFactionsMap extends FCommand
return; return;
} }
if (this.arg(0, ARBoolean.get(), !fme.isMapAutoUpdating())) if (this.arg(0, ARBoolean.get(), !mme.isMapAutoUpdating()))
{ {
// Turn on // Turn on
fme.setMapAutoUpdating(true); mme.setMapAutoUpdating(true);
msg("<i>Map auto update <green>ENABLED."); msg("<i>Map auto update <green>ENABLED.");
// And show the map once // And show the map once
@ -41,7 +41,7 @@ public class CmdFactionsMap extends FCommand
else else
{ {
// Turn off // Turn off
fme.setMapAutoUpdating(false); mme.setMapAutoUpdating(false);
msg("<i>Map auto update <red>DISABLED."); msg("<i>Map auto update <red>DISABLED.");
} }
} }

View File

@ -1,6 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.UPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.mcore.cmd.MCommand; import com.massivecraft.mcore.cmd.MCommand;
@ -8,12 +9,14 @@ import com.massivecraft.mcore.util.Txt;
public abstract class FCommand extends MCommand public abstract class FCommand extends MCommand
{ {
public MPlayer mme;
public UPlayer fme; public UPlayer fme;
public Faction myFaction; public Faction myFaction;
@Override @Override
public void fixSenderVars() public void fixSenderVars()
{ {
this.mme = MPlayer.get(sender);
this.fme = UPlayer.get(this.sender); this.fme = UPlayer.get(this.sender);
this.myFaction = this.fme.getFaction(); this.myFaction = this.fme.getFaction();
} }

View File

@ -20,7 +20,8 @@ public class MPlayer extends SenderEntity<MPlayer>
@Override @Override
public MPlayer load(MPlayer that) public MPlayer load(MPlayer that)
{ {
// TODO this.mapAutoUpdating = that.mapAutoUpdating;
this.usingAdminMode = that.usingAdminMode;
return this; return this;
} }
@ -28,8 +29,8 @@ public class MPlayer extends SenderEntity<MPlayer>
@Override @Override
public boolean isDefault() public boolean isDefault()
{ {
// TODO if (this.isMapAutoUpdating()) return false;
//return false; if (this.isUsingAdminMode()) return false;
return true; return true;
} }
@ -38,5 +39,12 @@ public class MPlayer extends SenderEntity<MPlayer>
// FIELDS // 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(); }
} }

View File

@ -93,27 +93,22 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
// Null means default for the universe. // Null means default for the universe.
private Double power = null; 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 public boolean isMapAutoUpdating() { return MPlayer.get(this).isMapAutoUpdating(); }
// TODO: Move this to the MPlayer public void setMapAutoUpdating(boolean mapAutoUpdating) { MPlayer.get(this).setMapAutoUpdating(mapAutoUpdating); }
private transient boolean mapAutoUpdating = false;
public void setMapAutoUpdating(boolean mapAutoUpdating) { this.mapAutoUpdating = mapAutoUpdating; }
public boolean isMapAutoUpdating() { return mapAutoUpdating; }
// FIELD: autoClaimEnabled public boolean isUsingAdminMode() { return MPlayer.get(this).isUsingAdminMode(); }
private transient Faction autoClaimFor = null; public void setUsingAdminMode(boolean usingAdminMode) { MPlayer.get(this).setUsingAdminMode(usingAdminMode); }
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;
// -------------------------------------------- // // -------------------------------------------- //
// CORE UTILITIES // CORE UTILITIES
@ -125,8 +120,7 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
this.setFactionId(null); this.setFactionId(null);
this.setRole(null); this.setRole(null);
this.setTitle(null); this.setTitle(null);
this.setAutoClaimFaction(null);
this.autoClaimFor = null;
} }
/* /*

View File

@ -28,18 +28,18 @@ import com.massivecraft.mcore.util.Txt;
public class TodoFactionsPlayerListener implements Listener public class TodoFactionsPlayerListener implements Listener
{ {
// -------------------------------------------- // // -------------------------------------------- //
// TERRITORY INFO MESSAGES // CHUNK CHANGE: DETECT
// -------------------------------------------- // // -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @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 the player is moving from one chunk to another ...
if (MUtil.isSameChunk(event)) return; if (MUtil.isSameChunk(event)) return;
// ... gather info on the player and the move ... // ... gather info on the player and the move ...
Player player = event.getPlayer(); 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 chunkFrom = PS.valueOf(event.getFrom()).getChunk(true);
PS chunkTo = PS.valueOf(event.getTo()).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 factionFrom = BoardColls.get().getFactionAt(chunkFrom);
Faction factionTo = BoardColls.get().getFactionAt(chunkTo); Faction factionTo = BoardColls.get().getFactionAt(chunkTo);
// ... send host faction info updates ... // ... and send info onwards.
if (uplayerTo.isMapAutoUpdating()) 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) else if (factionFrom != factionTo)
{ {
String msg = Txt.parse("<i>") + " ~ " + factionTo.getTag(uplayerTo); String msg = Txt.parse("<i>") + " ~ " + factionTo.getTag(uplayer);
if (factionTo.hasDescription()) if (factionTo.hasDescription())
{ {
msg += " - " + factionTo.getDescription(); msg += " - " + factionTo.getDescription();
@ -66,20 +77,29 @@ public class TodoFactionsPlayerListener implements Listener
TerritoryAccess accessTo = BoardColls.get().getTerritoryAccessAt(chunkTo); TerritoryAccess accessTo = BoardColls.get().getTerritoryAccessAt(chunkTo);
if (!accessTo.isDefault()) if (!accessTo.isDefault())
{ {
if (accessTo.subjectHasAccess(uplayerTo)) if (accessTo.subjectHasAccess(uplayer))
{ {
uplayerTo.msg("<g>You have access to this area."); uplayer.msg("<g>You have access to this area.");
} }
else if (accessTo.subjectAccessIsRestricted(uplayerTo)) else if (accessTo.subjectAccessIsRestricted(uplayer))
{ {
uplayerTo.msg("<b>This area has restricted access."); uplayer.msg("<b>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);
} }
// -------------------------------------------- // // -------------------------------------------- //