Removed WorldGuard integration. Can be readded later in a proper manner if anyone need it. Also moved some more Econ stuff to the listener.

This commit is contained in:
Olof Larsson 2013-04-24 13:26:59 +02:00
parent bd8d945c7b
commit e0c6e71b91
12 changed files with 192 additions and 308 deletions

View File

@ -24,7 +24,6 @@ import com.massivecraft.factions.entity.BoardColls;
import com.massivecraft.factions.entity.UPlayerColls; import com.massivecraft.factions.entity.UPlayerColls;
import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.factions.entity.FactionColls;
import com.massivecraft.factions.entity.MConfColl; import com.massivecraft.factions.entity.MConfColl;
import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.integration.herochat.HerochatFeatures; import com.massivecraft.factions.integration.herochat.HerochatFeatures;
import com.massivecraft.factions.integration.lwc.LwcFeatures; import com.massivecraft.factions.integration.lwc.LwcFeatures;
import com.massivecraft.factions.listeners.FactionsListenerChat; import com.massivecraft.factions.listeners.FactionsListenerChat;
@ -162,8 +161,6 @@ public class Factions extends MPlugin
LwcFeatures.get() LwcFeatures.get()
); );
Worldguard.init(this);
postEnable(); postEnable();
} }

View File

@ -36,7 +36,7 @@ public class CmdFactionsAutoClaim extends FCommand
fme.setAutoClaimFor(forFaction); fme.setAutoClaimFor(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.attemptClaim(forFaction, PS.valueOf(me), true); fme.tryClaim(forFaction, PS.valueOf(me), true, true);
} }
} }

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
@ -28,23 +29,29 @@ public class CmdFactionsClaim extends FCommand
@Override @Override
public void perform() public void perform()
{ {
// Args
final Faction forFaction = this.arg(0, ARFaction.get(me)); final Faction forFaction = this.arg(0, ARFaction.get(me));
if (forFaction == null) return; if (forFaction == null) return;
Integer radius = this.arg(1, ARInteger.get(), 1); Integer radius = this.arg(1, ARInteger.get(), 1);
if (radius == null) return; if (radius == null) return;
// FPerm
if (!FPerm.TERRITORY.has(sender, forFaction, true)) return;
// Validate
if (radius < 1) if (radius < 1)
{ {
msg("<b>If you specify a radius, it must be at least 1."); msg("<b>If you specify a radius, it must be at least 1.");
return; return;
} }
// Apply
// single chunk
if (radius < 2) if (radius < 2)
{ {
// single chunk fme.tryClaim(forFaction, PS.valueOf(me), true, true);
fme.attemptClaim(forFaction, PS.valueOf(me), true);
return; return;
} }
@ -55,7 +62,11 @@ public class CmdFactionsClaim extends FCommand
return; return;
} }
// TODO: I do not beleive in the spiral-task. Get rid of this. The failcount can be precalculated. // TODO: There must be a better way than using a spiral task.
// TODO: Do some research to allow for claming sets of chunks in a batch with atomicity.
// This will probably result in an alteration to the owner change event.
// It would possibly contain a set of chunks instead of a single chunk.
new SpiralTask(PS.valueOf(me), radius) new SpiralTask(PS.valueOf(me), radius)
{ {
private int failCount = 0; private int failCount = 0;
@ -64,15 +75,16 @@ public class CmdFactionsClaim extends FCommand
@Override @Override
public boolean work() public boolean work()
{ {
boolean success = fme.attemptClaim(forFaction, PS.valueOf(this.currentLocation()), true); boolean success = fme.tryClaim(forFaction, PS.valueOf(this.currentLocation()), true, true);
if (success) if (success)
failCount = 0; {
else if ( ! success && failCount++ >= limit) this.failCount = 0;
}
else if (this.failCount++ >= this.limit)
{ {
this.stop(); this.stop();
return false; return false;
} }
return true; return true;
} }
}; };

View File

@ -9,13 +9,11 @@ import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.event.FactionsEventDisband; import com.massivecraft.factions.event.FactionsEventDisband;
import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.money.Money;
public class CmdFactionsDisband extends FCommand public class CmdFactionsDisband extends FCommand
{ {
@ -78,19 +76,7 @@ public class CmdFactionsDisband extends FCommand
Factions.get().log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+"."); Factions.get().log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+".");
} }
if (Econ.isEnabled(faction))
{
//Give all the faction's money to the disbander
double amount = Money.get(faction);
Econ.transferMoney(fme, faction, fme, amount, false);
if (amount > 0.0)
{
String amountString = Money.format(faction, amount);
msg("<i>You have been given the disbanded faction's bank, totaling %s.", amountString);
Factions.get().log(fme.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+".");
}
}
faction.detach(); faction.detach();
} }

