Skip to content

Commit

Permalink
2.7.2 release (#233)
Browse files Browse the repository at this point in the history
- Added 1.21.1 compatibility (#232)
- Made map-cursor-lag-patch work on 1.12.2
- Replaced low-tps-physics modules with regional-activity modules. Any sort of activity that has the potential to lag or kill the server when happening at high frequencies can now be individually managed and configured. The base concept for this was suggested by @xKumorio (3b3t.org): Any time an activity is happening for the first time, the plugin will check in a radius around it for more activity of the same kind. If it exceeds a certain count within the configured timeframe, all activity in that radius (region) will be cancelled.
The only catch: Config defaults are pretty rough and will most likely need individual adjustments. Tests with a variety of lagmachine designs were pretty promising though. I would very much recommend to check out the entire `lag-preventions.regional-activity` section.
- Added a module against lag generated by forcing the server to send large ItemStacks. (Ex. fill chest with books, spam open chest). This is especially a problem with older game versions. Previous modules that were basically a worse attempt at fixing this issue have been removed in favor of this one. Basically works like an anti-spam that starts taking action once the player is exceeding a certain byte-size of requested data within a timeframe. Players will first be rate-limited and if they keep requesting data, locked out from requesting more for a configurable time.
- Replaced all deprecated NBT-API calls with the new ones. This makes AEF handling NBT more reliable.
- Added an illegal item module against illegal potion effects
- Added an illegal item module against illegal item attributes
- Fully reworked configurations for Crystal Aura, Anchor Aura and Bed Aura: You can now set place and break cooldowns per Hand on the Folia jar!
- Added a patch against MultiTask
- Rewrote the patch against SilentSwitch
- Improved the burrow patch slightly for more configurability
- Added a patch against PortalGodMode (#157)
- Improved compatibility with lower game versions by using reflections for TPS and MSPT. This also improved compatibility with unsupported older versions.
- Improved world height configuration and detection for Legacy users
- Fixed AEF being unable to detect player respawns on Folia
- Code optimizations and performance improvements
  • Loading branch information
xGinko authored Aug 13, 2024
1 parent 5285f5b commit d20da6e
Show file tree
Hide file tree
Showing 277 changed files with 11,348 additions and 3,898 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build and upload jar

on:
push:
branches: [ master ]
branches: [ dev ]
pull_request:
branches: [ master ]
branches: [ dev ]

jobs:
build:
Expand Down
1 change: 0 additions & 1 deletion AnarchyExploitFixesFolia/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ tasks.shadowJar {
relocate("org.reflections", "me.xginko.aef.libs.reflections")
relocate("org.apache.commons.math3", "me.xginko.aef.libs.fastmath")
relocate("com.github.benmanes.caffeine", "me.xginko.aef.libs.caffeine")
relocate("io.papermc.lib", "me.xginko.aef.libs.paperlib")
relocate("de.tr7zw.changeme.nbtapi", "me.xginko.aef.libs.nbtapi")
relocate("org.bstats", "me.xginko.aef.libs.bstats")
relocate("com.cryptomorin.xseries", "me.xginko.aef.libs.xseries")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import io.papermc.lib.PaperLib;
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.KyoriUtil;
import me.xginko.aef.utils.PlatformUtil;
import me.xginko.aef.utils.tickdata.TickReporter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
Expand Down Expand Up @@ -48,10 +49,11 @@ public final class AnarchyExploitFixes extends JavaPlugin {
private static CachingPermTool cachingPermTool;
private static ComponentLogger prefixedLogger, unPrefixedLogger;
private static Metrics metrics;
private static boolean isServerFolia, isPacketEventsInstalled;
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
Expand Down Expand Up @@ -89,6 +91,7 @@ public void onEnable() {

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

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

if (!PaperLib.isPaper()) {
if (!PlatformUtil.isPaper()) {
prefixedLogger.error("This plugin depends on Paper's API, which is not present on your server.");
PaperLib.suggestPaper(this, java.util.logging.Level.SEVERE);
getServer().getPluginManager().disablePlugin(this);
return;
}

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

if (PaperLib.getMinecraftVersion() < 19) {
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.");
getServer().getPluginManager().disablePlugin(this);
return;
}

try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
prefixedLogger.info("Detected Folia server");
isServerFolia = true;
} catch (ClassNotFoundException e) {
isServerFolia = false;
if (PlatformUtil.isFolia()) {
prefixedLogger.info("Detected Folia server.");
}

try {
Expand Down Expand Up @@ -153,14 +151,16 @@ public void onEnable() {

@Override
public void onDisable() {
AEFModule.ENABLED_MODULES.forEach(AEFModule::disable);
AEFModule.ENABLED_MODULES.clear();
if (isPacketEventsInstalled) {
AEFModule.ENABLED_MODULES.forEach(AEFModule::disable);
AEFModule.ENABLED_MODULES.clear();
AEFListener.LISTENERS.forEach(AEFListener::disable);
AEFListener.LISTENERS.clear();
PacketEvents.getAPI().terminate();
}
if (metrics != null) {
metrics.shutdown();
metrics = null;
if (languageCacheMap != null) {
languageCacheMap.clear();
languageCacheMap = null;
}
if (cachingPermTool != null) {
cachingPermTool.disable();
Expand All @@ -170,41 +170,48 @@ public void onDisable() {
tickReporter.disable();
tickReporter = null;
}
if (metrics != null) {
metrics.shutdown();
metrics = null;
}
unPrefixedLogger = null;
prefixedLogger = null;
instance = null;
config = null;
languageCacheMap = null;
prefixedLogger = null;
unPrefixedLogger = null;
}

public static AnarchyExploitFixes getInstance() {
return instance;
}

public static TickReporter getTickReporter() {
return tickReporter;
}

public static Config config() {
return config;
}

public static ComponentLogger getPrefixedLogger() {
return prefixedLogger;
}

public static ComponentLogger getUnprefixedLogger() {
return unPrefixedLogger;
}

public static LanguageCache getLang(Locale locale) {
return getLang(locale.toString().toLowerCase());
}

public static LanguageCache getLang(CommandSender commandSender) {
return commandSender instanceof Player player ? getLang(player.locale()) : getLang(config.default_lang);
}

public static LanguageCache getLang(String lang) {
if (!config.auto_lang) return languageCacheMap.get(config.default_lang.toString().toLowerCase());
return languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase()));
}
public static boolean isServerFolia() {
return isServerFolia;
}

public void createDirectory(File dir) throws IOException {
try {
Expand All @@ -225,9 +232,8 @@ private void reloadConfiguration() {
config = new Config();
if (tickReporter != null) tickReporter.disable();
tickReporter = TickReporter.create(this, config.tickData_cache_duration);
AEFListener.reloadListeners();
AEFModule.reloadModules();
if (metrics != null) metrics.shutdown();
metrics = new Metrics(this, 8700);
config.saveConfig();
} catch (Throwable t) {
prefixedLogger.error("Failed while loading config!", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public void enable() {
return subCommand.tabComplete(sender, alias, args);
}
}

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

return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Config {
public final Sound elytra_too_fast_sound;
public final Component cmd_say_format;
public final Duration tickData_cache_duration;
public final long elytra_speed_calc_period;
public final long elytra_speed_calc_period, elytra_old_chunk_limit;
public final int nether_ceiling_max_y, elytra_spawn_radius;
public final boolean auto_lang, packets_disabled, connectionMsgsAreOnByDefault,
cmd_say_enabled, cmd_help_enabled, cmd_toggleConMsgs_enabled,
Expand All @@ -29,9 +29,11 @@ public class Config {
elytra_teleport_back, elytra_calculate_3D;

public Config() throws Exception {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
// Load config.yml with ConfigMaster
this.config = ConfigFile.loadConfig(new File(AnarchyExploitFixes.getInstance().getDataFolder(), "config.yml"));
config.set("config-version", 1.1);
this.config = ConfigFile.loadConfig(new File(plugin.getDataFolder(), "config.yml"));
config.set("plugin-version", plugin.getPluginMeta().getVersion());
config.set("server-version", plugin.getServer().getVersion());

// Pre-structure to force order
structureConfig();
Expand Down Expand Up @@ -64,8 +66,13 @@ The time in ticks (1 sec = 20 ticks) a checked tps will be cached\s
A server restart is required when changing a command's enable status!""");

// Elytra Speed
this.elytra_speed_calc_period = getInt("elytra.elytra-speed.check-period-ticks", 10,
"The period in ticks players will be checked to determine their speed.");
this.elytra_old_chunk_limit = getLong("elytra.elytra-speed.old-chunk-inhabited-ticks", 200L, """
Time in ticks that a chunk has to have been inhabited to count as old chunk.\s
Note that the time is incremented once per tick per player within mob spawning\s
distance of a chunk.""");
this.elytra_speed_calc_period = getInt("elytra.elytra-speed.check-period-millis", 500, """
The period in millis players will be checked to determine their speed.\s
If you have lagging players with consistent high ping, you can increase this number.""");
this.elytra_calculate_3D = getBoolean("elytra.elytra-speed.calculate-3D-speed", false, """
If set to false, will only calculate 2-Dimensional speed without taking height\s
changes into consideration.""");
Expand Down Expand Up @@ -170,6 +177,16 @@ public int getInt(String path, int def) {
return config.getInteger(path, def);
}

public long getLong(String path, long def, String comment) {
config.addDefault(path, def, comment);
return config.getLong(path, def);
}

public long getLong(String path, long def) {
config.addDefault(path, def);
return config.getLong(path, def);
}

public List<String> getList(String path, List<String> def, String comment) {
config.addDefault(path, def, comment);
return config.getStringList(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.xginko.aef.events;

import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

public class PacketPlayerRespawnEvent extends Event {

private static final @NotNull HandlerList handlers = new HandlerList();

private final @NotNull Player player;

public PacketPlayerRespawnEvent(@NotNull Player player) {
super(false);
this.player = player;
}

public @NotNull Player getPlayer() {
return player;
}

public boolean isPotentialBedSpawn() {
if (player.getPotentialBedLocation() == null)
return false;
return player.getPotentialBedLocation().distanceSquared(player.getLocation()) <= 16;
}

@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package me.xginko.aef.listeners;

import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.utils.models.ConditionalEnableable;
import me.xginko.aef.utils.models.Disableable;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;

import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;

public interface AEFListener extends ConditionalEnableable, Disableable {

Reflections LISTENERS_PACKAGE = new Reflections(AEFListener.class.getPackage().getName());

Set<AEFListener> LISTENERS = new HashSet<>();

static void reloadListeners() {
LISTENERS.forEach(AEFListener::disable);
LISTENERS.clear();

for (Class<?> clazz : LISTENERS_PACKAGE.get(Scanners.SubTypes.of(AEFListener.class).asClass())) {
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) continue;

try {
AEFListener listener = (AEFListener) clazz.getDeclaredConstructor().newInstance();
if (listener.shouldEnable()) {
if (listener instanceof PacketListenerAbstract && AnarchyExploitFixes.config().packets_disabled) {
AnarchyExploitFixes.getPrefixedLogger()
.warn("Cannot enable listener {} because you disabled packets in config!", clazz.getSimpleName());
continue;
}

listener.enable();
LISTENERS.add(listener);
}
} catch (Throwable t) {
AnarchyExploitFixes.getPrefixedLogger().error("Failed to load listener {}", clazz.getSimpleName(), t);
}
}
}

}
Loading

0 comments on commit d20da6e

Please sign in to comment.