Skip to content

Commit

Permalink
fix #237
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 1, 2025
1 parent 3eb4b4a commit cf5dfc8
Show file tree
Hide file tree
Showing 95 changed files with 555 additions and 435 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.config.Config;
import me.xginko.aef.config.LanguageCache;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.modules.AEFModule;
import me.xginko.aef.utils.CachingPermTool;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.permissions.PermissionHandler;
import me.xginko.aef.utils.KyoriUtil;
import me.xginko.aef.utils.PlatformUtil;
import me.xginko.aef.utils.tickdata.TickReporter;
Expand Down Expand Up @@ -41,9 +41,11 @@ public final class AnarchyExploitFixes extends JavaPlugin {
private static AnarchyExploitFixes instance;
private static Map<String, LanguageCache> languageCacheMap;
private static Config config;

private static TickReporter tickReporter;
private static CachingPermTool cachingPermTool;
private static PermissionHandler permissionHandler;
private static ComponentLogger prefixedLogger, unPrefixedLogger;

private static Metrics metrics;
private static boolean isPacketEventsInstalled;

Expand Down Expand Up @@ -101,7 +103,7 @@ public void onEnable() {
}

instance = this;
cachingPermTool = CachingPermTool.enable(this);
permissionHandler = PermissionHandler.create(this);
metrics = new Metrics(this, 8700);

Stream.of(" ",
Expand Down Expand Up @@ -149,9 +151,9 @@ public void onDisable() {
languageCacheMap.clear();
languageCacheMap = null;
}
if (cachingPermTool != null) {
cachingPermTool.disable();
cachingPermTool = null;
if (permissionHandler != null) {
permissionHandler.disable();
permissionHandler = null;
}
if (tickReporter != null) {
tickReporter.disable();
Expand All @@ -171,6 +173,10 @@ public static AnarchyExploitFixes getInstance() {
return instance;
}

public static PermissionHandler permissions() {
return permissionHandler;
}

public static TickReporter tickReporter() {
return tickReporter;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.xginko.aef.commands;

import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -37,7 +37,7 @@ public void enable() {

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_HELP.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_HELP.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.xginko.aef.commands;

import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.CommandUtil;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down Expand Up @@ -40,7 +40,7 @@ public void enable() {

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_SAY.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_SAY.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.xginko.aef.commands;

import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.enums.AEFKey;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.enums.AEFKey;
import me.xginko.aef.utils.permissions.AEFPermission;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -44,7 +44,7 @@ public void enable() {
@Override
@SuppressWarnings("DataFlowIssue")
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_TOGGLE_CONNECT_MSGS.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_TOGGLE_CONNECT_MSGS.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.modules.AEFModule;
import me.xginko.aef.utils.KyoriUtil;
import net.kyori.adventure.text.Component;
Expand All @@ -29,7 +29,7 @@ public class DisableSubCmd extends SubCommand {

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_AEF_DISABLE.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_DISABLE.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.KyoriUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -31,7 +31,7 @@ public class ElytraSubCmd extends SubCommand {

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_AEF_ELYTRA.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_ELYTRA.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.KyoriUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class GearedSubCmd extends SubCommand {

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_AEF_GEARED.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_GEARED.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.KyoriUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand Down Expand Up @@ -31,12 +31,16 @@ public LagSubCmd() {
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)
throws CommandException, IllegalArgumentException
{
return args.length == 2 && sender.hasPermission(AEFPermission.CMD_AEF_LAG.get()) ? tabCompletes : Collections.emptyList();
if (args.length == 2 && AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_LAG.node()).toBoolean()) {
return tabCompletes;
}

return Collections.emptyList();
}

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_AEF_LAG.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_LAG.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.KyoriUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandException;
Expand All @@ -28,7 +28,7 @@ public class ReloadSubCmd extends SubCommand {

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_AEF_RELOAD.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_RELOAD.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.papermc.paper.plugin.configuration.PluginMeta;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.KyoriUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class VersionSubCmd extends SubCommand {
@Override
@SuppressWarnings({"UnstableApiUsage", "DataFlowIssue"})
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_AEF_VERSION.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_VERSION.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package me.xginko.aef.commands.aef.subcommands.bytesize;

import com.google.common.collect.ImmutableList;
import me.xginko.aef.commands.SubCommand;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -16,8 +16,9 @@ public class ByteSizeSubCmd extends SubCommand {
private final List<String> tabCompletes;

public ByteSizeSubCmd() {
this.subCommands = Arrays.asList(new InventorySubCmd(), new ItemSubCmd());
this.tabCompletes = subCommands.stream().map(SubCommand::label).collect(Collectors.toList());
this.subCommands = ImmutableList.of(new InventorySubCmd(), new ItemSubCmd());
this.tabCompletes = subCommands.stream().map(SubCommand::label)
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.github.benmanes.caffeine.cache.Caffeine;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.ItemUtil;
import me.xginko.aef.utils.KyoriUtil;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -40,7 +40,7 @@ public InventorySubCmd() {
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)
throws CommandException, IllegalArgumentException
{
if (!sender.hasPermission(AEFPermission.CMD_AEF_SIZE_INV.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_SIZE_INV.node()).toBoolean()) {
return Collections.emptyList();
}

Expand All @@ -63,7 +63,7 @@ public InventorySubCmd() {

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_AEF_SIZE_INV.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_SIZE_INV.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.github.benmanes.caffeine.cache.Caffeine;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.utils.ItemUtil;
import me.xginko.aef.utils.KyoriUtil;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -40,7 +40,7 @@ public ItemSubCmd() {
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)
throws CommandException, IllegalArgumentException
{
if (!sender.hasPermission(AEFPermission.CMD_AEF_SIZE_HAND.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_SIZE_HAND.node()).toBoolean()) {
return Collections.emptyList();
}

Expand All @@ -63,7 +63,7 @@ public ItemSubCmd() {

@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
if (!sender.hasPermission(AEFPermission.CMD_AEF_SIZE_HAND.get())) {
if (!AnarchyExploitFixes.permissions().permissionValue(sender, AEFPermission.CMD_AEF_SIZE_HAND.node()).toBoolean()) {
sender.sendMessage(AnarchyExploitFixes.getLang(sender).no_permission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package me.xginko.aef.modules.chat;

import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
import me.xginko.aef.enums.AEFPermission;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.utils.permissions.AEFPermission;
import me.xginko.aef.modules.AEFModule;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -38,7 +39,7 @@ private boolean isSuspectedScanPacket(String buffer) {

@EventHandler(priority = EventPriority.HIGHEST)
private void onAsyncCommandTabComplete(AsyncTabCompleteEvent event) {
if (event.getSender().hasPermission(AEFPermission.BYPASS_CHAT.get())) return;
if (AnarchyExploitFixes.permissions().permissionValue(event.getSender(), AEFPermission.BYPASS_CHAT.node()).toBoolean()) return;

if (isSuspectedScanPacket(event.getBuffer())) {
event.setCancelled(true);
Expand All @@ -47,7 +48,7 @@ private void onAsyncCommandTabComplete(AsyncTabCompleteEvent event) {

@EventHandler(priority = EventPriority.HIGHEST)
private void onCommandTabComplete(TabCompleteEvent event) {
if (event.getSender().hasPermission(AEFPermission.BYPASS_CHAT.get())) return;
if (AnarchyExploitFixes.permissions().permissionValue(event.getSender(), AEFPermission.BYPASS_CHAT.node()).toBoolean()) return;

if (isSuspectedScanPacket(event.getBuffer())) {
event.setCancelled(true);
Expand Down
Loading

0 comments on commit cf5dfc8

Please sign in to comment.