2011-07-18 22:06:02 +02:00
|
|
|
package com.massivecraft.factions.commands;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2011-07-22 07:25:12 -05:00
|
|
|
import java.util.Arrays;
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-30 20:17:00 -05:00
|
|
|
import java.util.Iterator;
|
2011-03-18 17:33:23 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-07-18 22:06:02 +02:00
|
|
|
|
|
|
|
import com.massivecraft.factions.Conf;
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-01 18:05:01 -05:00
|
|
|
import com.massivecraft.factions.Econ;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.Faction;
|
|
|
|
import com.massivecraft.factions.Factions;
|
|
|
|
import com.massivecraft.factions.struct.Role;
|
|
|
|
import com.massivecraft.factions.util.TextUtil;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
public class FBaseCommand {
|
2011-03-22 18:48:09 +01:00
|
|
|
public List<String> aliases;
|
2011-03-18 17:33:23 +01:00
|
|
|
public List<String> requiredParameters;
|
|
|
|
public List<String> optionalParameters;
|
|
|
|
|
|
|
|
public String helpNameAndParams;
|
|
|
|
public String helpDescription;
|
|
|
|
|
|
|
|
public CommandSender sender;
|
|
|
|
public boolean senderMustBePlayer;
|
2011-09-30 20:17:47 -05:00
|
|
|
public boolean senderIsConsole;
|
2011-03-18 17:33:23 +01:00
|
|
|
public Player player;
|
2011-03-19 13:00:03 +01:00
|
|
|
public FPlayer me;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
|
|
|
public List<String> parameters;
|
|
|
|
|
2011-05-08 17:16:43 +02:00
|
|
|
private static boolean lock = false;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
public FBaseCommand() {
|
2011-03-23 17:39:56 +01:00
|
|
|
aliases = new ArrayList<String>();
|
2011-03-18 17:33:23 +01:00
|
|
|
requiredParameters = new ArrayList<String>();
|
|
|
|
optionalParameters = new ArrayList<String>();
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
senderMustBePlayer = true;
|
2011-09-30 20:17:47 -05:00
|
|
|
senderIsConsole = false;
|
2011-03-18 17:33:23 +01:00
|
|
|
|
|
|
|
helpNameAndParams = "fail!";
|
|
|
|
helpDescription = "no description";
|
|
|
|
}
|
|
|
|
|
2011-03-22 18:48:09 +01:00
|
|
|
public List<String> getAliases() {
|
2011-03-18 17:33:23 +01:00
|
|
|
return aliases;
|
|
|
|
}
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-03-18 17:33:23 +01:00
|
|
|
public void execute(CommandSender sender, List<String> parameters) {
|
|
|
|
this.sender = sender;
|
|
|
|
this.parameters = parameters;
|
|
|
|
|
|
|
|
if ( ! validateCall()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-30 11:50:54 -05:00
|
|
|
if (sender instanceof Player) {
|
2011-03-18 17:33:23 +01:00
|
|
|
this.player = (Player)sender;
|
2011-03-19 13:00:03 +01:00
|
|
|
this.me = FPlayer.get(this.player);
|
2011-09-30 20:17:47 -05:00
|
|
|
senderIsConsole = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
senderIsConsole = true;
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
perform();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void perform() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendMessage(String message) {
|
|
|
|
sender.sendMessage(Conf.colorSystem+message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendMessage(List<String> messages) {
|
|
|
|
for(String message : messages) {
|
|
|
|
this.sendMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean validateCall() {
|
2011-09-30 20:17:47 -05:00
|
|
|
if ( this.senderMustBePlayer && senderIsConsole ) {
|
2011-03-23 17:39:56 +01:00
|
|
|
sendMessage("This command can only be used by ingame players.");
|
2011-03-18 17:33:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
if( ! hasPermission(sender)) {
|
|
|
|
sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+".");
|
2011-03-18 17:33:23 +01:00
|
|
|
return false;
|
2011-07-20 16:22:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure player doesn't have their access to the command revoked
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-30 20:17:00 -05:00
|
|
|
Iterator<String> iter = aliases.iterator();
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
if (Factions.isCommandDisabled(sender, iter.next())) {
|
|
|
|
sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+".");
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters.size() < requiredParameters.size()) {
|
2011-04-08 16:03:04 +02:00
|
|
|
sendMessage("Usage: "+this.getUseageTemplate(false));
|
2011-03-18 17:33:23 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
public boolean hasPermission(CommandSender sender) {
|
|
|
|
return Factions.hasPermParticipate(sender);
|
|
|
|
}
|
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// Help and usage description
|
|
|
|
// -------------------------------------------- //
|
2011-04-08 16:03:04 +02:00
|
|
|
|
|
|
|
public String getUseageTemplate(boolean withDescription) {
|
2011-03-22 15:45:41 +01:00
|
|
|
String ret = "";
|
|
|
|
|
2011-04-08 16:03:04 +02:00
|
|
|
ret += Conf.colorCommand;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
ret += Factions.instance.getBaseCommand()+ " " +TextUtil.implode(this.getAliases(), ",")+" ";
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
List<String> parts = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (String requiredParameter : this.requiredParameters) {
|
|
|
|
parts.add("["+requiredParameter+"]");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String optionalParameter : this.optionalParameters) {
|
|
|
|
parts.add("*["+optionalParameter+"]");
|
|
|
|
}
|
|
|
|
|
2011-04-08 16:03:04 +02:00
|
|
|
ret += Conf.colorParameter;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
ret += TextUtil.implode(parts, " ");
|
2011-03-22 18:48:09 +01:00
|
|
|
|
|
|
|
if (withDescription) {
|
|
|
|
ret += " "+Conf.colorSystem + this.helpDescription;
|
|
|
|
}
|
2011-03-22 15:45:41 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUseageTemplate() {
|
|
|
|
return getUseageTemplate(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// Assertions
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
public boolean assertHasFaction() {
|
|
|
|
if ( ! me.hasFaction()) {
|
|
|
|
sendMessage("You are not member of any faction.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean assertMinRole(Role role) {
|
2011-03-22 17:20:21 +01:00
|
|
|
if (me.getRole().value < role.value) {
|
2011-03-22 15:45:41 +01:00
|
|
|
sendMessage("You must be "+role+" to "+this.helpDescription+".");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// Commonly used logic
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
public FPlayer findFPlayer(String playerName, boolean defaultToMe) {
|
|
|
|
FPlayer fp = FPlayer.find(playerName);
|
|
|
|
|
|
|
|
if (fp == null) {
|
|
|
|
if (defaultToMe) {
|
|
|
|
return me;
|
|
|
|
}
|
|
|
|
sendMessage("The player \""+playerName+"\" could not be found");
|
|
|
|
}
|
|
|
|
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FPlayer findFPlayer(String playerName) {
|
|
|
|
return findFPlayer(playerName, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Faction findFaction(String factionName, boolean defaultToMine) {
|
2011-08-03 21:49:11 -05:00
|
|
|
// First we search faction names
|
2011-03-19 13:00:03 +01:00
|
|
|
Faction faction = Faction.findByTag(factionName);
|
|
|
|
if (faction != null) {
|
|
|
|
return faction;
|
|
|
|
}
|
2011-08-03 21:49:11 -05:00
|
|
|
|
|
|
|
// Next we search player names
|
|
|
|
FPlayer fp = FPlayer.find(factionName);
|
|
|
|
if (fp != null) {
|
|
|
|
return fp.getFaction();
|
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-09-30 20:17:47 -05:00
|
|
|
if (defaultToMine && !senderIsConsole) {
|
2011-03-19 13:00:03 +01:00
|
|
|
return me.getFaction();
|
|
|
|
}
|
|
|
|
|
2011-06-30 05:56:02 -05:00
|
|
|
sendMessage(Conf.colorSystem+"No faction or player \""+factionName+"\" was found");
|
2011-03-19 13:00:03 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Faction findFaction(String factionName) {
|
|
|
|
return findFaction(factionName, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canIAdministerYou(FPlayer i, FPlayer you) {
|
|
|
|
if ( ! i.getFaction().equals(you.getFaction())) {
|
|
|
|
i.sendMessage(you.getNameAndRelevant(i)+Conf.colorSystem+" is not in the same faction as you.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.ADMIN) ) {
|
2011-03-19 13:00:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
if (you.getRole().equals(Role.ADMIN)) {
|
2011-03-19 13:00:03 +01:00
|
|
|
i.sendMessage(Conf.colorSystem+"Only the faction admin can do that.");
|
2011-03-22 17:20:21 +01:00
|
|
|
} else if (i.getRole().equals(Role.MODERATOR)) {
|
2011-03-19 13:00:03 +01:00
|
|
|
i.sendMessage(Conf.colorSystem+"Moderators can't control each other...");
|
|
|
|
} else {
|
|
|
|
i.sendMessage(Conf.colorSystem+"You must be a faction moderator to do that.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-22 18:48:09 +01:00
|
|
|
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-01 18:05:01 -05:00
|
|
|
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
|
|
|
|
public boolean payForCommand(double cost) {
|
|
|
|
if (!Econ.enabled() || this.me == null || cost == 0.0 || Conf.adminBypassPlayers.contains(me.getName())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String desc = this.helpDescription.toLowerCase();
|
|
|
|
|
|
|
|
// pay up
|
|
|
|
if (cost > 0.0) {
|
|
|
|
String costString = Econ.moneyString(cost);
|
|
|
|
if (!Econ.deductMoney(me.getName(), cost)) {
|
|
|
|
sendMessage("It costs "+costString+" to "+desc+", which you can't currently afford.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sendMessage("You have paid "+costString+" to "+desc+".");
|
|
|
|
}
|
|
|
|
// wait... we pay you to use this command?
|
|
|
|
else {
|
|
|
|
String costString = Econ.moneyString(-cost);
|
|
|
|
Econ.addMoney(me.getName(), -cost);
|
|
|
|
sendMessage("You have been paid "+costString+" to "+desc+".");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-22 07:25:12 -05:00
|
|
|
public static final List<String> aliasTrue = new ArrayList<String>(Arrays.asList("true", "yes", "y", "ok", "on", "+"));
|
|
|
|
public static final List<String> aliasFalse = new ArrayList<String>(Arrays.asList("false", "no", "n", "off", "-"));
|
|
|
|
|
2011-03-22 18:48:09 +01:00
|
|
|
public boolean parseBool(String str) {
|
|
|
|
return aliasTrue.contains(str.toLowerCase());
|
|
|
|
}
|
2011-05-08 17:16:43 +02:00
|
|
|
|
|
|
|
public void setLock(boolean newLock) {
|
|
|
|
if( newLock ) {
|
2011-06-10 14:22:29 -05:00
|
|
|
sendMessage("Factions is now locked");
|
2011-05-08 17:16:43 +02:00
|
|
|
} else {
|
2011-06-10 14:22:29 -05:00
|
|
|
sendMessage("Factions in now unlocked");
|
2011-05-08 17:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lock = newLock;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isLocked() {
|
|
|
|
return lock;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendLockMessage() {
|
|
|
|
me.sendMessage("Factions is locked. Please try again later");
|
|
|
|
}
|
2011-03-18 17:33:23 +01:00
|
|
|
}
|