2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
import com.massivecraft.factions.*;
|
2012-03-13 13:58:51 +01:00
|
|
|
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
|
|
|
import com.massivecraft.factions.event.FactionCreateEvent;
|
2011-10-09 14:53:38 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.struct.Role;
|
2014-10-19 07:37:25 +02:00
|
|
|
import com.massivecraft.factions.util.MiscUtil;
|
2014-12-08 00:12:52 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2014-04-04 20:55:21 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
public class CmdCreate extends FCommand {
|
2014-08-05 17:17:27 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
public CmdCreate() {
|
2014-07-01 22:10:18 +02:00
|
|
|
super();
|
|
|
|
this.aliases.add("create");
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
this.requiredArgs.add("faction tag");
|
|
|
|
//this.optionalArgs.put("", "");
|
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
this.permission = Permission.CREATE.node;
|
|
|
|
this.disableOnLock = true;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeAdmin = false;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
|
|
|
String tag = this.argAsString(0);
|
|
|
|
|
|
|
|
if (fme.hasFaction()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_CREATE_MUSTLEAVE);
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
2014-10-19 07:37:25 +02:00
|
|
|
if (Factions.getInstance().isTagTaken(tag)) {
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_CREATE_INUSE);
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
2014-10-19 07:37:25 +02:00
|
|
|
ArrayList<String> tagValidationErrors = MiscUtil.validateTag(tag);
|
2014-07-01 22:10:18 +02:00
|
|
|
if (tagValidationErrors.size() > 0) {
|
|
|
|
sendMessage(tagValidationErrors);
|
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
|
2014-12-08 00:12:52 +01:00
|
|
|
if (!canAffordCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE.toString())) {
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
// trigger the faction creation event (cancellable)
|
|
|
|
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
|
2014-07-01 22:10:18 +02:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(createEvent);
|
|
|
|
if (createEvent.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
// then make 'em pay (if applicable)
|
2014-12-08 00:12:52 +01:00
|
|
|
if (!payForCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE, TL.COMMAND_CREATE_FORCREATE)) {
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-10-19 07:37:25 +02:00
|
|
|
Faction faction = Factions.getInstance().createFaction();
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
// TODO: Why would this even happen??? Auto increment clash??
|
|
|
|
if (faction == null) {
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_CREATE_ERROR);
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// finish setting up the Faction
|
|
|
|
faction.setTag(tag);
|
|
|
|
|
|
|
|
// trigger the faction join event for the creator
|
2014-10-19 07:37:25 +02:00
|
|
|
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(me), faction, FPlayerJoinEvent.PlayerJoinReason.CREATE);
|
2014-04-04 20:55:21 +02:00
|
|
|
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
|
|
|
|
// join event cannot be cancelled or you'll have an empty faction
|
|
|
|
|
|
|
|
// finish setting up the FPlayer
|
2014-07-01 22:10:18 +02:00
|
|
|
fme.setRole(Role.ADMIN);
|
|
|
|
fme.setFaction(faction);
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-10-19 07:37:25 +02:00
|
|
|
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
follower.msg(TL.COMMAND_CREATE_CREATED, fme.describeTo(follower, true), faction.getTag(follower));
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_CREATE_YOUSHOULD, p.cmdBase.cmdDescription.getUseageTemplate());
|
2011-03-23 17:39:56 +01:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
if (Conf.logFactionCreate) {
|
2014-12-14 20:09:07 +01:00
|
|
|
P.p.log(fme.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag);
|
2014-07-01 22:10:18 +02:00
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2015-01-22 00:58:33 +01:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_CREATE_DESCRIPTION;
|
|
|
|
}
|
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
}
|