Minor messaround with land claiming.

This commit is contained in:
Olof Larsson 2013-04-19 14:24:35 +02:00
parent c6739c4aa9
commit 9770cb8983
7 changed files with 42 additions and 52 deletions

View File

@ -4,7 +4,6 @@ import java.util.HashSet;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.massivecraft.factions.event.FactionsEventLandClaim;
@ -730,16 +729,15 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
}
}
public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure)
public boolean canClaimForFactionAtLocation(Faction forFaction, PS ps, boolean notifyFailure)
{
String error = null;
PS ps = PS.valueOf(location);
Faction myFaction = this.getFaction();
Faction currentFaction = BoardColl.get().getFactionAt(ps);
int ownedLand = forFaction.getLandCount();
if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(location))
if (ConfServer.worldGuardChecking && Worldguard.checkForRegionsInChunk(ps))
{
// Checks for WorldGuard regions in the chunk attempting to be claimed
error = Txt.parse("<b>This land is protected");
@ -814,51 +812,35 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
return error == null;
}
public boolean attemptClaim(Faction forFaction, Location location, boolean notifyFailure)
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it
// return value is false on failure, true on success
public boolean attemptClaim(Faction forFaction, PS psChunk, boolean notifyFailure)
{
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it
// return value is false on failure, true on success
PS flocation = PS.valueOf(location).getChunk(true);
Faction currentFaction = BoardColl.get().getFactionAt(flocation);
psChunk = psChunk.getChunk(true);
Faction currentFaction = BoardColl.get().getFactionAt(psChunk);
int ownedLand = forFaction.getLandCount();
if ( ! this.canClaimForFactionAtLocation(forFaction, location, notifyFailure)) return false;
// TODO: Add flag no costs??
// if economy is enabled and they're not on the bypass list, make sure they can pay
boolean mustPay = Econ.isEnabled() && ! this.isUsingAdminMode();
double cost = 0.0;
EconomyParticipator payee = null;
if (mustPay)
{
cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(flocation.getWorld()) > 0 && !BoardColl.get().isConnectedPs(flocation, forFaction))
cost += ConfServer.econClaimUnconnectedFee;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysLandCosts && this.hasFaction())
payee = this.getFaction();
else
payee = this;
if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false;
}
if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false;
// Event
FactionsEventLandClaim event = new FactionsEventLandClaim(sender, forFaction, flocation);
FactionsEventLandClaim event = new FactionsEventLandClaim(sender, forFaction, psChunk);
event.run();
if (event.isCancelled()) return false;
// then make 'em pay (if applicable)
// TODO: The economy integration should cancel the event above!
if (mustPay && ! Econ.modifyMoney(payee, -cost, "claim this land")) return false;
// Calculate the cost to claim the area
double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
if (ConfServer.econClaimUnconnectedFee != 0.0 && forFaction.getLandCountInWorld(psChunk.getWorld()) > 0 && !BoardColl.get().isConnectedPs(psChunk, forFaction))
{
cost += ConfServer.econClaimUnconnectedFee;
}
if (Econ.payForAction(cost, this, "claim this land")) return false;
// TODO: The LWC integration should listen to Monitor for the claim event.
if (LWCFeatures.getEnabled() && forFaction.isNormal() && ConfServer.onCaptureResetLwcLocks)
{
LWCFeatures.clearOtherProtections(flocation, this.getFaction());
LWCFeatures.clearOtherProtections(psChunk, this.getFaction());
}
// announce success
@ -870,11 +852,11 @@ public class FPlayer extends SenderEntity<FPlayer> implements EconomyParticipato
fp.msg("<h>%s<i> claimed land for <h>%s<i> from <h>%s<i>.", this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
}
BoardColl.get().setFactionAt(flocation, forFaction);
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
BoardColl.get().setFactionAt(psChunk, forFaction);
SpoutFeatures.updateTerritoryDisplayLoc(psChunk);
if (ConfServer.logLandClaims)
Factions.get().log(this.getName()+" claimed land at ("+flocation.getChunkX()+","+flocation.getChunkZ()+") for the faction: "+forFaction.getTag());
Factions.get().log(this.getName()+" claimed land at ("+psChunk.getChunkX()+","+psChunk.getChunkZ()+") for the faction: "+forFaction.getTag());
return true;
}

