This commit is contained in:
Olof Larsson
2011-10-09 21:57:43 +02:00
parent 3cdd5764d3
commit a5c8e2de49
59 changed files with 361 additions and 482 deletions

View File

@ -0,0 +1,62 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdAdmin extends FCommand
{
public CmdAdmin()
{
super();
this.aliases.add("admin");
this.requiredArgs.add("player name");
//this.optionalArgs.put("", "");
this.permission = Permission.ADMIN.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = true;
}
@Override
public void perform()
{
FPlayer fyou = this.argAsBestFPlayerMatch(0);
if (fyou == null) return;
if (fyou.getFaction() != myFaction)
{
sendMessageParsed("%s<i> is not a member in your faction.", fyou.getNameAndRelevant(fme));
return;
}
if (fyou == fme)
{
sendMessageParsed("<b>The target player musn't be yourself.");
return;
}
fme.setRole(Role.MODERATOR);
fyou.setRole(Role.ADMIN);
// Inform all players
for (FPlayer fplayer : FPlayers.i.getOnline())
{
if (fplayer.getFaction() == myFaction)
{
fplayer.sendMessageParsed("%s<i> gave %s<i> the leadership of your faction.", fme.getNameAndRelevant(fme), fyou.getNameAndRelevant(fme));
}
else
{
fplayer.sendMessageParsed("%s<i> gave %s<i> the leadership of %s", fme.getNameAndRelevant(fplayer), fyou.getNameAndRelevant(fplayer), myFaction.getTag(fplayer));
}
}
}
}

View File

@ -0,0 +1,59 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.struct.Permission;
public class CmdAutoClaim extends FCommand
{
public CmdAutoClaim()
{
super();
this.aliases.add("autoclaim");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flipp");
this.permission = Permission.AUTOCLAIM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
boolean enabled = this.argAsBool(0, ! fme.isAutoClaimEnabled());
fme.setIsAutoClaimEnabled(enabled);
if ( ! enabled)
{
sendMessageParsed("<i>Auto-claiming of land disabled.");
return;
}
FLocation flocation = new FLocation(fme);
if (Conf.worldsNoClaiming.contains(flocation.getWorldName()))
{
sendMessageParsed("<b>Sorry, this world has land claiming disabled.");
fme.setIsAutoClaimEnabled(false);
return;
}
if (myFaction.getLandRounded() >= myFaction.getPowerRounded())
{
sendMessageParsed("<b>You can't claim more land! You need more power!");
fme.setIsAutoClaimEnabled(false);
return;
}
sendMessageParsed("<i>Auto-claiming of land enabled.");
fme.attemptClaim(false);
}
}

View File

@ -0,0 +1,54 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdAutoSafeclaim extends FCommand
{
public CmdAutoSafeclaim()
{
super();
this.aliases.add("autosafe");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flipp");
this.permission = Permission.MANAGE_SAFE_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
this.setHelpShort("Auto-claim land for the safezone");
}
@Override
public void perform()
{
boolean enabled = this.argAsBool(0, ! fme.isAutoSafeClaimEnabled());
fme.setIsAutoSafeClaimEnabled(enabled);
if ( ! enabled)
{
sendMessageParsed("<i>Auto-claiming of safe zone disabled.");
return;
}
sendMessageParsed("<i>Auto-claiming of safe zone enabled.");
FLocation playerFlocation = new FLocation(fme);
if (!Board.getFactionAt(playerFlocation).isSafeZone())
{
Board.setFactionAt(Factions.i.getSafeZone(), playerFlocation);
sendMessageParsed("<i>This land is now a safe zone.");
}
}
}

View File

@ -0,0 +1,57 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdAutoWarclaim extends FCommand
{
public CmdAutoWarclaim()
{
super();
this.aliases.add("autosafe");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flipp");
this.permission = Permission.MANAGE_WAR_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
aliases.add("autowar");
this.setHelpShort("Auto-claim land for the warzone");
}
@Override
public void perform()
{
boolean enabled = this.argAsBool(0, ! fme.isAutoWarClaimEnabled());
fme.setIsAutoWarClaimEnabled(enabled);
if ( ! enabled)
{
sendMessageParsed("<i>Auto-claiming of war zone disabled.");
return;
}
sendMessageParsed("<i>Auto-claiming of war zone enabled.");
FLocation playerFlocation = new FLocation(fme);
if (!Board.getFactionAt(playerFlocation).isWarZone())
{
Board.setFactionAt(Factions.i.getWarZone(), playerFlocation);
sendMessageParsed("<i>This land is now a war zone.");
}
}
}

View File

@ -0,0 +1,54 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.Faction;
public class CmdBalance extends FCommand
{
public CmdBalance()
{
super();
this.aliases.add("balance");
this.aliases.add("money");
//this.requiredArgs.add("player name");
this.optionalArgs.put("factiontag", "yours");
this.permission = Permission.BALANCE.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.bankEnabled)
{
return;
}
Faction faction = this.argAsFaction(0, myFaction);
// TODO MAKE HIERARCHIAL COMMAND STRUCTURE HERE
if ( faction != myFaction && ! Permission.BALANCE_ANY.has(sender))
{
sendMessageParsed("<b>You do not have sufficient permissions to view the bank balance of other factions.");
return;
}
if (faction == null)
{
sendMessageParsed("<b>Faction %s<b> could not be found.", args.get(0));
return;
}
sendMessageParsed("<a>%s balance: %s", faction.getTag(), Econ.moneyString(faction.getMoney()));
}
}

View File

@ -0,0 +1,44 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.struct.Permission;
public class CmdBoom extends FCommand
{
public CmdBoom()
{
super();
this.aliases.add("noboom");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flipp");
this.permission = Permission.NO_BOOM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! myFaction.isPeaceful())
{
fme.sendMessageParsed("<b>This command is only usable by factions which are specially designated as peaceful.");
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.econCostNoBoom)) return;
myFaction.setPeacefulExplosionsEnabled(this.argAsBool(0, ! myFaction.getPeacefulExplosionsEnabled()));
String enabled = myFaction.noExplosionsInTerritory() ? "disabled" : "enabled";
// Inform
myFaction.sendMessageParsed("%s<i> has "+enabled+" explosions in your faction's territory.", fme.getNameAndRelevant(myFaction));
}
}

View File

@ -0,0 +1,42 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
public class CmdBypass extends FCommand
{
public CmdBypass()
{
super();
this.aliases.add("bypass");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flipp");
this.permission = Permission.BYPASS.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
fme.setIsAdminBypassing(this.argAsBool(0, ! fme.isAdminBypassing()));
// TODO: Move this to a transient field in the model??
if ( fme.isAdminBypassing())
{
fme.sendMessageParsed("<i>You have enabled admin bypass mode. You will be able to build or destroy anywhere.");
P.p.log(fme.getName() + " has ENABLED admin bypass mode.");
}
else
{
fme.sendMessageParsed("<i>You have disabled admin bypass mode.");
P.p.log(fme.getName() + " DISABLED admin bypass mode.");
}
}
}

View File

@ -0,0 +1,73 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Permission;
public class CmdChat extends FCommand
{
public CmdChat()
{
super();
this.aliases.add("c");
this.aliases.add("chat");
//this.requiredArgs.add("");
this.optionalArgs.put("mode", "next");
this.permission = Permission.CHAT.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.factionOnlyChat )
{
sendMessageParsed("<b>Faction-only chat is disabled on this server.");
return;
}
String modeString = this.argAsString(0).toLowerCase();
ChatMode modeTarget = fme.getChatMode().getNext();
if (modeString != null)
{
if(modeString.startsWith("p"))
{
modeTarget = ChatMode.PUBLIC;
}
else if (modeString.startsWith("a"))
{
modeTarget = ChatMode.ALLIANCE;
}
else if(modeString.startsWith("f"))
{
modeTarget = ChatMode.FACTION;
}
sendMessageParsed("<b>Unrecognised chat mode. <i>Please enter either 'a','f' or 'p'");
return;
}
fme.setChatMode(modeTarget);
if(fme.getChatMode() == ChatMode.PUBLIC)
{
sendMessageParsed("<i>Public chat mode.");
}
else if (fme.getChatMode() == ChatMode.ALLIANCE )
{
sendMessageParsed("<i>Alliance only chat mode.");
}
else
{
sendMessageParsed("<i>Faction only chat mode.");
}
}
}

View File

@ -0,0 +1,33 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
public class CmdClaim extends FCommand
{
public CmdClaim()
{
super();
this.aliases.add("claim");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.CLAIM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
aliases.add("claim");
}
@Override
public void perform()
{
fme.attemptClaim(true);
}
}

View File

