From ce27753c51c3af571a8fa7d9f473db059c6c563c Mon Sep 17 00:00:00 2001 From: lokka30 Date: Mon, 11 Nov 2024 22:19:38 +0800 Subject: [PATCH] project: Fix folder name case conflict --- BlackWidowLib/pom.xml | 71 --- .../blackwidow/lib/cmdblocking/Chain.java | 451 ------------------ .../blackwidow/lib/cmdblocking/EvalCause.java | 67 --- .../lib/cmdblocking/Evaluation.java | 221 --------- .../blackwidow/lib/cmdblocking/Evaluator.java | 101 ---- .../lib/cmdblocking/MatchResult.java | 92 ---- .../blackwidow/lib/cmdblocking/Policy.java | 44 -- .../lib/cmdblocking/package-info.java | 25 - .../lib/cmdblocking/TestCmdEvaluation.java | 342 ------------- BlackWidowPluginBukkit/pom.xml | 152 ------ .../blackwidow/plugin/bukkit/BlackWidow.java | 321 ------------- .../blackwidow/plugin/bukkit/cfg/YamlCfg.java | 191 -------- .../plugin/bukkit/cfg/settings/Settings.java | 92 ---- .../bukkit/cfg/translations/Translation.java | 217 --------- .../bukkit/cfg/translations/Translations.java | 80 ---- .../plugin/bukkit/command/CommandManager.java | 72 --- .../command/blackwidow/BlackWidowCommand.java | 51 -- .../subcommand/ReloadSubcommand.java | 57 --- .../subcommand/VersionSubcommand.java | 59 --- .../component/cmdblocking/BukkitChain.java | 137 ------ .../component/cmdblocking/CmdBlocker.java | 180 ------- .../bukkit/event/LoadActionsReadyEvent.java | 72 --- .../event/LoadRequirementsReadyEvent.java | 72 --- .../bukkit/listener/ListenerManager.java | 71 --- .../PlayerCommandPreprocessListener.java | 83 ---- .../bukkit/PlayerCommandSendListener.java | 77 --- .../paper/AsyncPlayerCommandSendListener.java | 71 --- .../plugin/bukkit/logic/Action.java | 49 -- .../plugin/bukkit/logic/Context.java | 105 ---- .../plugin/bukkit/logic/LogicManager.java | 159 ------ .../plugin/bukkit/logic/LogicUnit.java | 22 - .../plugin/bukkit/logic/Requirement.java | 56 --- .../inbuilt/action/SendMessageAction.java | 87 ---- .../requirement/HasPermissionRequirement.java | 71 --- .../requirement/InWorldRequirement.java | 68 --- .../plugin/bukkit/util/ClassUtil.java | 47 -- .../plugin/bukkit/util/DebugCategory.java | 25 - .../plugin/bukkit/util/ExceptionUtil.java | 92 ---- .../src/main/resources/plugin.yml | 34 -- .../src/main/resources/settings.yml | 41 -- .../src/main/resources/translations.yml | 19 - 41 files changed, 4344 deletions(-) delete mode 100644 BlackWidowLib/pom.xml delete mode 100644 BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Chain.java delete mode 100644 BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/EvalCause.java delete mode 100644 BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Evaluation.java delete mode 100644 BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Evaluator.java delete mode 100644 BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/MatchResult.java delete mode 100644 BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Policy.java delete mode 100644 BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/package-info.java delete mode 100644 BlackWidowLib/src/test/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/TestCmdEvaluation.java delete mode 100644 BlackWidowPluginBukkit/pom.xml delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/BlackWidow.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/YamlCfg.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/settings/Settings.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/translations/Translation.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/translations/Translations.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/CommandManager.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/BlackWidowCommand.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/subcommand/ReloadSubcommand.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/subcommand/VersionSubcommand.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/component/cmdblocking/BukkitChain.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/component/cmdblocking/CmdBlocker.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/event/LoadActionsReadyEvent.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/event/LoadRequirementsReadyEvent.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/ListenerManager.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/bukkit/PlayerCommandPreprocessListener.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/bukkit/PlayerCommandSendListener.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/paper/AsyncPlayerCommandSendListener.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Action.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Context.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/LogicManager.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/LogicUnit.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Requirement.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/action/SendMessageAction.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/requirement/HasPermissionRequirement.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/requirement/InWorldRequirement.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/ClassUtil.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/DebugCategory.java delete mode 100644 BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/ExceptionUtil.java delete mode 100644 BlackWidowPluginBukkit/src/main/resources/plugin.yml delete mode 100644 BlackWidowPluginBukkit/src/main/resources/settings.yml delete mode 100644 BlackWidowPluginBukkit/src/main/resources/translations.yml diff --git a/BlackWidowLib/pom.xml b/BlackWidowLib/pom.xml deleted file mode 100644 index 0b3d713..0000000 --- a/BlackWidowLib/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - 4.0.0 - - io.github.arcaneplugins.blackwidow - blackwidow - 1.0.0-SNAPSHOT - - - blackwidowlib - 1.0.0-SNAPSHOT - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - 21 - 8 - 8 - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.3.0 - - - - - - UTF-8 - 1.8 - 1.8 - - - - - - - org.junit.jupiter - junit-jupiter-engine - 5.10.2 - test - - - - - - \ No newline at end of file diff --git a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Chain.java b/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Chain.java deleted file mode 100644 index a90de37..0000000 --- a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Chain.java +++ /dev/null @@ -1,451 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.lib.cmdblocking; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.function.Supplier; -import java.util.regex.Pattern; - -/** - * Represents a {@code rules} sequence, and logic for if any of its rules are matched by a command, what policy to deal - * with the command that was matched. - *

- * A {@code rule} is a string used to match commands against. For example, {@code /cd *} will match {@code /cd hello}, - * {@code /cd hey how are you}, but not {@code /cd} (since the wildcard on the argument at index {@code 1} requires - * an argument there and matches against anything present. - *

- * - * @author lokka30 - * @since 1.0.0 - */ -public class Chain { - - private final String id; - private final boolean enabled; - private final Policy policy; - private final Collection rules; - private final boolean isRegex; - private final Map rulesRegexPatterns; - private final Map rulesAsArgs; - private final Collection causeFilters; - - /** - * Constructs a {@code Chain}. - * - * @param id Unique identifier for this chain. - * @param enabled Whether this chain is enabled. - * @param policy How a command should be dealt with (e.g., {@code DENY}) if any of the {@code rules} are matched. - * @param rules A collection of strings used to match commands against, an example being {@code /hello * are you}. - * @param isRegex Whether this chain's rules are regular expressions (regex). - * @param causeFilters A collection of causes which this chain will only evaluate against. - * @author lokka30 - * @since 1.0.0 - */ - public Chain( - final String id, - final boolean enabled, - final Policy policy, - final Collection rules, - final boolean isRegex, - final Collection causeFilters - ) { - this.id = Objects.requireNonNull(id, "id"); - this.enabled = enabled; - this.policy = Objects.requireNonNull(policy, "policy"); - this.rules = Objects.requireNonNull(rules, "rules"); - this.isRegex = isRegex; - this.rulesRegexPatterns = new HashMap<>(rules.size()); - this.rulesAsArgs = new HashMap<>(rules.size()); - this.causeFilters = causeFilters; - - if (id().isEmpty()) { - throw new IllegalArgumentException("id can't be empty"); - } - - if (!isRegex()) { - for (final String rule : rules()) { - if(rule.startsWith("/")) { - continue; - } - - throw new IllegalArgumentException("Rule string='" + rule + "' in chain id='" + id() + "' does" + - "not start with a slash (/); for a non-regex chain, all rules must start with a slash"); - } - } - - updatePrecompiledMaps(); - } - - /** - * Update the precompiled maps, being {@link Chain#rulesRegexPatterns()} and {@link Chain#rulesAsArgs()}. - * - * @author lokka30 - * @since 1.0.0 - */ - public void updatePrecompiledMaps() { - rulesAsArgs.clear(); - rulesRegexPatterns.clear(); - - for (final String rule : rules) { - if (rule.isEmpty()) { - throw new IllegalArgumentException("rule can't be empty"); - } - - if (isRegex()) { - rulesRegexPatterns.put(rule, Pattern.compile(rule, Pattern.CASE_INSENSITIVE)); - } else { - if (rule.charAt(0) != '/') { - throw new IllegalArgumentException("rule must begin with a slash (/)"); - } - - rulesAsArgs.put(rule, transformToArgs(rule)); - } - } - } - - /** - * Returns this {@code Chain}'s policy. - * - * @return Policy of this {@code Chain}. - * @author lokka30 - * @since 1.0.0 - */ - public final Policy policy() { - return Objects.requireNonNull(policy, "policy"); - } - - /** - * Returns this {@code Chain}'s rules. - * - * @return Rules of this {@code Chain}. - * @author lokka30 - * @since 1.0.0 - */ - public final Collection rules() { - return Objects.requireNonNull(rules, "rules"); - } - - /** - * Returns if this {@code Chain} uses Regex for matching rules. - * - * @return If this {@code} Chain uses Regex for matching rules. - * @author lokka30 - * @since 1.0.0 - */ - public final boolean isRegex() { - return isRegex; - } - - /** - * Returns the precompiled regex patterns for this chain. - *

- * - * This chain MUST use regex (see {@link Chain#isRegex()}) or this will fire a {@link IllegalStateException}! - * - *

- * - * @return precompiled regex patterns for the chain's rules (non-null) - * @author lokka30 - * @since 1.0.0 - */ - public final Map rulesRegexPatterns() { - if (!isRegex()) { - throw new IllegalStateException("Chain does not use regex rules and thus can't have regex patterns"); - } - return Objects.requireNonNull(rulesRegexPatterns, "rulesRegexPatterns"); - } - - /** - * Returns the precompiled rules as sanitized args. - *

- * - * This chain MUST NOT use regex (see {@link Chain#isRegex()}) or this will fire a {@link IllegalStateException}! - * - *

- * - * @return precompiled rules as args for the chain's rules (non-null) - * @author lokka30 - * @since 1.0.0 - */ - public final Map rulesAsArgs() { - if (isRegex()) { - throw new IllegalStateException("Chain uses regex rules and thus can't have rules as args"); - } - - return Objects.requireNonNull(rulesAsArgs, "rulesAsArgs"); - } - - /** - * Returns if this chain is enabled. - * - * @return Whether this chain is enabled. - * @author lokka30 - * @since 1.0.0 - */ - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public final boolean enabled() { - return enabled; - } - - /** - * Returns this chain's ID. - * - * @return This chain's ID. - * @author lokka30 - * @since 1.0.0 - */ - public final String id() { - return id; - } - - /** - * Transforms a command or rule string into an array of arguments, sanitized to make comparing various args simple. - *

- * {@code str}'s starting slash is removed, then converted to lowercase, then trimmed of whitespace, and finally, - * split by any whitespace into an array of arguments. - *

- * - * @param str A command or rule string. - * @return {@code str} converted into a lowercase sanitized array of whitespace-separated arguments. - * @author lokka30 - * @since 1.0.0 - */ - protected static String[] transformToArgs( - final String str - ) { - if (str.isEmpty()) { - throw new IllegalArgumentException("str parameter must not be empty"); - } - - if (str.charAt(0) != '/') { - throw new IllegalArgumentException("str parameter must start with a slash (/)"); - } - - return str - .substring(1) // we don't want the starting slash. - .toLowerCase(Locale.ROOT) // let's use lowercase for case insensitivity. - .trim() // trim leading and trialing whitespace otherwise it can break String#split below. - .split("\\s+"); // finally, split by whitespace via regex. - } - - /** - * Match a particular {@code command} against a particular {@code rule}. USES REGEXP. - * - * @param command Command to match with. - * @param rule Rule to match against. - * @param pattern Pattern to match against. - * @param debugger Consumer accepting debug logs. - * @return A {@link MatchResult match result} explaining whether it matched and how it determined the outcome. - * @author lokka30 - * @since 1.0.0 - */ - private MatchResult matchRulePattern( - final String command, - final String rule, - final Pattern pattern, - final EvalCause cause, - final Consumer> debugger - ) { - Objects.requireNonNull(command, "command"); - Objects.requireNonNull(rule, "rule"); - Objects.requireNonNull(pattern, "pattern"); - Objects.requireNonNull(debugger, "debugger"); - - if (!enabled()) { - return new MatchResult(false, rule, "chain is disabled"); - } - - if (!causeFilters().contains(cause)) { - return new MatchResult(false, rule, "cause not in causeFilters"); - } - - if (command.isEmpty()) { - throw new IllegalArgumentException("cmd can't be empty"); - } - - if (command.charAt(0) != '/') { - throw new IllegalArgumentException("cmd must start with a slash (/)"); - } - - if (rule.isEmpty()) { - throw new IllegalArgumentException("rule can't be empty"); - } - - if (!isRegex()) { - throw new IllegalStateException("Chain must have regexp rules"); - } - - return new MatchResult( - pattern.matcher(command).find(), - rule, - "regex pattern match find result" - ); - } - - /** - * Match a particular {@code command} against a particular {@code rule}. NOT regexp. - * - * @param cmdArgs Command to match with. - * @param ruleArgs Rule to match against. - * @param debugger Consumer accepting debug logs. - * @return A {@link MatchResult match result} explaining whether it matched and how it determined the outcome. - * @author lokka30 - * @since 1.0.0 - */ - private MatchResult matchRuleArgs( - final String cmd, - final String[] cmdArgs, - final String rule, - final String[] ruleArgs, - final EvalCause cause, - final Consumer> debugger - ) { - Objects.requireNonNull(cmd, "cmd"); - Objects.requireNonNull(cmdArgs, "cmdArgs"); - Objects.requireNonNull(rule, "rule"); - Objects.requireNonNull(ruleArgs, "ruleArgs"); - Objects.requireNonNull(debugger, "debugger"); - - if (!enabled()) { - return new MatchResult(false, rule, "chain is disabled"); - } - - if (!causeFilters().contains(cause)) { - return new MatchResult(false, rule, "cause not in causeFilters"); - } - - final int minLen = Math.min(cmdArgs.length, ruleArgs.length); - - debugger.accept(() -> "matchRule: Checking cmd='" + cmd + "', " + - "rule='" + rule + "', " + - "minLen='" + minLen + "', " + - "cmdArgs='" + Arrays.toString(cmdArgs) + "' (len='" + cmdArgs.length + "'), " + - "ruleArgs='" + Arrays.toString(ruleArgs) + "' (len='" + ruleArgs.length + "')."); - - if (ruleArgs.length == 0 && cmdArgs.length == 0) { - debugger.accept(() -> "matchRule: Yes, because rule args and cmd args are both empty arrays."); - return new MatchResult(true, rule, "rule and cmd are both empty"); - } - - if (ruleArgs.length > cmdArgs.length) { - debugger.accept(() -> "matchRule: No, because it's impossible for this command to match this rule, " + - "because it doesn't have an equal or greater number args."); - return new MatchResult(false, rule, "rule has more args than cmd, thus " + - "impossible to match"); - } - - for (int i = 0; i < minLen; i++) { - final String cmdArg = cmdArgs[i]; - final String ruleArg = ruleArgs[i]; - - final int finalI = i; - debugger.accept(() -> "matchRule [i='" + finalI + "']: cmdArg='" + cmdArg + "', ruleArg='" + ruleArg + "'."); - - // if the args don't match and the rule arg isn't a wildcard, nope - if (!cmdArg.equals(ruleArg) && !ruleArg.equals("*")) { - debugger.accept(() -> "matchRule: No, since args don't match and ruleArg is not a wildcard"); - return new MatchResult(false, rule, "arg at index '" + i + "' didn't match, and " + - "ruleArg is not a wildcard"); - } - - // if we're looking at the last arg of the rule, we've found a match. - if (i + 1 == ruleArgs.length) { - debugger.accept(() -> "matchRule: Yes, matched all args of rule."); - return new MatchResult(true, rule, "cmd matches rule"); - } - - // otherwise, check that all next args (if present) match - } - - // fallback to nope - debugger.accept(() -> "matchRule: No, there weren't any arg matches"); - return new MatchResult(false, rule, "cmd doesn't match rule"); - } - - /** - * Match a particular {@code command} against this chain's {@link Chain#rules() rules}. - * - * @param command Command to match with. - * @param debugger Consumer accepting debug logs. - * @return A {@link MatchResult match result} explaining whether it matched and how it determined the outcome. - * @author lokka30 - * @since 1.0.0 - */ - public final MatchResult matches( - final String command, - final EvalCause cause, - final Consumer> debugger - ) { - Objects.requireNonNull(command, "command"); - Objects.requireNonNull(debugger, "debugger"); - - if (command.isEmpty()) { - throw new IllegalArgumentException("command must not be empty"); - } - if (command.charAt(0) != '/') { - throw new IllegalArgumentException("command must start with a slash (/)"); - } - - if (!enabled()) { - return new MatchResult(false, null, "chain is disabled"); - } - - if (!causeFilters().contains(cause)) { - return new MatchResult(false, null, "cause not in causeFilters"); - } - - debugger.accept(() -> "matches: Checking cmd='" + command + "' on chain, len='" + rules().size() + "'."); - - for (final String rule : rules) { - debugger.accept(() -> "matches: Checking rule '" + rule + "'."); - - final MatchResult res = isRegex() ? - matchRulePattern(command, rule, rulesRegexPatterns().get(rule), cause, debugger) : - matchRuleArgs(command, transformToArgs(command), rule, rulesAsArgs().get(rule), cause, debugger); - - if (res.matched()) { - debugger.accept(() -> "matches: Matched!"); - return new MatchResult( - true, - res.rule(), - "in rule '" + rule + "'; " + res.description() - ); - } - - debugger.accept(() -> "matches: Didn't match, continuing."); - } - - debugger.accept(() -> "matches: No rules matched in this chain."); - return new MatchResult(false, null, "no rule matched"); - } - - /** - * @return A collection which specifies what {@link EvalCause}(s) are able to evaluate against the chain. - */ - public final Collection causeFilters() { - return this.causeFilters; - } - -} diff --git a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/EvalCause.java b/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/EvalCause.java deleted file mode 100644 index e822e98..0000000 --- a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/EvalCause.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.lib.cmdblocking; - -import java.util.Collection; -import java.util.EnumSet; -import java.util.function.Consumer; - -/** - * Represents various causes (reasons) of a {@link Chain} being evaluated. Usually supplied via - * {@link Evaluator#evaluate(String, Collection, Policy, boolean, EvalCause, Consumer, Consumer)}. - * - * @author lokka30 - * @since 1.0.0 - */ -public enum EvalCause { - - /** - * Cause of evaluation is due to command execution, e.g., user runs {@code /help}. - * - * @since 1.0.0 - */ - CMD_EXECUTION, - - /** - * Cause of evaluation is due to command suggestion, e.g., user types {@code /hel} and is suggested {@code /help}; - * in this case, {@code /help} was the suggested command related to this {@link EvalCause}. - * - * @since 1.0.0 - */ - CMD_SUGGESTION, - - /** - * Cause of this evaluation is unknown / a miscellaneous reason not listed here. - * - * @since 1.0.0 - */ - OTHER; - - private static final EnumSet SET_CAUSES = EnumSet.allOf(EvalCause.class); - - /** - * @return All values of this Enum as a {@link EnumSet}. - * @author lokka30 - * @since 1.0.0 - */ - public static EnumSet setValues() { - return SET_CAUSES; - } - -} diff --git a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Evaluation.java b/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Evaluation.java deleted file mode 100644 index 96f9929..0000000 --- a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Evaluation.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.lib.cmdblocking; - -import java.util.Objects; - -/** - * Represents a total evaluation made on whether a player can access a command. Contains additional information such - * as a reference to the particular rule matched, which {@link Chain chain} it belonged to, and a description of how - * this evaluation was made. - * - * @author lokka30 - * @since 1.0.0 - */ -public final class Evaluation { - - private final String command; - private final Policy policy; - private final Chain chain; - private final String rule; - private final String description; - - private boolean dueToColonInFirstArg = false; - private boolean dueToException = false; - private boolean dueToOperatorsBypassCmdBlocking = false; - private boolean dueToDefaultPolicy = false; - - /** - * Construct a {@code Evaluation}. - * - * @param command The command evaluated against. - * @param policy The policy evaluated. - * @param chain The chain containing the {@code rule} that was matched. Nullable. - * @param rule The rule that was matched. Nullable. - * @param description An explanation of how the evaluation was made. - * @author lokka30 - * @since 1.0.0 - */ - public Evaluation( - final String command, - final Policy policy, - final Chain chain, - final String rule, - final String description - ) { - this.command = Objects.requireNonNull(command, "command"); - this.policy = Objects.requireNonNull(policy, "policy"); - this.chain = chain; - this.rule = rule; - this.description = Objects.requireNonNull(description, "description"); - } - - /** - * Returns the command evaluated against. - * - * @return Command evaluated against. - * @author lokka30 - * @since 1.0.0 - */ - public String command() { - return command; - } - - /** - * Returns the policy that was evaluated. - * - * @return The policy that was evaluated. - * @author lokka30 - * @since 1.0.0 - */ - public Policy policy() { - return policy; - } - - /** - * Returns the chain containing the rule that was matched. - * Return value is nullable. - * - * @return The chain containing the rule that was matched. - * @author lokka30 - * @since 1.0.0 - */ - public Chain chain() { - return chain; - } - - /** - * Returns the rule that was matched. - * Return value is nullable. - * - * @return The rule that was matched. - * @author lokka30 - * @since 1.0.0 - */ - @SuppressWarnings("unused") - public String rule() { - return rule; - } - - /** - * Returns a description useful for debugging how the evaluation was made. - * - * @return Description of this evaluation. - * @author lokka30 - * @since 1.0.0 - */ - public String description() { - return description; - } - - /** - * Returns whether the evaluation was made due to a colon being found in the command's first argument when it was - * not allowed to have one. - * - * @return Whether evaluation was due to colon in first argument when disallowed. - * @author lokka30 - * @since 1.0.0 - */ - public boolean dueToColonInFirstArg() { - return dueToColonInFirstArg; - } - - /** - * Adjust whether the evaluation was made due to the colon being found in the command's first arg when disallowed. - * - * @param val New value. - * @return Instance of self. - * @author lokka30 - * @since 1.0.0 - */ - public Evaluation withDueToColonInFirstArg(final boolean val) { - this.dueToColonInFirstArg = val; - return this; - } - - /** - * Returns whether the evaluation was made due to an exception being thrown whilst attempting to evaluate the cmd. - * - * @return Whether evaluation was due to colon in first argument when disallowed. - * @author lokka30 - * @since 1.0.0 - */ - public boolean dueToException() { - return dueToException; - } - - /** - * Adjust whether the evaluation was made due to an exception being thrown whilst attempting to evaluate the cmd. - * - * @param val New value. - * @return Instance of self. - * @author lokka30 - * @since 1.0.0 - */ - public Evaluation withDueToException(final boolean val) { - this.dueToException = val; - return this; - } - - /** - * @return Whether the evaluation was caused due to operators bypassing command blocking. - * @author lokka30 - * @since 1.0.0 - */ - @SuppressWarnings("unused") - public boolean dueToOperatorsBypassCmdBlocking() { - return dueToOperatorsBypassCmdBlocking; - } - - /** - * Adjust whether this evaluation was caused directly by operators bypassing command blocking. - * - * @param val New value. - * @return Instance of self. - * @author lokka30 - * @since 1.0.0 - */ - public Evaluation withDueToOperatorsBypassCmdBlocking(final boolean val) { - this.dueToOperatorsBypassCmdBlocking = val; - return this; - } - - /** - * @return Whether the evaluation was caused due a default policy being evaluated. - * @author lokka30 - * @since 1.0.0 - */ - public boolean dueToDefaultPolicy() { - return dueToDefaultPolicy; - } - - /** - * Adjust whether this evaluation was caused directly by a default policy being used. - * - * @param val New value. - * @return Instance of self. - * @author lokka30 - * @since 1.0.0 - */ - public Evaluation withDueToDefaultPolicy(final boolean val) { - this.dueToDefaultPolicy = val; - return this; - } - -} diff --git a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Evaluator.java b/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Evaluator.java deleted file mode 100644 index feccac8..0000000 --- a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Evaluator.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.lib.cmdblocking; - -import java.util.Collection; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; -import java.util.function.Supplier; - -public class Evaluator { - - public static final AtomicBoolean SUPPRESS_EXCEPTION_MESSAGES = new AtomicBoolean(false); - - public static Evaluation evaluate( - final String cmd, - final Collection chains, - final Policy defaultPolicy, - final boolean denyColonInFirstArg, - final EvalCause cause, - final Consumer> debugLogger, - final Consumer> warningLogger - ) { - try { - Objects.requireNonNull(cmd, "cmd"); - Objects.requireNonNull(chains, "chains"); - Objects.requireNonNull(defaultPolicy, "defaultPolicy"); - Objects.requireNonNull(debugLogger, "debugLogger"); - Objects.requireNonNull(warningLogger, "warningLogger"); - - if (cmd.isEmpty()) { - throw new IllegalArgumentException("cmd can't be empty"); - } - - if (cmd.charAt(0) != '/') { - throw new IllegalArgumentException("cmd must start with a slash (/)"); - } - - int i = 0; - for (Chain chain : chains) { - final MatchResult res = chain.matches(cmd, cause, debugLogger); - if (res.matched()) { - return new Evaluation( - cmd, - chain.policy(), - chain, - res.rule(), - "in chain #" + i + " (id='" + chain.id() + "'; " + res.description() - ); - } - i++; - } - - if (denyColonInFirstArg && Chain.transformToArgs(cmd)[0].contains(":")) { - return new Evaluation(cmd, Policy.DENY, null, null, "colon found in first arg") - .withDueToColonInFirstArg(true); - } - } catch (Exception ex) { - if (!SUPPRESS_EXCEPTION_MESSAGES.get()) { - warningLogger.accept(() -> - "An exception was caught whilst evaluating cmd '" + cmd + "': '" + ex.getClass().getSimpleName() + - "'. For best security practice, this cmd will be forcefully denied due to the error. " + - "Message: '" + ex.getMessage() + "'; Stack trace:\n" - ); - //noinspection CallToPrintStackTrace - ex.printStackTrace(); - } - return new Evaluation( - cmd == null ? "/??? NULL COMMAND ???" : cmd, - Policy.DENY, - null, - null, - "exception caught, denying for security" - ).withDueToException(true); - } - - return new Evaluation( - cmd, - defaultPolicy, - null, - null, - "default policy, no chains matched" - ).withDueToDefaultPolicy(true); - } -} diff --git a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/MatchResult.java b/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/MatchResult.java deleted file mode 100644 index 8061e25..0000000 --- a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/MatchResult.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.lib.cmdblocking; - -import java.util.Objects; - -/** - * Class which acts as a container for a result whether a command matched a rule. - *

- * This class also contains other information which is useful for debugging, such as what rule was matched, and a - * description of what circumstance caused this rule to be triggered. - *

- * - * @author lokka30 - * @since 1.0.0 - */ -public final class MatchResult { - - private final boolean matched; - private final String rule; - private final String description; - - /** - * Construct a {@code MatchResult}. - * - * @param matched Whether the command matched the rule. - * @param rule Raw rule string containing the rule that the cmd matched. Null indicates no rule directly involved. - * @param description A description indicating how the command matched the rule. - * @author lokka30 - * @since 1.0.0 - */ - public MatchResult( - final boolean matched, - final String rule, - final String description - ) { - this.matched = matched; - this.rule = rule; - this.description = Objects.requireNonNull(description, "description"); - } - - /** - * Returns whether the command matched the rule. - * - * @return Whether the command matched the rule. - * @author lokka30 - * @since 1.0.0 - */ - public boolean matched() { - return matched; - } - - /** - * Returns the raw rule string which the command matched, or an empty string if there was no match. - * Returns nullable value. - * - * @return The raw rule string if matched, otherwise an empty string. - * @author lokka30 - * @since 1.0.0 - */ - public String rule() { - return rule; - } - - /** - * Returns a description useful for debugging. - * - * @return A description useful for debugging. - * @author lokka30 - * @since 1.0.0 - */ - public String description() { - return description; - } - -} diff --git a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Policy.java b/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Policy.java deleted file mode 100644 index 311ca97..0000000 --- a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/Policy.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.lib.cmdblocking; - -/** - * Values that determine what decision is made on how a player's command should be actioned, i.e., - * allowed or denied. - * - * @author lokka30 - * @since 1.0.0 - */ -public enum Policy { - - /** - * Represents a decision to allow the command to run. - * - * @since 1.0.0 - */ - ALLOW, - - /** - * Represents a decision to deny the command from being ran. - * - * @since 1.0.0 - */ - DENY, - -} diff --git a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/package-info.java b/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/package-info.java deleted file mode 100644 index deb67e5..0000000 --- a/BlackWidowLib/src/main/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -/** - * This package contains various library functions related to command blocking. - * - * @author lokka30 - * @since 1.0.0 - */ -package io.github.arcaneplugins.blackwidow.lib.cmdblocking; diff --git a/BlackWidowLib/src/test/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/TestCmdEvaluation.java b/BlackWidowLib/src/test/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/TestCmdEvaluation.java deleted file mode 100644 index d9ecd99..0000000 --- a/BlackWidowLib/src/test/java/io/github/arcaneplugins/blackwidow/lib/cmdblocking/TestCmdEvaluation.java +++ /dev/null @@ -1,342 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.lib.cmdblocking; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.regex.Pattern; - -public final class TestCmdEvaluation { - - // Various 'plugin checking' commands - private static final String[] TEST_PLUGIN_CMDS = { - "/plugins", "/pl", "/version", "/ver", "/icanhasbukkit", - "/about", "/?", "/help", "/ehelp", "/paper", "/spigot" - }; - - // Various programatically defined chains of rules, some regex ones provided at the bottom. - // Chains should NOT contain 'donotuseinchains', doing so will make some tests fail (by design). - private static final Collection TEST_CHAINS = Arrays.asList( - new Chain("0", true, Policy.DENY, Arrays.asList("/cd reload *", "/"), false, EvalCause.setValues()), - new Chain("1", true, Policy.ALLOW, Collections.singletonList("/cd reload"), false, EvalCause.setValues()), - new Chain("2", true, Policy.DENY, Collections.singletonList("/cd"), false, EvalCause.setValues()), - new Chain("3", true, Policy.DENY, Arrays.asList(TEST_PLUGIN_CMDS), false, EvalCause.setValues()), - new Chain("4", true, Policy.ALLOW, Collections.singletonList("/es version"), false, EvalCause.setValues()), - new Chain("5", true, Policy.DENY, Arrays.asList("/es give", "/es enchant"), false, EvalCause.setValues()), - new Chain("6", true, Policy.ALLOW, Collections.singletonList("^(/heywhats(up)?(?:$|\\W)cool(beans)?(?:$|\\W).*)"), true, EvalCause.setValues()), - new Chain("7", true, Policy.DENY, Collections.singletonList("^(/heywhats(up)?(?:$|\\W).*)"), true, EvalCause.setValues()), - new Chain("8", false, Policy.DENY, Collections.singletonList("/thisshouldnotbedenied"), false, EvalCause.setValues()), - new Chain("9", true, Policy.DENY, Collections.singletonList("/blocksuggestionsonly"), false, EnumSet.of(EvalCause.CMD_SUGGESTION)) - ); - - // Commands to be tested which are expected to be evaluated with a DENY policy. - public static final String[] TEST_CMDS_EXPECTING_DENY = { - "/cd abc", "/cd reloada", "/cd reloa", "/cd reload abc", - "/plugins", "/pl", "/version", "/ver", "/icanhasbukkit", - "/about", "/?", "/help", "/ehelp", "/paper", "/spigot", - "/es give", "/es enchant", "/cd", "/", "/:", "/hello:how", - "/the:quick brown fox", "/bukkit:help", - // regex: - "/heywhats", - "/heywhats coolio", - "/heywhats verycool", - "/heywhatsup", - "/heywhatsup coolio", - "/heywhatsup verycool", - }; - - // Commands to be tested which are expected to be evaluated with an ALLOW policy. - public static final String[] TEST_CMDS_EXPECTING_ALLOW = { - "/cd reload", "/CD RELOAD", "//", "/es", "/es version", "/abcdefg", "/thisshouldnotbedenied", - // regex: - "/heywhats cool", - "/heywhats coolbeans", - "/heywhatsup cool", - "/heywhatsup coolbeans", - "/heywhatsup cool beans", - }; - - // Commands to be tested which contains colons. - // 'donotuseinchains' term is used to make it clear PLEASE DO NOT USE THIS TERM IN ANY CHAINS or it can mess - // up the tests. - public static final String[] TEST_CMDS_WITH_COLONS = { - "/donotuseinchains:donotuseinchains", - "/donotuseinchains:donotuseinchains donotuseinchains", - }; - - // Commands to be tested which do NOT contain colons. - // 'donotuseinchains' term is used to make it clear PLEASE DO NOT USE THIS TERM IN ANY CHAINS or it can mess - // up the tests. - public static final String[] TEST_CMDS_WITHOUT_COLONS = { - "/donotuseinchains", - "/donotuseinchains donotuseinchains", - }; - - // Default policy to be used during these tests. ALLOW here represents a whitelist which is the usual setup. - public static final Policy TEST_DEFAULT_POLICY = Policy.ALLOW; - - // Handle debug logs here - private static final Consumer> debugLogger = (msg) -> { - }; // Do nothing - - // Handle warning logs here - private static final Consumer> warningLogger = (msg) -> System.out.println("[WARN] " + msg.get()); - - /** - * Short hand version of running the test evaluations. - * - * @param cmd Command to evaluate. - * @param denyColonInFirstArg Whether colons in the first arg should cause a denied evaluation. - * @return {@link Evaluation Evaluation} made with the provided parameters. - */ - private static Evaluation testEvaluation( - final String cmd, - final boolean denyColonInFirstArg - ) { - return Evaluator.evaluate( - cmd, - TEST_CHAINS, - TEST_DEFAULT_POLICY, - denyColonInFirstArg, - EvalCause.CMD_EXECUTION, - debugLogger, - warningLogger - ); - } - - /** - * Ensures all chains rules start with a slash if it is not a regex chain. - * - * @author lokka30 - * @since 1.0.0 - */ - @Test - public void testChainsMustStartWithSlash() { - for (final Chain chain : TEST_CHAINS) { - if(chain.isRegex()) { - continue; - } - - for(final String rule : chain.rules()) { - Assertions.assertTrue( - rule.startsWith("/"), - "Non-regex chain rules must start with a slash, failed on rule='" + rule + "'" - ); - } - } - } - - /** - * Example to ensure all commands expected to be denied are.. denied. - * - * @author lokka30 - * @since 1.0.0 - */ - @Test - public void testRulesExpectingDeny() { - for (final String cmd : TEST_CMDS_EXPECTING_DENY) { - final Evaluation eval = testEvaluation(cmd, true); - Assertions.assertFalse(eval.dueToException(), "Exception not expected here"); - Assertions.assertEquals(eval.policy(), Policy.DENY, "Wrong policy evaluated for cmd='" + - cmd + "'; description='" + eval.description() + "'"); - } - } - - /** - * Example to ensure all commands expected to be allowed are.. allowed. - * - * @author lokka30 - * @since 1.0.0 - */ - @Test - public void testRulesExpectingAllow() { - for (final String cmd : TEST_CMDS_EXPECTING_ALLOW) { - final Evaluation eval = testEvaluation(cmd, true); - Assertions.assertFalse(eval.dueToException(), "Exception not expected here"); - Assertions.assertEquals(eval.policy(), Policy.ALLOW, "Wrong policy evaluated for cmd='" + - cmd + "'; description='" + eval.description() + "'"); - } - } - - /** - * Example to ensure 'colon in first arg' commands are being denied when present AND when denyColonInFirstArg - * is enabled on the evaluate method. - * - * @author lokka30 - * @since 1.0.0 - */ - @Test - public void testColonBlocking() { - for (final String cmd : TEST_CMDS_WITH_COLONS) { - { - final Evaluation eval = testEvaluation(cmd, true); - - Assertions.assertFalse(eval.dueToException(), "Exception not expected here"); - Assertions.assertTrue(eval.dueToColonInFirstArg(), "Colon in first arg expected to be cause"); - Assertions.assertEquals(eval.policy(), Policy.DENY, - "Wrong policy evaluated for cmd='" + cmd + "'; description='" + - eval.description() + "'"); - } - - { - final Evaluation eval = testEvaluation(cmd, false); - - Assertions.assertFalse(eval.dueToException(), "Exception not expected here"); - Assertions.assertFalse(eval.dueToColonInFirstArg(), "Colon in first arg unexpected to be cause"); - Assertions.assertEquals(eval.policy(), Policy.ALLOW, - "Wrong policy evaluated for cmd='" + cmd + "'; description='" + - eval.description() + "'"); - } - } - - for (final String cmd : TEST_CMDS_WITHOUT_COLONS) { - { - final Evaluation eval = testEvaluation(cmd, true); - - Assertions.assertFalse(eval.dueToException(), "Exception not expected here"); - Assertions.assertFalse(eval.dueToColonInFirstArg(), "Colon in first arg unexpected to be cause"); - Assertions.assertEquals(eval.policy(), Policy.ALLOW, - "Wrong policy evaluated for cmd='" + cmd + "'; description='" + - eval.description() + "'"); - } - - { - final Evaluation eval = testEvaluation(cmd, false); - Assertions.assertFalse(eval.dueToException(), "Exception not expected here"); - Assertions.assertFalse(eval.dueToColonInFirstArg(), "Colon in first arg unexpected to be cause"); - Assertions.assertEquals(eval.policy(), Policy.ALLOW, - "Wrong policy evaluated for cmd='" + cmd + "'; description='" + - eval.description() + "'"); - } - } - } - - /** - * Example regex to block /pl and /plugins. - * - * @author lokka30 - * @since 1.0.0 - */ - @Test - public void testPluginCheckingRegex() { - final String regex = "^(/pl(ugins)?(?:$|\\W).*)"; - final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); - - Assertions.assertTrue(pattern.matcher("/pl").find(), "Invalid regex find result"); - Assertions.assertTrue(pattern.matcher("/pl help").find(), "Invalid regex find result"); - Assertions.assertTrue(pattern.matcher("/plugins").find(), "Invalid regex find result"); - Assertions.assertTrue(pattern.matcher("/plugins help").find(), "Invalid regex find result"); - Assertions.assertTrue(pattern.matcher("/plugins help /pl").find(), "Invalid regex find result"); - Assertions.assertFalse(pattern.matcher("/plot").find(), "Invalid regex find result"); - Assertions.assertFalse(pattern.matcher("/player").find(), "Invalid regex find result"); - Assertions.assertFalse(pattern.matcher("/tpa").find(), "Invalid regex find result"); - Assertions.assertFalse(pattern.matcher("/help").find(), "Invalid regex find result"); - Assertions.assertFalse(pattern.matcher("/help /pl").find(), "Invalid regex find result"); - Assertions.assertFalse(pattern.matcher("/help /plugins").find(), "Invalid regex find result"); - Assertions.assertFalse(pattern.matcher("/help /plugins help /pl").find(), "Invalid regex find result"); - } - - /** - * Example to ensure default policy of 'DENY' works ('ALLOW' is already tested thoroughly in other tests). - * - * @author lokka30 - * @since 1.0.0 - */ - @Test - public void testDenyDefaultPolicy() { - final Evaluation eval = Evaluator.evaluate( - "/donotuseinchains", - TEST_CHAINS, - Policy.DENY, - true, - EvalCause.CMD_EXECUTION, - debugLogger, - warningLogger - ); - - Assertions.assertFalse(eval.dueToException(), "Exception not expected here"); - Assertions.assertEquals(eval.policy(), Policy.DENY, "Wrong policy evaluated"); - } - - /** - * Example to ensure an exception being fired in the evaluation process causes a DENY policy to be evaluated - * for best-practice security. - *

- * To stop the exception messages from being printed whilst testing this particular case, the - * {@link Evaluator#SUPPRESS_EXCEPTION_MESSAGES SUPPRESS_EXCEPTION_MESSAGES} flag is enabled during the test. - *

- * - * @author lokka30 - * @since 1.0.0 - */ - @Test - public void testExceptionDeniesCmd() { - Evaluator.SUPPRESS_EXCEPTION_MESSAGES.set(true); - - final Evaluation eval = testEvaluation("DoesNotHaveStartingSlash", true); - - Assertions.assertTrue(eval.dueToException(), "Intentional exception was expected here"); - Assertions.assertEquals(eval.policy(), Policy.DENY, "Wrong security policy evaluated"); - - Evaluator.SUPPRESS_EXCEPTION_MESSAGES.set(false); - } - - /** - * Tests that the 'EvalCause' feature is working correctly - i.e., chains having a criteria of a particular - * eval cause being used should be respected. - * - * @author lokka30 - * @since 1.0.0 - */ - @Test - public void testEvalCauseFiltering() { - final String cmd = "/blocksuggestionsonly"; - - final Function eval = (cause) -> Evaluator.evaluate( - cmd, - TEST_CHAINS, - TEST_DEFAULT_POLICY, - true, - cause, - debugLogger, - warningLogger - ); - - final Evaluation evalExecution = eval.apply(EvalCause.CMD_EXECUTION); - final Evaluation evalSuggestion = eval.apply(EvalCause.CMD_SUGGESTION); - final Evaluation evalOther = eval.apply(EvalCause.OTHER); - - Assertions.assertTrue(evalExecution.dueToDefaultPolicy()); - Assertions.assertSame(evalExecution.policy(), Policy.ALLOW); - - Assertions.assertFalse(evalSuggestion.dueToDefaultPolicy()); // << notice - Assertions.assertSame(evalSuggestion.policy(), Policy.DENY); // << notice - - Assertions.assertTrue(evalOther.dueToDefaultPolicy()); - Assertions.assertSame(evalOther.policy(), Policy.ALLOW); - } -} diff --git a/BlackWidowPluginBukkit/pom.xml b/BlackWidowPluginBukkit/pom.xml deleted file mode 100644 index 9038881..0000000 --- a/BlackWidowPluginBukkit/pom.xml +++ /dev/null @@ -1,152 +0,0 @@ - - - - - 4.0.0 - - io.github.arcaneplugins.blackwidow - blackwidow - 1.0.0-SNAPSHOT - - - blackwidowpluginbukkit - 1.0.0-SNAPSHOT - - - 21 - 21 - UTF-8 - - - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - - - - io.github.arcaneplugins.blackwidow - blackwidowlib - 1.0.0-SNAPSHOT - compile - - - io.papermc.paper - paper-api - 1.21-R0.1-SNAPSHOT - provided - - - - org.spongepowered - configurate-yaml - 4.1.2 - compile - - - dev.jorel - commandapi-bukkit-shade - 9.6.0 - compile - - - net.kyori - adventure-platform-bukkit - 4.3.3 - compile - - - net.kyori - adventure-text-minimessage - 4.17.0 - compile - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.13.0 - - 21 - 21 - 21 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.6.0 - - - package - shade - - - true - - - *:* - - META-INF/** - module-info - module-info.class - - - - false - - - org.spongepowered. - io.github.arcaneplugins.blackwidow.deps.org.spongepowered. - - - - org.yaml. - io.github.arcaneplugins.blackwidow.deps.org.yaml. - - - dev.jorel. - io.github.arcaneplugins.blackwidow.deps.dev.jorel. - - - net.kyori. - io.github.arcaneplugins.blackwidow.deps.net.kyori. - - - - - - - - - - src/main/resources - true - - - - - \ No newline at end of file diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/BlackWidow.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/BlackWidow.java deleted file mode 100644 index 67a6175..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/BlackWidow.java +++ /dev/null @@ -1,321 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.YamlCfg; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.settings.Settings; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.translations.Translations; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.command.CommandManager; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.component.cmdblocking.CmdBlocker; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.listener.ListenerManager; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.LogicManager; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.util.ClassUtil; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.util.DebugCategory; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.util.ExceptionUtil; -import net.kyori.adventure.platform.bukkit.BukkitAudiences; -import net.kyori.adventure.text.minimessage.MiniMessage; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.EnumSet; -import java.util.List; -import java.util.Objects; -import java.util.function.Supplier; - -/** - * BlackWidow Bukkit Plugin main class. - * {@link BlackWidow#onEnable()} is ran on startup by the {@link org.bukkit.plugin.PluginManager Bukkit PluginManager}. - * - * @author lokka30 - * @since 1.0.0 - */ -public final class BlackWidow extends JavaPlugin { - - private final ListenerManager listenerManager = new ListenerManager(this); - private final CommandManager commandManager = new CommandManager(this); - private final CmdBlocker cmdBlocker = new CmdBlocker(this); - private final Settings settings = new Settings(this); - private final Translations translations = new Translations(this); - private final LogicManager logicManager = new LogicManager(this); - private final EnumSet debugCategories = EnumSet.noneOf(DebugCategory.class); - private final MiniMessage miniMessage = MiniMessage.miniMessage(); - - private boolean usingPaper = false; - private BukkitAudiences adventure = null; - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public void onLoad() { - final long startTime = System.currentTimeMillis(); - - try { - commandManager().init(); - } catch (Exception ex) { - ExceptionUtil.logException(this, ex, "An error occurred whilst initializing BlackWidow (Bukkit-onLoad)."); - return; - } - - final long duration = System.currentTimeMillis() - startTime; - getLogger().info("Plugin initialised (took %.3fs).".formatted(duration / 1_000f)); - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public void onEnable() { - final long startTime = System.currentTimeMillis(); - - try { - loadCompat(); - this.adventure = BukkitAudiences.create(this); - loadConfigs(); - logicManager().load(); - loadComponents(); - listenerManager().load(); - commandManager().load(); - } catch (Exception ex) { - ExceptionUtil.logException(this, ex, "An error occurred whilst enabling BlackWidow."); - return; - } - - final long duration = System.currentTimeMillis() - startTime; - getLogger().info("Plugin enabled (took %.3fs).".formatted(duration / 1_000f)); - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public void onDisable() { - final long startTime = System.currentTimeMillis(); - - try { - commandManager().disable(); - - if (adventure != null) { - adventure.close(); - adventure = null; - } - } catch (Exception ex) { - ExceptionUtil.logException(this, ex, "An error occurred whilst disabling BlackWidow."); - return; - } - - final long duration = System.currentTimeMillis() - startTime; - getLogger().info("Plugin disabled (took %.3fs).".formatted(duration / 1_000f)); - getLogger().info("Thank you for using BlackWidow"); - } - - /** - * Used to 'soft'-reload the plugin, i.e., reload configs and related configurable logic, without having to - * restart the plugin or the server. - * - * @author lokka30 - * @since 1.0.0 - */ - public void softReload() { - getLogger().info("Performing soft-reload."); - final long startTime = System.currentTimeMillis(); - - try { - loadCompat(); - loadConfigs(); - logicManager().load(); - loadComponents(); - } catch (Exception ex) { - ExceptionUtil.logException(this, ex, "An error occurred whilst performing a soft-reload."); - return; - } - - final long duration = System.currentTimeMillis() - startTime; - getLogger().info("Soft-reloaded (took %.3fs).".formatted(duration / 1_000f)); - } - - /** - * Load compatibility checking tools. - * - * @author lokka30 - * @since 1.0.0 - */ - private void loadCompat() { - getLogger().info("Loading compatibility."); - setUsingPaper(ClassUtil.classExists("io.papermc.paper.ServerBuildInfo")); - - if (!usingPaper()) { - getLogger().info("Server is not using PaperMC (or fork); Paper features are disabled."); - } - } - - /** - * Load the plugin's configuration. - * - * @author lokka30 - * @since 1.0.0 - */ - private void loadConfigs() { - getLogger().info("Loading configs."); - List.of(settings(), translations()).forEach(YamlCfg::load); - } - - /** - * Load the major components of the plugin. - * - * @author lokka30 - * @since 1.0.0 - */ - private void loadComponents() { - getLogger().info("Loading components."); - cmdBlocker().load(); - } - - /** - * Send a debug log if the debug category {@code cat} is enabled. - *

- * The supplier is used to avoid needlessly operating on the debug log message itself (e.g., fetching required data, - * concatenating strings, etc.) unless it's actually needed. - *

- * - * @param cat Debug category associated with the message. - * @param strSupp Supplier of the message that can be sent. - * @author lokka30 - * @since 1.0.0 - */ - public void debugLog( - final DebugCategory cat, - final Supplier strSupp - ) { - if (!enabledDebugCategories().contains(cat)) { - return; - } - - getLogger().info("[DEBUG - " + cat.name() + "]: " + strSupp.get()); - } - - /** - * @return Whether the server is believed to be using PaperMC or any derivative of. - * @author lokka30 - * @since 1.0.0 - */ - public boolean usingPaper() { - return usingPaper; - } - - /** - * Set whether the server is believed to be using PaperMC or any derivative of. - * - * @param val New value. - * @author lokka30 - * @since 1.0.0 - */ - private void setUsingPaper(final boolean val) { - this.usingPaper = val; - } - - /** - * @return An instance of the {@link ListenerManager}. - * @author lokka30 - * @since 1.0.0 - */ - public ListenerManager listenerManager() { - return Objects.requireNonNull(listenerManager, "listenerManager"); - } - - /** - * @return An instance of the {@link CommandManager}. - * @author lokka30 - * @since 1.0.0 - */ - public CommandManager commandManager() { - return Objects.requireNonNull(commandManager, "commandManager"); - } - - /** - * @return An instance of the {@link CmdBlocker}. - * @author lokka30 - * @since 1.0.0 - */ - public CmdBlocker cmdBlocker() { - return Objects.requireNonNull(cmdBlocker, "cmdBlocker"); - } - - /** - * @return Whether BlackWidow should enable using features only available for PaperMC or derivatives. - * @author lokka30 - * @since 1.0.0 - */ - public boolean usePaperFeatures() { - //TODO temporarily disable ALL paper-specific features. get it working on bukkit first :) - return false; - } - - /** - * @return An instance of the {@link Settings} configuration. - * @author lokka30 - * @since 1.0.0 - */ - public Settings settings() { - return Objects.requireNonNull(settings, "settings"); - } - - /** - * @return An instance of the {@link LogicManager}. - * @author lokka30 - * @since 1.0.0 - */ - public LogicManager logicManager() { - return Objects.requireNonNull(logicManager, "logicManager"); - } - - /** - * @return An {@link EnumSet enum set} of {@link DebugCategory debug categories} which were enabled by the user. - * @author lokka30 - * @since 1.0.0 - */ - public EnumSet enabledDebugCategories() { - return Objects.requireNonNull(debugCategories, "debugCategories"); - } - - /** - * @return An instance of the {@link Translations} configuration. - * @author lokka30 - * @since 1.0.0 - */ - public Translations translations() { - return Objects.requireNonNull(translations, "translations"); - } - - public BukkitAudiences adventure() { - return Objects.requireNonNull(adventure, "adventure"); - } - - public MiniMessage miniMessage() { - return Objects.requireNonNull(miniMessage, "miniMessage"); - } -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/YamlCfg.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/YamlCfg.java deleted file mode 100644 index 53cd711..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/YamlCfg.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import org.spongepowered.configurate.CommentedConfigurationNode; -import org.spongepowered.configurate.ConfigurateException; -import org.spongepowered.configurate.yaml.NodeStyle; -import org.spongepowered.configurate.yaml.YamlConfigurationLoader; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Objects; - -public abstract class YamlCfg { - - private final BlackWidow plugin; - private final Path filePath; - private final String filePathStr; - private final String fileName; - private final String description; - private final YamlConfigurationLoader loader; - private final int latestFileVersion; - private CommentedConfigurationNode root; - - public YamlCfg( - final BlackWidow plugin, - final String filePathStr, - final String fileName, - final String description, - final int latestFileVersion - ) { - this.plugin = Objects.requireNonNull(plugin, "plugin"); - this.filePathStr = Objects.requireNonNull(filePathStr, "filePathStr"); - this.fileName = Objects.requireNonNull(fileName, "fileName"); - this.description = Objects.requireNonNull(description, "description"); - this.latestFileVersion = latestFileVersion; - - if (filePathStr().isBlank()) { - throw new IllegalArgumentException("filePath can't be blank"); - } - - this.filePath = Path.of(plugin.getDataFolder().toString(), filePathStr()); - - if (fileName().isBlank()) { - throw new IllegalArgumentException("fileName can't be blank"); - } - - if (description().isBlank()) { - throw new IllegalArgumentException("description can't be blank"); - } - - this.loader = YamlConfigurationLoader.builder() - .path(filePath()) - .indent(2) - .nodeStyle(NodeStyle.BLOCK) - .build(); - } - - public final void load() { - try { - copyFromResourcesIfDoesntExist(); - setRoot(yamlLoader().load()); - - // upgrading - int installedVer = installedFileVersion(); - final int latestVer = latestFileVersion(); - if (installedVer <= 0) { - throw new IllegalArgumentException("Config '" + fileName() + "' has an installed file version below " + - "or equal to 0, indicating it has almost certainly been manually tampered with. Please address " + - "this issue ASAP, as a manually-adjusted file version can cause instability."); - } - if (installedVer < latestVer) { - plugin().getLogger().info("Config '" + fileName() + "' is outdated, automatically upgrading."); - while (installedVer < latestFileVersion()) { - plugin().getLogger().info("Upgrading '" + fileName() + "' from v" + - installedVer + " to v" + (installedVer + 1) + "."); - upgradeFile(); - write(); - installedVer = installedFileVersion(); - } - } else if (installedVer > latestVer) { - plugin().getLogger().warning("Config '" + fileName() + "' apparently has version '" + installedVer + - "' but the latest is '" + latestVer + "'. Was the file version manually tampered with, or used " + - "on a newer version of the plugin? Please address ASAP as this may cause instability."); - } - - // lastly, set 'context' metadata if not already present - root().node("do-not-touch", "version", "context").act(node -> { - if (!node.getString("").isBlank()) { - return; - } - - //noinspection deprecation,UnstableApiUsage - final String version = plugin().usePaperFeatures() ? - plugin().getPluginMeta().getVersion() : - plugin().getDescription().getVersion(); - - node.set(plugin().getName() + " " + version); - - write(); - }); - - loadMore(); - } catch (final Exception ex) { - throw new RuntimeException("Unable to load '" + fileName() + "': " + ex.getLocalizedMessage(), ex); - } - } - - protected abstract void loadMore(); - - public final void write() { - try { - yamlLoader().save(root()); - } catch (final ConfigurateException ex) { - throw new RuntimeException("Unable to save '" + fileName() + "'", ex); - } - } - - public final void copyFromResourcesIfDoesntExist() { - if (Files.exists(filePath())) { - return; - } - - plugin().saveResource(filePathStr(), false); - } - - protected final BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - - public final String fileName() { - return Objects.requireNonNull(fileName, "fileName"); - } - - public final String description() { - return Objects.requireNonNull(description, "description"); - } - - public final Path filePath() { - return Objects.requireNonNull(filePath, "filePath"); - } - - public final YamlConfigurationLoader yamlLoader() { - return Objects.requireNonNull(loader, "loader"); - } - - public final CommentedConfigurationNode root() { - return root; - } - - protected final void setRoot(CommentedConfigurationNode root) { - this.root = root; - } - - public final String filePathStr() { - return filePathStr; - } - - public final int latestFileVersion() { - return this.latestFileVersion; - } - - public final int installedFileVersion() { - final int installedVer = root().node("do-not-touch", "version", "installed").getInt(Integer.MIN_VALUE); - if (installedVer == Integer.MIN_VALUE) { - throw new IllegalArgumentException("Installed file version must be specified in file '" + fileName() + "'"); - } - return installedVer; - } - - //Note that no need to call 'write()' as this is done automatically after each upgrade by the loader - public abstract void upgradeFile(); - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/settings/Settings.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/settings/Settings.java deleted file mode 100644 index e11ebc0..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/settings/Settings.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.settings; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.YamlCfg; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.util.DebugCategory; -import org.spongepowered.configurate.ConfigurateException; - -import java.util.Collections; -import java.util.Objects; - -public final class Settings extends YamlCfg { - - // <<< !!! WARNING !!! NOTICE THIS MESSAGE !!! >>> - // REMEMBER TO UPDATE THE METHOD BELOW 'upgradeFile' IF THIS IS INCREMENTED. - // ALSO REMEMBER TO UPDATE THE FILE ITSELF - BOTH THE 'original' AND 'installed' VALUES SHOULD MATCH THIS. - // <<< !!! WARNING !!! NOTICE THIS MESSAGE !!! >>> - private static final int LATEST_FILE_VERSION = 1; - - public Settings( - final BlackWidow plugin - ) { - super( - plugin, - "settings.yml", - "settings.yml", - "Settings", - LATEST_FILE_VERSION - ); - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - protected void loadMore() { - try { - plugin().enabledDebugCategories().clear(); - plugin().enabledDebugCategories().addAll( - Objects.requireNonNullElse( - root() - .node("debug-categories") - .getList(DebugCategory.class), - Collections.emptySet() - ) - ); - } catch (final ConfigurateException ex) { - throw new RuntimeException(ex.getMessage(), ex); - } - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public void upgradeFile() { - final int installedVer = installedFileVersion(); - //noinspection SwitchStatementWithTooFewBranches - switch (installedVer) { - case 1 -> { - // Do nothing. - - //noinspection UnnecessaryBreak - break; - } - default -> throw new IllegalArgumentException("No upgrade logic defined for file version v" + installedVer); - } - } -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/translations/Translation.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/translations/Translation.java deleted file mode 100644 index 1ec2ac7..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/translations/Translation.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.translations; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.text.Component; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.spongepowered.configurate.ConfigurateException; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.Supplier; - -public enum Translation { - - COMMAND_BLACKWIDOW_RELOAD_STARTED( - new String[]{"command", "blackwidow", "reload", "started"}, - true, - List.of("%prefix%Reloading BlackWidow.") - ), - - COMMAND_BLACKWIDOW_RELOAD_FAILED( - new String[]{"command", "blackwidow", "reload", "failed"}, - true, - List.of("%prefix%Reload failed! Please see your server console for more details.") - ), - - COMMAND_BLACKWIDOW_RELOAD_COMPLETE( - new String[]{"command", "blackwidow", "reload", "complete"}, - true, - List.of("%prefix%Reload complete.") - ), - - COMMAND_BLACKWIDOW_VERSION( - new String[]{"command", "blackwidow", "version"}, - true, - List.of("*---* BlackWidowA security solution for Minecraft.'>BlackWidow v%version% *---*A security solution for Minecraft.From ArcanePlugins by %authors%.") - ), - - PREFIX( - new String[]{"prefix"}, - false, - "BlackWidow" + - "A security solution for Minecraft.'>BW: " + - "" - ), - - LIST_DELIMITER( - new String[]{"list-delimeter"}, - false, - ", " - ); - - private final String[] nodePath; - private final boolean isList; - private final Object defValue; - - Translation( - final String[] nodePath, - final boolean isList, - final Object defValue - ) { - this.nodePath = nodePath; - this.isList = isList; - this.defValue = defValue; - } - - public final String[] nodePath() { - return nodePath; - } - - public final boolean isList() { - return isList; - } - - public final Object defValue() { - return defValue; - } - - public String strSingle( - final BlackWidow plugin - ) { - if (isList()) { - throw new IllegalStateException("Translation is list type, but called `str` instead of `strList`"); - } - - return plugin.translations().root().node((Object[]) nodePath()).getString((String) defValue()); - } - - public static String placeholerify( - final BlackWidow plugin, - final String msg, - final Map> placeholders - ) { - // temp var to hold latest placeholderified version of `msg` - String formattedMsg = msg; - - // do placeholder replacement - for (final Map.Entry> placeholder : placeholders.entrySet()) { - final String id = "%" + placeholder.getKey() + "%"; - final Supplier val = placeholder.getValue(); - - if (!formattedMsg.contains(id)) { - continue; - } - - formattedMsg = formattedMsg.replace(id, val.get()); - } - - // other standard placeholders - formattedMsg = formattedMsg.replace("%prefix%", Translation.PREFIX.strSingle(plugin)); - - return formattedMsg; - } - - public static String joinSeparatedStrings( - final BlackWidow plugin, - final Collection strings - ) { - return String.join( - LIST_DELIMITER.strSingle(plugin), - strings - ); - } - - public static Component formatify( - final BlackWidow plugin, - final String msg, - final Map> placeholders - ) { - return plugin.miniMessage().deserialize( - placeholerify( - plugin, - msg, - placeholders - ) - ); - } - - public final List strList( - final BlackWidow plugin - ) { - if (!isList()) { - throw new IllegalStateException("Translation is not list type, but called `strList` instead of `str`"); - } - - try { - //noinspection unchecked - return Objects.requireNonNullElse( - plugin.translations().root().node((Object[]) nodePath()).getList(String.class), - (List) defValue() - ); - } catch (final ConfigurateException ex) { - throw new RuntimeException(ex.getMessage(), ex); - } - } - - public final void sendTo( - final BlackWidow plugin, - final Audience audience, - final Map> placeholders - ) { - Objects.requireNonNull(plugin, "plugin"); - Objects.requireNonNull(audience, "audience"); - - if (isList()) { - for (final String msg : strList(plugin)) { - audience.sendMessage(formatify(plugin, msg, placeholders)); - } - } else { - audience.sendMessage(formatify(plugin, strSingle(plugin), placeholders)); - } - } - - public final void sendTo( - final BlackWidow plugin, - final CommandSender sender, - final Map> placeholders - ) { - Objects.requireNonNull(plugin, "plugin"); - Objects.requireNonNull(sender, "sender"); - sendTo(plugin, plugin.adventure().sender(sender), placeholders); - } - - @SuppressWarnings("unused") - public final void sendTo( - final BlackWidow plugin, - final Player player, - final Map> placeholders - ) { - Objects.requireNonNull(plugin, "plugin"); - Objects.requireNonNull(player, "player"); - Objects.requireNonNull(placeholders, "placeholders"); - sendTo(plugin, plugin.adventure().player(player), placeholders); - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/translations/Translations.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/translations/Translations.java deleted file mode 100644 index 0fc961b..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/cfg/translations/Translations.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.translations; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.YamlCfg; - -public final class Translations extends YamlCfg { - - // <<< !!! WARNING !!! NOTICE THIS MESSAGE !!! >>> - // REMEMBER TO UPDATE THE METHOD BELOW 'upgradeFile' IF THIS IS INCREMENTED. - // ALSO REMEMBER TO UPDATE THE FILE ITSELF - BOTH THE 'original' AND 'installed' VALUES SHOULD MATCH THIS. - // <<< !!! WARNING !!! NOTICE THIS MESSAGE !!! >>> - private static final int LATEST_FILE_VERSION = 1; - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - public Translations( - final BlackWidow plugin - ) { - super( - plugin, - "translations.yml", - "translations.yml", - "Translations", - LATEST_FILE_VERSION - ); - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - protected void loadMore() { - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public void upgradeFile() { - final int installedVer = installedFileVersion(); - //noinspection SwitchStatementWithTooFewBranches - switch (installedVer) { - case 1 -> { - // Do nothing. - - //noinspection UnnecessaryBreak - break; - } - default -> throw new IllegalArgumentException("No upgrade logic defined for file version v" + installedVer); - } - } -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/CommandManager.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/CommandManager.java deleted file mode 100644 index d45c5ab..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/CommandManager.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.command; - -import dev.jorel.commandapi.CommandAPI; -import dev.jorel.commandapi.CommandAPIBukkitConfig; -import dev.jorel.commandapi.RegisteredCommand; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.command.blackwidow.BlackWidowCommand; - -public final class CommandManager { - - private final BlackWidow plugin; - - public CommandManager( - final BlackWidow plugin - ) { - this.plugin = plugin; - } - - public void init() { - plugin().getLogger().info("Initialising commands."); - CommandAPI.onLoad( - new CommandAPIBukkitConfig(plugin()) - .verboseOutput(false) - .silentLogs(true) - .usePluginNamespace() - ); - registerCommands(); - } - - private void registerCommands() { - new BlackWidowCommand(plugin()).register(); - } - - public void load() { - plugin().getLogger().info("Loading commands."); - CommandAPI.onEnable(); - } - - public void disable() { - plugin().getLogger().info("Disabling commands."); - CommandAPI.unregister("blackwidow", true); - CommandAPI.onDisable(); - CommandAPI.getRegisteredCommands() - .stream() - .map(RegisteredCommand::commandName) - .iterator() - .forEachRemaining(CommandAPI::unregister); - } - - private BlackWidow plugin() { - return plugin; - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/BlackWidowCommand.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/BlackWidowCommand.java deleted file mode 100644 index bcf818f..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/BlackWidowCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.command.blackwidow; - -import dev.jorel.commandapi.CommandAPICommand; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.command.blackwidow.subcommand.ReloadSubcommand; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.command.blackwidow.subcommand.VersionSubcommand; - -import java.util.Objects; - -public final class BlackWidowCommand extends CommandAPICommand { - - private final BlackWidow plugin; - - public BlackWidowCommand( - final BlackWidow plugin - ) { - super("blackwidow"); - this.plugin = plugin; - withAliases("bw"); - withPermission("blackwidow.command.bw"); - withShortDescription("Base command to view info of and manage the BlackWidow plugin."); - withFullDescription("Base command to view and manage the BlackWidow plugin."); - withSubcommands( - new ReloadSubcommand(plugin()), - new VersionSubcommand(plugin()) - ); - } - - private BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/subcommand/ReloadSubcommand.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/subcommand/ReloadSubcommand.java deleted file mode 100644 index ed73d65..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/subcommand/ReloadSubcommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.command.blackwidow.subcommand; - -import dev.jorel.commandapi.CommandAPICommand; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.translations.Translation; - -import java.util.Collections; -import java.util.Objects; - -public final class ReloadSubcommand extends CommandAPICommand { - - private final BlackWidow plugin; - - public ReloadSubcommand( - final BlackWidow plugin - ) { - super("reload"); - this.plugin = plugin; - withAliases("rl"); - withPermission("blackwidow.command.bw.reload"); - withShortDescription("Soft-reload BlackWidow's configurable features."); - withFullDescription("Soft-reloads BlackWidow to allow for changes to the configuration to take effect."); - executes((sender, args) -> { - Translation.COMMAND_BLACKWIDOW_RELOAD_STARTED.sendTo(plugin(), sender, Collections.emptyMap()); - try { - plugin().softReload(); - } catch (final Exception ex) { - Translation.COMMAND_BLACKWIDOW_RELOAD_FAILED.sendTo(plugin(), sender, Collections.emptyMap()); - return; - } - Translation.COMMAND_BLACKWIDOW_RELOAD_COMPLETE.sendTo(plugin(), sender, Collections.emptyMap()); - }); - } - - private BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/subcommand/VersionSubcommand.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/subcommand/VersionSubcommand.java deleted file mode 100644 index 4b494b8..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/command/blackwidow/subcommand/VersionSubcommand.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.command.blackwidow.subcommand; - -import dev.jorel.commandapi.CommandAPICommand; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.translations.Translation; - -import java.util.Map; -import java.util.Objects; - -public final class VersionSubcommand extends CommandAPICommand { - - private final BlackWidow plugin; - - public VersionSubcommand( - final BlackWidow plugin - ) { - super("version"); - this.plugin = plugin; - withAliases("ver", "about", "info"); - withPermission("blackwidow.command.bw.version"); - withShortDescription("View the version of BlackWidow currently installed."); - withFullDescription("Views the version of BlackWidow currently installed."); - executes((sender, args) -> { - //noinspection deprecation - Translation.COMMAND_BLACKWIDOW_VERSION.sendTo( - plugin(), - sender, - Map.of( - "version", () -> plugin().getDescription().getVersion(), - "authors", () -> Translation - .joinSeparatedStrings(plugin(), plugin().getDescription().getAuthors()) - ) - ); - }); - } - - private BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/component/cmdblocking/BukkitChain.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/component/cmdblocking/BukkitChain.java deleted file mode 100644 index 9593186..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/component/cmdblocking/BukkitChain.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.component.cmdblocking; - -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.Chain; -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.EvalCause; -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.Policy; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Action; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Requirement; -import org.spongepowered.configurate.CommentedConfigurationNode; -import org.spongepowered.configurate.serialize.SerializationException; - -import java.util.Collection; -import java.util.EnumSet; -import java.util.List; -import java.util.Objects; - -public final class BukkitChain extends Chain { - - private final BlackWidow plugin; - private final Collection requirements; - private final Collection actions; - - /** - * Constructs a {@code BukkitChain}. - * - * @param id {@inheritDoc} - * @param enabled {@inheritDoc} - * @param policy {@inheritDoc} - * @param rules {@inheritDoc} - * @param isRegex {@inheritDoc} - * @param requirements Requirements (on top of a matching rule) for this chain to be evaluated. - * @param actions What should be done if the chain is matched against. - * @author lokka30 - * @since 1.0.0 - */ - public BukkitChain( - final BlackWidow plugin, - final String id, - final boolean enabled, - final Policy policy, - final Collection rules, - final boolean isRegex, - final Collection causeFilters, - final Collection requirements, - final Collection actions - ) { - super(id, enabled, policy, rules, isRegex, causeFilters); - this.plugin = Objects.requireNonNull(plugin, "plugin"); - this.requirements = Objects.requireNonNull(requirements, "requirements"); - this.actions = Objects.requireNonNull(actions, "actions"); - } - - public BukkitChain( - final BlackWidow plugin, - final CommentedConfigurationNode node - ) { - this( - Objects.requireNonNull(plugin, "plugin"), - node.node("id").getString(), - node.node("enabled").getBoolean(true), - parsePolicyAtNode(node.node("policy")), - parseStringListAtNode(node.node("rules")), - node.node("regex").getBoolean(false), - parseEvalCauseListAtNode(node.node("cause-filters")), - plugin.logicManager().parseRequirementsInChildrenOfNode(node.node("requirements")), - plugin.logicManager().parseActionsInChildrenOfNode(node.node("actions")) - ); - } - - @SuppressWarnings("unused") - private BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - - private static Policy parsePolicyAtNode( - final CommentedConfigurationNode node - ) { - try { - return node.get(Policy.class, Policy.DENY); - } catch (final SerializationException ex) { - throw new RuntimeException("Unable to parse policy at node '" + node.path() + "'", ex); - } - } - - private static List parseStringListAtNode( - final CommentedConfigurationNode node - ) { - try { - return node.getList(String.class); - } catch (final SerializationException ex) { - throw new RuntimeException("Unable to parse string list at node '" + node.path() + "'", ex); - } - } - - public Collection requirements() { - return requirements; - } - - public Collection actions() { - return actions; - } - - public static Collection parseEvalCauseListAtNode( - final CommentedConfigurationNode node - ) { - - Objects.requireNonNull(node, "node"); - - try { - if (node.virtual()) { - return EnumSet.allOf(EvalCause.class); - } - - return node.getList(EvalCause.class); - } catch (final SerializationException ex) { - throw new RuntimeException("Unable to parse eval cause list at node '" + node.path() + "'", ex); - } - } -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/component/cmdblocking/CmdBlocker.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/component/cmdblocking/CmdBlocker.java deleted file mode 100644 index de19aab..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/component/cmdblocking/CmdBlocker.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.component.cmdblocking; - -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.EvalCause; -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.Evaluation; -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.Evaluator; -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.Policy; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Action; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Context; -import org.bukkit.entity.Player; -import org.spongepowered.configurate.CommentedConfigurationNode; - -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.Objects; - -public final class CmdBlocker { - - private final BlackWidow plugin; - - public CmdBlocker(final BlackWidow plugin) { - this.plugin = plugin; - } - - private Policy defaultBehaviourPolicy; - private final Collection defaultBehaviourActions = new LinkedHashSet<>(); - private boolean filterCmdExecution; - private boolean filterCmdSuggestion; - private boolean operatorsBypassCompletely; - private boolean denyColonInFirstArgEnabled; - private final Collection denyColonInFirstArgActions = new LinkedHashSet<>(); - private final Collection chains = new LinkedHashSet<>(); - - public void load() { - final CommentedConfigurationNode settingsRoot = plugin().settings().root(); - - try { - // defaultBehaviourPolicy - setDefaultBehaviourPolicy(settingsRoot.node("cmd-blocking", "default-behaviour", "policy").get(Policy.class)); - - // defaultBehaviourActions - defaultBehaviourActions().clear(); - defaultBehaviourActions().addAll(plugin().logicManager().parseActionsInChildrenOfNode(settingsRoot.node("cmd-blocking", "default-behaviour", "actions"))); - - // filterCmdExecution - setFilterCmdExecution(settingsRoot.node("cmd-blocking", "filtering", "execution").getBoolean(true)); - - // filterCmdSuggestion - setFilterCmdSuggestion(settingsRoot.node("cmd-blocking", "filtering", "suggestion").getBoolean(true)); - - // operatorsBypassCompletely - setOperatorsBypassCompletely(settingsRoot.node("cmd-blocking", "operators-bypass-completely").getBoolean(true)); - - // denyColonInFirstArgEnabled - setDenyColonInFirstArgEnabled(settingsRoot.node("cmd-blocking", "deny-colon-in-first-arg", "enabled").getBoolean(true)); - - // denyColonInFirstArgActions - denyColonInFirstArgActions().clear(); - denyColonInFirstArgActions().addAll(plugin().logicManager().parseActionsInChildrenOfNode(settingsRoot.node("cmd-blocking", "deny-colon-in-first-arg", "actions"))); - - // chains - parseChains(); - } catch (final Exception ex) { - throw new RuntimeException("Unable to load CmdBlocker", ex); - } - } - - private void parseChains() { - final CommentedConfigurationNode chainsRoot = plugin().settings().root().node("cmd-blocking", "chains"); - - chains().clear(); - - for (final CommentedConfigurationNode chainNode : chainsRoot.childrenList()) { - chains.add(new BukkitChain(plugin(), chainNode)); - } - } - - public Evaluation evalAndProcess(final Context context, final String cmd, final boolean runActions, final EvalCause cause) { - final Player player = context.player(false); - if (player != null && player.isOp() && operatorsBypassCompletely()) { - return new Evaluation(cmd, Policy.ALLOW, null, null, "Operators configured to bypass command blocking") - .withDueToOperatorsBypassCmdBlocking(true); - } - - // copy chains into a new LinkedHashSet, remove chains not applicable to context. - final Collection applicableChains = new LinkedHashSet<>(chains()); - applicableChains.removeIf(chain -> chain.requirements().stream().anyMatch(req -> !req.validate(context))); - - final Evaluation eval = Evaluator.evaluate(cmd, applicableChains, defaultBehaviourPolicy(), denyColonInFirstArgEnabled(), cause, (debugMsg) -> { /* do nothing */ }, (warnMsg) -> plugin().getLogger().warning(warnMsg.get())); - - if (runActions && eval.dueToColonInFirstArg()) { - denyColonInFirstArgActions().forEach(act -> act.run(context)); - } - - if (runActions && eval.chain() != null && eval.chain() instanceof BukkitChain chain) { - chain.actions().forEach(act -> act.run(context)); - } - - if (runActions && eval.dueToDefaultPolicy()) { - defaultBehaviourActions().forEach(act -> act.run(context)); - } - - return eval; - } - - private BlackWidow plugin() { - return plugin; - } - - public void setDefaultBehaviourPolicy(Policy defaultBehaviourPolicy) { - this.defaultBehaviourPolicy = defaultBehaviourPolicy; - } - - public Policy defaultBehaviourPolicy() { - return defaultBehaviourPolicy; - } - - public Collection defaultBehaviourActions() { - return Objects.requireNonNull(defaultBehaviourActions, "defaultBehaviourActions"); - } - - public boolean filterCmdExecution() { - return filterCmdExecution; - } - - public void setFilterCmdExecution(boolean filterCmdExecution) { - this.filterCmdExecution = filterCmdExecution; - } - - public boolean filterCmdSuggestion() { - return filterCmdSuggestion; - } - - public void setFilterCmdSuggestion(boolean filterCmdSuggestion) { - this.filterCmdSuggestion = filterCmdSuggestion; - } - - public boolean operatorsBypassCompletely() { - return operatorsBypassCompletely; - } - - public void setOperatorsBypassCompletely(boolean operatorsBypassCompletely) { - this.operatorsBypassCompletely = operatorsBypassCompletely; - } - - public boolean denyColonInFirstArgEnabled() { - return denyColonInFirstArgEnabled; - } - - public void setDenyColonInFirstArgEnabled(boolean denyColonInFirstArgEnabled) { - this.denyColonInFirstArgEnabled = denyColonInFirstArgEnabled; - } - - public Collection denyColonInFirstArgActions() { - return Objects.requireNonNull(denyColonInFirstArgActions, "denyColonInFirstArgActions"); - } - - public Collection chains() { - return Objects.requireNonNull(chains, "chains"); - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/event/LoadActionsReadyEvent.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/event/LoadActionsReadyEvent.java deleted file mode 100644 index d234c80..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/event/LoadActionsReadyEvent.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.event; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Action; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; -import org.spongepowered.configurate.CommentedConfigurationNode; - -import java.util.Map; -import java.util.Objects; -import java.util.function.Function; - -public final class LoadActionsReadyEvent extends Event { - - private final BlackWidow plugin; - private final Map> actParsers; - private static final HandlerList HANDLERS = new HandlerList(); - - public LoadActionsReadyEvent( - final BlackWidow plugin, - final Map> actParsers - ) { - this.plugin = Objects.requireNonNull(plugin, "plugin"); - this.actParsers = Objects.requireNonNull(actParsers, "actParsers"); - } - - /** - * {@inheritDoc} - */ - @Override - public @NotNull HandlerList getHandlers() { - return HANDLERS; - } - - /** - * See {@link #getHandlers()}. - * - * @return Handler list. - */ - @SuppressWarnings("unused") - public static HandlerList getHandlerList() { - return HANDLERS; - } - - public BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - - public Map> actionParsers() { - return Objects.requireNonNull(actParsers, "actParsers"); - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/event/LoadRequirementsReadyEvent.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/event/LoadRequirementsReadyEvent.java deleted file mode 100644 index 3cd5bf0..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/event/LoadRequirementsReadyEvent.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.event; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Requirement; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.jetbrains.annotations.NotNull; -import org.spongepowered.configurate.CommentedConfigurationNode; - -import java.util.Map; -import java.util.Objects; -import java.util.function.Function; - -public final class LoadRequirementsReadyEvent extends Event { - - private final BlackWidow plugin; - private final Map> reqParsers; - private static final HandlerList HANDLERS = new HandlerList(); - - public LoadRequirementsReadyEvent( - final BlackWidow plugin, - final Map> reqParsers - ) { - this.plugin = Objects.requireNonNull(plugin, "plugin"); - this.reqParsers = Objects.requireNonNull(reqParsers, "reqParsers"); - } - - /** - * {@inheritDoc} - */ - @Override - public @NotNull HandlerList getHandlers() { - return HANDLERS; - } - - /** - * See {@link #getHandlers()}. - * - * @return Handler list. - */ - @SuppressWarnings("unused") - public static HandlerList getHandlerList() { - return HANDLERS; - } - - public BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - - public Map> requirementParsers() { - return Objects.requireNonNull(reqParsers, "reqParsers"); - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/ListenerManager.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/ListenerManager.java deleted file mode 100644 index 9196c3c..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/ListenerManager.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.listener; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.listener.bukkit.PlayerCommandPreprocessListener; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.listener.bukkit.PlayerCommandSendListener; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.listener.paper.AsyncPlayerCommandSendListener; -import org.bukkit.event.Listener; - -import java.util.Collection; -import java.util.LinkedHashSet; - -public final class ListenerManager { - - private final BlackWidow plugin; - private final Collection listeners = new LinkedHashSet<>(); - - public ListenerManager( - final BlackWidow plugin - ) { - this.plugin = plugin; - } - - private void constructListeners() { - listeners().add( - new PlayerCommandPreprocessListener(plugin()) - ); - - listeners().add( - plugin().usingPaper() && plugin().usePaperFeatures() ? - new AsyncPlayerCommandSendListener(plugin()) : - new PlayerCommandSendListener(plugin()) - ); - } - - public void load() { - plugin().getLogger().info("Loading listeners."); - listeners().clear(); - constructListeners(); - - for (final Listener listener : listeners()) { - plugin().getServer().getPluginManager().registerEvents(listener, plugin()); - } - } - - public Collection listeners() { - return listeners; - } - - private BlackWidow plugin() { - return plugin; - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/bukkit/PlayerCommandPreprocessListener.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/bukkit/PlayerCommandPreprocessListener.java deleted file mode 100644 index 16b78a0..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/bukkit/PlayerCommandPreprocessListener.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.listener.bukkit; - -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.EvalCause; -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.Evaluation; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Context; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -import java.util.List; - -public final class PlayerCommandPreprocessListener implements Listener { - - private final BlackWidow plugin; - - public PlayerCommandPreprocessListener( - final BlackWidow plugin - ) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.LOWEST) - public void handle(final PlayerCommandPreprocessEvent event) { - if (event.isCancelled()) { - // Event is already cancelled - nothing to do! - return; - } - - final Player player = event.getPlayer(); - - final Context context = new Context(plugin()) - .withPlayer(player) - .withCommands(List.of(event.getMessage())); - - if (plugin().cmdBlocker().filterCmdExecution()) { - final Evaluation eval = plugin() - .cmdBlocker() - .evalAndProcess(context, event.getMessage(), true, EvalCause.CMD_EXECUTION); - - switch (eval.policy()) { - case ALLOW: - // Do nothing - break; - case DENY: - // Prevent command execution - event.setCancelled(true); - break; - case null, default: - event.setCancelled(true); - throw new IllegalStateException("Unexpected policy '" + eval.policy() + "', prevented " + - "command execution for best-practice security purposes."); - } - - // TODO Debug log the evaluation's description. - } - } - - private BlackWidow plugin() { - return plugin; - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/bukkit/PlayerCommandSendListener.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/bukkit/PlayerCommandSendListener.java deleted file mode 100644 index 45bfaee..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/bukkit/PlayerCommandSendListener.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.listener.bukkit; - -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.EvalCause; -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.Evaluation; -import io.github.arcaneplugins.blackwidow.lib.cmdblocking.Policy; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Context; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandSendEvent; - -public final class PlayerCommandSendListener implements Listener { - - private final BlackWidow plugin; - - public PlayerCommandSendListener( - final BlackWidow plugin - ) { - this.plugin = plugin; - } - - @EventHandler - public void handle(final PlayerCommandSendEvent event) { - if (event.getCommands().isEmpty()) { - // no commands to process - nothing to do here - return; - } - - final Player player = event.getPlayer(); - - final Context context = new Context(plugin()) - .withPlayer(player) - .withCommands(event.getCommands().stream().map(cmd -> "/" + cmd).toList()); - - if (plugin().cmdBlocker().filterCmdSuggestion()) { - event.getCommands().removeIf(cmd -> { - final Evaluation eval = plugin() - .cmdBlocker() - .evalAndProcess(context, "/" + cmd, false, EvalCause.CMD_SUGGESTION); - - if (eval.policy() == null || (eval.policy() != Policy.ALLOW && eval.policy() != Policy.DENY)) { - event.getCommands().clear(); - throw new IllegalStateException("Unexpected policy '" + eval.policy() + "', prevented " + - "all command suggestions for best-practice security purposes."); - } - - // TODO Debug log the evaluation's description. - - return eval.policy() == Policy.DENY; - }); - } - } - - private BlackWidow plugin() { - return plugin; - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/paper/AsyncPlayerCommandSendListener.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/paper/AsyncPlayerCommandSendListener.java deleted file mode 100644 index 5f93d21..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/listener/paper/AsyncPlayerCommandSendListener.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.listener.paper; - -import com.destroystokyo.paper.event.brigadier.AsyncPlayerSendCommandsEvent; -import com.mojang.brigadier.tree.RootCommandNode; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.util.DebugCategory; -import io.papermc.paper.command.brigadier.CommandSourceStack; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -@SuppressWarnings("UnstableApiUsage") // <-- :( -public final class AsyncPlayerCommandSendListener implements Listener { - - private final BlackWidow plugin; - - public AsyncPlayerCommandSendListener( - final BlackWidow plugin - ) { - this.plugin = plugin; - } - - @EventHandler - public void handle( - final AsyncPlayerSendCommandsEvent event - ) { - // Event Javadocs: - // https://jd.papermc.io/paper/1.21/com/destroystokyo/paper/event/brigadier/AsyncPlayerSendCommandsEvent.html - - if(!event.isAsynchronous() && !event.hasFiredAsync()) { - // as per paper API docs, this event can fire twice, once async and once sync. - // let's make sure we only handle the async scenario. - // OR, if the event will not be fired async, then handle it anyways. - return; - } - - final Player player = event.getPlayer(); - final RootCommandNode commandNode = event.getCommandNode(); - - //TODO Implement for Paper - - plugin().debugLog( - DebugCategory.ASYNC_PLAYER_COMMAND_SEND_LISTENER, - () -> "AsyncPlayerCommandSendListener{player=" + player.getName() + ", commandNode.toString=" + - commandNode + "};" - ); - } - - private BlackWidow plugin() { - return plugin; - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Action.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Action.java deleted file mode 100644 index bf6ce7d..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Action.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.logic; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; - -import java.util.Objects; - -public abstract class Action implements LogicUnit { - - private final BlackWidow plugin; - private final String id; - - public Action( - final BlackWidow plugin, - final String id - ) { - this.plugin = Objects.requireNonNull(plugin, "plugin"); - this.id = Objects.requireNonNull(id, "id"); - } - - public abstract void run(final Context context); - - public final String id() { - return Objects.requireNonNull(id, "id"); - } - - protected final BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Context.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Context.java deleted file mode 100644 index 84aa943..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Context.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.logic; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Collection; -import java.util.Objects; - -public final class Context { - - private final BlackWidow plugin; - - private Player player; - private Collection commands; - private CommandSender sender; - - public Context( - final BlackWidow plugin - ) { - this.plugin = Objects.requireNonNull(plugin, "plugin"); - } - - public BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - - public Context withPlayer(final Player player) { - this.player = player; - return this; - } - - public Player player(final boolean require) { - return require ? ContextException.require(player) : player; - } - - public Context withCommands(final Collection commands) { - this.commands = commands; - return this; - } - - @SuppressWarnings("unused") - public Collection commands(final boolean require) { - return require ? ContextException.require(commands) : commands; - } - - @SuppressWarnings("unused") - public Context withCommandSender(final CommandSender sender) { - this.sender = sender; - return this; - } - - public CommandSender commandSender(final boolean require) { - return require ? ContextException.require(sender) : sender; - } - - private static final class ContextException extends RuntimeException { - - private final String message; - - public ContextException( - final String message - ) { - this.message = message; - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public String getMessage() { - return message; - } - - public static T require(final T obj) { - if (obj != null) { - return obj; - } - - throw new ContextException("Attempted to access unavailable context"); - } - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/LogicManager.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/LogicManager.java deleted file mode 100644 index 27bdc67..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/LogicManager.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.logic; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.event.LoadActionsReadyEvent; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.event.LoadRequirementsReadyEvent; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.inbuilt.action.SendMessageAction; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.inbuilt.requirement.HasPermissionRequirement; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.inbuilt.requirement.InWorldRequirement; -import org.spongepowered.configurate.CommentedConfigurationNode; - -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Objects; -import java.util.function.Function; - -public final class LogicManager { - - private final Map> actParsers = new HashMap<>(); - private final Map> reqParsers = new HashMap<>(); - - private final BlackWidow plugin; - - public LogicManager( - final BlackWidow plugin - ) { - this.plugin = plugin; - } - - public void load() { - plugin().getLogger().info("Loading logic."); - loadStdRequirements(); - loadThirdPartyRequirements(); - loadStdActions(); - loadThirdPartyActions(); - } - - private void loadStdRequirements() { - requirementParsers().put(HasPermissionRequirement.ID, (n) -> new HasPermissionRequirement(plugin(), n)); - requirementParsers().put(InWorldRequirement.ID, (n) -> new InWorldRequirement(plugin(), n)); - } - - private void loadThirdPartyRequirements() { - final LoadRequirementsReadyEvent event = new LoadRequirementsReadyEvent( - plugin(), - requirementParsers() - ); - plugin().getServer().getPluginManager().callEvent(event); - } - - private void loadStdActions() { - actionParsers().put(SendMessageAction.ID, (n) -> new SendMessageAction(plugin(), n)); - } - - private void loadThirdPartyActions() { - final LoadActionsReadyEvent event = new LoadActionsReadyEvent( - plugin(), - actionParsers() - ); - plugin().getServer().getPluginManager().callEvent(event); - } - - public Action parseActionAtNode( - final CommentedConfigurationNode node - ) { - final String id = Objects.requireNonNull( - node.node("id").getString(), - "Action node at path '" + node.path() + "' must define an ID with 'id'" - ); - - try { - return Objects.requireNonNull( - actionParsers().get(id), - "Action node at path '" + node.path() + "' must define the ID ('id') of an Action that" + - "exists (did you make a typo?), but got '" + id + "'" - ).apply(node); - } catch (final Exception ex) { - throw new RuntimeException( - "Unable to parse Action with ID '" + id + "' at node path '" + node.path() + "': " + - ex.getLocalizedMessage(), - ex - ); - } - } - - public Collection parseActionsInChildrenOfNode( - final CommentedConfigurationNode nodes - ) { - final Collection actions = new LinkedHashSet<>(); - for (final CommentedConfigurationNode node : nodes.childrenList()) { - actions.add(parseActionAtNode(node)); - } - return actions; - } - - public Requirement parseRequirementAtNode( - final CommentedConfigurationNode node - ) { - final String id = Objects.requireNonNull( - node.node("id").getString(), - "Requirement node at path '" + node.path() + "' must define an ID with 'id'" - ); - - try { - return Objects.requireNonNull( - requirementParsers().get(id), - "Requirement node at path '" + node.path() + "' must define the ID ('id') of a Requirement that" + - "exists (did you make a typo?), but got '" + id + "'" - ).apply(node); - } catch (final Exception ex) { - throw new RuntimeException( - "Unable to parse Requirement with ID '" + id + "' at node path '" + node.path() + "': " + - ex.getLocalizedMessage(), - ex - ); - } - } - - public Collection parseRequirementsInChildrenOfNode( - final CommentedConfigurationNode nodes - ) { - final Collection requirements = new LinkedHashSet<>(); - for (final CommentedConfigurationNode node : nodes.childrenList()) { - requirements.add(parseRequirementAtNode(node)); - } - return requirements; - } - - private BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - - public Map> actionParsers() { - return actParsers; - } - - public Map> requirementParsers() { - return reqParsers; - } -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/LogicUnit.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/LogicUnit.java deleted file mode 100644 index 132e6aa..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/LogicUnit.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.logic; - -public interface LogicUnit { -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Requirement.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Requirement.java deleted file mode 100644 index 185fab7..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/Requirement.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.logic; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; - -import java.util.Objects; - -public abstract class Requirement implements LogicUnit { - - private final BlackWidow plugin; - private final String id; - private final boolean inverted; - - public Requirement( - final BlackWidow plugin, - final String id, - final boolean inverted - ) { - this.plugin = plugin; - this.id = id; - this.inverted = inverted; - } - - public final boolean validate(final Context context) { - return !inverted && validateImpl(context); - } - - protected abstract boolean validateImpl(final Context context); - - @SuppressWarnings("unused") - public final String id() { - return Objects.requireNonNull(id, "id"); - } - - protected final BlackWidow plugin() { - return Objects.requireNonNull(plugin, "plugin"); - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/action/SendMessageAction.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/action/SendMessageAction.java deleted file mode 100644 index 7bef17c..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/action/SendMessageAction.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.inbuilt.action; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.cfg.translations.Translation; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Action; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Context; -import net.kyori.adventure.audience.Audience; -import org.spongepowered.configurate.CommentedConfigurationNode; -import org.spongepowered.configurate.serialize.SerializationException; - -import java.util.Collection; -import java.util.Collections; -import java.util.Objects; - -public final class SendMessageAction extends Action { - - public static final String ID = "send-message"; - - private final Collection message; - - public SendMessageAction( - final BlackWidow plugin, - final Collection message - ) { - super(plugin, ID); - this.message = Objects.requireNonNull(message, "message"); - } - - public SendMessageAction( - final BlackWidow plugin, - final CommentedConfigurationNode node - ) { - super( - plugin, - Objects.requireNonNull(node.node("id").getString(), "id") - ); - - try { - this.message = Objects.requireNonNull( - node.node("msg").getList(String.class), - "msg" - ); - } catch (final SerializationException ex) { - throw new RuntimeException("Unable to read msg string list", ex); - } - } - - public Collection message() { - return Objects.requireNonNull(message, "message"); - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public void run(Context context) { - final Audience advPlayer = plugin() - .adventure() - .player(context.player(true)); - - message() - .stream() - .map(msg -> Translation.formatify(plugin(), msg, Collections.emptyMap())) - .forEachOrdered(advPlayer::sendMessage); - } -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/requirement/HasPermissionRequirement.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/requirement/HasPermissionRequirement.java deleted file mode 100644 index 869f348..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/requirement/HasPermissionRequirement.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.inbuilt.requirement; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Context; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Requirement; -import org.spongepowered.configurate.CommentedConfigurationNode; - -import java.util.Objects; - -public final class HasPermissionRequirement extends Requirement { - - public static final String ID = "has-perission"; - - private final String permission; - - public HasPermissionRequirement( - final BlackWidow plugin, - final String permission, - final boolean inverted - ) { - super(plugin, ID, inverted); - this.permission = Objects.requireNonNull(permission, "permission"); - } - - public HasPermissionRequirement( - final BlackWidow plugin, - final CommentedConfigurationNode node - ) { - this( - plugin, - Objects.requireNonNull(node.node("permission").getString(), "permission"), - node.node("inverted").getBoolean(false) - ); - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public boolean validateImpl(final Context context) { - return Objects.requireNonNullElse( - context.player(false), - context.commandSender(false) - ).hasPermission(permission()); - } - - public String permission() { - return Objects.requireNonNull(permission, "permission"); - } -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/requirement/InWorldRequirement.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/requirement/InWorldRequirement.java deleted file mode 100644 index 1409015..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/logic/inbuilt/requirement/InWorldRequirement.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.inbuilt.requirement; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Context; -import io.github.arcaneplugins.blackwidow.plugin.bukkit.logic.Requirement; -import org.spongepowered.configurate.CommentedConfigurationNode; - -import java.util.Objects; - -public final class InWorldRequirement extends Requirement { - - public static final String ID = "in-world"; - - private final String worldName; - - public InWorldRequirement( - final BlackWidow plugin, - final String worldName, - final boolean inverted - ) { - super(plugin, ID, inverted); - this.worldName = Objects.requireNonNull(worldName, "worldName"); - } - - public InWorldRequirement( - final BlackWidow plugin, - final CommentedConfigurationNode node - ) { - this( - plugin, - Objects.requireNonNull(node.node("world-name").getString(), "worldName"), - node.node("inverted").getBoolean(false) - ); - } - - /** - * {@inheritDoc} - * - * @author lokka30 - * @since 1.0.0 - */ - @Override - public boolean validateImpl(Context context) { - return context.player(true).getWorld().getName().equalsIgnoreCase(worldName()); - } - - public String worldName() { - return Objects.requireNonNull(worldName, "worldName"); - } -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/ClassUtil.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/ClassUtil.java deleted file mode 100644 index 59631cd..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/ClassUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.util; - -/** - * {@link ClassUtil} contains a variety of utilities related to {@link Class Java classes}. - * - * @author lokka30 - * @since 1.0.0 - */ -public final class ClassUtil { - - /** - * Returns whether a class at the specified classpath exists at runtime. Useful for confirming certain features - * are available before attempting to use them. - * - * @param classpath Classpath where the desired class is located. - * @return Whether the class was found. - * @author lokka30 - * @since 1.0.0 - */ - public static boolean classExists(final String classpath) { - try { - Class.forName(classpath); - } catch (ClassNotFoundException e) { - return false; - } - return true; - } - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/DebugCategory.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/DebugCategory.java deleted file mode 100644 index ce4dcae..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/DebugCategory.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.util; - -public enum DebugCategory { - - ASYNC_PLAYER_COMMAND_SEND_LISTENER - -} diff --git a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/ExceptionUtil.java b/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/ExceptionUtil.java deleted file mode 100644 index f9e84fa..0000000 --- a/BlackWidowPluginBukkit/src/main/java/io/github/arcaneplugins/blackwidow/plugin/bukkit/util/ExceptionUtil.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * BlackWidow: Security modifications for Minecraft servers and proxies - * Copyright (c) 2024 lokka30. - * - * 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 . - */ - -package io.github.arcaneplugins.blackwidow.plugin.bukkit.util; - -import io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow; - -import java.util.logging.Logger; - -public class ExceptionUtil { - - private ExceptionUtil() { - throw new IllegalStateException("Can't instantiate utility class"); - } - - public static void logException( - final BlackWidow plugin, - final Exception ex, - final String msg - ) { - final Logger logger = plugin.getLogger(); - - final String bigdiv = '+' + "-".repeat(43) + '+'; - final String minidiv = "=----->"; - - logger.severe(bigdiv); - logger.severe(""); - logger.severe(minidiv + "Warning: Please Read Below Carefully"); - logger.severe("\tBlackWidow has detected an issue, please carefully read the below and attempt to " + - "resolve the issue (or otherwise, report it to the maintainers via the details also provided below)."); - logger.severe(""); - logger.severe("\tSometimes, these are simple errors caused when users misconfigure the plugin, other " + - "times, it can be a bug (issue) with the plugin's code which the maintainers might not know about."); - logger.severe(""); - logger.severe(bigdiv); - logger.severe(""); - logger.severe(minidiv + "Details about this Issue"); - logger.severe("Context (if known):"); - logger.severe('\t' + msg); - logger.severe(""); - logger.severe("Localized Message:"); - logger.severe('\t' + ex.getLocalizedMessage()); - logger.severe(""); - logger.severe(bigdiv); - logger.severe(""); - logger.severe(minidiv + "Contacting Maintainers for Assistance"); - logger.severe("If this is an issue you can't fix, or if it is a bug report, please contact the " + - "maintainers by checking for recommended links in the GitHub repository description."); - logger.severe("Please visit: < https://github.com/ArcanePlugins/BlackWidow/ >"); - logger.severe(""); - logger.severe("Our Discord Server (should be linked within the page above) is usually the best avenue " + - "for users to report issues like these."); - logger.severe(""); - logger.severe("It's usually worth checking the Frequently Asked Questions page (if applicable)."); - logger.severe(""); - logger.severe(bigdiv); - logger.severe(""); - logger.severe(minidiv + "Java Exception Details (for Developers)"); - logger.severe("These details may be difficult to understand for those without Java experience."); - logger.severe("Regardless, it may contain useful details or expressions hinting to the root problem."); - logger.severe(""); - logger.severe("Exception Class:"); - logger.severe('\t' + ex.getClass().getSimpleName()); - logger.severe(""); - logger.severe("Exception Stack Trace:"); - //noinspection CallToPrintStackTrace - ex.printStackTrace(); - logger.severe(""); - logger.severe(bigdiv); - logger.severe(""); - logger.severe(minidiv + "ATTENTION Server Administrators:"); - logger.severe("Just saw noticed the bottom of this log in your console? Don't panic - please scroll " + - "up to the top of this big log message and read carefully."); - logger.severe(""); - logger.severe(bigdiv); - } -} diff --git a/BlackWidowPluginBukkit/src/main/resources/plugin.yml b/BlackWidowPluginBukkit/src/main/resources/plugin.yml deleted file mode 100644 index f582959..0000000 --- a/BlackWidowPluginBukkit/src/main/resources/plugin.yml +++ /dev/null @@ -1,34 +0,0 @@ -api-version: "1.21" -authors: [ "lokka30" ] -description: "Security solution for Minecraft servers and proxies" -main: "io.github.arcaneplugins.blackwidow.plugin.bukkit.BlackWidow" -name: "BlackWidow" -website: "https://github.com/ArcanePlugins/BlackWidow/" -version: "${project.version}" -perissions: - blackwidow.*: - default: op - description: "All BlackWidow permissions (admin/operator use)" - children: - blackwidow.command.*: true - blackwidow.command.*: - default: true - description: "Access to all BlackWidow commands" - children: - blackwidow.command.bw.*: true - blackwidow.command.bw: - default: true - description: "Access to the base `/bw` command" - blackwidow.command.bw.*: - default: op - description: "Access to all `/bw` subcommands" - children: - blackwidow.command.bw: true - blackwidow.command.bw.reload: true - blackwidow.command.bw.version: true - blackwidow.command.bw.reload: - default: op - description: "Access to `/bw reload`" - blackwidow.command.bw.version: - default: true - description: "Access to `/bw version`" diff --git a/BlackWidowPluginBukkit/src/main/resources/settings.yml b/BlackWidowPluginBukkit/src/main/resources/settings.yml deleted file mode 100644 index 1a3923a..0000000 --- a/BlackWidowPluginBukkit/src/main/resources/settings.yml +++ /dev/null @@ -1,41 +0,0 @@ -cmd-blocking: - chains: - - id: "stop-plugin-snooping" - enabled: true - policy: "DENY" - regex: false - rules: - - "/pl" - - "/plugins" - - "/ver" - - "/version" - - "/about" - - "/icanhasbukkit" - - "/?" - - "/help" - - "/ehelp" - - "/spigot" - - "/paper" - actions: - - id: "send-message" - msg: - - "%prefix% You can't run that command." - default-behaviour: - policy: "ALLOW" - actions: [ ] - deny-colon-in-first-arg: - enabled: true - actions: - - id: "send-message" - msg: - - "%prefix% You can''t use the colon character ':' in the first part of your - commands." - filtering: - execution: true - suggestion: true - operators-bypass-completely: true -do-not-touch: - version: - context: "" - original: 1 - installed: 1 diff --git a/BlackWidowPluginBukkit/src/main/resources/translations.yml b/BlackWidowPluginBukkit/src/main/resources/translations.yml deleted file mode 100644 index 910de39..0000000 --- a/BlackWidowPluginBukkit/src/main/resources/translations.yml +++ /dev/null @@ -1,19 +0,0 @@ -command: - blackwidow: - reload: - started: - - "%prefix% Reloading BlackWidow." - failed: - - "%prefix% Reload failed! Please see your server console for more details." - complete: - - "%prefix% Reload complete." - version: - - "*-----* BlackWidowA security solution for Minecraft.'>BlackWidow v%version% *-----*A security solution for Minecraft.From ArcanePlugins by %authors%." - -prefix: "BlackWidowA security solution for Minecraft.'>BW:" - -do-not-touch: - version: - context: "" - original: 1 - installed: 1