Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added /kickall & /nlkickall commands #993

Merged
merged 5 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Execute Gradle build
env:
STORAGE_TYPE: ${{ matrix.storageType }}
run: ./gradlew build
run: ./gradlew build --info

- name: Publish to Maven Central
# only publish once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ public CommonCommand[] getCommands() {
new InfoCommand(this),
new ImportCommand(this),
new KickCommand(this),
new KickAllCommand(this),
new LoglessKickCommand(this),
new LoglessKickAllCommand(this),
new MuteCommand(this),
new MuteIpCommand(this),
new NotesCommand(this),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package me.confuser.banmanager.common.commands;

import me.confuser.banmanager.common.BanManagerPlugin;
import me.confuser.banmanager.common.CommonPlayer;
import me.confuser.banmanager.common.data.PlayerData;
import me.confuser.banmanager.common.data.PlayerKickData;
import me.confuser.banmanager.common.util.Message;

import java.sql.SQLException;

public class KickAllCommand extends CommonCommand {

public KickAllCommand(BanManagerPlugin plugin) {
super(plugin, "kickall", true, 0);
}

@Override
public boolean onCommand(final CommonSender sender, CommandParser parser) {
final boolean isSilent = parser.isSilent();

if (parser.isInvalidReason()) {
Message.get("sender.error.invalidReason")
.set("reason", parser.getReason().getMessage())
.sendTo(sender);
return true;
}

if (isSilent && !sender.hasPermission(getPermission() + ".silent")) {
sender.sendMessage(Message.getString("sender.error.noPermission"));
return true;
}

final String reason = parser.args.length > 0 ? parser.getReason().getMessage() : "";

getPlugin().getScheduler().runAsync(() -> {
final PlayerData actor = sender.getData();

if (actor == null) return;

CommonPlayer[] onlinePlayers = getPlugin().getServer().getOnlinePlayers();

if (getPlugin().getConfig().isKickLoggingEnabled()) {
for (CommonPlayer player : onlinePlayers) {
if (!sender.hasPermission("bm.exempt.override.kick") && player.hasPermission("bm.exempt.kick")) {
continue;
}

PlayerData playerData = player.getData();

if (playerData == null) continue;

PlayerKickData data = new PlayerKickData(playerData, actor, reason);

try {
getPlugin().getPlayerKickStorage().addKick(data, isSilent);
} catch (SQLException e) {
sender.sendMessage(Message.get("sender.error.exception").toString());
e.printStackTrace();
}
}
}


getPlugin().getScheduler().runSync(() -> {
Message message = Message.get(reason.isEmpty() ? "kickall.notify.noReason" : "kickall.notify.reason");
message.set("actor", actor.getName()).set("reason", reason);

for (CommonPlayer player : onlinePlayers) {
if (!sender.hasPermission("bm.exempt.override.kick") && player.hasPermission("bm.exempt.kick")) {
continue;
}

Message kickMessage;

if (reason.isEmpty()) {
kickMessage = Message.get("kickall.player.noReason");
} else {
kickMessage = Message.get("kickall.player.reason").set("reason", reason);
}

kickMessage
.set("displayName", player.getDisplayName())
.set("player", player.getName())
.set("playerId", player.getUniqueId().toString())
.set("actor", actor.getName());

player.kick(kickMessage.toString());
}

if (isSilent || !sender.hasPermission("bm.notify.kick")) {
message.sendTo(sender);
}

if (!isSilent) getPlugin().getServer().broadcast(message.toString(), "bm.notify.kick");
});
});

return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package me.confuser.banmanager.common.commands;

import me.confuser.banmanager.common.BanManagerPlugin;
import me.confuser.banmanager.common.CommonPlayer;
import me.confuser.banmanager.common.data.PlayerData;
import me.confuser.banmanager.common.util.Message;

public class LoglessKickAllCommand extends CommonCommand {

public LoglessKickAllCommand(BanManagerPlugin plugin) {
super(plugin, "nlkickall", true, 0);
}

@Override
public boolean onCommand(final CommonSender sender, CommandParser parser) {
final boolean isSilent = parser.isSilent();

if (parser.isInvalidReason()) {
Message.get("sender.error.invalidReason")
.set("reason", parser.getReason().getMessage())
.sendTo(sender);
return true;
}

if (isSilent && !sender.hasPermission(getPermission() + ".silent")) {
sender.sendMessage(Message.getString("sender.error.noPermission"));
return true;
}

final String reason = parser.args.length > 0 ? parser.getReason().getMessage() : "";

getPlugin().getScheduler().runAsync(() -> {
final PlayerData actor = sender.getData();

if (actor == null) return;

getPlugin().getScheduler().runSync(() -> {
Message message = Message.get(reason.isEmpty() ? "kickall.notify.noReason" : "kickall.notify.reason");
message.set("actor", actor.getName()).set("reason", reason);

for (CommonPlayer player : getPlugin().getServer().getOnlinePlayers()) {
if (!sender.hasPermission("bm.exempt.override.kick") && player.hasPermission("bm.exempt.kick")) {
continue;
}

Message kickMessage;

if (reason.isEmpty()) {
kickMessage = Message.get("kickall.player.noReason");
} else {
kickMessage = Message.get("kickall.player.reason").set("reason", reason);
}

kickMessage
.set("displayName", player.getDisplayName())
.set("player", player.getName())
.set("playerId", player.getUniqueId().toString())
.set("actor", actor.getName());

player.kick(kickMessage.toString());
}

if (isSilent || !sender.hasPermission("bm.notify.kick")) {
message.sendTo(sender);
}

if (!isSilent) getPlugin().getServer().broadcast(message.toString(), "bm.notify.kick");
});
});

return true;
}

}
8 changes: 8 additions & 0 deletions common/src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ messages:
noReason: '&6[player] has been kicked by [actor]'
reason: '&6[player] has been kicked by [actor] for &4[reason]'

kickall:
player:
noReason: '&6You have been kicked'
reason: '&6You have been kicked for &4[reason]'
notify:
noReason: 'All players have been kicked by [actor]'
reason: 'All players have been kicked by [actor] for &4[reason]'

ban:
player:
disallowed: '&6You have been banned from this server for &4[reason]'
Expand Down
43 changes: 33 additions & 10 deletions common/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ main: "${mainPath}"
name: BanManager
version: "${internalVersion}"
author: confuser
website: http://dev.bukkit.org/bukkit-plugins/ban-management/
website: https://banmanagement.com
description: "A database driven punishment system"
softdepend:
- DiscordSRV
Expand Down Expand Up @@ -89,6 +89,11 @@ commands:
usage: "/kick <player> <reason>"
aliases: [bmkick]
permission: bm.command.kick
kickall:
description: "kick all players on the current server"
usage: "/kickall <reason>"
aliases: [bmkickall]
permission: bm.command.kickall
mute:
description: "mutes a player"
usage: "/mute <player> <reason>"
Expand Down Expand Up @@ -139,6 +144,11 @@ commands:
usage: "/nlkick <player> <reason>"
aliases: [bmnlkick]
permission: bm.command.nlkick
nlkickall:
description: "kick all players on the current server without logging"
usage: "/nlkickall <reason>"
aliases: [bmnlkickall]
permission: bm.command.nlkickall
bmreload:
description: "Reloads from the config everything except database connection info"
usage: "/bmreload"
Expand Down Expand Up @@ -289,7 +299,9 @@ permissions:
bm.command.unbanip: true
bm.command.import: true
bm.command.kick: true
bm.command.kickall: true
bm.command.nlkick: true
bm.command.nlkickall: true
bm.command.update: true
bm.command.mute: true
bm.command.mute.offline: true
Expand Down Expand Up @@ -360,7 +372,9 @@ permissions:
bm.command.unbanip: true
bm.command.import: true
bm.command.kick: true
bm.command.kickall: true
bm.command.nlkick: true
bm.command.nlkickall: true
bm.command.update: true
bm.command.mute: true
bm.command.mute.offline: true
Expand Down Expand Up @@ -561,6 +575,15 @@ permissions:
bm.command.kick:
description: Allows a player to kick another player
default: op
bm.command.kickall:
description: Allows a player to kick all players on the server
default: op
bm.command.nlkick:
description: Allows a player to kick another player without logging
default: op
bm.command.nlkickall:
description: Allows a player to kick all players on the server without logging
default: op
bm.command.update:
description: Notifies player of a plugin update
default: op
Expand Down Expand Up @@ -699,12 +722,12 @@ permissions:
bm.command.unbanname:
description: Allows unbanning a name
default: op
bm.command.bmutils:
description: Allows using bmutils base command
default: op
bm.command.bmutils.missingplayers:
description: Allows resolving missing players
default: op
bm.command.bmutils.duplicates:
description: Allows resolving duplicate player names
default: op
bm.command.bmutils:
description: Allows using bmutils base command
default: op
bm.command.bmutils.missingplayers:
description: Allows resolving missing players
default: op
bm.command.bmutils.duplicates:
description: Allows resolving duplicate player names
default: op
Loading
Loading