@ -0,0 +1,269 @@
package com.massivecraft.factions.cmd;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Set;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission;
public class CmdConfig extends FCommand
{
private static HashMap<String, String> properFieldNames = new HashMap<String, String>();
public CmdConfig()
{
super();
this.aliases.add("config");
this.requiredArgs.add("setting");
this.requiredArgs.add("value");
this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.CONFIG.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
// store a lookup map of lowercase field names paired with proper capitalization field names
// that way, if the person using this command messes up the capitalization, we can fix that
if (properFieldNames.isEmpty())
{
Field[] fields = Conf.class.getDeclaredFields();
for(int i = 0; i < fields.length; i++)
{
properFieldNames.put(fields[i].getName().toLowerCase(), fields[i].getName());
}
}
String field = this.argAsString(0).toLowerCase();
if (field.startsWith("\"") && field.endsWith("\""))
{
field = field.substring(1, field.length() - 1);
}
String fieldName = properFieldNames.get(field);
if (fieldName == null || fieldName.isEmpty())
{
sendMessageParsed("<b>No configuration setting \"<h>%s<b>\" exists.", field);
return;
}
String success = "";
String value = args.get(1);
for(int i = 2; i < args.size(); i++)
{
value += ' ' + args.get(i);
}
try
{
Field target = Conf.class.getField(fieldName);
// boolean
if (target.getType() == boolean.class)
{
boolean targetValue = this.strAsBool(value);
target.setBoolean(null, targetValue);
if (targetValue)
{
success = "\""+fieldName+"\" option set to true (enabled).";
}
else
{
success = "\""+fieldName+"\" option set to false (disabled).";
}
}
// int
else if (target.getType() == int.class)
{
try
{
int intVal = Integer.parseInt(value);
target.setInt(null, intVal);
success = "\""+fieldName+"\" option set to "+intVal+".";
}
catch(NumberFormatException ex)
{
sendMessage("Cannot set \""+fieldName+"\": integer (whole number) value required.");
return;
}
}
// double
else if (target.getType() == double.class)
{
try
{
double doubleVal = Double.parseDouble(value);
target.setDouble(null, doubleVal);
success = "\""+fieldName+"\" option set to "+doubleVal+".";
}
catch(NumberFormatException ex)
{
sendMessage("Cannot set \""+fieldName+"\": double (numeric) value required.");
return;
}
}
// String
else if (target.getType() == String.class)
{
target.set(null, value);
success = "\""+fieldName+"\" option set to \""+value+"\".";
}
// ChatColor
else if (target.getType() == ChatColor.class)
{
ChatColor newColor = null;
try
{
newColor = ChatColor.valueOf(value.toUpperCase());
}
catch (IllegalArgumentException ex)
{
}
if (newColor == null)
{
sendMessage("Cannot set \""+fieldName+"\": \""+value.toUpperCase()+"\" is not a valid color.");
return;
}
target.set(null, newColor);
success = "\""+fieldName+"\" color option set to \""+value.toUpperCase()+"\".";
}
// Set<?> or other parameterized collection
else if (target.getGenericType() instanceof ParameterizedType)
{
ParameterizedType targSet = (ParameterizedType)target.getGenericType();
Type innerType = targSet.getActualTypeArguments()[0];
// not a Set, somehow, and that should be the only collection we're using in Conf.java
if (targSet.getRawType() != Set.class)
{
sendMessage("\""+fieldName+"\" is not a data collection type which can be modified with this command.");
return;
}
// Set<Material>
else if (innerType == Material.class)
{
Material newMat = null;
try
{
newMat = Material.valueOf(value.toUpperCase());
}
catch (IllegalArgumentException ex)
{
}
if (newMat == null)
{
sendMessage("Cannot change \""+fieldName+"\" set: \""+value.toUpperCase()+"\" is not a valid material.");
return;
}
@SuppressWarnings("unchecked")
Set<Material> matSet = (Set<Material>)target.get(null);
// Material already present, so remove it
if (matSet.contains(newMat))
{
matSet.remove(newMat);
target.set(null, matSet);
success = "\""+fieldName+"\" set: Material \""+value.toUpperCase()+"\" removed.";
}
// Material not present yet, add it
else
{
matSet.add(newMat);
target.set(null, matSet);
success = "\""+fieldName+"\" set: Material \""+value.toUpperCase()+"\" added.";
}
}
// Set<String>
else if (innerType == String.class)
{
@SuppressWarnings("unchecked")
Set<String> stringSet = (Set<String>)target.get(null);
// String already present, so remove it
if (stringSet.contains(value))
{
stringSet.remove(value);
target.set(null, stringSet);
success = "\""+fieldName+"\" set: \""+value+"\" removed.";
}
// String not present yet, add it
else
{
stringSet.add(value);
target.set(null, stringSet);
success = "\""+fieldName+"\" set: \""+value+"\" added.";
}
}
// Set of unknown type
else
{
sendMessage("\""+fieldName+"\" is not a data type set which can be modified with this command.");
return;
}
}
// unknown type
else
{
sendMessage("\""+fieldName+"\" is not a data type which can be modified with this command.");
return;
}
}
catch (NoSuchFieldException ex)
{
sendMessage("Configuration setting \""+fieldName+"\" couldn't be matched, though it should be... please report this error.");
return;
}
catch (IllegalAccessException ex)
{
sendMessage("Error setting configuration setting \""+fieldName+"\" to \""+value+"\".");
return;
}
if (!success.isEmpty())
{
sendMessage(success);
if (sender instanceof Player)
{
P.p.log(success + " Command was run by "+fme.getName()+".");
}
}
// save change to disk
Conf.save();
// in case some Spout related setting was changed
SpoutFeatures.updateAppearances();
}
}

View File

@ -0,0 +1,76 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdCreate extends FCommand
{
public CmdCreate()
{
super();
this.aliases.add("create");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.CREATE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
String tag = this.argAsString(0);
if (fme.hasFaction())
{
sendMessage("You must leave your current faction first.");
return;
}
if (Factions.i.isTagTaken(tag))
{
sendMessage("That tag is already in use.");
return;
}
ArrayList<String> tagValidationErrors = Factions.validateTag(tag);
if (tagValidationErrors.size() > 0)
{
sendMessage(tagValidationErrors);
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.econCostCreate))
{
return;
}
Faction faction = Factions.i.create();
faction.setTag(tag);
fme.setRole(Role.ADMIN);
fme.setFaction(faction);
for (FPlayer follower : FPlayers.i.getOnline())
{
follower.sendMessageParsed("%s<i> created a new faction %s", fme.getNameAndRelevant(follower), faction.getTag(follower));
}
sendMessage("You should now: " + new CmdDescription().getUseageTemplate());
}
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
public class CmdDeinvite extends FCommand
{
public CmdDeinvite()
{
super();
this.aliases.add("deinvite");
this.aliases.add("deinv");
this.requiredArgs.add("player name");
//this.optionalArgs.put("", "");
this.permission = Permission.DEINVITE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return;
if (you.getFaction() == myFaction)
{
sendMessageParsed("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
sendMessageParsed("<i>You might want to: %s", new CmdKick().getUseageTemplate(false));
return;
}
myFaction.deinvite(you);
you.sendMessageParsed("%s<i> revoked your invitation to %s", fme.getNameAndRelevant(you), myFaction.getTag(you));
myFaction.sendMessageParsed("%s<i> revoked %s's<i> invitation.", fme.getNameAndRelevant(fme), you.getNameAndRelevant(fme));
}
}

View File

@ -0,0 +1,67 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
public class CmdDeposit extends FCommand
{
public CmdDeposit()
{
super();
this.aliases.add("deposit");
this.requiredArgs.add("amount");
//this.optionalArgs
this.permission = Permission.DEPOSIT.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.bankEnabled) return;
Faction faction = myFaction;
double amount = this.argAsDouble(0, 0);
if( amount > 0.0 )
{
String amountString = Econ.moneyString(amount);
if( ! Econ.deductMoney(fme.getName(), amount ) )
{
sendMessageParsed("<b>You cannot afford to deposit that much.");
}
else
{
faction.addMoney(amount);
sendMessage("You have deposited "+amountString+" into "+faction.getTag()+"'s bank.");
sendMessage(faction.getTag()+" now has "+Econ.moneyString(faction.getMoney()));
P.p.log(fme.getName() + " deposited "+amountString+" into "+faction.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayers.i.getOnline())
{
if (fplayer.getFaction() == faction)
{
fplayer.sendMessageParsed("%s has deposited %s", fme.getNameAndRelevant(fplayer), amountString);
}
}
}
}
}
}

View File

@ -0,0 +1,47 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TextUtil;
public class CmdDescription extends FCommand
{
public CmdDescription()
{
super();
this.aliases.add("desc");
this.requiredArgs.add("desc");
//this.optionalArgs
this.permission = Permission.DESCRIPTION.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(Conf.econCostDesc))
{
return;
}
myFaction.setDescription(TextUtil.implode(args, " "));
// Broadcast the description to everyone
for (FPlayer fplayer : FPlayers.i.getOnline())
{
fplayer.sendMessageParsed("The faction "+fplayer.getRelationColor(fme)+myFaction.getTag()+"<i> changed their description to:");
fplayer.sendMessageParsed("<i>"+myFaction.getDescription());
}
}
}

View File

@ -0,0 +1,90 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdDisband extends FCommand
{
public CmdDisband()
{
super();
this.aliases.add("disband");
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.DISBAND.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
// The faction, default to your own.. but null if console sender.
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
if (faction == null) return;
boolean isMyFaction = fme == null ? false : faction == myFaction;
if (isMyFaction)
{
if ( ! assertMinRole(Role.ADMIN)) return;
}
else
{
if ( ! Permission.DISBAND_ANY.has(me, true))
{
return;
}
}
if (faction.isPermanent())
{
sendMessageParsed("<i>This faction is designated as permanent, so you cannot disband it.");
return;
}
// Inform all players
for (FPlayer fplayer : FPlayers.i.getOnline())
{
String who = senderIsConsole ? "A server admin" : fme.getNameAndRelevant(fplayer);
if (fplayer.getFaction() == faction)
{
fplayer.sendMessageParsed("<h>%s<i> disbanded your faction.", who);
}
else
{
fplayer.sendMessageParsed("<h>%s<i> disbanded the faction %s.", who, faction.getTag(fplayer));
}
}
if (Conf.bankEnabled)
{
double amount = faction.getMoney();
Econ.addMoney(fme.getId(), amount); //Give all the faction's money to the disbander
if (amount > 0.0)
{
String amountString = Econ.moneyString(amount);
sendMessageParsed("<i>You have been given the disbanded faction's bank, totaling %s.", amountString);
P.p.log(fme.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+".");
}
}
faction.detach();
SpoutFeatures.updateAppearances();
}
}

View File

