Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdOwner.java

116 lines
3.2 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2011-07-31 03:17:00 +02:00
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.integration.SpoutFeatures;
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");
2011-10-09 21:57:43 +02:00
this.permission = Permission.OWNER.node;
this.disableOnLock = true;
2011-10-09 18:35:39 +02:00
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()
{
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)
{
2011-10-10 13:40:24 +02:00
fme.msg("<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)
{
2011-10-10 13:40:24 +02:00
fme.msg("<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)
{
2011-10-10 13:40:24 +02:00
fme.msg("<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())
{
2011-10-10 13:40:24 +02:00
fme.msg("<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)
{
2011-10-10 13:40:24 +02:00
fme.msg("%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);
SpoutFeatures.updateOwnerListLoc(flocation);
2011-10-10 13:40:24 +02:00
fme.msg("<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);
SpoutFeatures.updateOwnerListLoc(flocation);
2011-10-10 13:40:24 +02:00
fme.msg("<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-12 18:48:47 +02:00
if ( ! payForCommand(Conf.econCostOwner, "to set ownership of claimed land", "for setting ownership of claimed land")) return;
2011-07-31 03:17:00 +02:00
myFaction.setPlayerAsOwner(playerName, flocation);
SpoutFeatures.updateOwnerListLoc(flocation);
2011-10-10 13:40:24 +02:00
fme.msg("<i>You have added %s<i> to the owner list for this claimed land.", playerName);
2011-07-31 03:17:00 +02:00
}
}