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;
|
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;
|
2012-03-02 02:16:45 +01:00
|
|
|
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
|
|
|
import com.massivecraft.factions.event.FactionCreateEvent;
|
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
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsCreate()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addAliases("create");
|
2011-03-22 18:48:09 +01:00
|
|
|
|
2013-04-16 10:30:21 +02:00
|
|
|
this.addRequiredArg("faction tag");
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.CREATE.node));
|
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-04-16 11:05:49 +02:00
|
|
|
String tag = this.arg(0);
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-10-09 14:53:38 +02: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-12 09:47:43 +02:00
|
|
|
if (FactionColl.get().isTagTaken(tag))
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
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);
|
2011-10-09 14:53:38 +02:00
|
|
|
if (tagValidationErrors.size() > 0)
|
|
|
|
{
|
2011-03-19 13:00:03 +01:00
|
|
|
sendMessage(tagValidationErrors);
|
|
|
|
return;
|
|
|
|
}
|
2012-03-02 02:16:45 +01:00
|
|
|
|
2012-03-13 15:48:34 +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;
|
2012-03-13 15:48:34 +01:00
|
|
|
|
2012-03-09 23:09:33 +01:00
|
|
|
// trigger the faction creation event (cancellable)
|
2013-04-12 09:47:43 +02:00
|
|
|
String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get());
|
|
|
|
|
2013-04-16 09:48:57 +02:00
|
|
|
FactionCreateEvent createEvent = new FactionCreateEvent(sender, tag, factionId);
|
2012-03-09 23:09:33 +01:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(createEvent);
|
2012-03-02 02:16:45 +01:00
|
|
|
if(createEvent.isCancelled()) return;
|
|
|
|
|
2012-03-13 15:48:34 +01:00
|
|
|
// 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-12 09:47:43 +02:00
|
|
|
|
|
|
|
Faction faction = FactionColl.get().create(factionId);
|
2011-10-13 11:10:29 +02:00
|
|
|
|
2011-10-23 12:07:20 +02:00
|
|
|
// TODO: Why would this even happen??? Auto increment clash??
|
2011-10-13 11:10:29 +02:00
|
|
|
if (faction == null)
|
|
|
|
{
|
|
|
|
msg("<b>There was an internal error while trying to create your faction. Please try again.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-09 23:09:33 +01:00
|
|
|
// finish setting up the Faction
|
2013-04-12 08:56:26 +02:00
|
|
|
faction.setTag(tag);
|
|
|
|
|
|
|
|
// trigger the faction join event for the creator
|
2013-04-16 09:48:57 +02:00
|
|
|
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(sender),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE);
|
2013-04-12 08:56:26 +02:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
|
|
|
|
// join event cannot be cancelled or you'll have an empty faction
|
|
|
|
|
|
|
|
// finish setting up the FPlayer
|
2011-10-23 17:30:41 +02:00
|
|
|
fme.setRole(Rel.LEADER);
|
2011-10-09 14:53:38 +02:00
|
|
|
fme.setFaction(faction);
|
2011-08-20 02:41:28 +02:00
|
|
|
|
2013-04-12 08:56:26 +02:00
|
|
|
for (FPlayer follower : FPlayerColl.get().getAllOnline())
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
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());
|
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-09 13:15:25 +02:00
|
|
|
if (ConfServer.logFactionCreate)
|
2013-04-09 13:12:13 +02:00
|
|
|
Factions.get().log(fme.getName()+" created a new faction: "+tag);
|
2011-03-19 13:00:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|