-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added /kickall & /nlkickall commands (#993)
- Loading branch information
Showing
10 changed files
with
483 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
common/src/main/java/me/confuser/banmanager/common/commands/KickAllCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
common/src/main/java/me/confuser/banmanager/common/commands/LoglessKickAllCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.