From e0c6e71b9135d284de2abe3dbda8450bd61fdeb5 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 24 Apr 2013 13:26:59 +0200 Subject: [PATCH] Removed WorldGuard integration. Can be readded later in a proper manner if anyone need it. Also moved some more Econ stuff to the listener. --- src/com/massivecraft/factions/Factions.java | 3 - .../factions/cmd/CmdFactionsAutoClaim.java | 2 +- .../factions/cmd/CmdFactionsClaim.java | 30 ++- .../factions/cmd/CmdFactionsDisband.java | 16 +- .../factions/cmd/CmdFactionsUnclaim.java | 23 +- .../factions/cmd/CmdFactionsUnclaimall.java | 5 +- .../massivecraft/factions/entity/Faction.java | 2 +- .../massivecraft/factions/entity/UPlayer.java | 227 +++++++++--------- .../factions/entity/UPlayerColl.java | 2 +- .../factions/integration/Worldguard.java | 141 ----------- .../listeners/FactionsListenerEcon.java | 47 ++++ .../listeners/TodoFactionsPlayerListener.java | 2 +- 12 files changed, 192 insertions(+), 308 deletions(-) delete mode 100644 src/com/massivecraft/factions/integration/Worldguard.java diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 8536c024..cd3bd989 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -24,7 +24,6 @@ import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.UPlayerColls; import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.factions.entity.MConfColl; -import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.herochat.HerochatFeatures; import com.massivecraft.factions.integration.lwc.LwcFeatures; import com.massivecraft.factions.listeners.FactionsListenerChat; @@ -162,8 +161,6 @@ public class Factions extends MPlugin LwcFeatures.get() ); - Worldguard.init(this); - postEnable(); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java index 9d4ae392..29eb5deb 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java @@ -36,7 +36,7 @@ public class CmdFactionsAutoClaim extends FCommand fme.setAutoClaimFor(forFaction); msg("Now auto-claiming land for %s.", forFaction.describeTo(fme)); - fme.attemptClaim(forFaction, PS.valueOf(me), true); + fme.tryClaim(forFaction, PS.valueOf(me), true, true); } } \ No newline at end of file diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java index 016be03d..6e666502 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java @@ -1,5 +1,6 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.Faction; @@ -28,34 +29,44 @@ public class CmdFactionsClaim extends FCommand @Override public void perform() { + // Args final Faction forFaction = this.arg(0, ARFaction.get(me)); if (forFaction == null) return; Integer radius = this.arg(1, ARInteger.get(), 1); if (radius == null) return; - + // FPerm + if (!FPerm.TERRITORY.has(sender, forFaction, true)) return; + + // Validate if (radius < 1) { msg("If you specify a radius, it must be at least 1."); return; } + // Apply + + // single chunk if (radius < 2) { - // single chunk - fme.attemptClaim(forFaction, PS.valueOf(me), true); + fme.tryClaim(forFaction, PS.valueOf(me), true, true); return; } // radius claim - if (! Perm.CLAIM_RADIUS.has(sender, false)) + if (!Perm.CLAIM_RADIUS.has(sender, false)) { msg("You do not have permission to claim in a radius."); 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) { private int failCount = 0; @@ -64,15 +75,16 @@ public class CmdFactionsClaim extends FCommand @Override 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) - failCount = 0; - else if ( ! success && failCount++ >= limit) + { + this.failCount = 0; + } + else if (this.failCount++ >= this.limit) { this.stop(); return false; } - return true; } }; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java index 38fcbb3b..3afa7391 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -9,13 +9,11 @@ import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.FactionsEventDisband; import com.massivecraft.factions.event.FactionsEventMembershipChange; import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason; -import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.mcore.cmd.req.ReqHasPerm; -import com.massivecraft.mcore.money.Money; 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())+"."); } - 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("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(); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java index d0c2aca7..b5fae03b 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -1,12 +1,8 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.Faction; 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.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; @@ -27,29 +23,22 @@ public class CmdFactionsUnclaim extends FCommand { // Args PS chunk = PS.valueOf(me).getChunk(true); - Faction otherFaction = BoardColls.get().getFactionAt(chunk); - Faction newFaction = FactionColls.get().get(me).getNone(); // FPerm - // TODO: Recode so that pillage is possible - if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; - - // Event - FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction); - event.run(); - if (event.isCancelled()) return; + if (!FPerm.TERRITORY.has(sender, myFaction, true)) return; // Apply - BoardColls.get().setFactionAt(chunk, newFaction); + if (fme.tryClaim(newFaction, chunk, true, true)) return; // Inform - myFaction.msg("%s unclaimed some land.", fme.describeTo(myFaction, true)); + // TODO: Move the logging stuff into the try-method + /*myFaction.msg("%s unclaimed some land.", fme.describeTo(myFaction, true)); 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()); + }*/ } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index cadf49b9..e3a8f242 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd; import java.util.Set; +import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; @@ -30,8 +31,10 @@ public class CmdFactionsUnclaimall extends FCommand { // Args Faction faction = myFaction; - Faction newFaction = FactionColls.get().get(faction).getNone(); + + // FPerm + if (!FPerm.TERRITORY.has(sender, faction, true)) return; // Apply BoardColl boardColl = BoardColls.get().get(faction); diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 4a1779c9..567f38df 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -679,7 +679,7 @@ public class Faction extends Entity implements EconomyParticipator public int getLandCount() { - return BoardColls.get().getCount(this); + return BoardColls.get().get(this).getCount(this); } public int getLandCountInWorld(String worldName) { diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index ba39ad5f..a005baad 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -9,7 +9,6 @@ import org.bukkit.entity.Player; import com.massivecraft.factions.Const; import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.FFlag; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Lang; 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.FactionsEventMembershipChange; 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.mcore.mixin.Mixin; -import com.massivecraft.mcore.money.Money; import com.massivecraft.mcore.ps.PS; +import com.massivecraft.mcore.ps.PSFormatSlug; import com.massivecraft.mcore.store.SenderEntity; import com.massivecraft.mcore.util.MUtil; -import com.massivecraft.mcore.util.Txt; +import com.massivecraft.mcore.util.SenderUtil; public class UPlayer extends SenderEntity implements EconomyParticipator @@ -491,32 +488,25 @@ public class UPlayer extends SenderEntity implements EconomyParticipato boolean permanent = myFaction.getFlag(FFlag.PERMANENT); - if (!permanent && this.getRole() == Rel.LEADER && myFaction.getUPlayers().size() > 1) + if (myFaction.getUPlayers().size() > 1) { - msg("You must give the leader role to someone else first."); - return; - } - - if (!UConf.get(myFaction).canLeaveWithNegativePower && this.getPower() < 0) - { - msg("You cannot leave until your power is positive."); - return; + if (!permanent && this.getRole() == Rel.LEADER) + { + msg("You must give the leader role to someone else first."); + return; + } + + if (!UConf.get(myFaction).canLeaveWithNegativePower && this.getPower() < 0) + { + msg("You cannot leave until your power is positive."); + return; + } } // Event FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange(sender, this, myFaction, MembershipChangeReason.LEAVE); membershipChangeEvent.run(); 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()) { @@ -548,120 +538,121 @@ public class UPlayer extends SenderEntity 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(); - Faction currentFaction = BoardColls.get().getFactionAt(ps); - int ownedLand = forFaction.getLandCount(); + UConf uconf = UConf.get(newFaction); + MConf mconf = MConf.get(); - UConf uconf = UConf.get(ps); - - if (uconf.worldGuardChecking && Worldguard.checkForRegionsInChunk(ps)) - { - // Checks for WorldGuard regions in the chunk attempting to be claimed - error = Txt.parse("This land is protected"); - } - else if (MConf.get().worldsNoClaiming.contains(ps.getWorld())) - { - error = Txt.parse("Sorry, this world has land claiming disabled."); - } - else if (this.isUsingAdminMode()) + // Validate + if (newFaction == oldFaction) { + msg("%s already owns this land.", newFaction.describeTo(this, true)); return true; } - else if (forFaction == currentFaction) + + if (!this.isUsingAdminMode() && newFaction.isNormal()) { - error = Txt.parse("%s already own this land.", forFaction.describeTo(this, true)); - } - else if ( ! FPerm.TERRITORY.has(this, forFaction, true)) - { - return false; - } - else if (forFaction.getUPlayers().size() < uconf.claimsRequireMinFactionMembers) - { - error = Txt.parse("Factions must have at least %s members to claim land.", uconf.claimsRequireMinFactionMembers); - } - else if (ownedLand >= forFaction.getPowerRounded()) - { - error = Txt.parse("You can't claim more land! You need more power!"); - } - else if (uconf.claimedLandsMax != 0 && ownedLand >= uconf.claimedLandsMax && ! forFaction.getFlag(FFlag.INFPOWER)) - { - error = Txt.parse("Limit reached. You can't claim more land!"); - } - else if ( ! uconf.claimingFromOthersAllowed && currentFaction.isNormal()) - { - error = Txt.parse("You may not claim land from others."); - } - else if (currentFaction.getRelationTo(forFaction).isAtLeast(Rel.TRUCE) && ! currentFaction.isNone()) - { - error = Txt.parse("You can't claim this land due to your relation with the current owner."); - } - else if - ( - uconf.claimsMustBeConnected - && ! this.isUsingAdminMode() - && myFaction.getLandCountInWorld(ps.getWorld()) > 0 - && !BoardColls.get().isConnectedPs(ps, myFaction) - && (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) - ) - { - if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction) - error = Txt.parse("You can only claim additional land which is connected to your first claim or controlled by another faction!"); - else - error = Txt.parse("You can only claim additional land which is connected to your first claim!"); - } - else if (currentFaction.isNormal()) - { - if ( ! currentFaction.hasLandInflation()) + int ownedLand = newFaction.getLandCount(); + + if (!uconf.claimingFromOthersAllowed && oldFaction.isNormal()) { - // TODO more messages WARN current faction most importantly - error = Txt.parse("%s owns this land and is strong enough to keep it.", currentFaction.getTag(this)); + msg("You may not claim land from others."); + return false; } - else if ( ! BoardColls.get().isBorderPs(ps)) + + if (mconf.worldsNoClaiming.contains(ps.getWorld())) { - error = Txt.parse("You must start claiming land at the border of the territory."); + msg("Sorry, this world has land claiming disabled."); + return false; + } + + if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) + { + msg("You can't claim this land due to your relation with the current owner."); + return false; + } + + if (newFaction.getUPlayers().size() < uconf.claimsRequireMinFactionMembers) + { + msg("Factions must have at least %s members to claim land.", uconf.claimsRequireMinFactionMembers); + return false; + } + + if (uconf.claimedLandsMax != 0 && ownedLand >= uconf.claimedLandsMax && ! newFaction.getFlag(FFlag.INFPOWER)) + { + msg("Limit reached. You can't claim more land."); + return false; + } + + if (ownedLand >= newFaction.getPowerRounded()) + { + msg("You can't claim more land. You need more power."); + return false; + } + + if + ( + uconf.claimsMustBeConnected + && newFaction.getLandCountInWorld(ps.getWorld()) > 0 + && !BoardColls.get().isConnectedPs(ps, newFaction) + && (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !oldFaction.isNormal()) + ) + { + if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction) + { + msg("You can only claim additional land which is connected to your first claim or controlled by another faction!"); + } + else + { + msg("You can only claim additional land which is connected to your first claim!"); + } + return false; + } + + if (!oldFaction.hasLandInflation()) + { + msg("%s owns this land and is strong enough to keep it.", oldFaction.getTag(this)); + return false; + } + + if ( ! BoardColls.get().isBorderPs(ps)) + { + msg("You must start claiming land at the border of the territory."); + return false; } } - if (notifyFailure && error != null) - { - msg(error); - } - return error == null; - } - - // 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) - { - psChunk = psChunk.getChunk(true); - Faction currentFaction = BoardColls.get().getFactionAt(psChunk); - - if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false; - // Event - FactionsEventChunkChange event = new FactionsEventChunkChange(sender, psChunk, forFaction); + FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction); event.run(); if (event.isCancelled()) return false; - // announce success - Set informTheseUPlayers = new HashSet(); - informTheseUPlayers.add(this); - informTheseUPlayers.addAll(forFaction.getUPlayersWhereOnline(true)); - for (UPlayer fp : informTheseUPlayers) - { - fp.msg("%s claimed land for %s from %s.", this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp)); - } + // Apply + BoardColls.get().setFactionAt(chunk, newFaction); - BoardColls.get().setFactionAt(psChunk, forFaction); - + // Inform + Set informees = new HashSet(); + informees.add(this); + if (newFaction.isNormal()) + { + informees.addAll(newFaction.getUPlayers()); + } + if (oldFaction.isNormal()) + { + informees.addAll(oldFaction.getUPlayers()); + } 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("%s did %s %s for %s from %s.", this.describeTo(informee, true), event.getType().toString().toLowerCase(), chunk.toString(PSFormatSlug.get()), newFaction.describeTo(informee), oldFaction.describeTo(informee)); } return true; diff --git a/src/com/massivecraft/factions/entity/UPlayerColl.java b/src/com/massivecraft/factions/entity/UPlayerColl.java index d34df00f..16ca7fa5 100644 --- a/src/com/massivecraft/factions/entity/UPlayerColl.java +++ b/src/com/massivecraft/factions/entity/UPlayerColl.java @@ -99,7 +99,7 @@ public class UPlayerColl extends SenderColl } } - uplayer.resetFactionData(); + uplayer.leave(); uplayer.detach(); } } diff --git a/src/com/massivecraft/factions/integration/Worldguard.java b/src/com/massivecraft/factions/integration/Worldguard.java deleted file mode 100644 index de2137c2..00000000 --- a/src/com/massivecraft/factions/integration/Worldguard.java +++ /dev/null @@ -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 allregions = regionManager.getRegions(); - List allregionslist = new ArrayList(allregions.values()); - List 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; - } -} \ No newline at end of file diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java index dbf2821c..8b7c325c 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java @@ -14,6 +14,7 @@ import com.massivecraft.factions.event.FactionsEventChunkChange; import com.massivecraft.factions.event.FactionsEventChunkChangeType; import com.massivecraft.factions.event.FactionsEventCreate; import com.massivecraft.factions.event.FactionsEventDescriptionChange; +import com.massivecraft.factions.event.FactionsEventDisband; import com.massivecraft.factions.event.FactionsEventHomeChange; import com.massivecraft.factions.event.FactionsEventHomeTeleport; 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.FactionsEventTitleChange; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.mcore.money.Money; public class FactionsListenerEcon implements Listener { @@ -44,6 +46,51 @@ public class FactionsListenerEcon implements Listener 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("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 // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java index 91739826..fd613c15 100644 --- a/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/TodoFactionsPlayerListener.java @@ -78,7 +78,7 @@ public class TodoFactionsPlayerListener implements Listener if (uplayerTo.getAutoClaimFor() != null) { - uplayerTo.attemptClaim(uplayerTo.getAutoClaimFor(), PS.valueOf(event.getTo()), true); + uplayerTo.tryClaim(uplayerTo.getAutoClaimFor(), PS.valueOf(event.getTo()), true, true); } }