3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-07-06 07:18:03 +02:00

Add own permission for every sub command (#3501)

Dieser Commit ist enthalten in:
EnZaXD 2023-10-24 04:59:10 +02:00 committet von GitHub
Ursprung abe880dae6
Commit f35b4f1fac
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
9 geänderte Dateien mit 66 neuen und 51 gelöschten Zeilen

Datei anzeigen

@ -58,7 +58,7 @@ public abstract class ViaSubCommand {
* @return The permission required to use the commands * @return The permission required to use the commands
*/ */
public String permission() { public String permission() {
return "viaversion.admin"; return "viaversion.admin." + name();
} }
/** /**

Datei anzeigen

@ -9,6 +9,49 @@ loadbefore: [ ProtocolLib, ProxyPipe, SpigotLib, SkinRestorer ]
softdepend: [ ProtocolSupport, PacketListenerApi ] softdepend: [ ProtocolSupport, PacketListenerApi ]
commands: commands:
viaversion: viaversion:
permission: viaversion.admin # The permission is also referenced here to filter root suggestions (/via<tab>)
description: Shows ViaVersion Version and more. description: Shows ViaVersion Version and more.
aliases: [ viaver, vvbukkit ] aliases: [ viaver, vvbukkit ]
viaversion autoteam:
permission: viaversion.admin.autoteam
description: Toggle automatically teaming to prevent colliding.
aliases: [ autoteam ]
viaversion debug:
permission: viaversion.admin.debug
description: Toggles various debug modes.
aliases: /viaversion debug [clear/logposttransform/add/remove]
viaversion displayleaks:
permission: viaversion.admin.displayleaks
description: Toggles display of memory leaks.
aliases: [ displayleaks ]
viaversion dontbugme:
permission: viaversion.admin.dontbugme
description: Toggle checking for updates.
aliases: [ dontbugme ]
viaversion dump:
permission: viaversion.admin.dump
description: Dump information about your server, this is helpful if you report bugs.
aliases: [ dump ]
viaversion list:
permission: viaversion.admin.list
description: Lists all players with their protocol version.
aliases: [ list ]
viaversion pps:
permission: viaversion.admin.pps
description: Shows the packets per second of online players.
aliases: [ pps ]
viaversion reload:
permission: viaversion.admin.reload
description: Reloads all config files.
aliases: [ reload ]
permissions:
viaversion.admin:
default: op
children:
viaversion.admin.autoteam: true
viaversion.admin.debug: true
viaversion.admin.displayleaks: true
viaversion.admin.dontbugme: true
viaversion.admin.dump: true
viaversion.admin.list: true
viaversion.admin.pps: true
viaversion.admin.reload: true

Datei anzeigen

@ -27,7 +27,6 @@ import com.viaversion.viaversion.commands.defaultsubs.DebugSubCmd;
import com.viaversion.viaversion.commands.defaultsubs.DisplayLeaksSubCmd; import com.viaversion.viaversion.commands.defaultsubs.DisplayLeaksSubCmd;
import com.viaversion.viaversion.commands.defaultsubs.DontBugMeSubCmd; import com.viaversion.viaversion.commands.defaultsubs.DontBugMeSubCmd;
import com.viaversion.viaversion.commands.defaultsubs.DumpSubCmd; import com.viaversion.viaversion.commands.defaultsubs.DumpSubCmd;
import com.viaversion.viaversion.commands.defaultsubs.HelpSubCmd;
import com.viaversion.viaversion.commands.defaultsubs.ListSubCmd; import com.viaversion.viaversion.commands.defaultsubs.ListSubCmd;
import com.viaversion.viaversion.commands.defaultsubs.PPSSubCmd; import com.viaversion.viaversion.commands.defaultsubs.PPSSubCmd;
import com.viaversion.viaversion.commands.defaultsubs.ReloadSubCmd; import com.viaversion.viaversion.commands.defaultsubs.ReloadSubCmd;
@ -40,6 +39,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.viaversion.viaversion.api.command.ViaSubCommand.color; import static com.viaversion.viaversion.api.command.ViaSubCommand.color;
@ -69,6 +69,19 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
@Override @Override
public boolean onCommand(ViaCommandSender sender, String[] args) { public boolean onCommand(ViaCommandSender sender, String[] args) {
boolean hasPermissions = sender.hasPermission("viaversion.admin");
for (ViaSubCommand command : commandMap.values()) {
if (sender.hasPermission(command.permission())) {
hasPermissions = true;
break;
}
}
if (!hasPermissions) {
sender.sendMessage(color("&cYou are not allowed to use this command!"));
return false;
}
if (args.length == 0) { if (args.length == 0) {
showHelp(sender); showHelp(sender);
return false; return false;
@ -170,7 +183,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
} }
private boolean hasPermission(ViaCommandSender sender, String permission) { private boolean hasPermission(ViaCommandSender sender, String permission) {
return permission == null || sender.hasPermission(permission); return permission == null || sender.hasPermission("viaversion.admin") || sender.hasPermission(permission);
} }
private void registerDefaults() { private void registerDefaults() {
@ -181,7 +194,6 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
registerSubCommand(new DisplayLeaksSubCmd()); registerSubCommand(new DisplayLeaksSubCmd());
registerSubCommand(new DontBugMeSubCmd()); registerSubCommand(new DontBugMeSubCmd());
registerSubCommand(new AutoTeamSubCmd()); registerSubCommand(new AutoTeamSubCmd());
registerSubCommand(new HelpSubCmd());
registerSubCommand(new ReloadSubCmd()); registerSubCommand(new ReloadSubCmd());
} }
} }

Datei anzeigen

@ -34,7 +34,7 @@ public class DebugSubCmd extends ViaSubCommand {
@Override @Override
public String description() { public String description() {
return "Toggle debug mode"; return "Toggle various debug modes.";
} }
@Override @Override

Datei anzeigen

@ -31,7 +31,7 @@ public class DontBugMeSubCmd extends ViaSubCommand {
@Override @Override
public String description() { public String description() {
return "Toggle checking for updates"; return "Toggle checking for updates.";
} }
@Override @Override

Datei anzeigen

@ -1,40 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2023 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.commands.defaultsubs;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.command.ViaSubCommand;
public class HelpSubCmd extends ViaSubCommand {
@Override
public String name() {
return "help";
}
@Override
public String description() {
return "You are looking at it right now!";
}
@Override
public boolean execute(ViaCommandSender sender, String[] args) {
Via.getManager().getCommandHandler().showHelp(sender);
return true;
}
}

Datei anzeigen

@ -34,7 +34,7 @@ public class ListSubCmd extends ViaSubCommand {
@Override @Override
public String description() { public String description() {
return "Shows lists of the versions from logged in players"; return "Shows lists of the versions from logged in players.";
} }
@Override @Override

Datei anzeigen

@ -36,7 +36,7 @@ public class PPSSubCmd extends ViaSubCommand {
@Override @Override
public String description() { public String description() {
return "Shows the packets per second of online players"; return "Shows the packets per second of online players.";
} }
@Override @Override

Datei anzeigen

@ -29,7 +29,7 @@ public class ReloadSubCmd extends ViaSubCommand {
@Override @Override
public String description() { public String description() {
return "Reload the config from the disk"; return "Reload the config from the disk.";
} }
@Override @Override