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;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.Rel;
|
2013-04-25 13:25:15 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
2013-04-25 13:53:22 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqHasntFaction;
|
2013-04-22 17:59:51 +02:00
|
|
|
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;
|
2013-04-22 10:05:03 +02:00
|
|
|
import com.massivecraft.factions.entity.MConf;
|
2013-04-19 12:27:39 +02:00
|
|
|
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;
|
2014-06-04 14:02:23 +02:00
|
|
|
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
|
|
|
import com.massivecraft.massivecore.store.MStore;
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public class CmdFactionsCreate extends FCommand
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsCreate()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// Aliases
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addAliases("create");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Args
|
2013-04-24 19:01:17 +02:00
|
|
|
this.addRequiredArg("name");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Requirements
|
2013-04-25 13:25:15 +02:00
|
|
|
this.addRequirements(ReqFactionsEnabled.get());
|
2013-04-25 13:53:22 +02:00
|
|
|
this.addRequirements(ReqHasntFaction.get());
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.CREATE.node));
|
2011-03-23 17:39:56 +01:00
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2011-10-09 14:53:38 +02:00
|
|
|
public void perform()
|
2013-11-11 09:31:04 +01:00
|
|
|
{
|
2013-04-19 12:44:28 +02:00
|
|
|
// Args
|
2013-04-24 19:01:17 +02:00
|
|
|
String newName = this.arg(0);
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Verify
|
2013-04-25 07:29:19 +02:00
|
|
|
FactionColl coll = FactionColls.get().get(usender);
|
2013-04-22 13:03:21 +02:00
|
|
|
|
2013-04-24 19:01:17 +02:00
|
|
|
if (coll.isNameTaken(newName))
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-24 19:01:17 +02:00
|
|
|
msg("<b>That name is already in use.");
|
2011-03-19 13:00:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-24 19:01:17 +02:00
|
|
|
ArrayList<String> nameValidationErrors = coll.validateName(newName);
|
|
|
|
if (nameValidationErrors.size() > 0)
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-24 19:01:17 +02:00
|
|
|
sendMessage(nameValidationErrors);
|
2011-03-19 13:00:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-03-02 02:16:45 +01:00
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Pre-Generate Id
|
2013-05-03 09:58:43 +02:00
|
|
|
String factionId = MStore.createId();
|
2013-04-12 09:47:43 +02:00
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Event
|
2013-04-24 19:01:17 +02:00
|
|
|
FactionsEventCreate createEvent = new FactionsEventCreate(sender, coll.getUniverse(), factionId, newName);
|
2013-04-19 12:44:28 +02:00
|
|
|
createEvent.run();
|
2013-04-19 12:27:39 +02:00
|
|
|
if (createEvent.isCancelled()) return;
|
2013-04-12 09:47:43 +02:00
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Apply
|
2013-04-22 13:03:21 +02:00
|
|
|
Faction faction = coll.create(factionId);
|
2013-04-24 19:01:17 +02:00
|
|
|
faction.setName(newName);
|
2013-04-19 12:44:28 +02:00
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.setRole(Rel.LEADER);
|
|
|
|
usender.setFaction(faction);
|
2013-04-12 08:56:26 +02:00
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
FactionsEventMembershipChange joinEvent = new FactionsEventMembershipChange(sender, usender, faction, MembershipChangeReason.CREATE);
|
2013-04-19 12:27:39 +02:00
|
|
|
joinEvent.run();
|
|
|
|
// NOTE: join event cannot be cancelled or you'll have an empty faction
|
2013-04-12 08:56:26 +02:00
|
|
|
|
2013-04-19 12:44:28 +02:00
|
|
|
// Inform
|
2013-04-25 07:29:19 +02:00
|
|
|
for (UPlayer follower : UPlayerColls.get().get(usender).getAllOnline())
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
follower.msg("%s<i> created a new faction %s", usender.describeTo(follower, true), faction.getName(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());
|
Additional logging, with new conf.json settings to enable/disable logging of specific events:
"logFactionCreate": true, - log faction creation
"logFactionDisband": true, - log factions being disbanded, by command or by circumstance
"logFactionJoin": true, - log player joining a faction
"logFactionKick": true, - log player being kicked from a faction
"logFactionLeave": true, - log player leaving a faction
"logLandClaims": true, - log land being claimed (including safe zone and war zone)
"logLandUnclaims": true, - log land being unclaimed (including safe zone and war zone)
"logMoneyTransactions": true, - log money being deposited, withdrawn, and otherwise transferred in relation to faction banks
Also a fix for a potential NPE from players logging out and Spout appearance handler referencing them afterwards
2011-10-23 19:50:02 +02:00
|
|
|
|
2013-04-22 10:05:03 +02:00
|
|
|
if (MConf.get().logFactionCreate)
|
2013-04-19 12:44:28 +02:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
Factions.get().log(usender.getName()+" created a new faction: "+newName);
|
2013-04-19 12:44:28 +02:00
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|