Skip to content

Commit

Permalink
speed up module loading
Browse files Browse the repository at this point in the history
replace deprecated XSeries calls
reduce codesize where possible
  • Loading branch information
xGinko committed Dec 30, 2024
1 parent e8399a9 commit 4306941
Show file tree
Hide file tree
Showing 253 changed files with 2,335 additions and 2,732 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import me.xginko.aef.utils.tickdata.TickReporter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.bstats.bukkit.Metrics;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -48,6 +50,8 @@ public final class AnarchyExploitFixes extends JavaPlugin {
@Override
public void onLoad() {
PlatformUtil.load();
// Disable reflection logging because we want to do our own, pretty logging
Configurator.setLevel(AnarchyExploitFixes.class.getPackage().getName() + ".libs.reflections.Reflections", Level.OFF);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import me.xginko.aef.utils.models.ConditionalEnableable;
import me.xginko.aef.utils.models.Disableable;
import me.xginko.aef.utils.models.Enableable;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.reflections.Reflections;
import org.reflections.scanners.Scanners;

Expand All @@ -24,8 +22,6 @@ public abstract class AEFModule implements ConditionalEnableable, Disableable {
protected static final Set<AEFModule> ENABLED_MODULES;

static {
// Disable reflection logging for this operation because its just confusing and provides no value.
Configurator.setLevel(AnarchyExploitFixes.class.getPackage().getName() + ".libs.reflections.Reflections", Level.OFF);
AVAILABLE_MODULES = new Reflections(AEFModule.class.getPackage().getName())
.get(Scanners.SubTypes.of(AEFModule.class).asClass())
.stream()
Expand All @@ -36,15 +32,35 @@ public abstract class AEFModule implements ConditionalEnableable, Disableable {
ENABLED_MODULES = new HashSet<>();
}

protected final AnarchyExploitFixes plugin;
protected final Config config;
protected final AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
protected final Config config = AnarchyExploitFixes.config();
protected final String configPath, logFormat;
protected final boolean configEnabled;

public AEFModule(String configPath) {
this.plugin = AnarchyExploitFixes.getInstance();
this.config = AnarchyExploitFixes.config();
this.configPath = configPath;
shouldEnable(); // Ensure enable option is always first
this.configEnabled = true;

String[] paths = configPath.split("\\.");
if (paths.length <= 2) {
this.logFormat = "<" + configPath + "> {}";
} else {
this.logFormat = "<" + paths[paths.length - 2] + "." + paths[paths.length - 1] + "> {}";
}
}

public AEFModule(String configPath, boolean defEnabled) {
this(configPath, defEnabled, null);
}

public AEFModule(String configPath, boolean defEnabled, String comment) {
this.configPath = configPath;
if (comment == null || comment.isEmpty()) {
this.configEnabled = config.getBoolean(configPath + ".enable", defEnabled);
} else {
this.configEnabled = config.getBoolean(configPath + ".enable", defEnabled, comment);
}

String[] paths = configPath.split("\\.");
if (paths.length <= 2) {
this.logFormat = "<" + configPath + "> {}";
Expand All @@ -53,6 +69,10 @@ public AEFModule(String configPath) {
}
}

public boolean shouldEnable() {
return configEnabled;
}

public static void disableAll() {
ENABLED_MODULES.forEach(Disableable::disable);
ENABLED_MODULES.clear();
Expand All @@ -67,12 +87,11 @@ public static void reloadModules() {
if (module.shouldEnable()) {
if (module instanceof PacketModule && AnarchyExploitFixes.config().packets_disabled) {
module.warn("Cannot enable because you disabled packets in config!");
continue;
} else {
ENABLED_MODULES.add(module);
}

ENABLED_MODULES.add(module);
}
} catch (Throwable t) { // We want to catch everything here if it fails to init
} catch (Throwable t) {
AnarchyExploitFixes.prefixedLogger().warn("Failed initialising module class '{}'.", moduleClass.getSimpleName(), t);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FillNetherCeilingOnChunkload extends AEFModule implements Listener
private final boolean alsoCheckNewChunks, checkShouldPauseOnLowTPS;

public FillNetherCeilingOnChunkload() {
super("bedrock.fill-in-bedrock.nether-ceiling.fill-on-chunkload");
super("bedrock.fill-in-bedrock.nether-ceiling.fill-on-chunkload", false);
this.alsoCheckNewChunks = config.getBoolean(configPath + ".also-check-new-chunks", false, """
Recommended to leave off. Only useful if world generation is broken.""");
this.exemptedWorlds = new HashSet<>(config.getList(configPath + ".exempted-worlds",
Expand All @@ -37,11 +37,6 @@ public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FillNetherFloorOnChunkload extends AEFModule implements Listener {
private final boolean alsoCheckNewChunks, checkShouldPauseOnLowTPS;

public FillNetherFloorOnChunkload() {
super("bedrock.fill-in-bedrock.nether-floor.fill-on-chunkload");
super("bedrock.fill-in-bedrock.nether-floor.fill-on-chunkload", false);
this.alsoCheckNewChunks = config.getBoolean(configPath + ".also-check-new-chunks", false, """
Recommended to leave off. Only useful if world generation is broken.""");
this.exemptedWorlds = new HashSet<>(config.getList(configPath + ".exempted-worlds",
Expand All @@ -37,11 +37,6 @@ public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FillOverworldFloorOnChunkload extends AEFModule implements Listener
private final boolean alsoCheckNewChunks, checkShouldPauseOnLowTPS;

public FillOverworldFloorOnChunkload() {
super("bedrock.fill-in-bedrock.overworld-floor.fill-on-chunkload");
super("bedrock.fill-in-bedrock.overworld-floor.fill-on-chunkload", false);
this.alsoCheckNewChunks = config.getBoolean(configPath + ".also-check-new-chunks", false, """
Recommended to leave off. Only useful if world generation is broken.""");
this.exemptedWorlds = new HashSet<>(config.getList(configPath + ".exempted-worlds",
Expand All @@ -37,11 +37,6 @@ public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@

public class PeriodicallyFillNetherCeiling extends AEFModule implements Consumer<ScheduledTask> {

private ScheduledTask scheduledTask;
private final Set<String> exemptedWorlds;
private final long checkPeriod;
private final double pauseTPS;
private final boolean pauseOnLowTPS;


private ScheduledTask scheduledTask;

public PeriodicallyFillNetherCeiling() {
super("bedrock.fill-in-bedrock.nether-ceiling.periodically-check-and-fill");
config.addComment(configPath + ".enable","Only checks loaded chunks.");
super("bedrock.fill-in-bedrock.nether-ceiling.periodically-check-and-fill", false,
"Only checks loaded chunks.");
this.checkPeriod = config.getInt(configPath + ".check-period-in-seconds", 10) * 20L;
this.exemptedWorlds = new HashSet<>(config.getList(configPath + ".exempted-worlds",
List.of("exampleworld", "exampleworld2"),
Expand All @@ -34,18 +35,16 @@ public PeriodicallyFillNetherCeiling() {

@Override
public void enable() {
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler()
scheduledTask = plugin.getServer().getGlobalRegionScheduler()
.runAtFixedRate(plugin, this, checkPeriod, checkPeriod);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
if (scheduledTask != null) scheduledTask.cancel();
if (scheduledTask != null) {
scheduledTask.cancel();
scheduledTask = null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

public class PeriodicallyFillNetherFloor extends AEFModule implements Consumer<ScheduledTask> {

private ScheduledTask scheduledTask;
private final Set<String> exemptedWorlds;
private final long checkPeriod;
private final double pauseTPS;
private final boolean pauseOnLowTPS;

private ScheduledTask scheduledTask;

public PeriodicallyFillNetherFloor() {
super("bedrock.fill-in-bedrock.nether-floor.periodically-check-and-fill");
super("bedrock.fill-in-bedrock.nether-floor.periodically-check-and-fill", false);
config.addComment(configPath + ".enable","Only checks loaded chunks.");
this.checkPeriod = config.getInt(configPath + ".check-period-in-seconds", 10) * 20L;
this.exemptedWorlds = new HashSet<>(config.getList(configPath + ".exempted-worlds",
Expand All @@ -34,18 +35,16 @@ public PeriodicallyFillNetherFloor() {

@Override
public void enable() {
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler()
scheduledTask = plugin.getServer().getGlobalRegionScheduler()
.runAtFixedRate(plugin, this, checkPeriod, checkPeriod);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
if (scheduledTask != null) scheduledTask.cancel();
if (scheduledTask != null) {
scheduledTask.cancel();
scheduledTask = null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@

public class PeriodicallyFillOverworldFloor extends AEFModule implements Consumer<ScheduledTask> {

private ScheduledTask scheduledTask;
private final Set<String> exemptedWorlds;
private final long checkPeriod;
private final double pauseTPS;
private final boolean pauseOnLowTPS;

private ScheduledTask scheduledTask;

public PeriodicallyFillOverworldFloor() {
super("bedrock.fill-in-bedrock.overworld-floor.periodically-check-and-fill");
config.addComment(configPath + ".enable","Only checks loaded chunks.");
super("bedrock.fill-in-bedrock.overworld-floor.periodically-check-and-fill", false,
"Only checks loaded chunks.");
this.checkPeriod = config.getInt(configPath + ".check-period-in-seconds", 10) * 20L;
this.exemptedWorlds = new HashSet<>(config.getList(configPath + ".exempted-worlds",
List.of("exampleworld", "exampleworld2"),
Expand All @@ -35,18 +36,16 @@ public PeriodicallyFillOverworldFloor() {

@Override
public void enable() {
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler()
scheduledTask = plugin.getServer().getGlobalRegionScheduler()
.runAtFixedRate(plugin, this, checkPeriod, checkPeriod);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", false);
}

@Override
public void disable() {
if (scheduledTask != null) scheduledTask.cancel();
if (scheduledTask != null) {
scheduledTask.cancel();
scheduledTask = null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class PreventGoingBelowBedrockFloor extends AEFModule implements Listener
private final double damageOnMove;

public PreventGoingBelowBedrockFloor() {
super("bedrock.prevent-going-below-bedrock-floor");
config.addComment(configPath + ".enable", "Prevents players from going below the bedrock floor.");
super("bedrock.prevent-going-below-bedrock-floor", true,
"Prevents players from going below the bedrock floor.");
this.vehicleEject = config.getBoolean(configPath + ".leave-vehicle", true,
"Whether to make player leave their vehicle.");
this.closeElytra = config.getBoolean(configPath + ".stop-elytra", true,
Expand Down Expand Up @@ -52,11 +52,6 @@ public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", true);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class PreventPluginScanning extends AEFModule implements Listener {

public PreventPluginScanning() {
super("chat.prevent-scanning-server-plugins");
super("chat.prevent-scanning-server-plugins", true);
config.addComment(configPath + ".enable","""
Prevents hacked clients running .plugins to find out what plugins\s
the server is using.\s
Expand All @@ -28,11 +28,6 @@ public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

@Override
public boolean shouldEnable() {
return config.getBoolean(configPath + ".enable", true);
}

@Override
public void disable() {
HandlerList.unregisterAll(this);
Expand Down
Loading

0 comments on commit 4306941

Please sign in to comment.