Factions/src/com/massivecraft/factions/commands/FCommandCreate.java

82 lines
1.8 KiB
Java
Raw Normal View History

2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.commands;
2011-03-19 13:00:03 +01:00
import java.util.ArrayList;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.struct.Role;
2011-03-23 17:39:56 +01:00
2011-03-19 13:00:03 +01:00
public class FCommandCreate extends FCommand
{
public FCommandCreate()
{
super();
this.aliases.add("create");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.CREATE.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
2011-03-23 17:39:56 +01:00
}
@Override
public void perform()
{
if( isLocked() )
{
sendLockMessage();
return;
}
String tag = this.argAsString(0);
2011-03-19 13:00:03 +01:00
if (fme.hasFaction())
{
2011-03-19 13:00:03 +01:00
sendMessage("You must leave your current faction first.");
return;
}
if (Factions.i.isTagTaken(tag))
{
2011-03-19 13:00:03 +01:00
sendMessage("That tag is already in use.");
return;
}
ArrayList<String> tagValidationErrors = Factions.validateTag(tag);
if (tagValidationErrors.size() > 0)
{
2011-03-19 13:00:03 +01:00
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();
2011-03-19 13:00:03 +01:00
faction.setTag(tag);
fme.setRole(Role.ADMIN);
fme.setFaction(faction);
2011-08-20 02:41:28 +02:00
for (FPlayer follower : FPlayers.i.getOnline())
{
follower.sendMessageParsed("%s<i> created a new faction %s", fme.getNameAndRelevant(follower), faction.getTag(follower));
2011-03-19 13:00:03 +01:00
}
sendMessage("You should now: " + new FCommandDescription().getUseageTemplate());
2011-03-19 13:00:03 +01:00
}
}