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

106 lines
2.9 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.P;
2011-07-31 03:17:00 +02:00
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Role;
2011-10-08 23:22:02 +02:00
public class FCommandOwner extends FCommand {
2011-07-31 03:17:00 +02:00
public FCommandOwner() {
aliases.add("owner");
optionalParameters.add("player name");
helpDescription = "set ownership of claimed land";
}
@Override
public void perform() {
boolean hasBypass = P.hasPermAdminBypass(fme);
2011-07-31 03:17:00 +02:00
if ( ! hasBypass && ! assertHasFaction()) {
return;
}
if( isLocked() ) {
sendLockMessage();
return;
}
if ( ! Conf.ownedAreasEnabled) {
fme.sendMessage("Sorry, but owned areas are disabled on this server.");
2011-07-31 03:17:00 +02:00
return;
}
Faction myFaction = fme.getFaction();
2011-07-31 03:17:00 +02:00
if (!hasBypass && Conf.ownedAreasLimitPerFaction > 0 && myFaction.getCountOfClaimsWithOwners() >= Conf.ownedAreasLimitPerFaction) {
fme.sendMessage("Sorry, but you have reached the server's limit of "+Conf.ownedAreasLimitPerFaction+" owned areas per faction.");
2011-07-31 03:17:00 +02:00
return;
}
if (!hasBypass && !assertMinRole(Conf.ownedAreasModeratorsCanSet ? Role.MODERATOR : Role.ADMIN)) {
return;
}
FLocation flocation = new FLocation(fme);
2011-07-31 03:17:00 +02:00
if (Board.getIdAt(flocation) != myFaction.getId()) {
if (!hasBypass) {
fme.sendMessage("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;
}
myFaction = Board.getFactionAt(flocation);
if (!myFaction.isNormal()) {
fme.sendMessage("This land is not claimed by a faction. Ownership is not possible.");
2011-07-31 03:17:00 +02:00
return;
}
}
FPlayer target;
if (parameters.size() > 0) {
target = findFPlayer(parameters.get(0), false);
} else {
target = fme;
2011-07-31 03:17:00 +02:00
}
if (target == null) {
return;
}
String playerName = target.getName();
if (target.getFaction().getId() != myFaction.getId()) {
fme.sendMessage(playerName + " is not a member of this faction.");
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
if (parameters.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation)) {
myFaction.clearClaimOwnership(flocation);
fme.sendMessage("You have cleared ownership for this claimed area.");
2011-07-31 03:17:00 +02:00
return;
}
if (myFaction.isPlayerInOwnerList(playerName, flocation)) {
myFaction.removePlayerAsOwner(playerName, flocation);
fme.sendMessage("You have removed ownership of this claimed land from "+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
if (!payForCommand(Conf.econCostOwner)) {
return;
}
2011-07-31 03:17:00 +02:00
myFaction.setPlayerAsOwner(playerName, flocation);
fme.sendMessage("You have added "+playerName+" to the owner list for this claimed land.");
2011-07-31 03:17:00 +02:00
}
}