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

91 lines
2.9 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
2018-07-21 03:32:46 +02:00
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
2018-07-21 03:32:46 +02:00
import org.bukkit.Bukkit;
import java.util.HashMap;
2014-04-04 20:55:21 +02:00
public class CmdDisband extends FCommand {
2018-07-21 03:32:46 +02:00
private static HashMap<String, String> disbandMap = new HashMap<>();
2014-04-04 20:55:21 +02:00
public CmdDisband() {
2014-07-01 22:10:18 +02:00
super();
this.aliases.add("disband");
2014-04-04 20:55:21 +02:00
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours");
2014-07-01 22:10:18 +02:00
this.permission = Permission.DISBAND.node;
this.disableOnLock = true;
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
2018-03-26 23:43:15 +02:00
senderMustBeColeader = false;
2014-04-04 20:55:21 +02:00
senderMustBeAdmin = false;
}
@Override
public void perform() {
// The faction, default to your own.. but null if console sender.
2014-07-01 22:10:18 +02:00
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
if (faction == null) {
return;
}
2014-04-04 20:55:21 +02:00
2017-12-19 11:18:13 +01:00
boolean isMyFaction = fme != null && faction == myFaction;
2014-04-04 20:55:21 +02:00
2018-09-30 22:45:58 +02:00
if (!fme.isAdminBypassing() && isMyFaction) {
Access access = myFaction.getAccess(fme, PermissableAction.DISBAND);
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband faction");
return;
}
}
2014-04-04 20:55:21 +02:00
if (!faction.isNormal()) {
msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
2014-07-01 22:10:18 +02:00
return;
}
if (faction.isPermanent()) {
msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
2014-07-01 22:10:18 +02:00
return;
2014-04-04 20:55:21 +02:00
}
2018-07-21 03:32:46 +02:00
// check for tnt before disbanding.
if (!disbandMap.containsKey(me.getUniqueId().toString()) && faction.getTnt() > 0 && isMyFaction) {
2018-07-21 03:32:46 +02:00
msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));
disbandMap.put(me.getUniqueId().toString(), faction.getId());
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() {
@Override
public void run() {
disbandMap.remove(me.getUniqueId().toString());
}
}, 200L);
} else {
//Check if the faction we asked confirmation for is the one being disbanded.
if (faction.getId().equals(disbandMap.get(me.getUniqueId().toString())) || faction.getTnt() == 0) {
faction.disband(me);
}
}
2014-04-04 20:55:21 +02:00
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_DISBAND_DESCRIPTION;
}
}