View File

@ -1,12 +1,8 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.entity.BoardColls;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.factions.entity.FactionColls;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.event.FactionsEventChunkChange;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
@ -27,29 +23,22 @@ public class CmdFactionsUnclaim extends FCommand
{ {
// Args // Args
PS chunk = PS.valueOf(me).getChunk(true); PS chunk = PS.valueOf(me).getChunk(true);
Faction otherFaction = BoardColls.get().getFactionAt(chunk);
Faction newFaction = FactionColls.get().get(me).getNone(); Faction newFaction = FactionColls.get().get(me).getNone();
// FPerm // FPerm
// TODO: Recode so that pillage is possible if (!FPerm.TERRITORY.has(sender, myFaction, true)) return;
if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return;
// Event
FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction);
event.run();
if (event.isCancelled()) return;
// Apply // Apply
BoardColls.get().setFactionAt(chunk, newFaction); if (fme.tryClaim(newFaction, chunk, true, true)) return;
// Inform // Inform
myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true)); // TODO: Move the logging stuff into the try-method
/*myFaction.msg("%s<i> unclaimed some land.", fme.describeTo(myFaction, true));
if (MConf.get().logLandUnclaims) if (MConf.get().logLandUnclaims)
{ {
Factions.get().log(fme.getName()+" unclaimed land at ("+chunk.getChunkX()+","+chunk.getChunkZ()+") from the faction: "+otherFaction.getTag()); Factions.get().log(fme.getName()+" unclaimed land at ("+chunk.getChunkX()+","+chunk.getChunkZ()+") from the faction: "+oldFaction.getTag());
} }*/
} }
} }

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
import java.util.Set; import java.util.Set;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
@ -30,9 +31,11 @@ public class CmdFactionsUnclaimall extends FCommand
{ {
// Args // Args
Faction faction = myFaction; Faction faction = myFaction;
Faction newFaction = FactionColls.get().get(faction).getNone(); Faction newFaction = FactionColls.get().get(faction).getNone();
// FPerm
if (!FPerm.TERRITORY.has(sender, faction, true)) return;
// Apply // Apply
BoardColl boardColl = BoardColls.get().get(faction); BoardColl boardColl = BoardColls.get().get(faction);
Set<PS> chunks = boardColl.getChunks(faction); Set<PS> chunks = boardColl.getChunks(faction);

View File

@ -679,7 +679,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public int getLandCount() public int getLandCount()
{ {
return BoardColls.get().getCount(this); return BoardColls.get().get(this).getCount(this);
} }
public int getLandCountInWorld(String worldName) public int getLandCountInWorld(String worldName)
{ {

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.massivecraft.factions.Const; import com.massivecraft.factions.Const;
import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Lang; import com.massivecraft.factions.Lang;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
@ -17,15 +16,13 @@ import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.event.FactionsEventChunkChange; import com.massivecraft.factions.event.FactionsEventChunkChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.mixin.Mixin;
import com.massivecraft.mcore.money.Money;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.ps.PSFormatSlug;
import com.massivecraft.mcore.store.SenderEntity; import com.massivecraft.mcore.store.SenderEntity;
import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.util.SenderUtil;
public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipator public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipator
@ -491,7 +488,9 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
boolean permanent = myFaction.getFlag(FFlag.PERMANENT); boolean permanent = myFaction.getFlag(FFlag.PERMANENT);
if (!permanent && this.getRole() == Rel.LEADER && myFaction.getUPlayers().size() > 1) if (myFaction.getUPlayers().size() > 1)
{
if (!permanent && this.getRole() == Rel.LEADER)
{ {
msg("<b>You must give the leader role to someone else first."); msg("<b>You must give the leader role to someone else first.");
return; return;
@ -502,22 +501,13 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
msg("<b>You cannot leave until your power is positive."); msg("<b>You cannot leave until your power is positive.");
return; return;
} }
}
// Event // Event
FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(sender, this, myFaction, MembershipChangeReason.LEAVE); FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(sender, this, myFaction, MembershipChangeReason.LEAVE);
membershipChangeEvent.run(); membershipChangeEvent.run();
if (membershipChangeEvent.isCancelled()) return; if (membershipChangeEvent.isCancelled()) return;
// Am I the last one in the faction?
if (myFaction.getUPlayers().size() == 1)
{
// Transfer all money
if (Econ.isEnabled(this))
{
Econ.transferMoney(this, myFaction, this, Money.get(this));
}
}
if (myFaction.isNormal()) if (myFaction.isNormal())
{ {
for (UPlayer uplayer : myFaction.getUPlayersWhereOnline(true)) for (UPlayer uplayer : myFaction.getUPlayersWhereOnline(true))
@ -549,119 +539,120 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
} }
} }
public boolean canClaimForFactionAtLocation(Faction forFaction, PS ps, boolean notifyFailure) public boolean tryClaim(Faction newFaction, PS ps, boolean verbooseChange, boolean verbooseSame)
{ {
String error = null; PS chunk = ps.getChunk(true);
Faction oldFaction = BoardColls.get().getFactionAt(chunk);
Faction myFaction = this.getFaction(); UConf uconf = UConf.get(newFaction);
Faction currentFaction = BoardColls.get().getFactionAt(ps); MConf mconf = MConf.get();
int ownedLand = forFaction.getLandCount();
UConf uconf = UConf.get(ps); // Validate
if (newFaction == oldFaction)
if (uconf.worldGuardChecking && Worldguard.checkForRegionsInChunk(ps))
{
// Checks for WorldGuard regions in the chunk attempting to be claimed
error = Txt.parse("<b>This land is protected");
}
else if (MConf.get().worldsNoClaiming.contains(ps.getWorld()))
{
error = Txt.parse("<b>Sorry, this world has land claiming disabled.");
}
else if (this.isUsingAdminMode())
{ {
msg("%s<i> already owns this land.", newFaction.describeTo(this, true));
return true; return true;
} }
else if (forFaction == currentFaction)
if (!this.isUsingAdminMode() && newFaction.isNormal())
{ {
error = Txt.parse("%s<i> already own this land.", forFaction.describeTo(this, true)); int ownedLand = newFaction.getLandCount();
}
else if ( ! FPerm.TERRITORY.has(this, forFaction, true)) if (!uconf.claimingFromOthersAllowed && oldFaction.isNormal())
{ {
msg("<b>You may not claim land from others.");
return false; return false;
} }
else if (forFaction.getUPlayers().size() < uconf.claimsRequireMinFactionMembers)
if (mconf.worldsNoClaiming.contains(ps.getWorld()))
{ {
error = Txt.parse("Factions must have at least <h>%s<b> members to claim land.", uconf.claimsRequireMinFactionMembers); msg("<b>Sorry, this world has land claiming disabled.");
return false;
} }
else if (ownedLand >= forFaction.getPowerRounded())
if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE))
{ {
error = Txt.parse("<b>You can't claim more land! You need more power!"); msg("<b>You can't claim this land due to your relation with the current owner.");
return false;
} }
else if (uconf.claimedLandsMax != 0 && ownedLand >= uconf.claimedLandsMax && ! forFaction.getFlag(FFlag.INFPOWER))
if (newFaction.getUPlayers().size() < uconf.claimsRequireMinFactionMembers)
{ {
error = Txt.parse("<b>Limit reached. You can't claim more land!"); msg("Factions must have at least <h>%s<b> members to claim land.", uconf.claimsRequireMinFactionMembers);
return false;
} }
else if ( ! uconf.claimingFromOthersAllowed && currentFaction.isNormal())
if (uconf.claimedLandsMax != 0 && ownedLand >= uconf.claimedLandsMax && ! newFaction.getFlag(FFlag.INFPOWER))
{ {
error = Txt.parse("<b>You may not claim land from others."); msg("<b>Limit reached. You can't claim more land.");
return false;
} }
else if (currentFaction.getRelationTo(forFaction).isAtLeast(Rel.TRUCE) && ! currentFaction.isNone())
if (ownedLand >= newFaction.getPowerRounded())
{ {
error = Txt.parse("<b>You can't claim this land due to your relation with the current owner."); msg("<b>You can't claim more land. You need more power.");
return false;
} }
else if
if
( (
uconf.claimsMustBeConnected uconf.claimsMustBeConnected
&& ! this.isUsingAdminMode() && newFaction.getLandCountInWorld(ps.getWorld()) > 0
&& myFaction.getLandCountInWorld(ps.getWorld()) > 0 && !BoardColls.get().isConnectedPs(ps, newFaction)
&& !BoardColls.get().isConnectedPs(ps, myFaction) && (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !oldFaction.isNormal())
&& (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())
) )
{ {
if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction) if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
error = Txt.parse("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!"); {
msg("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!");
}
else else
error = Txt.parse("<b>You can only claim additional land which is connected to your first claim!");
}
else if (currentFaction.isNormal())
{ {
if ( ! currentFaction.hasLandInflation()) msg("<b>You can only claim additional land which is connected to your first claim!");
{
// TODO more messages WARN current faction most importantly
error = Txt.parse("%s<i> owns this land and is strong enough to keep it.", currentFaction.getTag(this));
}
else if ( ! BoardColls.get().isBorderPs(ps))
{
error = Txt.parse("<b>You must start claiming land at the border of the territory.");
} }
return false;
} }
if (notifyFailure && error != null) if (!oldFaction.hasLandInflation())
{ {
msg(error); msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getTag(this));
} return false;
return error == null;
} }
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it if ( ! BoardColls.get().isBorderPs(ps))
// return value is false on failure, true on success
public boolean attemptClaim(Faction forFaction, PS psChunk, boolean notifyFailure)
{ {
psChunk = psChunk.getChunk(true); msg("<b>You must start claiming land at the border of the territory.");
Faction currentFaction = BoardColls.get().getFactionAt(psChunk); return false;
}
if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false; }
// Event // Event
FactionsEventChunkChange event = new FactionsEventChunkChange(sender, psChunk, forFaction); FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction);
event.run(); event.run();
if (event.isCancelled()) return false; if (event.isCancelled()) return false;
// announce success // Apply
Set<UPlayer> informTheseUPlayers = new HashSet<UPlayer>(); BoardColls.get().setFactionAt(chunk, newFaction);
informTheseUPlayers.add(this);
informTheseUPlayers.addAll(forFaction.getUPlayersWhereOnline(true)); // Inform
for (UPlayer fp : informTheseUPlayers) Set<UPlayer> informees = new HashSet<UPlayer>();
informees.add(this);
if (newFaction.isNormal())
{ {
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)); informees.addAll(newFaction.getUPlayers());
}
if (oldFaction.isNormal())
{
informees.addAll(oldFaction.getUPlayers());
} }
BoardColls.get().setFactionAt(psChunk, forFaction);
if (MConf.get().logLandClaims) if (MConf.get().logLandClaims)
{ {
Factions.get().log(this.getName()+" claimed land at ("+psChunk.getChunkX()+","+psChunk.getChunkZ()+") for the faction: "+forFaction.getTag()); informees.add(UPlayer.get(SenderUtil.getConsole()));
}
for (UPlayer informee : informees)
{
informee.msg("<h>%s<i> did %s %s <i>for <h>%s<i> from <h>%s<i>.", this.describeTo(informee, true), event.getType().toString().toLowerCase(), chunk.toString(PSFormatSlug.get()), newFaction.describeTo(informee), oldFaction.describeTo(informee));
} }
return true; return true;

