Skip to content

Commit

Permalink
simplify commands and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Feb 6, 2024
1 parent 23604a2 commit e62d789
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,66 @@
package me.moomoo.anarchyexploitfixes.commands;

import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.arguments.parser.StandardParameters;
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.paper.PaperCommandManager;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

public interface AnarchyExploitFixesCommand {

boolean shouldRegister();

static void registerCommands() {
try {
CommandManager commandManager = new CommandManager();

List<AnarchyExploitFixesCommand> allCommands = new ArrayList<>(4);
allCommands.add(new AEFCommand());
allCommands.add(new HelpCommand());
allCommands.add(new SayCommand());
allCommands.add(new ToggleConnectionMsgsCommand());

allCommands.forEach(toParse -> {
if (toParse.shouldRegister()) commandManager.parser().parse(toParse);
});
} catch (Exception e) {
AnarchyExploitFixes.getLog().severe("Failed to create command manager! - " + e.getLocalizedMessage());
PaperCommandManager<CommandSender> manager = new PaperCommandManager<>(
/* Owning plugin */ AnarchyExploitFixes.getInstance(),
/* Coordinator function */ AsynchronousCommandExecutionCoordinator.<CommandSender>builder().build(),
/* Command Sender -> C */ Function.identity(),
/* C -> Command Sender */ Function.identity()
);

if (manager.hasCapability(CloudBukkitCapabilities.BRIGADIER))
manager.registerBrigadier();
if (manager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION))
manager.registerAsynchronousCompletions();

// Command error messages
manager.registerExceptionHandler(cloud.commandframework.exceptions.NoPermissionException.class, (sender, exception) ->
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission));
manager.registerExceptionHandler(cloud.commandframework.exceptions.ArgumentParseException.class, (sender, exception) ->
sender.sendMessage(AnarchyExploitFixes.getLang(sender).failed_argument_parse));
manager.registerExceptionHandler(cloud.commandframework.exceptions.InvalidSyntaxException.class, (sender, exception) ->
sender.sendMessage(AnarchyExploitFixes.getLang(sender).invalid_syntax
.replaceText(TextReplacementConfig.builder().matchLiteral("%syntax%").replacement("/"+exception.getCorrectSyntax()).build())));

final AnnotationParser<CommandSender> parser = new AnnotationParser<>(
manager,
CommandSender.class,
parameters -> CommandMeta.simple().with(
CommandMeta.DESCRIPTION,
parameters.get(StandardParameters.DESCRIPTION, "No description")
).build()
);

for (AnarchyExploitFixesCommand command : Set.of(
new AEFCommand(),
new HelpCommand(),
new SayCommand(),
new ToggleConnectionMsgsCommand()
)) {
if (command.shouldRegister()) {
parser.parse(command);
}
}
} catch (Throwable t) {
AnarchyExploitFixes.getLog().severe("Error registering commands! - " + t.getLocalizedMessage());
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().disablePlugin(plugin);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
package me.moomoo.anarchyexploitfixes.commands;

import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.arguments.parser.StandardParameters;
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.paper.PaperCommandManager;
import com.google.common.collect.Sets;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

public interface AnarchyExploitFixesCommand {

boolean shouldRegister();

static void registerCommands() {
try {
CommandManager commandManager = new CommandManager();

List<AnarchyExploitFixesCommand> allCommands = new ArrayList<>(4);
allCommands.add(new AEFCommand());
allCommands.add(new HelpCommand());
allCommands.add(new SayCommand());
allCommands.add(new ToggleConnectionMsgsCommand());

allCommands.forEach(toParse -> {
if (toParse.shouldRegister()) commandManager.parser().parse(toParse);
});
} catch (Exception e) {
AnarchyExploitFixes.getLog().severe("Failed to create command manager! - " + e.getLocalizedMessage());
PaperCommandManager<CommandSender> manager = new PaperCommandManager<>(
/* Owning plugin */ AnarchyExploitFixes.getInstance(),
/* Coordinator function */ AsynchronousCommandExecutionCoordinator.<CommandSender>builder().build(),
/* Command Sender -> C */ Function.identity(),
/* C -> Command Sender */ Function.identity()
);

if (manager.hasCapability(CloudBukkitCapabilities.BRIGADIER))
manager.registerBrigadier();
if (manager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION))
manager.registerAsynchronousCompletions();

// Command error messages
manager.registerExceptionHandler(cloud.commandframework.exceptions.NoPermissionException.class, (sender, exception) ->
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission));
manager.registerExceptionHandler(cloud.commandframework.exceptions.ArgumentParseException.class, (sender, exception) ->
sender.sendMessage(AnarchyExploitFixes.getLang(sender).failed_argument_parse));
manager.registerExceptionHandler(cloud.commandframework.exceptions.InvalidSyntaxException.class, (sender, exception) ->
sender.sendMessage(AnarchyExploitFixes.getLang(sender).invalid_syntax.replace("%syntax%", "/"+exception.getCorrectSyntax())));

final AnnotationParser<CommandSender> parser = new AnnotationParser<>(
manager,
CommandSender.class,
parameters -> CommandMeta.simple().with(
CommandMeta.DESCRIPTION,
parameters.get(StandardParameters.DESCRIPTION, "No description")
).build()
);

for (AnarchyExploitFixesCommand command : Sets.newHashSet(
new AEFCommand(),
new HelpCommand(),
new SayCommand(),
new ToggleConnectionMsgsCommand()
)) {
if (command.shouldRegister()) {
parser.parse(command);
}
}
} catch (Throwable t) {
AnarchyExploitFixes.getLog().severe("Error registering commands! - " + t.getLocalizedMessage());
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().disablePlugin(plugin);
}
Expand Down

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ Need to let us know of any exploits in private? Contact us on discord: `moo#0529

## Notice

Please note that some exploits have already been patched
by [2LS ExploitFixer](https://builtbybit.com/resources/exploitfixer-ultimate-anticrasher.26463/) or [Panilla](https://www.spigotmc.org/resources/panilla-prevent-hacked-items.65694/), meaning they are most likely not included in AEF.
Please note that some exploits have already been patched by
[LPX AntiPacketExploit](https://builtbybit.com/resources/lpx-antipacketexploit.15709/),
[ArkFlame ExploitFixer](https://builtbybit.com/resources/exploitfixer-ultimate-anticrasher.26463/) or [Panilla](https://www.spigotmc.org/resources/panilla-prevent-hacked-items.65694/),
meaning they are most likely not included in AEF.
I recommend using those alongside AEF to patch the majority of exploits.

## Features
Expand Down

0 comments on commit e62d789

Please sign in to comment.