Faction Bans

Adds /f ban, /f unban, and /f banlist
Permission: factions.ban - included with factions.kithalfplayer
Also added as a /f perm that can be granted. Otherwise, defaults to faction mods.
Number of bans now shows up in f show
Banning a player will notify your faction and target player. It'll also kick the player from your faction if they are currently in it.
TODO: make /f banlist prettier
This commit is contained in:
Trent Hensler
2018-02-28 20:23:37 -08:00
parent cca207c1a5
commit 151d38fd7b
16 changed files with 360 additions and 12 deletions

View File

@@ -0,0 +1,88 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
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;
senderMustBeAdmin = false;
}
@Override
public void perform() {
Access access = myFaction.getAccess(fme, PermissableAction.BAN);
if (access == Access.DENY) {
fme.msg(TL.GENERIC_NOPERMISSION, "ban");
return;
}
// Can the player set the home for this faction?
// Check for ALLOW access as well before we check for role.
if (access != Access.ALLOW) {
if (!Permission.BAN.has(sender) && !(assertMinRole(Role.MODERATOR))) {
return;
}
} else {
if (!Permission.BAN.has(sender, true)) {
return;
}
}
// 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.
}
// 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;
}
}

View File

@@ -0,0 +1,67 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import java.util.ArrayList;
import java.util.List;
public class CmdBanlist extends FCommand {
public CmdBanlist() {
super();
this.aliases.add("banlist");
this.aliases.add("bans");
this.aliases.add("banl");
this.optionalArgs.put("faction", "faction");
this.permission = Permission.BAN.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
Faction target = myFaction;
if (!args.isEmpty()) {
target = argAsFaction(0);
}
if (target == Factions.getInstance().getWilderness()) {
sender.sendMessage(TL.COMMAND_BANLIST_NOFACTION.toString());
return;
}
List<String> lines = new ArrayList<>();
lines.add(TL.COMMAND_BANLIST_HEADER.format(target.getBannedPlayers().size(), target.getTag(myFaction)));
int i = 1;
for (BanInfo info : target.getBannedPlayers()) {
FPlayer banned = FPlayers.getInstance().getById(info.getBanned());
FPlayer banner = FPlayers.getInstance().getById(info.getBanner());
String timestamp = TL.sdf.format(info.getTime());
lines.add(TL.COMMAND_BANLIST_ENTRY.format(i, banned.getName(), banner.getName(), timestamp));
i++;
}
for (String s : lines) {
fme.sendMessage(s);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_BANLIST_DESCRIPTION;
}
}

View File

@@ -31,13 +31,13 @@ public class CmdInvite extends FCommand {
@Override
public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) {
FPlayer target = this.argAsBestFPlayerMatch(0);
if (target == null) {
return;
}
if (you.getFaction() == myFaction) {
msg(TL.COMMAND_INVITE_ALREADYMEMBER, you.getName(), myFaction.getTag());
if (target.getFaction() == myFaction) {
msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), myFaction.getTag());
msg(TL.GENERIC_YOUMAYWANT.toString() + p.cmdBase.cmdKick.getUseageTemplate(false));
return;
}
@@ -47,32 +47,37 @@ public class CmdInvite extends FCommand {
return;
}
Access access = myFaction.getAccess(you, PermissableAction.INVITE);
Access access = myFaction.getAccess(target, PermissableAction.INVITE);
if (access == Access.DENY || (access == Access.UNDEFINED && !assertMinRole(Role.MODERATOR))) {
fme.msg(TL.GENERIC_NOPERMISSION, "invite");
return;
}
myFaction.invite(you);
if (!you.isOnline()) {
if (myFaction.isBanned(target)) {
fme.msg(TL.COMMAND_INVITE_BANNED, target.getName());
return;
}
myFaction.invite(target);
if (!target.isOnline()) {
return;
}
// Tooltips, colors, and commands only apply to the string immediately before it.
FancyMessage message = new FancyMessage(fme.describeTo(you, true))
FancyMessage message = new FancyMessage(fme.describeTo(target, true))
.tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
.command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag())
.then(TL.COMMAND_INVITE_INVITEDYOU.toString())
.color(ChatColor.YELLOW)
.tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
.command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag())
.then(myFaction.describeTo(you)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
.then(myFaction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
.command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag());
message.send(you.getPlayer());
message.send(target.getPlayer());
//you.msg("%s<i> invited you to %s", fme.describeTo(you, true), myFaction.describeTo(you));
myFaction.msg(TL.COMMAND_INVITE_INVITED, fme.describeTo(myFaction, true), you.describeTo(myFaction));
myFaction.msg(TL.COMMAND_INVITE_INVITED, fme.describeTo(myFaction, true), target.describeTo(myFaction));
}
@Override

View File

@@ -79,6 +79,12 @@ public class CmdJoin extends FCommand {
return;
}
// Check for ban
if (!fme.isAdminBypassing() && faction.isBanned(fme)) {
fme.msg(TL.COMMAND_JOIN_BANNED, faction.getTag(fme));
return;
}
// trigger the join event (cancellable)
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(me), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND);
Bukkit.getServer().getPluginManager().callEvent(joinEvent);

View File

@@ -0,0 +1,69 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
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;
public class CmdUnban extends FCommand {
public CmdUnban() {
super();
this.aliases.add("unban");
this.requiredArgs.add("target");
this.permission = Permission.BAN.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
Access access = myFaction.getAccess(fme, PermissableAction.BAN);
if (access == Access.DENY) {
fme.msg(TL.GENERIC_NOPERMISSION, "ban");
return;
}
// Can the player set the home for this faction?
// Check for ALLOW access as well before we check for role.
// TODO: no more duplicate code :(
if (access != Access.ALLOW) {
if (!Permission.BAN.has(sender) && !(assertMinRole(Role.MODERATOR))) {
return;
}
} else {
if (!Permission.BAN.has(sender, true)) {
return;
}
}
// 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.
}
if (!myFaction.isBanned(target)) {
fme.msg(TL.COMMAND_UNBAN_NOTBANNED, target.getName());
return;
}
myFaction.unban(target);
myFaction.msg(TL.COMMAND_UNBAN_UNBANNED, fme.getName(), target.getName());
target.msg(TL.COMMAND_UNBAN_TARGET, myFaction.getTag(target));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_UNBAN_DESCRIPTION;
}
}

View File

@@ -76,6 +76,9 @@ public class FCmdRoot extends FCommand {
public CmdSetDefaultRole cmdSetDefaultRole = new CmdSetDefaultRole();
public CmdMapHeight cmdMapHeight = new CmdMapHeight();
public CmdClaimAt cmdClaimAt = new CmdClaimAt();
public CmdBan cmdban = new CmdBan();
public CmdUnban cmdUnban = new CmdUnban();
public CmdBanlist cmdbanlist = new CmdBanlist();
public FCmdRoot() {
super();
@@ -166,6 +169,9 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdSetDefaultRole);
this.addSubCommand(this.cmdMapHeight);
this.addSubCommand(this.cmdClaimAt);
this.addSubCommand(this.cmdban);
this.addSubCommand(this.cmdUnban);
this.addSubCommand(this.cmdbanlist);
if (P.p.isHookedPlayervaults()) {
P.p.log("Found playervaults hook, adding /f vault and /f setmaxvault commands.");
this.addSubCommand(new CmdSetMaxVaults());