}
}
public boolean tryClaim(Faction newFaction, PS ps, boolean verbooseChange, boolean verbooseSame)
{
PS chunk = ps.getChunk(true);
Faction oldFaction = BoardColls.get().getFactionAt(chunk);
UConf uconf = UConf.get(newFaction);
MConf mconf = MConf.get();
// Validate
if (newFaction == oldFaction)
{
msg("%s<i> already owns this land.", newFaction.describeTo(this, true));
return true;
}
if (!this.isUsingAdminMode())
{
if (newFaction.isNormal())
{
if (mconf.worldsNoClaiming.contains(ps.getWorld()))
{
msg("<b>Sorry, this world has land claiming disabled.");
return false;
}
if (!FPerm.TERRITORY.has(this, newFaction, true))
{
return false;
}
if (newFaction.getUPlayers().size() < uconf.claimsRequireMinFactionMembers)
{
msg("Factions must have at least <h>%s<b> members to claim land.", uconf.claimsRequireMinFactionMembers);
return false;
}
int ownedLand = newFaction.getLandCount();
if (uconf.claimedLandsMax != 0 && ownedLand >= uconf.claimedLandsMax && ! newFaction.getFlag(FFlag.INFPOWER))
{
msg("<b>Limit reached. You can't claim more land.");
return false;
}
if (ownedLand >= newFaction.getPowerRounded())
{
msg("<b>You can't claim more land. You need more power.");
return false;
}
if
(
uconf.claimsMustBeConnected
&&
newFaction.getLandCountInWorld(ps.getWorld()) > 0
&&
!BoardColls.get().isConnectedPs(chunk, newFaction)
&&
(!uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || oldFaction.isNone())
)
{
if (uconf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
{
msg("<b>You can only claim additional land which is connected to your first claim or controlled by another faction!");
}
else
{
msg("<b>You can only claim additional land which is connected to your first claim!");
}
return false;
}
}
if (oldFaction.isNormal())
{
if (!FPerm.TERRITORY.has(this, oldFaction, false))
{
if (!uconf.claimingFromOthersAllowed)
{
msg("<b>You may not claim land from others.");
return false;
}
if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE))
{
msg("<b>You can't claim this land due to your relation with the current owner.");
return false;
}
if (!oldFaction.hasLandInflation())
{
msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getName(this));
return false;
}
if ( ! BoardColls.get().isBorderPs(chunk))
{
msg("<b>You must start claiming land at the border of the territory.");
return false;
}
}
}
}
// Event
FactionsEventChunkChange event = new FactionsEventChunkChange(sender, chunk, newFaction);
event.run();
if (event.isCancelled()) return false;
// Apply
BoardColls.get().setFactionAt(chunk, newFaction);
// Inform
Set<UPlayer> informees = new HashSet<UPlayer>();
informees.add(this);
if (newFaction.isNormal())
{
informees.addAll(newFaction.getUPlayers());
}
if (oldFaction.isNormal())
{
informees.addAll(oldFaction.getUPlayers());
}
if (MConf.get().logLandClaims)
{
informees.add(UPlayer.get(SenderUtil.getConsole()));
}
String chunkString = chunk.toString(PSFormatHumanSpace.get());
String typeString = event.getType().toString().toLowerCase();
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), typeString, chunkString, newFaction.describeTo(informee), oldFaction.describeTo(informee));
}