SteamWar/BungeeCore
Archiviert
13
2

Remove deprecated guard api
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-08-22 20:25:36 +02:00
Ursprung 6d717eb1b0
Commit e29fb553f0
6 geänderte Dateien mit 36 neuen und 87 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.command.*; import de.steamwar.command.*;
@ -42,7 +43,7 @@ public class DevCommand extends SWCommand {
} }
@Register @Register
public void simpleCommand(@Guard ProxiedPlayer player) { public void simpleCommand(@Validator ProxiedPlayer player) {
updateDevServers(); updateDevServers();
ChatSender sender = ChatSender.of(player); ChatSender sender = ChatSender.of(player);
if (devServers.isEmpty()) { if (devServers.isEmpty()) {
@ -63,7 +64,7 @@ public class DevCommand extends SWCommand {
} }
@Register @Register
public void selectedCommand(@Guard ProxiedPlayer player, @Mapper("dev") String name) { public void selectedCommand(@Validator ProxiedPlayer player, @Mapper("dev") String name) {
updateDevServers(); updateDevServers();
ChatSender sender = ChatSender.of(player); ChatSender sender = ChatSender.of(player);
ServerInfo info = devServers.get(name.toLowerCase()); ServerInfo info = devServers.get(name.toLowerCase());
@ -75,20 +76,16 @@ public class DevCommand extends SWCommand {
player.connect(info); player.connect(info);
} }
@ClassGuard(value = ProxiedPlayer.class, local = true) @ClassValidator(value = ProxiedPlayer.class, local = true)
public GuardChecker punishmentGuardChecker() { public TypeValidator<ProxiedPlayer> punishmentGuardChecker() {
return (commandSender, guardCheckType, previousArguments, s) -> { return (sender, value, messageSender) -> {
ChatSender sender = ChatSender.of(commandSender); SteamwarUser user = SteamwarUser.get(value);
if (guardCheckType == GuardCheckType.COMMAND) { if (user.isPunished(Punishment.PunishmentType.NoDevServer)) {
if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoDevServer)) { Message message = user.punishmentMessage(Punishment.PunishmentType.NoDevServer);
return GuardResult.DENIED; messageSender.send(message.getFormat(), message.getParams());
return false;
} }
} else { return true;
if (sender.user().isPunished(Punishment.PunishmentType.NoDevServer)) {
return GuardResult.DENIED;
}
}
return GuardResult.ALLOWED;
}; };
} }

Datei anzeigen

@ -23,11 +23,8 @@ import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.bungeecore.listeners.PollSystem;
import de.steamwar.bungeecore.sql.PollAnswer; import de.steamwar.bungeecore.sql.PollAnswer;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.command.GuardCheckType;
import de.steamwar.command.GuardChecker;
import de.steamwar.command.GuardResult;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import net.md_5.bungee.api.CommandSender; import de.steamwar.command.TypeValidator;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class PollCommand extends SWCommand { public class PollCommand extends SWCommand {
@ -42,7 +39,7 @@ public class PollCommand extends SWCommand {
} }
@Register(noTabComplete = true) @Register(noTabComplete = true)
public void answerPoll(@Guard ProxiedPlayer player, String answerString) { public void answerPoll(@Validator ProxiedPlayer player, String answerString) {
int answer; int answer;
try { try {
answer = Integer.parseUnsignedInt(answerString); answer = Integer.parseUnsignedInt(answerString);
@ -62,16 +59,14 @@ public class PollCommand extends SWCommand {
pollAnswer.setAnswer(answer); pollAnswer.setAnswer(answer);
} }
@ClassGuard(value = ProxiedPlayer.class, local = true) @ClassValidator(value = ProxiedPlayer.class, local = true)
public GuardChecker noPoll() { public TypeValidator<ProxiedPlayer> noPoll() {
return (commandSender, guardCheckType, previousArguments, s) -> { return (sender, value, messageSender) -> {
if(PollSystem.noCurrentPoll()){ if(PollSystem.noCurrentPoll()){
if (guardCheckType == GuardCheckType.COMMAND) { messageSender.send("POLL_NO_POLL");
Message.send("POLL_NO_POLL", commandSender); return false;
} }
return GuardResult.DENIED; return true;
}
return GuardResult.ALLOWED;
}; };
} }
} }

Datei anzeigen

@ -22,10 +22,8 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.bungeecore.listeners.PollSystem;
import de.steamwar.bungeecore.sql.PollAnswer; import de.steamwar.bungeecore.sql.PollAnswer;
import de.steamwar.command.GuardCheckType;
import de.steamwar.command.GuardChecker;
import de.steamwar.command.GuardResult;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.Map; import java.util.Map;
@ -37,7 +35,7 @@ public class PollresultCommand extends SWCommand {
} }
@Register @Register
public void genericCommand(@Guard ProxiedPlayer player) { public void genericCommand(@Validator ProxiedPlayer player) {
Map<String, Integer> voted = PollAnswer.getCurrentResults(); Map<String, Integer> voted = PollAnswer.getCurrentResults();
Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion()); Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion());
for (Map.Entry<String, Integer> e: voted.entrySet()) { for (Map.Entry<String, Integer> e: voted.entrySet()) {
@ -45,16 +43,14 @@ public class PollresultCommand extends SWCommand {
} }
} }
@ClassGuard(value = ProxiedPlayer.class, local = true) @ClassValidator(value = ProxiedPlayer.class, local = true)
public GuardChecker noPoll() { public TypeValidator<ProxiedPlayer> noPoll() {
return (commandSender, guardCheckType, previousArguments, s) -> { return (sender, value, messageSender) -> {
if(PollSystem.noCurrentPoll()){ if (PollSystem.noCurrentPoll()) {
if (guardCheckType == GuardCheckType.COMMAND) { messageSender.send("POLL_NO_POLL");
Message.send("POLL_NO_POLL", commandSender); return false;
} }
return GuardResult.DENIED; return true;
}
return GuardResult.ALLOWED;
}; };
} }
} }

