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

116 lines
3.0 KiB
Java
Raw Normal View History

2011-07-31 03:17:00 +02:00
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;
2011-10-09 18:35:39 +02:00
import com.massivecraft.factions.struct.Permission;
2011-07-31 03:17:00 +02:00
import com.massivecraft.factions.struct.Role;
2011-10-09 20:10:19 +02:00
public class CmdOwner extends FCommand
2011-10-09 18:35:39 +02:00
{
2011-07-31 03:17:00 +02:00
2011-10-09 20:10:19 +02:00
public CmdOwner()
2011-10-09 18:35:39 +02:00
{
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;
2011-07-31 03:17:00 +02:00
}
2011-10-09 18:35:39 +02:00
// TODO: Fix colors!
2011-07-31 03:17:00 +02:00
@Override
2011-10-09 18:35:39 +02:00
public void perform()
{
if( isLocked() )
{
sendLockMessage();
2011-07-31 03:17:00 +02:00
return;
}
2011-10-09 18:35:39 +02:00
boolean hasBypass = fme.isAdminBypassing();
if ( ! hasBypass && ! assertHasFaction()) {
2011-07-31 03:17:00 +02:00
return;
}
2011-10-09 18:35:39 +02:00
if ( ! Conf.ownedAreasEnabled)
{
fme.sendMessageParsed("<b>Sorry, but owned areas are disabled on this server.");
2011-07-31 03:17:00 +02:00
return;
}
2011-10-09 18:35:39 +02:00
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);
2011-07-31 03:17:00 +02:00
return;
}
2011-10-09 18:35:39 +02:00
if ( ! hasBypass && !assertMinRole(Conf.ownedAreasModeratorsCanSet ? Role.MODERATOR : Role.ADMIN))
{
2011-07-31 03:17:00 +02:00
return;
}
FLocation flocation = new FLocation(fme);
2011-07-31 03:17:00 +02:00
2011-10-09 18:35:39 +02:00
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.");
2011-07-31 03:17:00 +02:00
return;
}
2011-10-09 18:35:39 +02:00
if ( ! factionHere.isNormal())
{
fme.sendMessageParsed("<b>This land is not claimed by a faction. Ownership is not possible.");
2011-07-31 03:17:00 +02:00
return;
}
}
2011-10-09 18:35:39 +02:00
FPlayer target = this.argAsBestFPlayerMatch(0, fme);
if (target == null) return;
2011-07-31 03:17:00 +02:00
String playerName = target.getName();
2011-10-09 18:35:39 +02:00
if (target.getFaction() != myFaction)
{
fme.sendMessageParsed("%s<i> is not a member of this faction.", playerName);
2011-07-31 03:17:00 +02:00
return;
}
// if no player name was passed, and this claim does already have owners set, clear them
2011-10-09 18:35:39 +02:00
if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation))
{
2011-07-31 03:17:00 +02:00
myFaction.clearClaimOwnership(flocation);
2011-10-09 18:35:39 +02:00
fme.sendMessageParsed("<i>You have cleared ownership for this claimed area.");
2011-07-31 03:17:00 +02:00
return;
}
2011-10-09 18:35:39 +02:00
if (myFaction.isPlayerInOwnerList(playerName, flocation))
{
2011-07-31 03:17:00 +02:00
myFaction.removePlayerAsOwner(playerName, flocation);
2011-10-09 18:35:39 +02:00
fme.sendMessageParsed("<i>You have removed ownership of this claimed land from %s<i>.", playerName);
2011-07-31 03:17:00 +02:00
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
2011-10-09 18:35:39 +02:00
if ( ! payForCommand(Conf.econCostOwner)) return;
2011-07-31 03:17:00 +02:00
myFaction.setPlayerAsOwner(playerName, flocation);
2011-10-09 18:35:39 +02:00
fme.sendMessageParsed("<i>You have added %s<i> to the owner list for this claimed land.", playerName);
2011-07-31 03:17:00 +02:00
}
}