Skip to content

Commit

Permalink
fix #160
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Dec 23, 2023
1 parent 949e9ac commit 1e72110
Show file tree
Hide file tree
Showing 301 changed files with 315 additions and 210 deletions.
2 changes: 2 additions & 0 deletions AnarchyExploitFixesFolia/build.gradle.kts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
plugins {
id("me.moomoo.anarchyexploitfixes.wrapper")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.papermc.paperweight.userdev") version "1.5.11"
}

dependencies {
compileOnly("dev.folia:folia-api:1.20.2-R0.1-SNAPSHOT")
api("com.github.ben-manes.caffeine:caffeine:3.1.8") // Fast caching
paperweight.foliaDevBundle("1.19.4-R0.1-SNAPSHOT")
}

configure<JavaPluginExtension> {
Expand Down
55 changes: 24 additions & 31 deletions ...chyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.moomoo.anarchyexploitfixes.config.Config;
import me.moomoo.anarchyexploitfixes.config.LanguageCache;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import me.moomoo.anarchyexploitfixes.utils.TPSCache;
import org.bstats.bukkit.Metrics;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;
Expand All @@ -15,9 +16,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand All @@ -26,11 +24,12 @@
public class AnarchyExploitFixes extends JavaPlugin {

private static AnarchyExploitFixes instance;
private static Logger logger;
private static Config config;
private static HashMap<String, LanguageCache> languageCacheMap;
private static ScheduledFuture<?> scheduled_tps_check;
public double tps = 20;
private static Config config;
private static Logger logger;
private static boolean isServerFolia;

public TPSCache tpsCache;
public final HashSet<UUID> NEW_CHUNK_PLAYERS = new HashSet<>();

@Override
Expand All @@ -49,6 +48,7 @@ public void onEnable() {
logger.info(" ");
logger.info(" ");

// Check for paper as the api is needed for this plugin
if (!PaperLib.isPaper()) {
logger.severe("##########################################################");
logger.severe("# #");
Expand All @@ -63,6 +63,12 @@ public void onEnable() {
}

logger.info("Detected Version 1." + PaperLib.getMinecraftVersion() + "." + PaperLib.getMinecraftPatchVersion());
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
isServerFolia = true;
} catch (ClassNotFoundException e) {
isServerFolia = false;
}

logger.info("Loading Translations");
reloadLang();
Expand All @@ -76,36 +82,24 @@ public void onEnable() {
logger.info("Loading metrics");
new Metrics(this, 8700);

// Scheduled TPS checker
/*
* While this works on all non folia servers, it's useless on folia because different regions have different tps.
* Needs urgent change!
* */
scheduled_tps_check = Executors.newScheduledThreadPool(1).scheduleAtFixedRate(
() -> new Thread(() -> tps = getServer().getTPS()[0]).start(), 1, 1, TimeUnit.SECONDS
);

logger.info("Done.");
}

public static AnarchyExploitFixes getInstance() {
return instance;
}
public static NamespacedKey getKey(String key) {
return new NamespacedKey(instance, key);
public static HashMap<String, LanguageCache> getLanguageCacheMap() {
return languageCacheMap;
}
public static Config getConfiguration() {
return config;
}
public static HashMap<String, LanguageCache> getLanguageCacheMap() {
return languageCacheMap;
public static NamespacedKey getKey(String key) {
return new NamespacedKey(instance, key);
}
public static Logger getLog() {
return logger;
}
public static boolean isProtocolLibInstalled() {
return instance.getServer().getPluginManager().isPluginEnabled("ProtocolLib");
}
public static LanguageCache getLang(Locale locale) {
return getLang(locale.toString().toLowerCase());
}
Expand All @@ -115,24 +109,23 @@ public static LanguageCache getLang(CommandSender commandSender) {
public static LanguageCache getLang(String lang) {
return config.auto_lang ? languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase())) : languageCacheMap.get(config.default_lang.toString().toLowerCase());
}

public void disablePlugin() {
AnarchyExploitFixesModule.modules.forEach(AnarchyExploitFixesModule::disable);
AnarchyExploitFixesModule.unregisterPacketListeners(this);
scheduled_tps_check.cancel(true);
public static boolean isProtocolLibInstalled() {
return instance.getServer().getPluginManager().isPluginEnabled("ProtocolLib");
}
public static boolean isServerFolia() {
return isServerFolia;
}

public void reloadPlugin() {
if (scheduled_tps_check.isCancelled())
scheduled_tps_check = Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() ->
new Thread(() -> tps = getServer().getTPS()[0]).start(), 1, 1, TimeUnit.SECONDS);
reloadLang();
reloadConfiguration();
}

private void reloadConfiguration() {
try {
config = new Config();
if (isServerFolia) this.tpsCache = new TPSCache.Folia(this, config.max_tps_check_interval_millis);
else this.tpsCache = new TPSCache.Default(this, config.max_tps_check_interval_millis);
AnarchyExploitFixesModule.reloadModules();
config.saveConfig();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cloud.commandframework.annotations.CommandPermission;
import io.papermc.paper.plugin.configuration.PluginMeta;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
Expand Down Expand Up @@ -52,7 +53,8 @@ public void disableCommand(
final CommandSender sender
) {
sender.sendMessage(Component.text("Disabling plugin.").color(NamedTextColor.RED));
plugin.disablePlugin();
AnarchyExploitFixesModule.modules.forEach(AnarchyExploitFixesModule::disable);
AnarchyExploitFixesModule.unregisterPacketListeners(plugin);
sender.sendMessage(Component.text("All enabled plugin features have been disabled.").color(NamedTextColor.GREEN));
sender.sendMessage(Component.text("Use /aef reload to enable the plugin again. " +
"You can also use third party options like plugman or serverutils.").color(NamedTextColor.WHITE));
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/config/Config.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Config {
private final ConfigFile config;
public final Locale default_lang;
public final Component cmd_say_format;
public final long max_tps_check_interval_millis;
public final int nether_ceiling_max_y;
public final boolean auto_lang, protocolLib_IsDisabled, connectionMsgsAreOnByDefault,
cmd_say_enabled, cmd_help_enabled, cmd_toggleConMsgs_enabled;
Expand All @@ -35,6 +36,7 @@ public Config() throws Exception {
this.auto_lang = getBoolean("language.auto-language", true, "If set to true, will display messages based on client language");

// General Settings
this.max_tps_check_interval_millis = getInt("general.max-tps-check-interval-in-ticks", 20, "How long a checked tps is cached to save resources in ticks (1 sec = 20 ticks)") * 50L;
this.protocolLib_IsDisabled = getBoolean("general.disable-all-ProtocolLib", false, "Use only if you are having problems with ProtocolLib when starting the plugin.");
this.nether_ceiling_max_y = getInt("general.nether-ceiling-y", 127, "The Y-level at which the nether ceiling generates the last layer of bedrock on your server.");
this.cmd_say_enabled = getBoolean("general.commands.say.enable", false);
Expand Down
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ public void disable() {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onChunkLoad(ChunkLoadEvent event) {
if (checkShouldPauseOnLowTPS && (plugin.tps <= pauseTPS)) return;
if (!alsoCheckNewChunks && event.isNewChunk()) return;
World world = event.getWorld();
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (!world.getEnvironment().equals(World.Environment.NETHER)) return;

Chunk chunk = event.getChunk();
plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> fillInBedrock(chunk, ceilingY));
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> fillInBedrock(chunk, ceilingY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ public void disable() {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onChunkLoad(ChunkLoadEvent event) {
if (checkShouldPauseOnLowTPS && (plugin.tps <= pauseTPS)) return;
if (!alsoCheckNewChunks && event.isNewChunk()) return;
World world = event.getWorld();
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (!world.getEnvironment().equals(World.Environment.NETHER)) return;

Chunk chunk = event.getChunk();
plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> fillInBedrock(chunk, world.getMinHeight()));
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> fillInBedrock(chunk, world.getMinHeight()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ public void disable() {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onChunkLoad(ChunkLoadEvent event) {
if (checkShouldPauseOnLowTPS && (plugin.tps <= pauseTPS)) return;
if (!alsoCheckNewChunks && event.isNewChunk()) return;
World world = event.getWorld();
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (!world.getEnvironment().equals(World.Environment.NORMAL)) return;
if (!world.getEnvironment().equals(World.Environment.NETHER)) return;

Chunk chunk = event.getChunk();
plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> fillInBedrock(chunk, world.getMinHeight()));
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> fillInBedrock(chunk, world.getMinHeight()));
}
}
25 changes: 13 additions & 12 deletions ...ain/java/me/moomoo/anarchyexploitfixes/modules/bedrock/PeriodicallyFillNetherCeiling.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ public void disable() {
}

private void run() {
if (checkShouldPauseOnLowTPS && (plugin.tps <= pauseTPS)) return;

for (World world : plugin.getServer().getWorlds()) {
if (world.getEnvironment().equals(World.Environment.NETHER)) {
if (!exemptedWorlds.contains(world.getName())) {
for (Chunk chunk : world.getLoadedChunks()) {
plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
fillInBedrock(chunk, ceilingY);
}
});
if (!world.getEnvironment().equals(World.Environment.NETHER)) continue;
if (exemptedWorlds.contains(world.getName())) continue;

for (Chunk chunk : world.getLoadedChunks()) {
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) continue;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
fillInBedrock(chunk, ceilingY);
}
}
});
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions .../main/java/me/moomoo/anarchyexploitfixes/modules/bedrock/PeriodicallyFillNetherFloor.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ public void disable() {
}

private void run() {
if (checkShouldPauseOnLowTPS && (plugin.tps <= pauseTPS)) return;

for (World world : plugin.getServer().getWorlds()) {
if (world.getEnvironment().equals(World.Environment.NETHER)) {
if (!exemptedWorlds.contains(world.getName())) {
for (Chunk chunk : world.getLoadedChunks()) {
plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
fillInBedrock(chunk, world.getMinHeight());
}
});
if (!world.getEnvironment().equals(World.Environment.NETHER)) continue;
if (exemptedWorlds.contains(world.getName())) continue;

for (Chunk chunk : world.getLoadedChunks()) {
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) continue;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
fillInBedrock(chunk, world.getMinHeight());
}
}
});
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions ...in/java/me/moomoo/anarchyexploitfixes/modules/bedrock/PeriodicallyFillOverworldFloor.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,21 @@ public void disable() {
}

private void run() {
if (checkShouldPauseOnLowTPS && (plugin.tps <= pauseTPS)) return;

for (World world : plugin.getServer().getWorlds()) {
if (world.getEnvironment().equals(World.Environment.NORMAL)) {
if (!exemptedWorlds.contains(world.getName())) {
for (Chunk chunk : world.getLoadedChunks()) {
plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
fillInBedrock(chunk, world.getMinHeight());
}
});
if (!world.getEnvironment().equals(World.Environment.NORMAL)) continue;
if (exemptedWorlds.contains(world.getName())) continue;

for (Chunk chunk : world.getLoadedChunks()) {
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) continue;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
fillInBedrock(chunk, world.getMinHeight());
}
}
});
}
}
}
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule;
import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
Expand Down
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
return;
}

if (spawn_DenyOnLowTPS && plugin.tps <= spawn_DenyElytraTPS) {
if (spawn_DenyOnLowTPS && plugin.tpsCache.getTPS(event.getTo()) <= spawn_DenyElytraTPS) {
if (teleportBack) player.teleportAsync(event.getFrom());
else event.setCancelled(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
return;
}

if (global_DenyOnLowTPS && plugin.tps <= global_DenyElytraTPS) {
if (global_DenyOnLowTPS && plugin.tpsCache.getTPS(event.getTo()) <= global_DenyElytraTPS) {
if (teleportBack) player.teleportAsync(event.getFrom());
else event.setCancelled(true);

Expand Down Expand Up @@ -128,7 +128,7 @@ private void onPlayerMove(PlayerMoveEvent event) {

if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) {
// Speed New Chunks
if (global_EnableBursting && plugin.tps >= global_BurstNewChunk_TPS) {
if (global_EnableBursting && plugin.tpsCache.getTPS(event.getTo()) >= global_BurstNewChunk_TPS) {
// Burst Speed New Chunks
if (flySpeed > global_BurstSpeedNewChunks+tolerance) {
if (teleportBack) player.teleportAsync(event.getFrom());
Expand Down Expand Up @@ -214,7 +214,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
}
} else {
// Speed Old Chunks
if (global_EnableBursting && plugin.tps >= global_BurstOldChunk_TPS) {
if (global_EnableBursting && plugin.tpsCache.getTPS(event.getTo()) >= global_BurstOldChunk_TPS) {
// Burst Speed Old Chunks
if (flySpeed > global_BurstSpeedOldChunks+tolerance) {
if (teleportBack) player.teleportAsync(event.getFrom());
Expand Down
Loading

0 comments on commit 1e72110

Please sign in to comment.