@ -0,0 +1,190 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
public class CmdHelp extends FCommand
{
public CmdHelp()
{
super();
this.aliases.add("help");
this.aliases.add("h");
this.aliases.add("?");
//this.requiredArgs.add("");
this.optionalArgs.put("page", "1");
this.permission = Permission.HELP.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
int page = this.argAsInt(0, 1);
sendMessage(p.txt.titleize("Factions Help ("+page+"/"+helpPages.size()+")"));
page -= 1;
if (page < 0 || page >= helpPages.size())
{
sendMessageParsed("<b>This page does not exist");
return;
}
sendMessage(helpPages.get(page));
}
//----------------------------------------------//
// Build the help pages
//----------------------------------------------//
public static ArrayList<ArrayList<String>> helpPages;
public static void updateHelp()
{
helpPages = new ArrayList<ArrayList<String>>();
ArrayList<String> pageLines;
pageLines = new ArrayList<String>();
pageLines.add( new CmdHelp().getUseageTemplate() );
pageLines.add( new CmdList().getUseageTemplate() );
pageLines.add( new CmdShow().getUseageTemplate() );
pageLines.add( new CmdPower().getUseageTemplate() );
pageLines.add( new CmdJoin().getUseageTemplate() );
pageLines.add( new CmdLeave().getUseageTemplate() );
pageLines.add( new CmdChat().getUseageTemplate() );
pageLines.add( new CmdHome().getUseageTemplate() );
pageLines.add( "Learn how to create a faction on the next page." );
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add( new CmdCreate().getUseageTemplate() );
pageLines.add( new CmdDescription().getUseageTemplate() );
pageLines.add( new CmdTag().getUseageTemplate() );
pageLines.add( "You might want to close it and use invitations:" );
pageLines.add( new CmdOpen().getUseageTemplate() );
pageLines.add( new CmdInvite().getUseageTemplate() );
pageLines.add( new CmdDeinvite().getUseageTemplate() );
pageLines.add( "And don't forget to set your home:" );
pageLines.add( new CmdSethome().getUseageTemplate() );
helpPages.add(pageLines);
if (Econ.enabled() && Conf.bankEnabled)
{
pageLines = new ArrayList<String>();
pageLines.add( "" );
pageLines.add( "Your faction has a bank which is used to pay for certain" );
pageLines.add( "things, so it will need to have money deposited into it." );
pageLines.add( "" );
pageLines.add( new CmdBalance().getUseageTemplate() );
pageLines.add( new CmdDeposit().getUseageTemplate() );
pageLines.add( new CmdWithdraw().getUseageTemplate() );
pageLines.add( new CmdPay().getUseageTemplate() );
pageLines.add( "" );
helpPages.add(pageLines);
}
pageLines = new ArrayList<String>();
pageLines.add( new CmdClaim().getUseageTemplate() );
pageLines.add( new CmdAutoClaim().getUseageTemplate() );
pageLines.add( new CmdUnclaim().getUseageTemplate() );
pageLines.add( new CmdUnclaimall().getUseageTemplate() );
pageLines.add( new CmdKick().getUseageTemplate() );
pageLines.add( new CmdMod().getUseageTemplate() );
pageLines.add( new CmdAdmin().getUseageTemplate() );
pageLines.add( new CmdTitle().getUseageTemplate() );
pageLines.add( "Player titles are just for fun. No rules connected to them." );
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add( new CmdMap().getUseageTemplate() );
pageLines.add( new CmdBoom().getUseageTemplate() );
pageLines.add("");
pageLines.add( new CmdOwner().getUseageTemplate() );
pageLines.add( new CmdOwnerList().getUseageTemplate() );
pageLines.add("");
pageLines.add("Claimed land with ownership set is further protected so");
pageLines.add("that only the owner(s), faction admin, and possibly the");
pageLines.add("faction moderators have full access.");
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add( new CmdDisband().getUseageTemplate() );
pageLines.add("");
pageLines.add( new CmdRelationAlly().getUseageTemplate() );
pageLines.add( new CmdRelationNeutral().getUseageTemplate() );
pageLines.add( new CmdRelationEnemy().getUseageTemplate() );
pageLines.add("Set the relation you WISH to have with another faction.");
pageLines.add("Your default relation with other factions will be neutral.");
pageLines.add("If BOTH factions choose \"ally\" you will be allies.");
pageLines.add("If ONE faction chooses \"enemy\" you will be enemies.");
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add("You can never hurt members or allies.");
pageLines.add("You can not hurt neutrals in their own territory.");
pageLines.add("You can always hurt enemies and players without faction.");
pageLines.add("");
pageLines.add("Damage from enemies is reduced in your own territory.");
pageLines.add("When you die you lose power. It is restored over time.");
pageLines.add("The power of a faction is the sum of all member power.");
pageLines.add("The power of a faction determines how much land it can hold.");
pageLines.add("You can claim land from factions with too little power.");
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add("Only faction members can build and destroy in their own");
pageLines.add("territory. Usage of the following items is also restricted:");
pageLines.add("Door, Chest, Furnace, Dispenser, Diode.");
pageLines.add("");
pageLines.add("Make sure to put pressure plates in front of doors for your");
pageLines.add("guest visitors. Otherwise they can't get through. You can");
pageLines.add("also use this to create member only areas.");
pageLines.add("As dispensers are protected, you can create traps without");
pageLines.add("worrying about those arrows getting stolen.");
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add("Finally some commands for the server admins:");
pageLines.add( new CmdBypass().getUseageTemplate() );
pageLines.add( new CmdSafeclaim().getUseageTemplate() );
pageLines.add( new CmdAutoSafeclaim().getUseageTemplate() );
pageLines.add( new CmdSafeunclaimall().getUseageTemplate() );
pageLines.add( new CmdWarclaim().getUseageTemplate() );
pageLines.add( new CmdAutoWarclaim().getUseageTemplate() );
pageLines.add( new CmdWarunclaimall().getUseageTemplate() );
pageLines.add("Note: " + new CmdUnclaim().getUseageTemplate(false) + P.p.txt.parse("<i>") + " works on safe/war zones as well.");
helpPages.add(pageLines);
pageLines = new ArrayList<String>();
pageLines.add("More commands for server admins:");
pageLines.add( new CmdPeaceful().getUseageTemplate() );
pageLines.add( new CmdPermanent().getUseageTemplate() );
pageLines.add("Peaceful factions are protected from PvP and land capture.");
pageLines.add( new CmdLock().getUseageTemplate() );
pageLines.add( new CmdReload().getUseageTemplate() );
pageLines.add( new CmdSaveAll().getUseageTemplate() );
pageLines.add( new CmdVersion().getUseageTemplate() );
pageLines.add( new CmdConfig().getUseageTemplate() );
helpPages.add(pageLines);
}
static
{
updateHelp();
}
}

View File

@ -0,0 +1,131 @@
package com.massivecraft.factions.cmd;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
public class CmdHome extends FCommand
{
public CmdHome()
{
super();
this.aliases.add("home");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.HOME.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
// TODO: Hide this command on help also.
if ( ! Conf.homesEnabled)
{
fme.sendMessage("Sorry, Faction homes are disabled on this server.");
return;
}
if ( ! Conf.homesTeleportCommandEnabled)
{
fme.sendMessage("Sorry, the ability to teleport to Faction homes is disabled on this server.");
return;
}
if ( ! myFaction.hasHome())
{
fme.sendMessage("You faction does not have a home. " + (fme.getRole().value < Role.MODERATOR.value ? " Ask your leader to:" : "You should:"));
fme.sendMessage(new CmdSethome().getUseageTemplate());
return;
}
if ( ! Conf.homesTeleportAllowedFromEnemyTerritory && fme.isInEnemyTerritory())
{
fme.sendMessage("You cannot teleport to your faction home while in the territory of an enemy faction.");
return;
}
if ( ! Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID())
{
fme.sendMessage("You cannot teleport to your faction home while in a different world.");
return;
}
Faction faction = Board.getFactionAt(new FLocation(me.getLocation()));
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
if
(
Conf.homesTeleportAllowedEnemyDistance > 0
&&
! faction.isSafeZone()
&&
(
! fme.isInOwnTerritory()
||
(
fme.isInOwnTerritory()
&&
! Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory
)
)
)
{
Location loc = me.getLocation();
World w = loc.getWorld();
double x = loc.getX();
double y = loc.getY();
double z = loc.getZ();
for (Player p : me.getServer().getOnlinePlayers())
{
if (p == null || !p.isOnline() || p.isDead() || p == fme || p.getWorld() != w)
continue;
FPlayer fp = FPlayers.i.get(p);
if (fme.getRelation(fp) != Relation.ENEMY)
continue;
Location l = p.getLocation();
double dx = Math.abs(x - l.getX());
double dy = Math.abs(y - l.getY());
double dz = Math.abs(z - l.getZ());
double max = Conf.homesTeleportAllowedEnemyDistance;
// box-shaped distance check
if (dx > max || dy > max || dz > max)
continue;
fme.sendMessage("You cannot teleport to your faction home while an enemy is within " + Conf.homesTeleportAllowedEnemyDistance + " blocks of you.");
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.econCostHome))
{
return;
}
me.teleport(myFaction.getHome());
}
}

View File

@ -0,0 +1,52 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
public class CmdInvite extends FCommand
{
public CmdInvite()
{
super();
this.aliases.add("invite");
this.aliases.add("inv");
this.requiredArgs.add("player name");
//this.optionalArgs.put("", "");
this.permission = Permission.INVITE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return;
if (you.getFaction() == myFaction)
{
sendMessageParsed("%s<i> is already a member of %s", you.getName(), myFaction.getTag());
sendMessageParsed("<i>You might want to: " + new CmdKick().getUseageTemplate(false));
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.econCostInvite))
{
return;
}
myFaction.invite(you);
you.sendMessageParsed("%s<i> invited you to %s", fme.getNameAndRelevant(you), myFaction.getTag(you));
myFaction.sendMessageParsed("%s<i> invited %s<i> to your faction.", fme.getNameAndRelevant(fme), you.getNameAndRelevant(fme));
}
}

View File

