Skip to content

Commit

Permalink
Ability to deny/allow commands without permission plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
hevav committed Jan 23, 2023
1 parent 0f5da70 commit 8d406a7
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Test server: [``ely.su``](https://hotmc.ru/minecraft-server-203216)
- ***limbofilter.commands.sendfilter* | /sendfilter** - Send Player to Filter Command
- ***limbofilter.admin.stats* | /lfilter stats** - Plugin Statistics Command
- ***limbofilter.admin.reload* | /lfilter reload** - Reload Plugin Command
- ***limboauth.admin.***\* - Gives All Admin Permissions
- ***limbofilter.admin.***\* - Gives All Admin Permissions

## LimboFilter /vs/ popular antibot solutions:

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.1.2
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

setGroup("net.elytrium")
setVersion("1.1.1")
setVersion("1.1.2")

compileJava {
getOptions().setEncoding("UTF-8")
Expand Down Expand Up @@ -113,4 +113,6 @@ String getCurrentShortRevision() {

setStandardOutput(outputStream)
}

return outputStream.toString().trim()
}
51 changes: 36 additions & 15 deletions src/main/java/net/elytrium/limbofilter/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.elytrium.commons.kyori.serialization.Serializers;
import net.elytrium.limboapi.api.chunk.Dimension;
import net.elytrium.limboapi.api.player.GameMode;
import net.elytrium.limbofilter.commands.CommandPermissionState;
import net.elytrium.limbofilter.handler.BotFilterSessionHandler;

public class Settings extends YamlConfig {
Expand Down Expand Up @@ -327,6 +328,21 @@ public static class OFFSET_1_7 {
)
public Dimension BOTFILTER_DIMENSION = Dimension.THE_END;

@Create
public COORDS COORDS;

public static class COORDS {

public double CAPTCHA_X = 0;
@Comment("If your server supports Minecraft 1.7, don't set captcha-y to 0. https://media.discordapp.net/attachments/878241549857738793/915165038464098314/unknown.png")
public double CAPTCHA_Y = 0;
public double CAPTCHA_Z = 0;
public double CAPTCHA_YAW = 90;
public double CAPTCHA_PITCH = 38;
public double FALLING_CHECK_YAW = 90;
public double FALLING_CHECK_PITCH = 10;
}

@Create
public MAIN.TCP_LISTENER TCP_LISTENER;

Expand Down Expand Up @@ -361,6 +377,26 @@ public static class TCP_LISTENER {
public boolean DEBUG_ON_SUCCESS = false;
}

@Create
public MAIN.COMMAND_PERMISSION_STATE COMMAND_PERMISSION_STATE;

@Comment({
"Available values: FALSE, TRUE, PERMISSION",
" FALSE - the command will be disallowed",
" TRUE - the command will be allowed if player has false permission state",
" PERMISSION - the command will be allowed if player has true permission state"
})
public static class COMMAND_PERMISSION_STATE {
@Comment("Permission: limbofilter.admin.sendfilter")
public CommandPermissionState SEND_FILTER = CommandPermissionState.PERMISSION;
@Comment("Permission: limbofilter.admin.reload")
public CommandPermissionState RELOAD = CommandPermissionState.PERMISSION;
@Comment("Permission: limbofilter.admin.stats")
public CommandPermissionState STATS = CommandPermissionState.PERMISSION;
@Comment("Permission: limbofilter.admin.help")
public CommandPermissionState HELP = CommandPermissionState.TRUE;
}

@Create
public MAIN.STRINGS STRINGS;

Expand Down Expand Up @@ -399,20 +435,5 @@ public static class STRINGS {

public String CAPTCHA_NOT_READY_YET = "{PRFX} Captcha is not ready yet. Try again in a few seconds";
}

@Create
public COORDS COORDS;

public static class COORDS {

public double CAPTCHA_X = 0;
@Comment("If your server supports Minecraft 1.7, don't set captcha-y to 0. https://media.discordapp.net/attachments/878241549857738793/915165038464098314/unknown.png")
public double CAPTCHA_Y = 0;
public double CAPTCHA_Z = 0;
public double CAPTCHA_YAW = 90;
public double CAPTCHA_PITCH = 38;
public double FALLING_CHECK_YAW = 90;
public double FALLING_CHECK_PITCH = 10;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2021 - 2023 Elytrium
*
* 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 <http://www.gnu.org/licenses/>.
*/

package net.elytrium.limbofilter.commands;

import com.velocitypowered.api.permission.PermissionSubject;
import com.velocitypowered.api.permission.Tristate;
import java.util.function.BiFunction;

public enum CommandPermissionState {
FALSE((source, permission) -> false),
TRUE((source, permission) -> source.getPermissionValue(permission) != Tristate.FALSE),
PERMISSION(PermissionSubject::hasPermission);

private final BiFunction<PermissionSubject, String, Boolean> hasPermissionFunction;

CommandPermissionState(BiFunction<PermissionSubject, String, Boolean> hasPermissionFunction) {
this.hasPermissionFunction = hasPermissionFunction;
}

public boolean hasPermission(PermissionSubject permissionSubject, String permission) {
return this.hasPermissionFunction.apply(permissionSubject, permission);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public void execute(SimpleCommand.Invocation invocation) {
}
}

@Override
public boolean hasPermission(Invocation invocation) {
return Settings.IMP.MAIN.COMMAND_PERMISSION_STATE.HELP
.hasPermission(invocation.source(), "limbofilter.commands.help");
}

private void showHelp(CommandSource source) {
HELP_MESSAGE.forEach(source::sendMessage);

Expand Down Expand Up @@ -157,38 +163,42 @@ private Component createStatsComponent(InetAddress address, long ping) {
}

private enum Subcommand {
RELOAD("Reload config.", (LimboFilterCommand parent, CommandSource source, String[] args) -> {
parent.plugin.reload();
source.sendMessage(parent.reloadComponent);
}),
STATS("Enable/Disable statistics of connections and blocked bots.", (LimboFilterCommand parent, CommandSource source, String[] args) -> {
if (source instanceof Player) {
Player player = (Player) source;
UUID playerUuid = player.getUniqueId();
if (PLAYERS_WITH_STATS.contains(playerUuid)) {
PLAYERS_WITH_STATS.remove(playerUuid);
source.sendMessage(parent.statsDisabledComponent);
} else {
PLAYERS_WITH_STATS.add(playerUuid);
source.sendMessage(parent.statsEnabledComponent);
}
} else {
source.sendMessage(parent.createStatsComponent(null, -1));
}
});
RELOAD("Reload config.", Settings.IMP.MAIN.COMMAND_PERMISSION_STATE.RELOAD,
(LimboFilterCommand parent, CommandSource source, String[] args) -> {
parent.plugin.reload();
source.sendMessage(parent.reloadComponent);
}),
STATS("Enable/Disable statistics of connections and blocked bots.", Settings.IMP.MAIN.COMMAND_PERMISSION_STATE.STATS,
(LimboFilterCommand parent, CommandSource source, String[] args) -> {
if (source instanceof Player) {
Player player = (Player) source;
UUID playerUuid = player.getUniqueId();
if (PLAYERS_WITH_STATS.contains(playerUuid)) {
PLAYERS_WITH_STATS.remove(playerUuid);
source.sendMessage(parent.statsDisabledComponent);
} else {
PLAYERS_WITH_STATS.add(playerUuid);
source.sendMessage(parent.statsEnabledComponent);
}
} else {
source.sendMessage(parent.createStatsComponent(null, -1));
}
});

private final String command;
private final String description;
private final CommandPermissionState permissionState;
private final SubcommandExecutor executor;

Subcommand(String description, SubcommandExecutor executor) {
Subcommand(String description, CommandPermissionState permissionState, SubcommandExecutor executor) {
this.permissionState = permissionState;
this.command = this.name().toLowerCase(Locale.ROOT);
this.description = description;
this.executor = executor;
}

public boolean hasPermission(CommandSource source) {
return source.hasPermission("limbofilter.admin." + this.command);
return this.permissionState.hasPermission(source, "limbofilter.admin." + this.command);
}

public Component getMessageLine() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void execute(SimpleCommand.Invocation invocation) {

@Override
public boolean hasPermission(SimpleCommand.Invocation invocation) {
return invocation.source().hasPermission("limbofilter.commands.sendfilter");
return Settings.IMP.MAIN.COMMAND_PERMISSION_STATE.SEND_FILTER
.hasPermission(invocation.source(), "limbofilter.admin.sendfilter");
}
}

0 comments on commit 8d406a7

Please sign in to comment.