Saber-Factions/src/com/massivecraft/factions/commands/FCommandOwner.java

116 lines
3.0 KiB
Java

package com.massivecraft.factions.commands;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class FCommandOwner extends FCommand
{
public FCommandOwner()
{
super();
this.aliases.add("owner");
//this.requiredArgs.add("");
this.optionalArgs.put("player name", "you");
this.permission = Permission.COMMAND_OWNER.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
// TODO: Fix colors!
@Override
public void perform()
{
if( isLocked() )
{
sendLockMessage();
return;
}
boolean hasBypass = fme.isAdminBypassing();
if ( ! hasBypass && ! assertHasFaction()) {
return;
}
if ( ! Conf.ownedAreasEnabled)
{
fme.sendMessageParsed("<b>Sorry, but owned areas are disabled on this server.");
return;
}
if ( ! hasBypass && Conf.ownedAreasLimitPerFaction > 0 && myFaction.getCountOfClaimsWithOwners() >= Conf.ownedAreasLimitPerFaction)
{
fme.sendMessageParsed("<b>Sorry, but you have reached the server's <h>limit of %d <b>owned areas per faction.", Conf.ownedAreasLimitPerFaction);
return;
}
if ( ! hasBypass && !assertMinRole(Conf.ownedAreasModeratorsCanSet ? Role.MODERATOR : Role.ADMIN))
{
return;
}
FLocation flocation = new FLocation(fme);
Faction factionHere = Board.getFactionAt(flocation);
if (factionHere != myFaction)
{
if ( ! hasBypass)
{
fme.sendMessageParsed("<b>This land is not claimed by your faction, so you can't set ownership of it.");
return;
}
if ( ! factionHere.isNormal())
{
fme.sendMessageParsed("<b>This land is not claimed by a faction. Ownership is not possible.");
return;
}
}
FPlayer target = this.argAsBestFPlayerMatch(0, fme);
if (target == null) return;
String playerName = target.getName();
if (target.getFaction() != myFaction)
{
fme.sendMessageParsed("%s<i> is not a member of this faction.", playerName);
return;
}
// if no player name was passed, and this claim does already have owners set, clear them
if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation))
{
myFaction.clearClaimOwnership(flocation);
fme.sendMessageParsed("<i>You have cleared ownership for this claimed area.");
return;
}
if (myFaction.isPlayerInOwnerList(playerName, flocation))
{
myFaction.removePlayerAsOwner(playerName, flocation);
fme.sendMessageParsed("<i>You have removed ownership of this claimed land from %s<i>.", playerName);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(Conf.econCostOwner)) return;
myFaction.setPlayerAsOwner(playerName, flocation);
fme.sendMessageParsed("<i>You have added %s<i> to the owner list for this claimed land.", playerName);
}
}