@ -0,0 +1,76 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
public class CmdJoin extends FCommand
{
public CmdJoin()
{
super();
this.aliases.add("join");
this.requiredArgs.add("faction name");
//this.optionalArgs.put("", "");
this.permission = Permission.JOIN.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
Faction faction = this.argAsFaction(0);
if (faction == null) return;
if ( ! faction.isNormal())
{
sendMessageParsed("<b>You may only join normal factions. This is a system faction.");
return;
}
if (faction == myFaction)
{
sendMessageParsed("<b>You are already a member of %s", faction.getTag(fme));
return;
}
if (fme.hasFaction())
{
sendMessageParsed("<b>You must leave your current faction first.");
return;
}
if (!Conf.CanLeaveWithNegativePower && fme.getPower() < 0)
{
sendMessageParsed("<b>You cannot join a faction until your power is positive.");
return;
}
if( ! faction.getOpen() && ! faction.isInvited(fme))
{
sendMessageParsed("<i>This guild requires invitation.");
faction.sendMessageParsed("%s<i> tried to join your faction.", fme.getNameAndRelevant(faction));
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.econCostJoin))
{
return;
}
fme.sendMessageParsed("<i>You successfully joined %s", faction.getTag(fme));
faction.sendMessageParsed("<i>%s joined your faction.", fme.getNameAndRelevant(faction));
fme.resetFactionData();
fme.setFaction(faction);
faction.deinvite(fme);
}
}

View File

@ -0,0 +1,94 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
public class CmdKick extends FCommand
{
public CmdKick()
{
super();
this.aliases.add("kick");
this.requiredArgs.add("player name");
//this.optionalArgs.put("", "");
this.permission = Permission.KICK.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return;
if (fme == you)
{
sendMessageParsed("<b>You cannot kick yourself.");
sendMessageParsed("<i>You might want to: %s", new CmdLeave().getUseageTemplate(false));
return;
}
Faction yourFaction = you.getFaction();
// players with admin-level "disband" permission can bypass these requirements
if ( ! Permission.KICK_ANY.has(sender))
{
if (yourFaction != myFaction)
{
sendMessageParsed("%s<b> is not a member of %s", you.getNameAndRelevant(fme), myFaction.getTag(fme));
return;
}
if (you.getRole().value >= fme.getRole().value)
{
// TODO add more informative messages.
sendMessageParsed("<b>Your rank is too low to kick this player.");
return;
}
if ( ! Conf.CanLeaveWithNegativePower && you.getPower() < 0)
{
sendMessageParsed("<b>You cannot kick that member until their power is positive.");
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.econCostKick))
{
return;
}
yourFaction.sendMessageParsed("%s<i> kicked %s<i> from the faction! :O", fme.getNameAndRelevant(yourFaction), you.getNameAndRelevant(yourFaction));
you.sendMessageParsed("%s<i> kicked you from %s<i>! :O", fme.getNameAndRelevant(you), yourFaction.getTag(you));
if (yourFaction != myFaction)
{
fme.sendMessageParsed("<i>You kicked %s<i> from the faction %s<i>!", you.getNameAndRelevant(myFaction), yourFaction.getTag(fme));
}
yourFaction.deinvite(you);
you.resetFactionData();
if (yourFaction.getFPlayers().isEmpty() && !yourFaction.isPermanent())
{
// Remove this faction
for (FPlayer fplayer : FPlayers.i.getOnline())
{
fplayer.sendMessageParsed("The faction %s<i> was disbanded.", yourFaction.getTag(fplayer));
}
yourFaction.detach();
}
}
}

View File

@ -0,0 +1,30 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
public class CmdLeave extends FCommand {
public CmdLeave()
{
super();
this.aliases.add("leave");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.LEAVE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
fme.leave(true);
}
}

View File

@ -0,0 +1,86 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdList extends FCommand
{
public CmdList()
{
super();
this.aliases.add("list");
this.aliases.add("ls");
//this.requiredArgs.add("");
this.optionalArgs.put("page", "1");
this.permission = Permission.LIST.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(Conf.econCostList)) return;
ArrayList<Faction> factionList = new ArrayList<Faction>(Factions.i.get());
factionList.remove(Factions.i.getNone());
factionList.remove(Factions.i.getSafeZone());
factionList.remove(Factions.i.getWarZone());
// Sort by total followers first
Collections.sort(factionList, new Comparator<Faction>(){
@Override
public int compare(Faction f1, Faction f2) {
if (f1.getFPlayers().size() < f2.getFPlayers().size())
return 1;
else if (f1.getFPlayers().size() > f2.getFPlayers().size())
return -1;
return 0;
}
});
// Then sort by how many members are online now
Collections.sort(factionList, new Comparator<Faction>(){
@Override
public int compare(Faction f1, Faction f2) {
if (f1.getFPlayersWhereOnline(true).size() < f2.getFPlayersWhereOnline(true).size())
return 1;
else if (f1.getFPlayersWhereOnline(true).size() > f2.getFPlayersWhereOnline(true).size())
return -1;
return 0;
}
});
ArrayList<String> lines = new ArrayList<String>();
lines.add(p.txt.parse("Factionless <i> %d online", Factions.i.getNone().getFPlayersWhereOnline(true).size()));
for (Faction faction : factionList)
{
lines.add(p.txt.parse("%s<i> %d/%d online, %d/%d/%d",
faction.getTag(fme),
faction.getFPlayersWhereOnline(true).size(),
faction.getFPlayers().size(),
faction.getLandRounded(),
faction.getPowerRounded(),
faction.getPowerMaxRounded())
);
}
sendMessage(p.txt.getPage(lines, this.argAsInt(0, 1), "Faction List"));
}
}

View File

@ -0,0 +1,46 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
public class CmdLock extends FCommand {
// TODO: This solution needs refactoring.
/*
factions.lock:
description: use the /f lock [on/off] command to temporarily lock the data files from being overwritten
default: op
*/
public CmdLock()
{
super();
this.aliases.add("lock");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flipp");
this.permission = Permission.LOCK.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
p.setLocked(this.argAsBool(0, ! p.getLocked()));
if( p.getLocked())
{
sendMessageParsed("<i>Factions is now locked");
}
else
{
sendMessageParsed("<i>Factions in now unlocked");
}
}
}

View File

@ -0,0 +1,67 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.struct.Permission;
public class CmdMap extends FCommand
{
public CmdMap()
{
super();
this.aliases.add("map");
//this.requiredArgs.add("");
this.optionalArgs.put("on/off", "once");
this.permission = Permission.MAP.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if (this.argIsSet(0))
{
if (this.argAsBool(0, ! fme.isMapAutoUpdating()))
{
// Turn on
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(Conf.econCostMap)) return;
fme.setMapAutoUpdating(true);
sendMessageParsed("<i>Map auto update <green>ENABLED.");
// And show the map once
showMap();
}
else
{
// Turn off
fme.setMapAutoUpdating(false);
sendMessageParsed("<i>Map auto update <red>DISABLED.");
}
}
else
{
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(Conf.econCostMap)) return;
showMap();
}
}
public void showMap()
{
sendMessage(Board.getMap(myFaction, new FLocation(fme), fme.getPlayer().getLocation().getYaw()));
}
}

View File

@ -0,0 +1,59 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdMod extends FCommand
{
public CmdMod()
{
super();
this.aliases.add("mod");
this.requiredArgs.add("player name");
//this.optionalArgs.put("", "");
this.permission = Permission.MOD.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = true;
}
@Override
public void perform()
{
FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return;
if (you.getFaction() != myFaction)
{
sendMessageParsed("%s<b> is not a member in your faction.", you.getNameAndRelevant(fme));
return;
}
if (you == fme)
{
sendMessageParsed("<b>The target player musn't be yourself.");
return;
}
if (you.getRole() == Role.MODERATOR)
{
// Revoke
you.setRole(Role.NORMAL);
myFaction.sendMessageParsed("%s<i> is no longer moderator in your faction.", you.getNameAndRelevant(myFaction));
}
else
{
// Give
you.setRole(Role.MODERATOR);
myFaction.sendMessageParsed("%s<i> was promoted to moderator in your faction.", you.getNameAndRelevant(myFaction));
}
}
}

View File

@ -0,0 +1,49 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdOpen extends FCommand
{
public CmdOpen()
{
super();
this.aliases.add("open");
//this.requiredArgs.add("");
this.optionalArgs.put("yes/no", "flipp");
this.permission = Permission.OPEN.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(Conf.econCostOpen)) return;
myFaction.setOpen(this.argAsBool(0, ! myFaction.getOpen()));
String open = myFaction.getOpen() ? "open" : "closed";
// Inform
myFaction.sendMessageParsed("%s<i> changed the faction to ", fme.getNameAndRelevant(myFaction));
for (Faction faction : Factions.i.get())
{
if (faction == myFaction)
{
continue;
}
faction.sendMessageParsed("<i>The faction %s<i> is now %s", myFaction.getTag(faction), open);
}
}
}

View File

@ -0,0 +1,110 @@
package com.massivecraft.factions.cmd;
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.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdOwner extends FCommand
{
public CmdOwner()
{
super();
this.aliases.add("owner");
//this.requiredArgs.add("");
this.optionalArgs.put("player name", "you");
this.permission = Permission.OWNER.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
// TODO: Fix colors!
@Override
public void perform()
{
boolean hasBypass = fme.isAdminBypassing();
if ( ! hasBypass && ! assertHasFaction()) {
return;
}
if ( ! Conf.ownedAreasEnabled)
{
fme.sendMessageParsed("<b>Sorry, but owned areas are disabled on this server.");
return;
}
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);
return;
}
if ( ! hasBypass && !assertMinRole(Conf.ownedAreasModeratorsCanSet ? Role.MODERATOR : Role.ADMIN))
{
return;
}
FLocation flocation = new FLocation(fme);
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.");
return;
}
if ( ! factionHere.isNormal())
{
fme.sendMessageParsed("<b>This land is not claimed by a faction. Ownership is not possible.");
return;
}
}
FPlayer target = this.argAsBestFPlayerMatch(0, fme);
if (target == null) return;
String playerName = target.getName();
if (target.getFaction() != myFaction)
{
fme.sendMessageParsed("%s<i> is not a member of this faction.", playerName);
return;
}
// if no player name was passed, and this claim does already have owners set, clear them
if (args.isEmpty() && myFaction.doesLocationHaveOwnersSet(flocation))
{
myFaction.clearClaimOwnership(flocation);
fme.sendMessageParsed("<i>You have cleared ownership for this claimed area.");
return;
}
if (myFaction.isPlayerInOwnerList(playerName, flocation))
{
myFaction.removePlayerAsOwner(playerName, flocation);
fme.sendMessageParsed("<i>You have removed ownership of this claimed land from %s<i>.", playerName);
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;
myFaction.setPlayerAsOwner(playerName, flocation);
fme.sendMessageParsed("<i>You have added %s<i> to the owner list for this claimed land.", playerName);
}
}

