2018-03-01 05:23:37 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.P;
|
|
|
|
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
2018-04-01 16:13:23 +02:00
|
|
|
import com.massivecraft.factions.struct.BanInfo;
|
2018-03-01 05:23:37 +01:00
|
|
|
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;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
|
|
|
import java.util.logging.Level;
|
|
|
|
|
|
|
|
public class CmdBan extends FCommand {
|
|
|
|
|
|
|
|
public CmdBan() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("ban");
|
|
|
|
|
|
|
|
this.requiredArgs.add("target");
|
|
|
|
|
|
|
|
this.permission = Permission.BAN.node;
|
|
|
|
this.disableOnLock = true;
|
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeModerator = false;
|
2018-03-26 23:43:15 +02:00
|
|
|
senderMustBeColeader = false;
|
2018-03-01 05:23:37 +01:00
|
|
|
senderMustBeAdmin = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
|
|
|
|
2018-09-09 00:28:09 +02:00
|
|
|
// Adds bypass to admins and clean permission check
|
|
|
|
if (!fme.isAdminBypassing()) {
|
|
|
|
Access access = myFaction.getAccess(fme, PermissableAction.BAN);
|
2018-10-19 02:39:48 +02:00
|
|
|
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
|
2018-09-09 00:28:09 +02:00
|
|
|
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "ban");
|
|
|
|
return;
|
|
|
|
}
|
2018-03-01 05:23:37 +01:00
|
|
|
}
|
|
|
|
|
2018-09-09 00:28:09 +02:00
|
|
|
|
2018-03-01 05:23:37 +01:00
|
|
|
// Good on permission checks. Now lets just ban the player.
|
|
|
|
FPlayer target = argAsFPlayer(0);
|
|
|
|
if (target == null) {
|
|
|
|
return; // the above method sends a message if fails to find someone.
|
|
|
|
}
|
|
|
|
|
2018-03-04 04:12:14 +01:00
|
|
|
if (fme == target) {
|
|
|
|
// You may not ban yourself
|
|
|
|
fme.msg(TL.COMMAND_BAN_SELF);
|
|
|
|
return;
|
|
|
|
} else if (target.getFaction() == myFaction && target.getRole().value >= fme.getRole().value) {
|
|
|
|
// You may not ban someone that has same or higher faction rank
|
|
|
|
fme.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-01 16:13:23 +02:00
|
|
|
for (BanInfo banInfo : myFaction.getBannedPlayers()) {
|
|
|
|
if (banInfo.getBanned().equals(target.getId())) {
|
|
|
|
msg(TL.COMMAND_BAN_ALREADYBANNED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-01 05:23:37 +01:00
|
|
|
// Ban the user.
|
|
|
|
myFaction.ban(target, fme);
|
|
|
|
myFaction.deinvite(target); // can't hurt
|
|
|
|
|
|
|
|
// If in same Faction, lets make sure to kick them and throw an event.
|
|
|
|
if (target.getFaction() == myFaction) {
|
|
|
|
|
|
|
|
FPlayerLeaveEvent event = new FPlayerLeaveEvent(target, myFaction, FPlayerLeaveEvent.PlayerLeaveReason.BANNED);
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
// if someone cancels a ban, we'll get people complaining here. So lets log it.
|
|
|
|
P.p.log(Level.WARNING, "Attempted to ban {0} but someone cancelled the kick event. This isn't good.", target.getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Didn't get cancelled so remove them and reset their invite.
|
|
|
|
myFaction.removeFPlayer(target);
|
|
|
|
target.resetFactionData();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lets inform the people!
|
|
|
|
target.msg(TL.COMMAND_BAN_TARGET, myFaction.getTag(target.getFaction()));
|
|
|
|
myFaction.msg(TL.COMMAND_BAN_BANNED, fme.getName(), target.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_BAN_DESCRIPTION;
|
|
|
|
}
|
|
|
|
}
|