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

100 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
2014-04-04 20:55:21 +02:00
import com.massivecraft.factions.*;
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;
2014-04-04 20:55:21 +02:00
public class CmdOwner extends FCommand {
public CmdOwner() {
2014-07-01 22:10:18 +02:00
super();
this.aliases.add("owner");
2014-04-04 20:55:21 +02:00
//this.requiredArgs.add("");
this.optionalArgs.put("player name", "you");
2014-07-01 22:10:18 +02:00
this.permission = Permission.OWNER.node;
this.disableOnLock = true;
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
2014-04-04 20:55:21 +02:00
}
// TODO: Fix colors!
@Override
public void perform() {
boolean hasBypass = fme.isAdminBypassing();
if (!hasBypass && !assertHasFaction()) {
return;
}
if (!Conf.ownedAreasEnabled) {
2014-07-01 22:10:18 +02:00
fme.msg("<b>Sorry, but owned areas are disabled on this server.");
return;
2014-04-04 20:55:21 +02:00
}
if (!hasBypass && Conf.ownedAreasLimitPerFaction > 0 && myFaction.getCountOfClaimsWithOwners() >= Conf.ownedAreasLimitPerFaction) {
fme.msg("<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.getInstance().getFactionAt(flocation);
2014-07-01 22:10:18 +02:00
if (factionHere != myFaction) {
2014-04-04 20:55:21 +02:00
if (!hasBypass) {
2014-07-01 22:10:18 +02:00
fme.msg("<b>This land is not claimed by your faction, so you can't set ownership of it.");
return;
2014-04-04 20:55:21 +02:00
}
if (!factionHere.isNormal()) {
2014-07-01 22:10:18 +02:00
fme.msg("<b>This land is not claimed by a faction. Ownership is not possible.");
return;
2014-04-04 20:55:21 +02:00
}
}
2014-07-01 22:10:18 +02:00
FPlayer target = this.argAsBestFPlayerMatch(0, fme);
if (target == null) {
return;
}
2014-04-04 20:55:21 +02:00
String playerName = target.getName();
if (target.getFaction() != myFaction) {
2014-07-01 22:10:18 +02:00
fme.msg("%s<i> is not a member of this faction.", playerName);
return;
2014-04-04 20:55:21 +02:00
}
// if no player name was passed, and this claim does already have owners set, clear them
if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation)) {
2014-07-01 22:10:18 +02:00
myFaction.clearClaimOwnership(flocation);
fme.msg("<i>You have cleared ownership for this claimed area.");
2014-04-04 20:55:21 +02:00
return;
}
2014-04-17 03:10:12 +02:00
if (myFaction.isPlayerInOwnerList(target, flocation)) {
myFaction.removePlayerAsOwner(target, flocation);
2014-07-01 22:10:18 +02:00
fme.msg("<i>You have removed ownership of this claimed land from %s<i>.", playerName);
return;
2014-04-04 20:55:21 +02:00
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
2014-07-01 21:49:42 +02:00
if (!payForCommand(Conf.econCostOwner, "to set ownership of claimed land", "for setting ownership of claimed land")) {
2014-04-04 20:55:21 +02:00
return;
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
2014-04-17 03:10:12 +02:00
myFaction.setPlayerAsOwner(target, flocation);
2014-04-04 20:55:21 +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
}