View File

@ -0,0 +1,73 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.struct.Permission;
public class CmdOwnerList extends FCommand
{
public CmdOwnerList()
{
super();
this.aliases.add("ownerlist");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.OWNERLIST.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
boolean hasBypass = fme.isAdminBypassing();
if ( ! hasBypass && ! assertHasFaction())
{
return;
}
if ( ! Conf.ownedAreasEnabled)
{
fme.sendMessageParsed("<b>Owned areas are disabled on this server.");
return;
}
FLocation flocation = new FLocation(fme);
if (Board.getIdAt(flocation) != myFaction.getId())
{
if (!hasBypass)
{
fme.sendMessageParsed("<b>This land is not claimed by your faction.");
return;
}
myFaction = Board.getFactionAt(flocation);
if (!myFaction.isNormal())
{
fme.sendMessageParsed("<i>This land is not claimed by any faction, thus no owners.");
return;
}
}
String owners = myFaction.getOwnerListString(flocation);
if (owners == null || owners.isEmpty())
{
fme.sendMessageParsed("<i>No owners are set here; everyone in the faction has access.");
return;
}
fme.sendMessageParsed("<i>Current owner(s) of this land: %s", owners);
}
}

View File

@ -0,0 +1,73 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdPay extends FCommand
{
public CmdPay()
{
this.aliases.add("pay");
this.requiredArgs.add("faction");
this.requiredArgs.add("amount");
//this.optionalArgs.put("", "");
this.permission = Permission.PAY.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.bankEnabled) return;
if ( ! Conf.bankMembersCanWithdraw && ! assertMinRole(Role.MODERATOR))
{
sendMessageParsed("<b>Only faction moderators or admins are able to pay another faction.");
return;
}
Faction us = fme.getFaction();
Faction them = this.argAsFaction(0);
if ( them == null ) return;
double amount = this.argAsDouble(1, 0d);
if( amount > 0.0 )
{
String amountString = Econ.moneyString(amount);
if( amount > us.getMoney() )
{
amount = us.getMoney();
}
us.removeMoney(amount);
them.addMoney(amount);
sendMessageParsed("<i>You have paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
sendMessageParsed("<i>"+us.getTag()+" now has "+Econ.moneyString(us.getMoney()));
P.p.log(fme.getName() + " paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayers.i.getOnline())
{
if (fplayer.getFaction() == us || fplayer.getFaction() == them)
{
fplayer.sendMessageParsed(fme.getNameAndRelevant(fplayer)+"<i> has sent "+amountString+" from "+us.getTag()+" to "+them.getTag());
}
}
}
}
}

View File

@ -0,0 +1,63 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission;
public class CmdPeaceful extends FCommand
{
public CmdPeaceful()
{
super();
this.aliases.add("peaceful");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.SET_PEACEFUL.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
Faction faction = this.argAsFaction(0);
if (faction == null) return;
String change;
if (faction.isPeaceful())
{
change = "removed peaceful status from";
faction.setPeaceful(false);
}
else
{
change = "granted peaceful status to";
faction.setPeaceful(true);
}
// Inform all players
for (FPlayer fplayer : FPlayers.i.getOnline())
{
if (fplayer.getFaction() == faction)
{
fplayer.sendMessageParsed(fme.getNameAndRelevant(fplayer)+"<i> has "+change+" your faction.");
}
else
{
fplayer.sendMessageParsed(fme.getNameAndRelevant(fplayer)+"<i> has "+change+" the faction \"" + faction.getTag(fplayer) + "\".");
}
}
SpoutFeatures.updateAppearances(faction);
}
}

View File

@ -0,0 +1,59 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
public class CmdPermanent extends FCommand
{
public CmdPermanent()
{
super();
this.aliases.add("permanent");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.SET_PERMANENT.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
Faction faction = this.argAsFaction(0);
if (faction == null) return;
String change;
if(faction.isPermanent())
{
change = "removed permanent status from";
faction.setPermanent(false);
}
else
{
change = "added permanent status to";
faction.setPermanent(true);
}
// Inform all players
for (FPlayer fplayer : FPlayers.i.getOnline())
{
if (fplayer.getFaction() == faction)
{
fplayer.sendMessageParsed(fme.getNameAndRelevant(fplayer)+"<i> has "+change+" your faction.");
}
else
{
fplayer.sendMessageParsed(fme.getNameAndRelevant(fplayer)+"<i> has "+change+" the faction \"" + faction.getTag(fplayer) + "\".");
}
}
}
}

View File

@ -0,0 +1,42 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
public class CmdPower extends FCommand
{
public CmdPower()
{
super();
this.aliases.add("power");
this.aliases.add("pow");
//this.requiredArgs.add("faction tag");
this.optionalArgs.put("player name", "you");
this.permission = Permission.POWER.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
FPlayer target = this.argAsBestFPlayerMatch(0, fme);
if (target == null) return;
if (target != me && ! Permission.POWER_ANY.has(sender, true)) 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.econCostPower)) return;
sendMessageParsed("%s<a> - Power / Maxpower: <i>%d / %d", target.getNameAndRelevant(fme), target.getPowerRounded(), target.getPowerMaxRounded());
}
}

View File

@ -0,0 +1,12 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Relation;
public class CmdRelationAlly extends FRelationCommand
{
public CmdRelationAlly()
{
aliases.add("ally");
targetRelation = Relation.ALLY;
}
}

View File

@ -0,0 +1,12 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Relation;
public class CmdRelationEnemy extends FRelationCommand
{
public CmdRelationEnemy()
{
aliases.add("enemy");
targetRelation = Relation.ENEMY;
}
}

View File

@ -0,0 +1,12 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Relation;
public class CmdRelationNeutral extends FRelationCommand
{
public CmdRelationNeutral()
{
aliases.add("neutral");
targetRelation = Relation.NEUTRAL;
}
}

View File

@ -0,0 +1,78 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
public class CmdReload extends FCommand
{
public CmdReload()
{
super();
this.aliases.add("reload");
//this.requiredArgs.add("");
this.optionalArgs.put("file", "all");
this.permission = Permission.RELOAD.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
long timeInitStart = System.currentTimeMillis();
String file = this.argAsString(0, "all").toLowerCase();
String fileName;
if (file.startsWith("c"))
{
Conf.load();
fileName = "conf.json";
}
else if (file.startsWith("b"))
{
Board.load();
fileName = "board.json";
}
else if (file.startsWith("f"))
{
Factions.i.loadFromDisc();
fileName = "factions.json";
}
else if (file.startsWith("p"))
{
FPlayers.i.loadFromDisc();
fileName = "players.json";
}
else if (file.startsWith("a"))
{
fileName = "all";
Conf.load();
FPlayers.i.loadFromDisc();
Factions.i.loadFromDisc();
Board.load();
}
else
{
P.p.log("RELOAD CANCELLED - SPECIFIED FILE INVALID");
sendMessageParsed("<b>Invalid file specified. <i>Valid files: all, conf, board, factions, players");
return;
}
long timeReload = (System.currentTimeMillis()-timeInitStart);
sendMessageParsed("reloaded %s from disk, took %dms", fileName, timeReload);
}
}

View File

@ -0,0 +1,50 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdSafeclaim extends FCommand
{
public CmdSafeclaim()
{
this.aliases.add("safeclaim");
this.aliases.add("safe");
//this.requiredArgs.add("");
this.optionalArgs.put("radius", "0");
this.permission = Permission.MANAGE_SAFE_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.setHelpShort("Claim land for the safezone");
}
@Override
public void perform()
{
// The current location of the player
FLocation playerFlocation = new FLocation(fme);
int radius = this.argAsInt(0, 0);
if (radius < 0) radius = 0;
FLocation from = playerFlocation.getRelative(radius, radius);
FLocation to = playerFlocation.getRelative(-radius, -radius);
for (FLocation locToClaim : FLocation.getArea(from, to))
{
Board.setFactionAt(Factions.i.getSafeZone(), locToClaim);
}
sendMessageParsed("<i>You claimed <h>%d chunks<i> for the <a>safe zone<i>.", (1+radius*2)*(1+radius*2));
}
}

View File

@ -0,0 +1,36 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdSafeunclaimall extends FCommand
{
public CmdSafeunclaimall()
{
this.aliases.add("safeunclaimall");
this.aliases.add("safedeclaimall");
//this.requiredArgs.add("");
this.optionalArgs.put("radius", "0");
this.permission = Permission.MANAGE_SAFE_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.setHelpShort("Unclaim all safezone land");
}
@Override
public void perform()
{
Board.unclaimAll(Factions.i.getSafeZone().getId());
sendMessageParsed("<i>You unclaimed ALL safe zone land.");
}
}

View File

@ -0,0 +1,40 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdSaveAll extends FCommand
{
public CmdSaveAll()
{
super();
this.aliases.add("saveall");
this.aliases.add("save");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.SAVE.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
FPlayers.i.saveToDisc();
Factions.i.saveToDisc();
Board.save();
Conf.save();
sendMessageParsed("<i>Factions saved to disk!");
}
}

View File

@ -0,0 +1,77 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdSethome extends FCommand
{
public CmdSethome()
{
this.aliases.add("sethome");
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "mine");
this.permission = Permission.SETHOME.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.homesEnabled)
{
fme.sendMessageParsed("<b>Sorry, Faction homes are disabled on this server.");
return;
}
Faction faction = this.argAsFaction(0, myFaction);
if (faction == null) return;
// Can the player set the home for this faction?
if (faction == myFaction)
{
if ( ! Permission.SETHOME_ANY.has(sender) && ! assertMinRole(Role.MODERATOR)) return;
}
else
{
if (Permission.SETHOME_ANY.has(sender, true)) return;
}
// Can the player set the faction home HERE?
if
(
! Permission.BYPASS.has(me)
&&
Conf.homesMustBeInClaimedTerritory
&&
Board.getFactionAt(new FLocation(me)) != faction
)
{
fme.sendMessageParsed("<b>Sorry, your faction home can only be set inside your own claimed territory.");
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.econCostSethome)) return;
faction.setHome(me.getLocation());
faction.sendMessage(fme.getNameAndRelevant(myFaction)+"<i> set the home for your faction. You can now use:");
faction.sendMessage(new CmdHome().getUseageTemplate());
if (faction != myFaction)
{
fme.sendMessageParsed("<b>You have set the home for the "+faction.getTag(fme)+"<i> faction.");
}
}
}

View File

@ -0,0 +1,164 @@
package com.massivecraft.factions.cmd;
import java.util.Collection;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdShow extends FCommand
{
public CmdShow()
{
this.aliases.add("show");
this.aliases.add("who");
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.SHOW.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
Faction faction = this.argAsFaction(0, myFaction);
if (faction == null) 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.econCostShow)) return;
Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);
sendMessageParsed(p.txt.titleize(faction.getTag(fme)));
sendMessageParsed("<a>Description: <i>%s", faction.getDescription());
if ( ! faction.isNormal())
{
return;
}
String peaceStatus = "";
if (faction.isPeaceful())
{
peaceStatus = " "+Conf.colorNeutral+"This faction is Peaceful";
}
sendMessageParsed("<a>Joining: <i>"+(faction.getOpen() ? "no invitation is needed" : "invitation is required")+peaceStatus);
sendMessageParsed("<a>Land / Power / Maxpower: <i> %d/%d/%d", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded());
if (faction.isPermanent())
{
sendMessageParsed("<a>This faction is permanent, remaining even with no members.");
}
// show the land value
if (Econ.enabled())
{
double value = Econ.calculateTotalLandValue(faction.getLandRounded());
double refund = value * Conf.econClaimRefundMultiplier;
if (value > 0)
{
String stringValue = Econ.moneyString(value);
String stringRefund = (refund > 0.0) ? (" ("+Econ.moneyString(refund)+" depreciated)") : "";
sendMessageParsed("<a>Total land value: <i>" + stringValue + stringRefund);
}
//Show bank contents
if(Conf.bankEnabled) {
sendMessageParsed("<a>Bank contains: <i>"+Econ.moneyString(faction.getMoney()));
}
}
String listpart;
// List relation
String allyList = p.txt.parse("<a>Allies: ");
String enemyList = p.txt.parse("<a>Enemies: ");
for (Faction otherFaction : Factions.i.get())
{
if (otherFaction == faction)
{
continue;
}
listpart = otherFaction.getTag(fme)+p.txt.parse("<i>")+", ";
if (otherFaction.getRelation(faction).isAlly())
{
allyList += listpart;
}
else if (otherFaction.getRelation(faction).isEnemy())
{
enemyList += listpart;
}
}
if (allyList.endsWith(", "))
{
allyList = allyList.substring(0, allyList.length()-2);
}
if (enemyList.endsWith(", "))
{
enemyList = enemyList.substring(0, enemyList.length()-2);
}
sendMessage(allyList);
sendMessage(enemyList);
// List the members...
String onlineList = p.txt.parse("<a>")+"Members online: ";
String offlineList = p.txt.parse("<a>")+"Members offline: ";
for (FPlayer follower : admins)
{
listpart = follower.getNameAndTitle(fme)+p.txt.parse("<i>")+", ";
if (follower.isOnline())
{
onlineList += listpart;
}
else
{
offlineList += listpart;
}
}
for (FPlayer follower : mods)
{
listpart = follower.getNameAndTitle(fme)+p.txt.parse("<i>")+", ";
if
(follower.isOnline())
{
onlineList += listpart;
} else {
offlineList += listpart;
}
}
for (FPlayer follower : normals) {
listpart = follower.getNameAndTitle(fme)+p.txt.parse("<i>")+", ";
if (follower.isOnline()) {
onlineList += listpart;
} else {
offlineList += listpart;
}
}
if (onlineList.endsWith(", ")) {
onlineList = onlineList.substring(0, onlineList.length()-2);
}
if (offlineList.endsWith(", ")) {
offlineList = offlineList.substring(0, offlineList.length()-2);
}
sendMessage(onlineList);
sendMessage(offlineList);
}
}

View File

@ -0,0 +1,74 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.MiscUtil;
public class CmdTag extends FCommand
{
public CmdTag()
{
this.aliases.add("tag");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.TAG.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
String tag = this.argAsString(0);
// TODO does not first test cover selfcase?
if (Factions.i.isTagTaken(tag) && ! MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag()))
{
sendMessageParsed("<b>That tag is already taken");
return;
}
ArrayList<String> errors = new ArrayList<String>();
errors.addAll(Factions.validateTag(tag));
if (errors.size() > 0)
{
sendMessage(errors);
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.econCostTag)) return;
String oldtag = myFaction.getTag();
myFaction.setTag(tag);
// Inform
myFaction.sendMessageParsed("%s<i> changed your faction tag to %s", fme.getNameAndRelevant(myFaction), myFaction.getTag(myFaction));
for (Faction faction : Factions.i.get())
{
if (faction == myFaction)
{
continue;
}
faction.sendMessageParsed("<i>The faction %s<i> changed their name to %s.", fme.getRelationColor(faction)+oldtag, myFaction.getTag(faction));
}
if (Conf.spoutFactionTagsOverNames)
{
SpoutFeatures.updateAppearances(myFaction);
}
}
}

View File

@ -0,0 +1,52 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TextUtil;
public class CmdTitle extends FCommand
{
public CmdTitle()
{
this.aliases.add("title");
this.requiredArgs.add("player name");
this.optionalArgs.put("title", "");
this.permission = Permission.TITLE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return;
args.remove(0);
String title = TextUtil.implode(args, " ");
if ( ! canIAdministerYou(fme, you)) 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.econCostTitle)) return;
you.setTitle(title);
// Inform
myFaction.sendMessageParsed("%s<i> changed a title: %s", fme.getNameAndRelevant(myFaction), you.getNameAndRelevant(myFaction));
if (Conf.spoutFactionTitlesOverNames)
{
SpoutFeatures.updateAppearances(me);
}
}
}

View File

@ -0,0 +1,142 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdUnclaim extends FCommand
{
public CmdUnclaim()
{
this.aliases.add("unclaim");
this.aliases.add("declaim");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.UNCLAIM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
FLocation flocation = new FLocation(fme);
Faction otherFaction = Board.getFactionAt(flocation);
if (otherFaction.isSafeZone())
{
if (Permission.MANAGE_SAFE_ZONE.has(sender))
{
Board.removeAt(flocation);
sendMessageParsed("<i>Safe zone was unclaimed.");
}
else
{
sendMessageParsed("<b>This is a safe zone. You lack permissions to unclaim.");
}
return;
}
else if (otherFaction.isWarZone())
{
if (Permission.MANAGE_WAR_ZONE.has(sender))
{
Board.removeAt(flocation);
sendMessageParsed("<i>War zone was unclaimed.");
}
else
{
sendMessageParsed("<b>This is a war zone. You lack permissions to unclaim.");
}
return;
}
if (fme.isAdminBypassing())
{
Board.removeAt(flocation);
otherFaction.sendMessageParsed("%s<i> unclaimed some of your land.", fme.getNameAndRelevant(otherFaction));
sendMessageParsed("<i>You unclaimed this land.");
return;
}
if ( ! assertHasFaction())
{
return;
}
if ( ! assertMinRole(Role.MODERATOR))
{
return;
}
if ( myFaction != otherFaction)
{
sendMessageParsed("<b>You don't own this land.");
return;
}
String moneyBack = "<i>";
if (Econ.enabled())
{
double refund = Econ.calculateClaimRefund(myFaction.getLandRounded());
// a real refund
if (refund > 0.0)
{
if(Conf.bankFactionPaysLandCosts)
{
Faction faction = myFaction;
faction.addMoney(refund);
moneyBack = " "+faction.getTag()+"<i> received a refund of <h>"+Econ.moneyString(refund)+"<i>.";
}
else
{
Econ.addMoney(fme.getName(), refund);
moneyBack = " They received a refund of <h>"+Econ.moneyString(refund)+"<i>.";
}
}
// wait, you're charging people to unclaim land? outrageous
else if (refund < 0.0)
{
if(Conf.bankFactionPaysLandCosts)
{
Faction faction = myFaction;
if(!faction.removeMoney(-refund))
{
sendMessageParsed("<b>Unclaiming this land will cost <h>%s<b> which your faction can't currently afford.", Econ.moneyString(-refund));
return;
}
moneyBack = " It cost "+faction.getTag()+" <h>"+Econ.moneyString(refund)+"<i>.";
}
else
{
if (!Econ.deductMoney(fme.getName(), -refund))
{
sendMessageParsed("<b>Unclaiming this land will cost <h>%s<b> which you can't currently afford.", Econ.moneyString(-refund));
return;
}
moneyBack = " It cost them <h>"+Econ.moneyString(refund)+"<i>.";
}
}
// no refund
else
{
moneyBack = "";
}
}
Board.removeAt(flocation);
myFaction.sendMessageParsed("%s<i> unclaimed some land."+moneyBack, fme.getNameAndRelevant(myFaction));
}
}

