Dieser Commit ist enthalten in:
Ursprung
6d717eb1b0
Commit
e29fb553f0
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.command.*;
|
||||
@ -42,7 +43,7 @@ public class DevCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register
|
||||
public void simpleCommand(@Guard ProxiedPlayer player) {
|
||||
public void simpleCommand(@Validator ProxiedPlayer player) {
|
||||
updateDevServers();
|
||||
ChatSender sender = ChatSender.of(player);
|
||||
if (devServers.isEmpty()) {
|
||||
@ -63,7 +64,7 @@ public class DevCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register
|
||||
public void selectedCommand(@Guard ProxiedPlayer player, @Mapper("dev") String name) {
|
||||
public void selectedCommand(@Validator ProxiedPlayer player, @Mapper("dev") String name) {
|
||||
updateDevServers();
|
||||
ChatSender sender = ChatSender.of(player);
|
||||
ServerInfo info = devServers.get(name.toLowerCase());
|
||||
@ -75,20 +76,16 @@ public class DevCommand extends SWCommand {
|
||||
player.connect(info);
|
||||
}
|
||||
|
||||
@ClassGuard(value = ProxiedPlayer.class, local = true)
|
||||
public GuardChecker punishmentGuardChecker() {
|
||||
return (commandSender, guardCheckType, previousArguments, s) -> {
|
||||
ChatSender sender = ChatSender.of(commandSender);
|
||||
if (guardCheckType == GuardCheckType.COMMAND) {
|
||||
if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoDevServer)) {
|
||||
return GuardResult.DENIED;
|
||||
}
|
||||
} else {
|
||||
if (sender.user().isPunished(Punishment.PunishmentType.NoDevServer)) {
|
||||
return GuardResult.DENIED;
|
||||
}
|
||||
@ClassValidator(value = ProxiedPlayer.class, local = true)
|
||||
public TypeValidator<ProxiedPlayer> punishmentGuardChecker() {
|
||||
return (sender, value, messageSender) -> {
|
||||
SteamwarUser user = SteamwarUser.get(value);
|
||||
if (user.isPunished(Punishment.PunishmentType.NoDevServer)) {
|
||||
Message message = user.punishmentMessage(Punishment.PunishmentType.NoDevServer);
|
||||
messageSender.send(message.getFormat(), message.getParams());
|
||||
return false;
|
||||
}
|
||||
return GuardResult.ALLOWED;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,8 @@ import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.listeners.PollSystem;
|
||||
import de.steamwar.bungeecore.sql.PollAnswer;
|
||||
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 net.md_5.bungee.api.CommandSender;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class PollCommand extends SWCommand {
|
||||
@ -42,7 +39,7 @@ public class PollCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register(noTabComplete = true)
|
||||
public void answerPoll(@Guard ProxiedPlayer player, String answerString) {
|
||||
public void answerPoll(@Validator ProxiedPlayer player, String answerString) {
|
||||
int answer;
|
||||
try {
|
||||
answer = Integer.parseUnsignedInt(answerString);
|
||||
@ -62,16 +59,14 @@ public class PollCommand extends SWCommand {
|
||||
pollAnswer.setAnswer(answer);
|
||||
}
|
||||
|
||||
@ClassGuard(value = ProxiedPlayer.class, local = true)
|
||||
public GuardChecker noPoll() {
|
||||
return (commandSender, guardCheckType, previousArguments, s) -> {
|
||||
@ClassValidator(value = ProxiedPlayer.class, local = true)
|
||||
public TypeValidator<ProxiedPlayer> noPoll() {
|
||||
return (sender, value, messageSender) -> {
|
||||
if(PollSystem.noCurrentPoll()){
|
||||
if (guardCheckType == GuardCheckType.COMMAND) {
|
||||
Message.send("POLL_NO_POLL", commandSender);
|
||||
}
|
||||
return GuardResult.DENIED;
|
||||
messageSender.send("POLL_NO_POLL");
|
||||
return false;
|
||||
}
|
||||
return GuardResult.ALLOWED;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,8 @@ package de.steamwar.bungeecore.commands;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.listeners.PollSystem;
|
||||
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.TypeValidator;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.Map;
|
||||
@ -37,7 +35,7 @@ public class PollresultCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(@Guard ProxiedPlayer player) {
|
||||
public void genericCommand(@Validator ProxiedPlayer player) {
|
||||
Map<String, Integer> voted = PollAnswer.getCurrentResults();
|
||||
Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion());
|
||||
for (Map.Entry<String, Integer> e: voted.entrySet()) {
|
||||
@ -45,16 +43,14 @@ public class PollresultCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@ClassGuard(value = ProxiedPlayer.class, local = true)
|
||||
public GuardChecker noPoll() {
|
||||
return (commandSender, guardCheckType, previousArguments, s) -> {
|
||||
if(PollSystem.noCurrentPoll()){
|
||||
if (guardCheckType == GuardCheckType.COMMAND) {
|
||||
Message.send("POLL_NO_POLL", commandSender);
|
||||
}
|
||||
return GuardResult.DENIED;
|
||||
@ClassValidator(value = ProxiedPlayer.class, local = true)
|
||||
public TypeValidator<ProxiedPlayer> noPoll() {
|
||||
return (sender, value, messageSender) -> {
|
||||
if (PollSystem.noCurrentPoll()) {
|
||||
messageSender.send("POLL_NO_POLL");
|
||||
return false;
|
||||
}
|
||||
return GuardResult.ALLOWED;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,8 @@ import de.steamwar.bungeecore.inventory.SWListInv;
|
||||
import de.steamwar.bungeecore.inventory.SWStreamInv;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
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.TypeValidator;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
@ -78,22 +77,14 @@ public class TutorialCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register("unreleased")
|
||||
public void unreleased(@Guard("unreleased") ProxiedPlayer player) {
|
||||
public void unreleased(@Validator("unreleased") ProxiedPlayer player) {
|
||||
openInventory(player, false, false);
|
||||
}
|
||||
|
||||
@Guard("unreleased")
|
||||
public GuardChecker unreleasedChecker() {
|
||||
return (commandSender, guardCheckType, previousArguments, s) -> {
|
||||
if (commandSender instanceof ProxiedPlayer) {
|
||||
if (SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup().isTeamGroup()) {
|
||||
return GuardResult.ALLOWED;
|
||||
} else {
|
||||
return GuardResult.DENIED_WITH_HELP;
|
||||
}
|
||||
} else {
|
||||
return GuardResult.ALLOWED;
|
||||
}
|
||||
@Validator("unreleased")
|
||||
public TypeValidator<ProxiedPlayer> unreleasedChecker() {
|
||||
return (sender, value, messageSender) -> {
|
||||
return (SteamwarUser.get((value).getUniqueId()).getUserGroup().isTeamGroup());
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
@ -149,7 +149,7 @@ public class SWCommand extends AbstractSWCommand<CommandSender> {
|
||||
}
|
||||
if (args.length == 0 || atomicInteger.get() == commandList.size()) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren