2018-12-21 22:46:10 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2019-02-11 05:57:45 +01:00
|
|
|
import com.massivecraft.factions.*;
|
2018-12-21 22:46:10 +01:00
|
|
|
import com.massivecraft.factions.event.FactionDisbandEvent.PlayerDisbandReason;
|
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.struct.Role;
|
2019-02-11 05:57:45 +01:00
|
|
|
import com.massivecraft.factions.util.UtilFly;
|
2018-12-21 22:46:10 +01:00
|
|
|
import com.massivecraft.factions.zcore.fperms.Access;
|
|
|
|
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
|
|
|
import org.bukkit.Bukkit;
|
2019-09-14 21:13:01 +02:00
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
2018-12-21 22:46:10 +01:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
|
|
|
|
public class CmdDisband extends FCommand {
|
|
|
|
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
private static HashMap<String, String> disbandMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
public CmdDisband() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("disband");
|
|
|
|
|
|
|
|
this.optionalArgs.put("faction tag", "yours");
|
|
|
|
|
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.DISBAND)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
|
|
|
// The faction, default to your own.. but null if console sender.
|
|
|
|
Faction faction = context.argAsFaction(0, context.fPlayer == null ? null : context.faction);
|
|
|
|
if (faction == null) return;
|
|
|
|
|
|
|
|
boolean isMyFaction = context.fPlayer != null && faction == context.faction;
|
|
|
|
|
|
|
|
if (!isMyFaction) {
|
|
|
|
if (!Permission.DISBAND_ANY.has(context.sender, true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (context.fPlayer != null && !context.fPlayer.isAdminBypassing()) {
|
|
|
|
Access access = faction.getAccess(context.fPlayer, PermissableAction.DISBAND);
|
|
|
|
if (context.fPlayer.getRole() != Role.LEADER && faction.getFPlayerLeader() != context.fPlayer && access != Access.ALLOW) {
|
|
|
|
context.msg(TL.GENERIC_FPERM_NOPERMISSION, "disband " + faction.getTag());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!faction.isNormal()) {
|
|
|
|
context.msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (faction.isPermanent()) {
|
|
|
|
context.msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// THis means they are a console command sender.
|
|
|
|
if (context.player == null) {
|
|
|
|
faction.disband(null, PlayerDisbandReason.PLUGIN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for tnt before disbanding.
|
|
|
|
if (!disbandMap.containsKey(context.player.getUniqueId().toString()) && faction.getTnt() > 0) {
|
|
|
|
context.msg(TL.COMMAND_DISBAND_CONFIRM.toString().replace("{tnt}", faction.getTnt() + ""));
|
|
|
|
disbandMap.put(context.player.getUniqueId().toString(), faction.getId());
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> disbandMap.remove(context.player.getUniqueId().toString()), 200L);
|
|
|
|
} else if (faction.getId().equals(disbandMap.get(context.player.getUniqueId().toString())) || faction.getTnt() == 0) {
|
|
|
|
if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast", true)) {
|
|
|
|
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
|
|
|
|
String amountString = context.sender instanceof ConsoleCommandSender ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(follower);
|
|
|
|
if (follower.getFaction() == faction) {
|
|
|
|
follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString);
|
2019-11-21 15:38:15 +01:00
|
|
|
if (!follower.canFlyAtLocation()) {
|
|
|
|
follower.setFFlying(false, false);
|
|
|
|
}
|
2019-09-15 11:19:06 +02:00
|
|
|
} else {
|
|
|
|
follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower));
|
2019-08-24 19:18:50 +02:00
|
|
|
}
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
2019-11-21 15:38:15 +01:00
|
|
|
context.fPlayer.setFFlying(false, false);
|
2019-09-15 11:19:06 +02:00
|
|
|
} else {
|
|
|
|
context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER));
|
|
|
|
}
|
2019-11-21 15:38:15 +01:00
|
|
|
faction.disband(context.player, PlayerDisbandReason.COMMAND);
|
|
|
|
if (!context.fPlayer.canFlyAtLocation()) {
|
|
|
|
context.fPlayer.setFFlying(false, false);
|
|
|
|
}
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_DISBAND_DESCRIPTION;
|
|
|
|
}
|
2018-12-21 22:46:10 +01:00
|
|
|
}
|