View File

@ -0,0 +1,85 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
public class CmdUnclaimall extends FCommand
{
public CmdUnclaimall()
{
this.aliases.add("unclaimall");
this.aliases.add("declaimall");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.UNCLAIM_ALL.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
String moneyBack = "<i>";
if (Econ.enabled())
{
double refund = Econ.calculateTotalLandRefund(myFaction.getLandRounded());
// a real refund
if (refund > 0.0)
{
if(Conf.bankFactionPaysLandCosts)
{
Faction faction = myFaction;
faction.addMoney(refund);
moneyBack = " "+faction.getTag()+" <i>received a refund of <h>"+Econ.moneyString(refund)+"<i>.";
}
else
{
Econ.addMoney(fme.getName(), refund);
moneyBack = " They received a refund of <h>"+Econ.moneyString(refund)+"<i>.";
}
}
// wait, you're charging people to unclaim land? outrageous
else if (refund < 0.0)
{
if(Conf.bankFactionPaysLandCosts)
{
Faction faction = myFaction;
if(!faction.removeMoney(-refund))
{
sendMessageParsed("<b>Unclaiming all faction land will cost <h>"+Econ.moneyString(-refund)+"<b>, which your faction can't currently afford.");
return;
}
moneyBack = " It cost "+faction.getTag()+" "+Econ.moneyString(refund)+".";
}
else
{
if (!Econ.deductMoney(fme.getName(), -refund))
{
sendMessageParsed("<b>Unclaiming all faction land will cost <h>"+Econ.moneyString(-refund)+"<b>, which you can't currently afford.");
return;
}
moneyBack = "<i> It cost them <h>"+Econ.moneyString(refund)+"<i>.";
}
moneyBack = "<i> It cost them <h>"+Econ.moneyString(refund)+"<i>.";
}
// no refund
else
{
moneyBack = "";
}
}
Board.unclaimAll(myFaction.getId());
myFaction.sendMessageParsed("%s<i> unclaimed ALL of your faction's land."+moneyBack, fme.getNameAndRelevant(myFaction));
}
}

View File

@ -0,0 +1,30 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
public class CmdVersion extends FCommand
{
public CmdVersion()
{
this.aliases.add("version");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.VERSION.node;
this.disableOnLock = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
sendMessageParsed("<i>You are running "+P.p.getDescription().getFullName());
}
}

View File

@ -0,0 +1,48 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdWarclaim extends FCommand
{
public CmdWarclaim()
{
this.aliases.add("warclaim");
this.aliases.add("war");
//this.requiredArgs.add("");
this.optionalArgs.put("radius", "0");
this.permission = Permission.MANAGE_WAR_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.setHelpShort("Claim land for the warzone");
}
public void perform()
{
// The current location of the player
FLocation playerFlocation = new FLocation(fme);
int radius = this.argAsInt(0, 0);
if (radius < 0) radius = 0;
FLocation from = playerFlocation.getRelative(radius, radius);
FLocation to = playerFlocation.getRelative(-radius, -radius);
for (FLocation locToClaim : FLocation.getArea(from, to))
{
Board.setFactionAt(Factions.i.getWarZone(), locToClaim);
}
sendMessageParsed("<i>You claimed <h>%d chunks<i> for the <a>war zone<i>.", (1+radius*2)*(1+radius*2));
}
}

View File

@ -0,0 +1,36 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
public class CmdWarunclaimall extends FCommand
{
public CmdWarunclaimall()
{
this.aliases.add("warunclaimall");
this.aliases.add("wardeclaimall");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Permission.MANAGE_WAR_ZONE.node;
this.disableOnLock = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.setHelpShort("unclaim all warzone land");
}
@Override
public void perform()
{
Board.unclaimAll(Factions.i.getWarZone().getId());
sendMessageParsed("<i>You unclaimed ALL war zone land.");
}
}

View File

@ -0,0 +1,75 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdWithdraw extends FCommand
{
public CmdWithdraw()
{
this.aliases.add("withdraw");
this.requiredArgs.add("amount");
//this.optionalArgs.put("factiontag", "yours");
this.permission = Permission.WITHDRAW.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
if ( ! Conf.bankEnabled) return;
if ( ! Conf.bankMembersCanWithdraw && ! assertMinRole(Role.MODERATOR))
{
sendMessageParsed("<b>Only faction moderators or admins are able to withdraw from the bank.");
return;
}
Faction faction = myFaction;
double amount = this.argAsDouble(0, 0d);
if( amount > 0.0 )
{
String amountString = Econ.moneyString(amount);
if( amount > faction.getMoney() )
{
amount = faction.getMoney();
}
// TODO: Improve messages.
faction.removeMoney(amount);
Econ.addMoney(fme.getName(), amount);
sendMessageParsed("<i>You have withdrawn "+amountString+" from "+faction.getTag()+"'s bank.");
sendMessageParsed("<i>"+faction.getTag()+" now has "+Econ.moneyString(faction.getMoney()));
P.p.log(fme.getName() + " withdrew "+amountString+" from "+faction.getTag()+"'s bank.");
// TODO: FAction.getOnlineMembers().
for (FPlayer fplayer : FPlayers.i.getOnline())
{
if (fplayer.getFaction() == faction)
{
fplayer.sendMessageParsed("%s<i> has withdrawn %s", fme.getNameAndRelevant(fplayer), amountString);
}
}
}
}
}

View File

@ -0,0 +1,133 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
public class FCmdRoot extends FCommand
{
public CmdAdmin cmdAdmin = new CmdAdmin();
public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim();
public CmdAutoSafeclaim cmdAutoSafeclaim = new CmdAutoSafeclaim();
public CmdAutoWarclaim cmdAutoWarclaim = new CmdAutoWarclaim();
public CmdBalance cmdBalance = new CmdBalance();
public CmdBoom cmdBoom = new CmdBoom();
public CmdBypass cmdBypass = new CmdBypass();
public CmdChat cmdChat = new CmdChat();
public CmdClaim cmdClaim = new CmdClaim();
public CmdConfig cmdConfig = new CmdConfig();
public CmdCreate cmdCreate = new CmdCreate();
public CmdDeinvite cmdDeinvite = new CmdDeinvite();
public CmdDeposit cmdDeposit = new CmdDeposit();
public CmdDescription cmdDescription = new CmdDescription();
public CmdDisband cmdDisband = new CmdDisband();
public CmdHelp cmdHelp = new CmdHelp();
public CmdHome cmdHome = new CmdHome();
public CmdInvite cmdInvite = new CmdInvite();
public CmdJoin cmdJoin = new CmdJoin();
public CmdKick cmdKick = new CmdKick();
public CmdLeave cmdLeave = new CmdLeave();
public CmdList cmdList = new CmdList();
public CmdLock cmdLock = new CmdLock();
public CmdMap cmdMap = new CmdMap();
public CmdMod cmdMod = new CmdMod();
public CmdOpen cmdOpen = new CmdOpen();
public CmdOwner cmdOwner = new CmdOwner();
public CmdOwnerList cmdOwnerList = new CmdOwnerList();
public CmdPay cmdPay = new CmdPay();
public CmdPeaceful cmdPeaceful = new CmdPeaceful();
public CmdPermanent cmdPermanent = new CmdPermanent();
public CmdPower cmdPower = new CmdPower();
public CmdRelationAlly cmdRelationAlly = new CmdRelationAlly();
public CmdRelationEnemy cmdRelationEnemy = new CmdRelationEnemy();
public CmdRelationNeutral cmdRelationNeutral = new CmdRelationNeutral();
public CmdReload cmdReload = new CmdReload();
public CmdSafeclaim cmdSafeclaim = new CmdSafeclaim();
public CmdSafeunclaimall cmdSafeunclaimall = new CmdSafeunclaimall();
public CmdSaveAll cmdSaveAll = new CmdSaveAll();
public CmdSethome cmdSethome = new CmdSethome();
public CmdShow cmdShow = new CmdShow();
public CmdTag cmdTag = new CmdTag();
public CmdTitle cmdTitle = new CmdTitle();
public CmdUnclaim cmdUnclaim = new CmdUnclaim();
public CmdUnclaimall cmdUnclaimall = new CmdUnclaimall();
public CmdVersion cmdVersion = new CmdVersion();
public CmdWarclaim cmdWarclaim = new CmdWarclaim();
public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall();
public CmdWithdraw cmdWithdraw = new CmdWithdraw();
public FCmdRoot()
{
super();
this.aliases.addAll(Conf.baseCommandAliases);
this.allowNoSlashAccess = Conf.allowNoSlashCommand;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
this.disableOnLock = false;
this.setHelpShort("The faction base command");
this.helpLong.add(p.txt.tags("<i>This command contains all faction stuff."));
//this.subCommands.add(p.cmdHelp);
this.subCommands.add(this.cmdAdmin);
this.subCommands.add(this.cmdAutoClaim);
this.subCommands.add(this.cmdAutoSafeclaim);
this.subCommands.add(this.cmdAutoWarclaim);
this.subCommands.add(this.cmdBalance);
this.subCommands.add(this.cmdBoom);
this.subCommands.add(this.cmdBypass);
this.subCommands.add(this.cmdChat);
this.subCommands.add(this.cmdClaim);
this.subCommands.add(this.cmdConfig);
this.subCommands.add(this.cmdCreate);
this.subCommands.add(this.cmdDeinvite);
this.subCommands.add(this.cmdDeposit);
this.subCommands.add(this.cmdDescription);
this.subCommands.add(this.cmdDisband);
this.subCommands.add(this.cmdHelp);
this.subCommands.add(this.cmdHome);
this.subCommands.add(this.cmdInvite);
this.subCommands.add(this.cmdJoin);
this.subCommands.add(this.cmdKick);
this.subCommands.add(this.cmdLeave);
this.subCommands.add(this.cmdList);
this.subCommands.add(this.cmdLock);
this.subCommands.add(this.cmdMap);
this.subCommands.add(this.cmdMod);
this.subCommands.add(this.cmdOpen);
this.subCommands.add(this.cmdOwner);
this.subCommands.add(this.cmdOwnerList);
this.subCommands.add(this.cmdPay);
this.subCommands.add(this.cmdPeaceful);
this.subCommands.add(this.cmdPermanent);
this.subCommands.add(this.cmdPower);
this.subCommands.add(this.cmdRelationAlly);
this.subCommands.add(this.cmdRelationEnemy);
this.subCommands.add(this.cmdRelationNeutral);
this.subCommands.add(this.cmdReload);
this.subCommands.add(this.cmdSafeclaim);
this.subCommands.add(this.cmdSafeunclaimall);
this.subCommands.add(this.cmdSaveAll);
this.subCommands.add(this.cmdSethome);
this.subCommands.add(this.cmdShow);
this.subCommands.add(this.cmdTag);
this.subCommands.add(this.cmdTitle);
this.subCommands.add(this.cmdUnclaim);
this.subCommands.add(this.cmdUnclaimall);
this.subCommands.add(this.cmdVersion);
this.subCommands.add(this.cmdWarclaim);
this.subCommands.add(this.cmdWarunclaimall);
this.subCommands.add(this.cmdWithdraw);
}
@Override
public void perform()
{
this.commandChain.add(this);
this.cmdHelp.execute(this.sender, this.args, this.commandChain);
}
}