Datei anzeigen

@ -26,9 +26,8 @@ import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Tutorial; import de.steamwar.bungeecore.sql.Tutorial;
import de.steamwar.command.GuardChecker;
import de.steamwar.command.GuardResult;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -78,22 +77,14 @@ public class TutorialCommand extends SWCommand {
} }
@Register("unreleased") @Register("unreleased")
public void unreleased(@Guard("unreleased") ProxiedPlayer player) { public void unreleased(@Validator("unreleased") ProxiedPlayer player) {
openInventory(player, false, false); openInventory(player, false, false);
} }
@Guard("unreleased") @Validator("unreleased")
public GuardChecker unreleasedChecker() { public TypeValidator<ProxiedPlayer> unreleasedChecker() {
return (commandSender, guardCheckType, previousArguments, s) -> { return (sender, value, messageSender) -> {
if (commandSender instanceof ProxiedPlayer) { return (SteamwarUser.get((value).getUniqueId()).getUserGroup().isTeamGroup());
if (SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup().isTeamGroup()) {
return GuardResult.ALLOWED;
} else {
return GuardResult.DENIED_WITH_HELP;
}
} else {
return GuardResult.ALLOWED;
}
}; };
} }

Datei anzeigen

@ -1,30 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.command;
import net.md_5.bungee.api.CommandSender;
@FunctionalInterface
public interface GuardChecker extends AbstractGuardChecker<CommandSender> {
/**
* While guarding the first parameter of the command the parameter s of this method is {@code null}
*/
GuardResult guard(CommandSender commandSender, GuardCheckType guardCheckType, String[] previousArguments, String s);
}

Datei anzeigen

@ -149,7 +149,7 @@ public class SWCommand extends AbstractSWCommand<CommandSender> {
} }
if (args.length == 0 || atomicInteger.get() == commandList.size()) { if (args.length == 0 || atomicInteger.get() == commandList.size()) {
commandList.forEach(subCommand -> { commandList.forEach(subCommand -> {
if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) {
send(chatSender, subCommand); send(chatSender, subCommand);
} }
}); });