View File

@ -99,7 +99,7 @@ public class UPlayerColl extends SenderColl<UPlayer>
} }
} }
uplayer.resetFactionData(); uplayer.leave();
uplayer.detach(); uplayer.detach();
} }
} }

View File

@ -1,141 +0,0 @@
package com.massivecraft.factions.integration;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.UConf;
import com.massivecraft.mcore.ps.PS;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.BlockVector;
import org.bukkit.World;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import org.bukkit.entity.Player;
/*
* Worldguard Region Checking
* Author: Spathizilla
*/
public class Worldguard
{
private static WorldGuardPlugin wg;
private static boolean enabled = false;
public static void init(Plugin plugin)
{
Plugin wgplug = plugin.getServer().getPluginManager().getPlugin("WorldGuard");
if (wgplug == null || !(wgplug instanceof WorldGuardPlugin))
{
enabled = false;
wg = null;
Factions.get().log("Could not hook to WorldGuard. WorldGuard checks are disabled.");
}
else
{
wg = (WorldGuardPlugin) wgplug;
enabled = true;
Factions.get().log("Successfully hooked to WorldGuard.");
}
}
public static boolean isEnabled()
{
return enabled;
}
// PVP Flag check
// Returns:
// True: PVP is allowed
// False: PVP is disallowed
public static boolean isPVP(Player player)
{
// No WG hooks so we'll always bypass this check.
if (!enabled) return true;
if (!UConf.get(player).worldGuardChecking) return true;
Location loc = player.getLocation();
World world = loc.getWorld();
Vector pt = toVector(loc);
RegionManager regionManager = wg.getRegionManager(world);
ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
return set.allows(DefaultFlag.PVP);
}
// Check for Regions in chunk the chunk
// Returns:
// True: Regions found within chunk
// False: No regions found within chunk
public static boolean checkForRegionsInChunk(PS psChunk)
{
// No WG hooks so we'll always bypass this check.
if (!enabled) return false;
if (!UConf.get(psChunk).worldGuardChecking) return true;
World world = null;
Chunk chunk = null;
try
{
world = psChunk.asBukkitWorld(true);
chunk = psChunk.asBukkitChunk(true);
}
catch (Exception e)
{
return false;
}
int minChunkX = chunk.getX() << 4;
int minChunkZ = chunk.getZ() << 4;
int maxChunkX = minChunkX + 15;
int maxChunkZ = minChunkZ + 15;
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ);
BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ);
RegionManager regionManager = wg.getRegionManager(world);
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
Map<String, ProtectedRegion> allregions = regionManager.getRegions();
List<ProtectedRegion> allregionslist = new ArrayList<ProtectedRegion>(allregions.values());
List<ProtectedRegion> overlaps;
boolean foundregions = false;
try
{
overlaps = region.getIntersectingRegions(allregionslist);
if (overlaps == null || overlaps.isEmpty())
{
foundregions = false;
}
else
{
foundregions = true;
}
}
catch (Exception e)
{
e.printStackTrace();
}
region = null;
allregionslist = null;
overlaps = null;
return foundregions;
}
}

