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

92 lines
2.5 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;
2013-04-09 13:00:09 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.UPlayer;
import com.massivecraft.factions.entity.UPlayerColls;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl;
2013-04-22 13:03:21 +02:00
import com.massivecraft.factions.entity.FactionColls;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.event.FactionsEventCreate;
2013-04-19 14:08:45 +02:00
import com.massivecraft.factions.event.FactionsEventMembershipChange;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason;
2013-04-16 10:11:59 +02:00
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
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()
{
2013-04-16 10:11:59 +02:00
this.addAliases("create");
this.addRequiredArg("faction tag");
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.CREATE.node));
2011-03-23 17:39:56 +01:00
}
@Override
public void perform()
{
// Args
String newTag = this.arg(0);
2011-03-19 13:00:03 +01:00
// Verify
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-22 13:03:21 +02:00
FactionColl coll = FactionColls.get().get(fme);
if (coll.isTagTaken(newTag))
{
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;
}
ArrayList<String> tagValidationErrors = coll.validateTag(newTag);
if (tagValidationErrors.size() > 0)
{
2011-03-19 13:00:03 +01:00
sendMessage(tagValidationErrors);
return;
}
2012-03-02 02:16:45 +01:00
// Pre-Generate Id
2013-04-22 13:03:21 +02:00
String factionId = coll.getIdStrategy().generate(coll);
// Event
2013-04-22 13:03:21 +02:00
FactionsEventCreate createEvent = new FactionsEventCreate(sender, coll.getUniverse(), factionId, newTag);
createEvent.run();
if (createEvent.isCancelled()) return;
// Apply
2013-04-22 13:03:21 +02:00
Faction faction = coll.create(factionId);
faction.setTag(newTag);
fme.setRole(Rel.LEADER);
fme.setFaction(faction);
2013-04-12 08:56:26 +02:00
2013-04-19 14:08:45 +02:00
FactionsEventMembershipChange joinEvent = new FactionsEventMembershipChange(sender, fme, faction, MembershipChangeReason.CREATE);
joinEvent.run();
// NOTE: join event cannot be cancelled or you'll have an empty faction
2013-04-12 08:56:26 +02:00
// Inform
for (UPlayer follower : UPlayerColls.get().get(fme).getAllOnline())
{
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-16 11:27:03 +02:00
msg("<i>You should now: %s", Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate());
if (MConf.get().logFactionCreate)
{
Factions.get().log(fme.getName()+" created a new faction: "+newTag);
}
2011-03-19 13:00:03 +01:00
}
}