Skip to content

Commit

Permalink
2.7.3 release
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 4, 2025
1 parent c1f195e commit f7ee43c
Show file tree
Hide file tree
Showing 335 changed files with 5,897 additions and 9,849 deletions.
1 change: 0 additions & 1 deletion AnarchyExploitFixesFolia/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ tasks.shadowJar {
archiveFileName = "${rootProject.name}-${project.name}-${project.version}.${archiveExtension.get()}"
exclude(
"com/cryptomorin/xseries/XBiome*",
"com/cryptomorin/xseries/XPotion*",
"com/cryptomorin/xseries/NMSExtras*",
"com/cryptomorin/xseries/NoteBlockMusic*",
"com/cryptomorin/xseries/SkullCacheListener*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package me.xginko.aef;

import com.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import de.tr7zw.changeme.nbtapi.NBT;
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.listeners.AEFListener;
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 All @@ -24,8 +24,6 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -34,6 +32,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -45,31 +44,33 @@ 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;

@Override
public void onLoad() {
PlatformUtil.load();
prefixedLogger = ComponentLogger.logger(getLogger().getName());
unPrefixedLogger = ComponentLogger.logger("");
// Disable logging for some shaded libraries as those can get very verbose
String shadedLibs = getClass().getPackageName() + ".libs";
Configurator.setLevel(shadedLibs + ".reflections.Reflections", Level.OFF);
isPacketEventsInstalled = getServer().getPluginManager().getPlugin("packetevents") != null;
if (isPacketEventsInstalled) {
// Configure and load packetevents
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().getSettings().kickOnPacketException(true).reEncodeByDefault(false).checkForUpdates(false);
PacketEvents.getAPI().load();
}
// Disable info logging for Reflections because it does not provide additional value to the user and makes startup log look ugly.
Configurator.setLevel(AnarchyExploitFixes.class.getPackage().getName() + ".libs.reflections.Reflections", Level.WARN);
}

@Override
public void onEnable() {
if (!PlatformUtil.isPaper()) {
getLogger().severe("This plugin depends on Paper's API, which is not present on your server.");
getServer().getPluginManager().disablePlugin(this);
return;
}

prefixedLogger = ComponentLogger.logger(getLogger().getName());
unPrefixedLogger = ComponentLogger.logger("");

isPacketEventsInstalled = getServer().getPluginManager().getPlugin("packetevents") != null;
if (!isPacketEventsInstalled) {
Stream.of(" ",
" _ _ _ _ _ ",
Expand All @@ -89,10 +90,6 @@ public void onEnable() {
return;
}

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

Stream.of(" ",
" ",
" █████ ███████ ███████ ",
Expand All @@ -104,32 +101,29 @@ public void onEnable() {
" "
).map(str -> Component.text(str).color(KyoriUtil.AEF_WHITE)).forEach(prefixedLogger::info);

if (!PlatformUtil.isPaper()) {
prefixedLogger.error("This plugin depends on Paper's API, which is not present on your server.");
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
prefixedLogger.info("Detected {} {}", PlatformUtil.getServerType().niceName(),
serverVersion.name().replace("V_", "").replace('_', '.'));
if (serverVersion.isOlderThanOrEquals(ServerVersion.V_1_19_3) ||
serverVersion.equals(ServerVersion.V_1_19_4) && !PlatformUtil.isFolia()) {
prefixedLogger.error("This plugin jar is incompatible with your Server. Please use the Legacy jar.");
getServer().getPluginManager().disablePlugin(this);
return;
}

prefixedLogger.info("Detected Version 1.{}.{}", PlatformUtil.getMinecraftVersion(), PlatformUtil.getMinecraftPatchVersion());

if (PlatformUtil.getMinecraftVersion() < 19) {
prefixedLogger.error("The Folia jar is intended for Paper and Folia servers running 1.19 and above.");
prefixedLogger.error("Please replace it with the Legacy jar.");
try {
Files.createDirectories(getDataFolder().toPath());
} catch (Exception e) {
prefixedLogger.error("Unable to create plugin directory.", e);
getServer().getPluginManager().disablePlugin(this);
return;
}

if (PlatformUtil.isFolia()) {
prefixedLogger.info("Detected Folia server.");
}
instance = this;

try {
createDirectory(getDataFolder());
} catch (IOException e) {
prefixedLogger.error("Unable to create plugin folder!", e);
getServer().getPluginManager().disablePlugin(this);
return;
}
prefixedLogger.info("Registering Permissions");
permissionHandler = PermissionHandler.create(this);
AEFPermission.registerAll();

prefixedLogger.info("Loading Config");
reloadConfiguration();
Expand All @@ -140,31 +134,30 @@ public void onEnable() {
prefixedLogger.info("Registering Commands");
AEFCommand.registerCommands();

prefixedLogger.info("Registering Permissions");
AEFPermission.registerPermissions();
prefixedLogger.info("Loading NBT-API");
// Hide all messages with a log level lower than WARNING because of the same reason as Reflections logging.
Logger.getLogger("NBTAPI").setLevel(java.util.logging.Level.WARNING);
if (!NBT.preloadApi()) prefixedLogger.error("Error initializing NBT-API! This will break some modules!");

prefixedLogger.info("Initializing PacketEvents");
PacketEvents.getAPI().init();
prefixedLogger.info("Loading Metrics");
metrics = new Metrics(this, 8700);

prefixedLogger.info("Ready.");
prefixedLogger.info("Done.");
}

@Override
public void onDisable() {
AEFPermission.unregisterAll();
if (isPacketEventsInstalled) {
AEFModule.ENABLED_MODULES.forEach(AEFModule::disable);
AEFModule.ENABLED_MODULES.clear();
AEFListener.LISTENERS.forEach(AEFListener::disable);
AEFListener.LISTENERS.clear();
PacketEvents.getAPI().terminate();
AEFModule.disableAll();
}
if (languageCacheMap != null) {
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 @@ -184,19 +177,23 @@ public static AnarchyExploitFixes getInstance() {
return instance;
}

public static TickReporter getTickReporter() {
public static PermissionHandler permissions() {
return permissionHandler;
}

public static TickReporter tickReporter() {
return tickReporter;
}

public static Config config() {
return config;
}

public static ComponentLogger getPrefixedLogger() {
public static ComponentLogger prefixedLogger() {
return prefixedLogger;
}

public static ComponentLogger getUnprefixedLogger() {
public static ComponentLogger unprefixedLogger() {
return unPrefixedLogger;
}

Expand All @@ -213,26 +210,16 @@ public static LanguageCache getLang(String lang) {
return languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase()));
}

public void createDirectory(File dir) throws IOException {
try {
Files.createDirectories(dir.toPath());
} catch (FileAlreadyExistsException e) { // Thrown if dir exists but is not a directory
if (dir.delete()) createDirectory(dir);
}
}

public void reloadPlugin() {
reloadConfiguration();
reloadLang();
}

private void reloadConfiguration() {
try {
createDirectory(getDataFolder());
config = new Config();
if (tickReporter != null) tickReporter.disable();
tickReporter = TickReporter.create(this, config.tickData_cache_duration);
AEFListener.reloadListeners();
AEFModule.reloadModules();
config.saveConfig();
} catch (Throwable t) {
Expand Down Expand Up @@ -276,10 +263,9 @@ public void reloadLang() {

private @NotNull List<String> getAvailableTranslations() {
try (final JarFile pluginJar = new JarFile(getFile())) {
createDirectory(new File(getDataFolder(), "/lang"));
final Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE);
final File[] langDirFiles = new File(getDataFolder() + "/lang").listFiles();
return Stream.concat(pluginJar.stream().map(ZipEntry::getName), Arrays.stream(langDirFiles).map(File::getName))
final File langFolder = new File(getDataFolder(), "/lang");
return (langFolder.exists() ? Arrays.stream(langFolder.listFiles()).map(File::getName) : pluginJar.stream().map(ZipEntry::getName))
.map(langPattern::matcher)
.filter(Matcher::find)
.map(matcher -> matcher.group(1))
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.bukkit())) {
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.bukkit())) {
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.bukkit())) {
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
@@ -1,5 +1,7 @@
package me.xginko.aef.commands.aef;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.commands.SubCommand;
Expand All @@ -18,11 +20,14 @@

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AEFCmd extends Command implements AEFCommand {

private final @NotNull List<SubCommand> subCommands;
private final @NotNull Set<SubCommand> subCommands;
private final @NotNull List<String> tabCompletes;
private final @NotNull List<Component> overview;

Expand All @@ -46,16 +51,17 @@ public AEFCmd() {
" <#00edff>/aef bytesize <mainhand/inventory> (player) (utf8/utf16)",
" <#869699>- <#e2fdff>Get the byte size of an item or inventory.",
""
).map(MiniMessage.miniMessage()::deserialize).toList();
this.subCommands = List.of(
).map(MiniMessage.miniMessage()::deserialize)
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
this.subCommands = ImmutableSet.of(
new ReloadSubCmd(),
new VersionSubCmd(),
new DisableSubCmd(),
new LagSubCmd(),
new ElytraSubCmd(),
new GearedSubCmd()
);
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted().toList();
new GearedSubCmd());
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted()
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
}

@Override
Expand All @@ -75,7 +81,9 @@ public void enable() {
throws CommandException, IllegalArgumentException
{
if (args.length == 1) {
return tabCompletes;
return tabCompletes.stream()
.filter(cmd -> cmd.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT)))
.collect(Collectors.toList());
}

if (args.length > 1) {
Expand All @@ -84,8 +92,6 @@ public void enable() {
return subCommand.tabComplete(sender, alias, args);
}
}

return tabCompletes.stream().filter(cmd -> cmd.startsWith(args[0])).toList();
}

return Collections.emptyList();
Expand Down
Loading

0 comments on commit f7ee43c

Please sign in to comment.