Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java

131 lines
4.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
2014-04-04 20:55:21 +02:00
import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FPlayerJoinEvent;
import com.massivecraft.factions.event.FactionCreateEvent;
2019-03-11 06:12:25 +01:00
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.MiscUtil;
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 {
public CmdCreate() {
super();
this.aliases.add("create");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
this.permission = Permission.CREATE.node;
this.disableOnLock = true;
2019-06-02 20:28:42 +02:00
this.disableOnSpam = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
String tag = this.argAsString(0);
if (fme.hasFaction()) {
msg(TL.COMMAND_CREATE_MUSTLEAVE);
return;
}
2019-06-02 20:28:42 +02:00
if (!fme.isCooldownEnded("create")) {
fme.msg(TL.COMMAND_ONCOOOLDOWN, fme.getCooldown("create"));
return;
}
if (Factions.getInstance().isTagTaken(tag)) {
msg(TL.COMMAND_CREATE_INUSE);
return;
}
ArrayList<String> tagValidationErrors = MiscUtil.validateTag(tag);
if (tagValidationErrors.size() > 0) {
sendMessage(tagValidationErrors);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE.toString())) {
return;
}
// trigger the faction creation event (cancellable)
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
Bukkit.getServer().getPluginManager().callEvent(createEvent);
if (createEvent.isCancelled()) {
return;
}
// then make 'em pay (if applicable)
if (!payForCommand(Conf.econCostCreate, TL.COMMAND_CREATE_TOCREATE, TL.COMMAND_CREATE_FORCREATE)) {
return;
}
Faction faction = Factions.getInstance().createFaction();
// TODO: Why would this even happen??? Auto increment clash??
if (faction == null) {
msg(TL.COMMAND_CREATE_ERROR);
return;
}
// finish setting up the Faction
faction.setTag(tag);
// trigger the faction join event for the creator
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(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.setFaction(faction, false);
// We should consider adding the role just AFTER joining the faction.
// That way we don't have to mess up deleting more stuff.
// And prevent the user from being returned to NORMAL after deleting his old faction.
fme.setRole(Role.LEADER);
2019-06-29 03:49:46 +02:00
if (SaberFactions.plugin.getConfig().getBoolean("faction-creation-broadcast", true)) {
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
follower.msg(TL.COMMAND_CREATE_CREATED, fme.describeTo(follower, true), faction.getTag(follower));
}
}
msg(TL.COMMAND_CREATE_YOUSHOULD, p.cmdBase.cmdDescription.getUseageTemplate());
2019-06-30 11:19:23 +02:00
if (Conf.econEnabled)
Econ.setBalance(faction.getAccountId(), Conf.econFactionStartingBalance);
2019-03-11 06:12:25 +01:00
2019-06-30 11:19:23 +02:00
if (Conf.logFactionCreate)
2019-06-29 03:49:46 +02:00
SaberFactions.plugin.log(fme.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag);
2019-06-30 11:19:23 +02:00
if (SaberFactions.plugin.getConfig().getBoolean("fpaypal.Enabled"))
this.fme.msg(TL.COMMAND_PAYPALSET_CREATED);
2019-06-30 11:19:23 +02:00
if (Conf.useCustomDefaultPermissions) faction.setDefaultPerms();
2019-06-30 11:22:55 +02:00
if (Conf.usePermissionHints) fme.msg(TL.COMMAND_HINT_PERMISSION);
2019-06-30 11:19:23 +02:00
2019-06-02 20:28:42 +02:00
2019-06-29 03:49:46 +02:00
fme.setCooldown("create", System.currentTimeMillis() + (SaberFactions.plugin.getConfig().getInt("fcooldowns.f-create") * 1000));
2019-06-02 20:28:42 +02:00
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_CREATE_DESCRIPTION;
}
2018-03-26 23:43:15 +02:00
}