View File

@ -0,0 +1,334 @@
package com.massivecraft.factions.cmd;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.MCommand;
public abstract class FCommand extends MCommand<P>
{
public boolean disableOnLock;
public FPlayer fme;
public Faction myFaction;
public boolean senderMustBeMember;
public boolean senderMustBeModerator;
public boolean senderMustBeAdmin;
public FCommand()
{
super(P.p);
// Due to safety reasons it defaults to disable on lock.
disableOnLock = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain)
{
if (sender instanceof Player)
{
this.fme = FPlayers.i.get((Player)sender);
this.myFaction = this.fme.getFaction();
}
else
{
this.fme = null;
this.myFaction = null;
}
super.execute(sender, args, commandChain);
}
@Override
public boolean isEnabled()
{
if (p.getLocked() && this.disableOnLock)
{
sendMessageParsed("<b>Factions was locked by an admin. Please try again later.");
return false;
}
return true;
}
@Override
public boolean validSenderType(CommandSender sender, boolean informSenderIfNot)
{
boolean superValid = super.validSenderType(sender, informSenderIfNot);
if ( ! superValid) return false;
if ( ! (this.senderMustBeMember || this.senderMustBeModerator || this.senderMustBeAdmin)) return true;
if ( ! (sender instanceof Player)) return false;
FPlayer fplayer = FPlayers.i.get((Player)sender);
if ( ! fplayer.hasFaction())
{
sender.sendMessage(p.txt.parse("<b>You are not member of any faction."));
return false;
}
if (this.senderMustBeModerator && ! fplayer.getRole().isAtLeast(Role.MODERATOR))
{
sender.sendMessage(p.txt.parse("<b>Only faction moderators can %s.", this.getHelpShort()));
return false;
}
if (this.senderMustBeAdmin && ! fplayer.getRole().isAtLeast(Role.ADMIN))
{
sender.sendMessage(p.txt.parse("<b>Only faction admins can %s.", this.getHelpShort()));
return false;
}
return true;
}
// -------------------------------------------- //
// Assertions
// -------------------------------------------- //
public boolean assertHasFaction()
{
if (me == null) return true;
if ( ! fme.hasFaction())
{
sendMessage("You are not member of any faction.");
return false;
}
return true;
}
public boolean assertMinRole(Role role)
{
if (me == null) return true;
if (fme.getRole().value < role.value)
{
sendMessageParsed("<b>You <h>must be "+role+"<b> to "+this.getHelpShort()+".");
return false;
}
return true;
}
// -------------------------------------------- //
// Argument Readers
// -------------------------------------------- //
// ARG AS FPLAYER
public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg)
{
FPlayer ret = def;
String name = this.argAsString(idx);
if (name != null)
{
FPlayer fplayer = FPlayers.i.get(name);
if (fplayer != null)
{
ret = fplayer;
}
}
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The player \"<p>%s<b>\" could not be found.", name));
}
return ret;
}
public FPlayer argAsFPlayer(int idx, FPlayer def)
{
return this.argAsFPlayer(idx, def, true);
}
public FPlayer argAsFPlayer(int idx)
{
return this.argAsFPlayer(idx, null);
}
// ARG AS BEST FPLAYER MATCH
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg)
{
FPlayer ret = def;
String name = this.argAsString(idx);
if (name != null)
{
FPlayer fplayer = FPlayers.i.find(name);
if (fplayer != null)
{
ret = fplayer;
}
}
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The player \"<p>%s<b>\" could not be found.", name));
}
return ret;
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def)
{
return this.argAsBestFPlayerMatch(idx, def, true);
}
public FPlayer argAsBestFPlayerMatch(int idx)
{
return this.argAsBestFPlayerMatch(idx, null);
}
// ARG AS FACTION
public Faction argAsFaction(int idx, Faction def, boolean msg)
{
Faction ret = def;
String name = this.argAsString(idx);
if (name != null)
{
// First we search faction names
Faction faction = Factions.i.findByTag(name);
if (faction != null)
{
ret = faction;
}
// Next we search player names
FPlayer fplayer = FPlayers.i.find(name);
if (fplayer != null)
{
ret = fplayer.getFaction();
}
}
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The faction or player \"<p>%s<b>\" could not be found.", name));
}
return ret;
}
public Faction argAsFaction(int idx, Faction def)
{
return this.argAsFaction(idx, def, true);
}
public Faction argAsFaction(int idx)
{
return this.argAsFaction(idx, null);
}
// -------------------------------------------- //
// Commonly used logic
// -------------------------------------------- //
public boolean canIAdministerYou(FPlayer i, FPlayer you)
{
if ( ! i.getFaction().equals(you.getFaction()))
{
i.sendMessage(p.txt.parse("%s <b>is not in the same faction as you.",you.getNameAndRelevant(i)));
return false;
}
if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.ADMIN) )
{
return true;
}
if (you.getRole().equals(Role.ADMIN))
{
i.sendMessage(p.txt.parse("<b>Only the faction admin can do that."));
}
else if (i.getRole().equals(Role.MODERATOR))
{
if ( i == you )
{
return true; //Moderators can control themselves
}
else
{
i.sendMessage(p.txt.parse("<b>Moderators can't control each other..."));
}
}
else
{
i.sendMessage(p.txt.parse("<b>You must be a faction moderator to do that."));
}
return false;
}
// 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.fme == null || cost == 0.0 || fme.isAdminBypassing())
{
return true;
}
String desc = this.getHelpShort().toLowerCase();
Faction faction = fme.getFaction();
// pay up
if (cost > 0.0)
{
String costString = Econ.moneyString(cost);
if(Conf.bankFactionPaysCosts && fme.hasFaction() )
{
if(!faction.removeMoney(cost))
{
sendMessage("It costs "+costString+" to "+desc+", which your faction can't currently afford.");
return false;
}
else
{
sendMessage(faction.getTag()+" has paid "+costString+" to "+desc+".");
}
}
else
{
if (!Econ.deductMoney(fme.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);
if(Conf.bankFactionPaysCosts && fme.hasFaction() )
{
faction.addMoney(-cost);
sendMessage(faction.getTag()+" has been paid "+costString+" to "+desc+".");
}
else
{
Econ.addMoney(fme.getName(), -cost);
}
sendMessage("You have been paid "+costString+" to "+desc+".");
}
return true;
}
}

View File

@ -0,0 +1,80 @@
package com.massivecraft.factions.cmd;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
public abstract class FRelationCommand extends FCommand
{
public Relation targetRelation;
public FRelationCommand()
{
super();
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("player name", "you");
this.permission = Permission.RELATION.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
}
@Override
public void perform()
{
Faction them = this.argAsFaction(0);
if ( ! them.isNormal())
{
sendMessageParsed("<b>Nope! You can't.");
return;
}
if (them == myFaction)
{
sendMessageParsed("<b>Nope! You can't declare a relation to yourself :)");
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(targetRelation.getRelationCost())) return;
myFaction.setRelationWish(them, targetRelation);
Relation currentRelation = myFaction.getRelation(them, true);
ChatColor currentRelationColor = currentRelation.getColor();
if (targetRelation.value == currentRelation.value)
{
them.sendMessageParsed("<i>Your faction is now "+currentRelationColor+targetRelation.toString()+"<i> to "+currentRelationColor+myFaction.getTag());
myFaction.sendMessageParsed("<i>Your faction is now "+currentRelationColor+targetRelation.toString()+"<i> to "+currentRelationColor+them.getTag());
}
else
{
them.sendMessageParsed(currentRelationColor+myFaction.getTag()+"<i> wishes to be your "+targetRelation.getColor()+targetRelation.toString());
them.sendMessageParsed("<i>Type <c>/"+Conf.baseCommandAliases.get(0)+" "+targetRelation+" "+myFaction.getTag()+"<i> to accept.");
myFaction.sendMessageParsed(currentRelationColor+them.getTag()+"<i> were informed that you wish to be "+targetRelation.getColor()+targetRelation);
}
if ( ! targetRelation.isNeutral() && them.isPeaceful())
{
them.sendMessageParsed("<i>This will have no effect while your faction is peaceful.");
myFaction.sendMessageParsed("<i>This will have no effect while their faction is peaceful.");
}
if ( ! targetRelation.isNeutral() && myFaction.isPeaceful())
{
them.sendMessageParsed("<i>This will have no effect while their faction is peaceful.");
myFaction.sendMessageParsed("<i>This will have no effect while your faction is peaceful.");
}
SpoutFeatures.updateAppearances(myFaction, them);
}
}