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:
		
							parent
							
								
									bd8d945c7b
								
							
						
					
					
						commit
						e0c6e71b91
					
				@ -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();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
@ -36,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, PS.valueOf(me), true);
 | 
			
		||||
		fme.tryClaim(forFaction, PS.valueOf(me), true, true);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@ -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("<b>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("<b>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;
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
@ -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("<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();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -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<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)
 | 
			
		||||
		{
 | 
			
		||||
			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());
 | 
			
		||||
		}*/
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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,9 +31,11 @@ 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);
 | 
			
		||||
		Set<PS> chunks = boardColl.getChunks(faction);
 | 
			
		||||
 | 
			
		||||
@ -679,7 +679,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
 | 
			
		||||
	
 | 
			
		||||
	public int getLandCount()
 | 
			
		||||
	{
 | 
			
		||||
		return BoardColls.get().getCount(this);
 | 
			
		||||
		return BoardColls.get().get(this).getCount(this);
 | 
			
		||||
	}
 | 
			
		||||
	public int getLandCountInWorld(String worldName)
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
@ -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<UPlayer> implements EconomyParticipator
 | 
			
		||||
@ -491,7 +488,9 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
 | 
			
		||||
 | 
			
		||||
		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.");
 | 
			
		||||
				return;
 | 
			
		||||
@ -502,22 +501,13 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
 | 
			
		||||
				msg("<b>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())
 | 
			
		||||
		{
 | 
			
		||||
			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();
 | 
			
		||||
		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("<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())
 | 
			
		||||
		// Validate
 | 
			
		||||
		if (newFaction == oldFaction)
 | 
			
		||||
		{
 | 
			
		||||
			msg("%s<i> already owns this land.", newFaction.describeTo(this, 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));
 | 
			
		||||
		}
 | 
			
		||||
		else if ( ! FPerm.TERRITORY.has(this, forFaction, true))
 | 
			
		||||
			int ownedLand = newFaction.getLandCount();
 | 
			
		||||
			
 | 
			
		||||
			if (!uconf.claimingFromOthersAllowed && oldFaction.isNormal())
 | 
			
		||||
			{
 | 
			
		||||
				msg("<b>You may not claim land from others.");
 | 
			
		||||
				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
 | 
			
		||||
			&& ! this.isUsingAdminMode()
 | 
			
		||||
			&& myFaction.getLandCountInWorld(ps.getWorld()) > 0
 | 
			
		||||
			&& !BoardColls.get().isConnectedPs(ps, myFaction)
 | 
			
		||||
			&& (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal())
 | 
			
		||||
				&& newFaction.getLandCountInWorld(ps.getWorld()) > 0
 | 
			
		||||
				&& !BoardColls.get().isConnectedPs(ps, newFaction)
 | 
			
		||||
				&& (!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !oldFaction.isNormal())
 | 
			
		||||
			)
 | 
			
		||||
			{
 | 
			
		||||
				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
 | 
			
		||||
				error = Txt.parse("<b>You can only claim additional land which is connected to your first claim!");
 | 
			
		||||
		}
 | 
			
		||||
		else if (currentFaction.isNormal())
 | 
			
		||||
				{
 | 
			
		||||
			if ( ! currentFaction.hasLandInflation())
 | 
			
		||||
			{
 | 
			
		||||
				 // 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.");
 | 
			
		||||
					msg("<b>You can only claim additional land which is connected to your first claim!");
 | 
			
		||||
				}
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
		if (notifyFailure && error != null)
 | 
			
		||||
			if (!oldFaction.hasLandInflation())
 | 
			
		||||
			{
 | 
			
		||||
			msg(error);
 | 
			
		||||
		}
 | 
			
		||||
		return error == null;
 | 
			
		||||
				msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getTag(this));
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
	// 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)
 | 
			
		||||
			if ( ! BoardColls.get().isBorderPs(ps))
 | 
			
		||||
			{
 | 
			
		||||
		psChunk = psChunk.getChunk(true);
 | 
			
		||||
		Faction currentFaction = BoardColls.get().getFactionAt(psChunk);
 | 
			
		||||
		
 | 
			
		||||
		if ( ! this.canClaimForFactionAtLocation(forFaction, psChunk, notifyFailure)) return false;
 | 
			
		||||
				msg("<b>You must start claiming land at the border of the territory.");
 | 
			
		||||
				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<UPlayer> informTheseUPlayers = new HashSet<UPlayer>();
 | 
			
		||||
		informTheseUPlayers.add(this);
 | 
			
		||||
		informTheseUPlayers.addAll(forFaction.getUPlayersWhereOnline(true));
 | 
			
		||||
		for (UPlayer fp : informTheseUPlayers)
 | 
			
		||||
		// Apply
 | 
			
		||||
		BoardColls.get().setFactionAt(chunk, newFaction);
 | 
			
		||||
		
 | 
			
		||||
		// Inform
 | 
			
		||||
		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)
 | 
			
		||||
		{
 | 
			
		||||
			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;
 | 
			
		||||
 | 
			
		||||
@ -99,7 +99,7 @@ public class UPlayerColl extends SenderColl<UPlayer>
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			uplayer.resetFactionData();
 | 
			
		||||
			uplayer.leave();
 | 
			
		||||
			uplayer.detach();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -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("<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
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user