mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 22:22:51 +00:00
Add permission to BanCommand, rework its targeting
This commit is contained in:
parent
371e701dd9
commit
e9c65c0adf
@ -2,36 +2,26 @@ package emu.grasscutter.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.Account;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
|
||||
@Command(
|
||||
label = "ban",
|
||||
usage = "ban <player> [time] [reason]",
|
||||
usage = "ban <@player> [time] [reason]",
|
||||
description = "commands.ban.description",
|
||||
targetRequirement = Command.TargetRequirement.NONE
|
||||
permission = "server.ban",
|
||||
targetRequirement = Command.TargetRequirement.PLAYER
|
||||
)
|
||||
public final class BanCommand implements CommandHandler {
|
||||
|
||||
private boolean banAccount(int uid, int time, String reason) {
|
||||
Player player = Grasscutter.getGameServer().getPlayerByUid(uid, true);
|
||||
private boolean banAccount(Player targetPlayer, int time, String reason) {
|
||||
Account account = targetPlayer.getAccount();
|
||||
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Account account = player.getAccount();
|
||||
if (account == null) {
|
||||
account = DatabaseHelper.getAccountByPlayerId(uid);
|
||||
if (account == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
account.setBanReason(reason);
|
||||
@ -40,51 +30,36 @@ public final class BanCommand implements CommandHandler {
|
||||
account.setBanned(true);
|
||||
account.save();
|
||||
|
||||
Player banUser = Grasscutter.getGameServer().getPlayerByUid(uid);
|
||||
|
||||
if (banUser != null) {
|
||||
banUser.getSession().close();
|
||||
GameSession session = targetPlayer.getSession();
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.size() < 1) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.ban.command_usage"));
|
||||
return;
|
||||
}
|
||||
|
||||
int uid = 0;
|
||||
int time = 2051190000;
|
||||
String reason = "Reason not specified.";
|
||||
|
||||
if (args.size() >= 1) {
|
||||
try {
|
||||
uid = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.ban.invalid_player_id"));
|
||||
return;
|
||||
}
|
||||
switch (args.size()) {
|
||||
case 2:
|
||||
reason = args.get(1); // Fall-through
|
||||
case 1:
|
||||
try {
|
||||
time = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.ban.invalid_time");
|
||||
return;
|
||||
} // Fall-through, unimportant
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (args.size() >= 2) {
|
||||
try {
|
||||
time = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.ban.invalid_time"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() >= 3) {
|
||||
reason = args.get(2);
|
||||
}
|
||||
|
||||
if (banAccount(uid, time, reason)) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.ban.success"));
|
||||
if (banAccount(targetPlayer, time, reason)) {
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.ban.success");
|
||||
} else {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.ban.failure"));
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.ban.failure");
|
||||
}
|
||||
}
|
||||
}
|
@ -2,37 +2,25 @@ package emu.grasscutter.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.Account;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
@Command(
|
||||
label = "unban",
|
||||
usage = "unban <player>",
|
||||
usage = "unban <@player>",
|
||||
description = "commands.unban.description",
|
||||
targetRequirement = Command.TargetRequirement.NONE
|
||||
permission = "server.ban",
|
||||
targetRequirement = Command.TargetRequirement.PLAYER
|
||||
)
|
||||
public final class UnBanCommand implements CommandHandler {
|
||||
|
||||
private boolean unBanAccount(int uid) {
|
||||
Player player = Grasscutter.getGameServer().getPlayerByUid(uid, true);
|
||||
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Account account = player.getAccount();
|
||||
private boolean unBanAccount(Player targetPlayer) {
|
||||
Account account = targetPlayer.getAccount();
|
||||
|
||||
if (account == null) {
|
||||
account = DatabaseHelper.getAccountByPlayerId(uid);
|
||||
if (account == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
account.setBanReason(null);
|
||||
@ -46,24 +34,10 @@ public final class UnBanCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.size() < 1) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.unban.command_usage"));
|
||||
return;
|
||||
}
|
||||
|
||||
int uid = 0;
|
||||
|
||||
try {
|
||||
uid = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.unban.invalid_player_id"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (unBanAccount(uid)) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.unban.success"));
|
||||
if (unBanAccount(targetPlayer)) {
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.unban.success");
|
||||
} else {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.unban.failure"));
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.unban.failure");
|
||||
}
|
||||
}
|
||||
}
|
@ -390,18 +390,16 @@
|
||||
"description": "Changes weather ID and climate type. Weather IDs can be found in WeatherExcelConfigData.json.\nClimate types: sunny, cloudy, rain, thunderstorm, snow, mist"
|
||||
},
|
||||
"ban": {
|
||||
"command_usage": "Usage: ban <playerId> [timestamp] [reason]",
|
||||
"command_usage": "Usage: ban <@playerId> [timestamp] [reason]",
|
||||
"success": "Successful.",
|
||||
"failure": "Failed, player not found.",
|
||||
"invalid_time": "Unable to parse timestamp.",
|
||||
"invalid_player_id": "Unable to parse player ID.",
|
||||
"description": "Ban a player"
|
||||
},
|
||||
"unban": {
|
||||
"command_usage": "Usage: unban <playerId>",
|
||||
"command_usage": "Usage: unban <@playerId>",
|
||||
"success": "Successful.",
|
||||
"failure": "Failed, player not found.",
|
||||
"invalid_player_id": "Unable to parse player ID.",
|
||||
"description": "Unban a player"
|
||||
}
|
||||
},
|
||||
|
@ -395,15 +395,13 @@
|
||||
"success": "Succès.",
|
||||
"failure": "Échec, joueur introuvable.",
|
||||
"invalid_time": "Impossible d'analyser le timestamp.",
|
||||
"invalid_player_id": "Impossible d'analyser le player ID.",
|
||||
"command_usage": "Usage: ban <playerId> [timestamp] [raison]"
|
||||
"command_usage": "Usage: ban <@playerId> [timestamp] [raison]"
|
||||
},
|
||||
"unban": {
|
||||
"description": "Retire le bannissement d'un joueur",
|
||||
"success": "Succès.",
|
||||
"failure": "Échec, joueur introuvable.",
|
||||
"invalid_player_id": "Imossible d'analyser player ID.",
|
||||
"command_usage": "Usage: unban <playerId>"
|
||||
"command_usage": "Usage: unban <@playerId>"
|
||||
}
|
||||
},
|
||||
"gacha": {
|
||||
|
@ -306,6 +306,19 @@
|
||||
"unlocktower": {
|
||||
"success": "odblokować gotowe",
|
||||
"description": "Odblokuj głęboką spiralę"
|
||||
},
|
||||
"ban": {
|
||||
"command_usage": "Usage: ban <@playerId> [timestamp] [reason]",
|
||||
"success": "Successful.",
|
||||
"failure": "Failed, player not found.",
|
||||
"invalid_time": "Unable to parse timestamp.",
|
||||
"description": "Ban a player"
|
||||
},
|
||||
"unban": {
|
||||
"command_usage": "Usage: unban <@playerId>",
|
||||
"success": "Successful.",
|
||||
"failure": "Failed, player not found.",
|
||||
"description": "Unban a player"
|
||||
}
|
||||
},
|
||||
"gacha": {
|
||||
|
@ -395,15 +395,13 @@
|
||||
"success": "Успех.",
|
||||
"failure": "Неудача, игрок не найден.",
|
||||
"invalid_time": "Не удалось определить промежуток времени.",
|
||||
"invalid_player_id": "Не удалось определить ID игрока.",
|
||||
"command_usage": "Применение: ban <Id игрока> [промежуток_времени] [причина]"
|
||||
"command_usage": "Применение: ban <@Id игрока> [промежуток_времени] [причина]"
|
||||
},
|
||||
"unban": {
|
||||
"description": "Разбанивает игрока",
|
||||
"success": "Успех.",
|
||||
"failure": "Неудача, игрок не найден.",
|
||||
"invalid_player_id": "Не удалось определить ID игрока.",
|
||||
"command_usage": "Применение: unban <Id_игрока>"
|
||||
"command_usage": "Применение: unban <@Id_игрока>"
|
||||
}
|
||||
},
|
||||
"gacha": {
|
||||
|
@ -390,18 +390,16 @@
|
||||
"description": "更改天气ID和气候类型。天气ID可以在 WeatherExcelConfigData.json 中找到。\n气候类型:sunny(晴天), cloudy(多云), rain(雨), thunderstorm(雷雨), snow(雪), mist(雾)"
|
||||
},
|
||||
"ban": {
|
||||
"command_usage": "用法:ban <玩家ID> [时间] [原因]",
|
||||
"command_usage": "用法:ban <@玩家ID> [时间] [原因]",
|
||||
"success": "成功封禁玩家。",
|
||||
"failure": "封禁玩家失败,因为玩家不存在。",
|
||||
"invalid_time": "无法解析时间戳。",
|
||||
"invalid_player_id": "无法解析玩家ID。",
|
||||
"description": "封禁玩家"
|
||||
},
|
||||
"unban": {
|
||||
"command_usage": "用法:unban <玩家ID>",
|
||||
"command_usage": "用法:unban <@玩家ID>",
|
||||
"success": "成功取消玩家的封禁。",
|
||||
"failure": "取消玩家的封禁失败,因为玩家不存在。",
|
||||
"invalid_player_id": "无法解析玩家ID。",
|
||||
"description": "取消玩家的封禁"
|
||||
}
|
||||
},
|
||||
|
@ -397,15 +397,13 @@
|
||||
"success": "停權成功。",
|
||||
"failure": "停權失敗,玩家帳號不存在。",
|
||||
"invalid_time": "無效的時間戳。",
|
||||
"invalid_player_id": "無效的玩家ID。",
|
||||
"command_usage": "用法:ban <playerId> [timestamp] [reason]"
|
||||
"command_usage": "用法:ban <@playerId> [timestamp] [reason]"
|
||||
},
|
||||
"unban": {
|
||||
"description": "撤銷停權指定玩家。",
|
||||
"success": "撤銷停權成功。",
|
||||
"failure": "撤銷停權失敗,玩家帳號不存在。",
|
||||
"invalid_player_id": "無效的玩家ID。",
|
||||
"command_usage": "用法:unban <playerId>"
|
||||
"command_usage": "用法:unban <@playerId>"
|
||||
}
|
||||
},
|
||||
"gacha": {
|
||||
|
Loading…
Reference in New Issue
Block a user