View File

@ -14,6 +14,7 @@ import com.massivecraft.factions.event.FactionsEventChunkChange;
import com.massivecraft.factions.event.FactionsEventChunkChangeType; import com.massivecraft.factions.event.FactionsEventChunkChangeType;
import com.massivecraft.factions.event.FactionsEventCreate; import com.massivecraft.factions.event.FactionsEventCreate;
import com.massivecraft.factions.event.FactionsEventDescriptionChange; import com.massivecraft.factions.event.FactionsEventDescriptionChange;
import com.massivecraft.factions.event.FactionsEventDisband;
import com.massivecraft.factions.event.FactionsEventHomeChange; import com.massivecraft.factions.event.FactionsEventHomeChange;
import com.massivecraft.factions.event.FactionsEventHomeTeleport; import com.massivecraft.factions.event.FactionsEventHomeTeleport;
import com.massivecraft.factions.event.FactionsEventInvitedChange; import com.massivecraft.factions.event.FactionsEventInvitedChange;
@ -24,6 +25,7 @@ import com.massivecraft.factions.event.FactionsEventRelationChange;
import com.massivecraft.factions.event.FactionsEventTagChange; import com.massivecraft.factions.event.FactionsEventTagChange;
import com.massivecraft.factions.event.FactionsEventTitleChange; import com.massivecraft.factions.event.FactionsEventTitleChange;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.money.Money;
public class FactionsListenerEcon implements Listener public class FactionsListenerEcon implements Listener
{ {
@ -44,6 +46,51 @@ public class FactionsListenerEcon implements Listener
Bukkit.getPluginManager().registerEvents(this, Factions.get()); Bukkit.getPluginManager().registerEvents(this, Factions.get());
} }
// -------------------------------------------- //
// TAKE ON LEAVE
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void takeOnLeave(FactionsEventMembershipChange event)
{
// If a player is leaving the faction ...
if (event.getReason() != MembershipChangeReason.LEAVE) return;
// ... and that player was the last one in the faction ...
UPlayer uplayer = event.getUPlayer();
Faction oldFaction = uplayer.getFaction();
if (oldFaction.getUPlayers().size() > 1) return;
// ... then transfer all money to the player.
Econ.transferMoney(uplayer, oldFaction, uplayer, Money.get(oldFaction));
}
// -------------------------------------------- //
// TAKE ON DISBAND
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void takeOnDisband(FactionsEventDisband event)
{
// If there is a usender ...
UPlayer usender = event.getUSender();
if (usender == null) return;
// ... and economy is enabled ...
if (!Econ.isEnabled(usender)) return;
// ... then transfer all the faction money to the sender.
Faction faction = event.getFaction();
double amount = Money.get(faction);
String amountString = Money.format(faction, amount);
Econ.transferMoney(usender, faction, usender, amount, false);
usender.msg("<i>You have been given the disbanded faction's bank, totaling %s.", amountString);
Factions.get().log(usender.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+".");
}
// -------------------------------------------- // // -------------------------------------------- //
// PAY FOR ACTION // PAY FOR ACTION
// -------------------------------------------- // // -------------------------------------------- //

View File

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