Factions/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java

105 lines
3.0 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2011-03-19 13:00:03 +01:00
import java.util.ArrayList;
2012-03-02 02:16:45 +01:00
import org.bukkit.Bukkit;
2013-04-09 13:15:25 +02:00
import com.massivecraft.factions.ConfServer;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.FPlayer;
2013-04-09 13:22:23 +02:00
import com.massivecraft.factions.FPlayerColl;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Faction;
2013-04-09 12:58:39 +02:00
import com.massivecraft.factions.FactionColl;
2013-04-09 13:00:09 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
2012-03-02 02:16:45 +01:00
import com.massivecraft.factions.event.FPlayerJoinEvent;
import com.massivecraft.factions.event.FactionCreateEvent;
2011-03-19 13:00:03 +01:00
2013-04-10 13:12:22 +02:00
public class CmdFactionsCreate extends FCommand
{
2013-04-10 13:12:22 +02:00
public CmdFactionsCreate()
{
super();
this.aliases.add("create");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Perm.CREATE.node;
2011-10-09 21:57:43 +02:00
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
2011-10-23 17:55:53 +02:00
senderMustBeOfficer = false;
senderMustBeLeader = false;
2011-03-23 17:39:56 +01:00
}
@Override
public void perform()
{
String tag = this.argAsString(0);
2011-03-19 13:00:03 +01:00
if (fme.hasFaction())
{
2011-10-10 13:40:24 +02:00
msg("<b>You must leave your current faction first.");
2011-03-19 13:00:03 +01:00
return;
}
2013-04-09 12:58:39 +02:00
if (FactionColl.i.isTagTaken(tag))
{
2011-10-10 13:40:24 +02:00
msg("<b>That tag is already in use.");
2011-03-19 13:00:03 +01:00
return;
}
2013-04-09 12:58:39 +02:00
ArrayList<String> tagValidationErrors = FactionColl.validateTag(tag);
if (tagValidationErrors.size() > 0)
{
2011-03-19 13:00:03 +01:00
sendMessage(tagValidationErrors);
return;
}
2012-03-02 02:16:45 +01:00
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
2013-04-09 13:15:25 +02:00
if ( ! canAffordCommand(ConfServer.econCostCreate, "to create a new faction")) return;
// trigger the faction creation event (cancellable)
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
Bukkit.getServer().getPluginManager().callEvent(createEvent);
2012-03-02 02:16:45 +01:00
if(createEvent.isCancelled()) return;
// then make 'em pay (if applicable)
2013-04-09 13:15:25 +02:00
if ( ! payForCommand(ConfServer.econCostCreate, "to create a new faction", "for creating a new faction")) return;
2013-04-09 12:58:39 +02:00
Faction faction = FactionColl.i.create();
// TODO: Why would this even happen??? Auto increment clash??
if (faction == null)
{
msg("<b>There was an internal error while trying to create your faction. Please try again.");
return;
}
// finish setting up the Faction
faction.setTag(tag);
// trigger the faction join event for the creator
2013-04-09 13:22:23 +02:00
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE);
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
// join event cannot be cancelled or you'll have an empty faction
// finish setting up the FPlayer
fme.setRole(Rel.LEADER);
fme.setFaction(faction);
2011-08-20 02:41:28 +02:00
2013-04-09 13:22:23 +02:00
for (FPlayer follower : FPlayerColl.i.getOnline())
{
2011-10-21 19:20:33 +02:00
follower.msg("%s<i> created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower));
2011-03-19 13:00:03 +01:00
}
2013-04-10 13:12:22 +02:00
msg("<i>You should now: %s", p.cmdBase.cmdFactionsDescription.getUseageTemplate());
2013-04-09 13:15:25 +02:00
if (ConfServer.logFactionCreate)
Factions.get().log(fme.getName()+" created a new faction: "+tag);
2011-03-19 13:00:03 +01:00
}
}