View File

@ -6,6 +6,7 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS;
public class CmdFactionsAutoClaim extends FCommand
{
@ -35,7 +36,7 @@ public class CmdFactionsAutoClaim extends FCommand
fme.setAutoClaimFor(forFaction);
msg("<i>Now auto-claiming land for <h>%s<i>.", forFaction.describeTo(fme));
fme.attemptClaim(forFaction, me.getLocation(), true);
fme.attemptClaim(forFaction, PS.valueOf(me), true);
}
}

View File

@ -44,7 +44,7 @@ public class CmdFactionsClaim extends FCommand
if (radius < 2)
{
// single chunk
fme.attemptClaim(forFaction, me.getLocation(), true);
fme.attemptClaim(forFaction, PS.valueOf(me), true);
return;
}
@ -64,7 +64,7 @@ public class CmdFactionsClaim extends FCommand
@Override
public boolean work()
{
boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
boolean success = fme.attemptClaim(forFaction, PS.valueOf(this.currentLocation()), true);
if (success)
failCount = 0;
else if ( ! success && failCount++ >= limit)

View File

@ -5,7 +5,6 @@ import java.util.Set;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.RegisteredServiceProvider;
import com.massivecraft.factions.ConfServer;
@ -71,12 +70,11 @@ public class Econ
// UTIL
// -------------------------------------------- //
public static boolean payForAction(double cost, CommandSender sender, String actionDescription)
public static boolean payForAction(double cost, FPlayer fsender, String actionDescription)
{
if (!isEnabled()) return true;
if (cost == 0D) return true;
FPlayer fsender = FPlayer.get(sender);
if (fsender.isUsingAdminMode()) return true;
Faction fsenderFaction = fsender.getFaction();

View File

@ -1,6 +1,8 @@
package com.massivecraft.factions.integration;
import com.massivecraft.factions.Factions;
import com.massivecraft.mcore.ps.PS;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -79,16 +81,23 @@ public class Worldguard
// Returns:
// True: Regions found within chunk
// False: No regions found within chunk
public static boolean checkForRegionsInChunk(Location loc)
public static boolean checkForRegionsInChunk(PS psChunk)
{
if ( ! enabled)
// No WG hooks so we'll always bypass this check.
if (!enabled) return false;
World world = null;
Chunk chunk = null;
try
{
world = psChunk.asBukkitWorld(true);
chunk = psChunk.asBukkitChunk(true);
}
catch (Exception e)
{
// No WG hooks so we'll always bypass this check.
return false;
}
World world = loc.getWorld();
Chunk chunk = world.getChunkAt(loc);
int minChunkX = chunk.getX() << 4;
int minChunkZ = chunk.getZ() << 4;
int maxChunkX = minChunkX + 15;

View File

@ -51,7 +51,7 @@ public class FactionsListenerEcon implements Listener
if (event.getSender() == null) return;
// ... and the sender can't afford ...
if (Econ.payForAction(cost, event.getSender(), command.getDesc())) return;
if (Econ.payForAction(cost, event.getFSender(), command.getDesc())) return;
// ... then cancel.
event.setCancelled(true);

View File

@ -108,7 +108,7 @@ public class TodoFactionsPlayerListener implements Listener
if (fplayer.getAutoClaimFor() != null)
{
fplayer.attemptClaim(fplayer.getAutoClaimFor(), event.getTo(), true);
fplayer.attemptClaim(fplayer.getAutoClaimFor(), PS.valueOf(event.getTo()), true);
}
}