From 7eec1c23b03382a227d153ba02b657fa4f3c58a6 Mon Sep 17 00:00:00 2001 From: xGinko Date: Mon, 2 Oct 2023 23:52:28 +0200 Subject: [PATCH] naming conventions --- .../optimizevillagers/OptVillagersRadius.java | 8 ++-- .../UnOptVillagersRadius.java | 8 ++-- .../subcommands/DisableSubCmd.java | 5 +- .../modules/VillagerChunkLimit.java | 20 ++++---- .../extras/PreventUnoptimizedTrading.java | 8 ++-- .../modules/mechanics/LevelVillagers.java | 6 +-- .../modules/mechanics/RestockTrades.java | 10 ++-- .../optimizations/OptimizeByBlock.java | 22 ++++----- .../optimizations/OptimizeByNametag.java | 20 ++++---- .../optimizations/OptimizeByWorkstation.java | 22 ++++----- .../optimizevillagers/OptVillagersRadius.java | 8 ++-- .../UnOptVillagersRadius.java | 8 ++-- .../modules/VillagerChunkLimit.java | 46 +++++++++++-------- .../extras/PreventUnoptimizedTrading.java | 8 ++-- .../modules/mechanics/LevelVillagers.java | 6 +-- .../modules/mechanics/RestockTrades.java | 10 ++-- .../optimizations/OptimizeByBlock.java | 22 ++++----- .../optimizations/OptimizeByNametag.java | 20 ++++---- .../optimizations/OptimizeByWorkstation.java | 22 ++++----- 19 files changed, 146 insertions(+), 133 deletions(-) diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/optimizevillagers/OptVillagersRadius.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/optimizevillagers/OptVillagersRadius.java index 39f28cc..d7516c2 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/optimizevillagers/OptVillagersRadius.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/optimizevillagers/OptVillagersRadius.java @@ -28,11 +28,11 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete private final List tabCompletes = List.of("5", "10", "25", "50"); private final long cooldown; - private final int maxRadius; + private final int max_radius; public OptVillagersRadius() { Config config = VillagerOptimizer.getConfiguration(); - this.maxRadius = config.getInt("optimization-methods.commands.optimizevillagers.max-block-radius", 100); + this.max_radius = config.getInt("optimization-methods.commands.optimizevillagers.max-block-radius", 100); this.cooldown = config.getInt("optimization-methods.commands.optimizevillagers.cooldown-seconds", 600, """ Cooldown in seconds until a villager can be optimized again using the command.\s Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L; @@ -65,10 +65,10 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete try { int specifiedRadius = Integer.parseInt(args[0]); - if (specifiedRadius > maxRadius) { + if (specifiedRadius > max_radius) { final TextReplacementConfig limit = TextReplacementConfig.builder() .matchLiteral("%distance%") - .replacement(Integer.toString(maxRadius)) + .replacement(Integer.toString(max_radius)) .build(); VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit))); return true; diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/unoptimizevillagers/UnOptVillagersRadius.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/unoptimizevillagers/UnOptVillagersRadius.java index bef847f..f91ca7e 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/unoptimizevillagers/UnOptVillagersRadius.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/unoptimizevillagers/UnOptVillagersRadius.java @@ -26,10 +26,10 @@ import java.util.List; public class UnOptVillagersRadius implements VillagerOptimizerCommand, TabCompleter { private final List tabCompletes = List.of("5", "10", "25", "50"); - private final int maxRadius; + private final int max_radius; public UnOptVillagersRadius() { - this.maxRadius = VillagerOptimizer.getConfiguration().getInt("optimization-methods.commands.unoptimizevillagers.max-block-radius", 100); + this.max_radius = VillagerOptimizer.getConfiguration().getInt("optimization-methods.commands.unoptimizevillagers.max-block-radius", 100); } @Override @@ -59,10 +59,10 @@ public class UnOptVillagersRadius implements VillagerOptimizerCommand, TabComple try { int specifiedRadius = Integer.parseInt(args[0]); - if (specifiedRadius > maxRadius) { + if (specifiedRadius > max_radius) { final TextReplacementConfig limit = TextReplacementConfig.builder() .matchLiteral("%distance%") - .replacement(Integer.toString(maxRadius)) + .replacement(Integer.toString(max_radius)) .build(); VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit))); return true; diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/villageroptimizer/subcommands/DisableSubCmd.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/villageroptimizer/subcommands/DisableSubCmd.java index f9ddd3f..7c8e6c7 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/villageroptimizer/subcommands/DisableSubCmd.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/commands/villageroptimizer/subcommands/DisableSubCmd.java @@ -8,6 +8,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; public class DisableSubCmd extends SubCommand { @@ -30,7 +31,9 @@ public class DisableSubCmd extends SubCommand { public void perform(CommandSender sender, String[] args) { if (sender.hasPermission(Permissions.Commands.DISABLE.get())) { sender.sendMessage(Component.text("Disabling VillagerOptimizer...").color(NamedTextColor.RED)); - VillagerOptimizerModule.modules.forEach(VillagerOptimizerModule::disable); + VillagerOptimizer plugin = VillagerOptimizer.getInstance(); + HandlerList.unregisterAll(plugin); + plugin.getServer().getScheduler().cancelTasks(plugin); VillagerOptimizerModule.modules.clear(); VillagerOptimizer.getCache().cacheMap().clear(); sender.sendMessage(Component.text("Disabled all plugin listeners and tasks.").color(NamedTextColor.GREEN)); diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/VillagerChunkLimit.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/VillagerChunkLimit.java index 9e07aee..c65c55c 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/VillagerChunkLimit.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/VillagerChunkLimit.java @@ -25,10 +25,10 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener, Ru private final Server server; private final VillagerCache villagerCache; - private final List removalPriority = new ArrayList<>(16); + private final List removal_priority = new ArrayList<>(16); private final long check_period; private final int max_unoptimized_per_chunk, max_optimized_per_chunk; - private final boolean logIsEnabled; + private final boolean log_enabled; protected VillagerChunkLimit() { shouldEnable(); @@ -47,7 +47,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener, Ru Check all loaded chunks every X ticks. 1 second = 20 ticks\s A shorter delay in between checks is more efficient but is also more resource intense.\s A larger delay is less resource intense but could become inefficient."""); - this.logIsEnabled = config.getBoolean("villager-chunk-limit.log-removals", false); + this.log_enabled = config.getBoolean("villager-chunk-limit.log-removals", false); config.getList("villager-chunk-limit.removal-priority", List.of( "NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER", "FLETCHER", "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN" @@ -57,7 +57,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener, Ru ).forEach(configuredProfession -> { try { Villager.Profession profession = Villager.Profession.valueOf(configuredProfession); - this.removalPriority.add(profession); + this.removal_priority.add(profession); } catch (IllegalArgumentException e) { LogUtil.moduleLog(Level.WARNING, "villager-chunk-limit", "Villager profession '"+configuredProfession+"' not recognized. Make sure you're using the correct profession enums."); @@ -128,8 +128,9 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener, Ru for (int i = 0; i < unoptimized_vils_too_many; i++) { Villager villager = unoptimized_villagers.get(i); villager.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit", - "Removed unoptimized villager of profession type '"+villager.getProfession().name()+"' at "+villager.getLocation()); + if (log_enabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit", + "Removed unoptimized villager of profession type '"+villager.getProfession().name()+"' at "+villager.getLocation() + ); } } @@ -142,14 +143,15 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener, Ru for (int i = 0; i < optimized_vils_too_many; i++) { Villager villager = optimized_villagers.get(i); villager.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit", - "Removed optimized villager of profession type '"+villager.getProfession().name()+"' at "+villager.getLocation()); + if (log_enabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit", + "Removed optimized villager of profession type '"+villager.getProfession().name()+"' at "+villager.getLocation() + ); } } } private int getProfessionPriority(Villager villager) { final Villager.Profession profession = villager.getProfession(); - return removalPriority.contains(profession) ? removalPriority.indexOf(profession) : Integer.MAX_VALUE; + return removal_priority.contains(profession) ? removal_priority.indexOf(profession) : Integer.MAX_VALUE; } } \ No newline at end of file diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/extras/PreventUnoptimizedTrading.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/extras/PreventUnoptimizedTrading.java index 9007091..a354ecf 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/extras/PreventUnoptimizedTrading.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/extras/PreventUnoptimizedTrading.java @@ -17,7 +17,7 @@ import org.bukkit.event.inventory.TradeSelectEvent; public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Listener { private final VillagerCache villagerCache; - private final boolean notifyPlayer; + private final boolean notify_player; public PreventUnoptimizedTrading() { shouldEnable(); @@ -27,7 +27,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste Will prevent players from selecting and using trades of unoptimized villagers.\s Use this if you have a lot of villagers and therefore want to force your players to optimize them.\s Inventories can still be opened so players can move villagers around."""); - this.notifyPlayer = config.getBoolean("gameplay.prevent-trading-with-unoptimized.notify-player", true, + this.notify_player = config.getBoolean("gameplay.prevent-trading-with-unoptimized.notify-player", true, "Sends players a message when they try to trade with an unoptimized villager."); } @@ -52,7 +52,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste && !villagerCache.getOrAdd(villager).isOptimized() ) { event.setCancelled(true); - if (notifyPlayer) + if (notify_player) VillagerOptimizer.getLang(player.locale()).optimize_for_trading.forEach(player::sendMessage); } } @@ -67,7 +67,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste && !villagerCache.getOrAdd(villager).isOptimized() ) { event.setCancelled(true); - if (notifyPlayer) + if (notify_player) VillagerOptimizer.getLang(player.locale()).optimize_for_trading.forEach(player::sendMessage); } } diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/mechanics/LevelVillagers.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/mechanics/LevelVillagers.java index 8128ea1..88b7706 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/mechanics/LevelVillagers.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/mechanics/LevelVillagers.java @@ -21,7 +21,7 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener { private final VillagerOptimizer plugin; private final VillagerCache villagerCache; - private final boolean shouldNotify; + private final boolean notify_player; private final long cooldown; public LevelVillagers() { @@ -35,7 +35,7 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener { this.cooldown = config.getInt("gameplay.villager-leveling.level-check-cooldown-seconds", 5, """ Cooldown in seconds until the level of a villager will be checked and updated again.\s Recommended to leave as is.""") * 1000L; - this.shouldNotify = config.getBoolean("gameplay.villager-leveling.notify-player", true, + this.notify_player = config.getBoolean("gameplay.villager-leveling.notify-player", true, "Tell players to wait when a villager is leveling up."); } @@ -70,7 +70,7 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener { }, 100L); } } else { - if (shouldNotify) { + if (notify_player) { Player player = (Player) event.getPlayer(); final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/mechanics/RestockTrades.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/mechanics/RestockTrades.java index ad5e764..2b50fdf 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/mechanics/RestockTrades.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/mechanics/RestockTrades.java @@ -20,7 +20,7 @@ public class RestockTrades implements VillagerOptimizerModule, Listener { private final VillagerCache villagerCache; private final long restock_delay_millis; - private final boolean shouldLog, notifyPlayer; + private final boolean log_enabled, notify_player; public RestockTrades() { shouldEnable(); @@ -31,9 +31,9 @@ public class RestockTrades implements VillagerOptimizerModule, Listener { Don't have enough AI to do trade restocks themselves, so this needs to always be enabled."""); this.restock_delay_millis = config.getInt("gameplay.trade-restocking.delay-in-ticks", 1000, "1 second = 20 ticks. There are 24.000 ticks in a single minecraft day.") * 50L; - this.notifyPlayer = config.getBoolean("gameplay.trade-restocking.notify-player", true, + this.notify_player = config.getBoolean("gameplay.trade-restocking.notify-player", true, "Sends the player a message when the trades were restocked on a clicked villager."); - this.shouldLog = config.getBoolean("gameplay.trade-restocking.log", false); + this.log_enabled = config.getBoolean("gameplay.trade-restocking.log", false); } @Override @@ -60,14 +60,14 @@ public class RestockTrades implements VillagerOptimizerModule, Listener { if (wVillager.canRestock(restock_delay_millis) || player_bypassing) { wVillager.restock(); wVillager.saveRestockTime(); - if (notifyPlayer && !player_bypassing) { + if (notify_player && !player_bypassing) { final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") .replacement(CommonUtil.formatTime(wVillager.getRestockCooldownMillis(restock_delay_millis))) .build(); VillagerOptimizer.getLang(player.locale()).trades_restocked.forEach(line -> player.sendMessage(line.replaceText(timeLeft))); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info("Restocked optimized villager at "+ wVillager.villager().getLocation()); } } diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByBlock.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByBlock.java index f6875c4..968f179 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByBlock.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByBlock.java @@ -34,7 +34,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { private final HashSet blocks_that_disable = new HashSet<>(4); private final long cooldown; private final double search_radius; - private final boolean onlyWhileSneaking, shouldNotifyPlayer, shouldLog; + private final boolean only_while_sneaking, notify_player, log_enabled; public OptimizeByBlock() { shouldEnable(); @@ -60,11 +60,11 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { this.search_radius = config.getDouble("optimization-methods.block-optimization.search-radius-in-blocks", 2.0, """ The radius in blocks a villager can be away from the player when he places an optimize block.\s The closest unoptimized villager to the player will be optimized.""") / 2; - this.onlyWhileSneaking = config.getBoolean("optimization-methods.block-optimization.only-when-sneaking", true, + this.only_while_sneaking = config.getBoolean("optimization-methods.block-optimization.only-when-sneaking", true, "Only optimize/unoptimize by workstation when player is sneaking during place or break."); - this.shouldNotifyPlayer = config.getBoolean("optimization-methods.block-optimization.notify-player", true, + this.notify_player = config.getBoolean("optimization-methods.block-optimization.notify-player", true, "Sends players a message when they successfully optimized or unoptimized a villager."); - this.shouldLog = config.getBoolean("optimization-methods.block-optimization.log", false); + this.log_enabled = config.getBoolean("optimization-methods.block-optimization.log", false); } @Override @@ -84,7 +84,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { if (!blocks_that_disable.contains(placed.getType())) return; Player player = event.getPlayer(); if (!player.hasPermission(Permissions.Optimize.BLOCK.get())) return; - if (onlyWhileSneaking && !player.isSneaking()) return; + if (only_while_sneaking && !player.isSneaking()) return; final Location blockLoc = placed.getLocation(); WrappedVillager closestOptimizableVillager = null; @@ -115,7 +115,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { closestOptimizableVillager.setOptimization(optimizeEvent.getOptimizationType()); closestOptimizableVillager.saveOptimizeTime(); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig vilProfession = TextReplacementConfig.builder() .matchLiteral("%vil_profession%") .replacement(closestOptimizableVillager.villager().getProfession().toString().toLowerCase()) @@ -129,10 +129,10 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { .replaceText(placedMaterial) )); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info("Villager was optimized by block at "+closestOptimizableVillager.villager().getLocation()); } else { - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") .replacement(CommonUtil.formatTime(closestOptimizableVillager.getOptimizeCooldownMillis(cooldown))) @@ -148,7 +148,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { if (!blocks_that_disable.contains(broken.getType())) return; Player player = event.getPlayer(); if (!player.hasPermission(Permissions.Optimize.BLOCK.get())) return; - if (onlyWhileSneaking && !player.isSneaking()) return; + if (only_while_sneaking && !player.isSneaking()) return; final Location blockLoc = broken.getLocation(); WrappedVillager closestOptimizedVillager = null; @@ -175,7 +175,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { closestOptimizedVillager.setOptimization(OptimizationType.NONE); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig vilProfession = TextReplacementConfig.builder() .matchLiteral("%vil_profession%") .replacement(closestOptimizedVillager.villager().getProfession().toString().toLowerCase()) @@ -189,7 +189,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { .replaceText(brokenMaterial) )); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info("Villager unoptimized because nearby optimization block broken at: "+closestOptimizedVillager.villager().getLocation()); } } \ No newline at end of file diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByNametag.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByNametag.java index 75b1673..baee2b8 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByNametag.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByNametag.java @@ -32,7 +32,7 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { private final VillagerCache villagerCache; private final HashSet nametags = new HashSet<>(4); private final long cooldown; - private final boolean consumeNametag, shouldNotifyPlayer, shouldLog; + private final boolean consume_nametag, notify_player, log_enabled; public OptimizeByNametag() { shouldEnable(); @@ -43,14 +43,14 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { Nametag optimized villagers will be unoptimized again when they are renamed to something else."""); this.nametags.addAll(config.getList("optimization-methods.nametag-optimization.names", List.of("Optimize", "DisableAI"), "Names are case insensitive, capital letters won't matter.").stream().map(String::toLowerCase).toList()); - this.consumeNametag = config.getBoolean("optimization-methods.nametag-optimization.nametags-get-consumed", true, + this.consume_nametag = config.getBoolean("optimization-methods.nametag-optimization.nametags-get-consumed", true, "Enable or disable consumption of the used nametag item."); this.cooldown = config.getInt("optimization-methods.nametag-optimization.optimize-cooldown-seconds", 600, """ Cooldown in seconds until a villager can be optimized again using a nametag.\s Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L; - this.shouldNotifyPlayer = config.getBoolean("optimization-methods.nametag-optimization.notify-player", true, + this.notify_player = config.getBoolean("optimization-methods.nametag-optimization.notify-player", true, "Sends players a message when they successfully optimized a villager."); - this.shouldLog = config.getBoolean("optimization-methods.nametag-optimization.log", false); + this.log_enabled = config.getBoolean("optimization-methods.nametag-optimization.log", false); } @Override @@ -88,7 +88,7 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { VillagerOptimizer.callEvent(optimizeEvent); if (optimizeEvent.isCancelled()) return; - if (!consumeNametag) { + if (!consume_nametag) { event.setCancelled(true); villager.customName(newVillagerName); } @@ -96,13 +96,13 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { wVillager.setOptimization(optimizeEvent.getOptimizationType()); wVillager.saveOptimizeTime(); - if (shouldNotifyPlayer) + if (notify_player) VillagerOptimizer.getLang(player.locale()).nametag_optimize_success.forEach(player::sendMessage); - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info(player.getName() + " optimized a villager using nametag: '" + name + "'"); } else { event.setCancelled(true); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") .replacement(CommonUtil.formatTime(wVillager.getOptimizeCooldownMillis(cooldown))) @@ -118,9 +118,9 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { wVillager.setOptimization(OptimizationType.NONE); - if (shouldNotifyPlayer) + if (notify_player) VillagerOptimizer.getLang(player.locale()).nametag_unoptimize_success.forEach(player::sendMessage); - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info(event.getPlayer().getName() + " disabled optimizations for a villager using nametag: '" + name + "'"); } } diff --git a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByWorkstation.java b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByWorkstation.java index 57a00d8..6d32dbd 100644 --- a/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByWorkstation.java +++ b/VillagerOptimizer-1.16.5/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByWorkstation.java @@ -29,7 +29,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener private final VillagerCache villagerCache; private final long cooldown; private final double search_radius; - private final boolean onlyWhileSneaking, shouldLog, shouldNotifyPlayer; + private final boolean only_while_sneaking, log_enabled, notify_player; public OptimizeByWorkstation() { shouldEnable(); @@ -44,11 +44,11 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener this.cooldown = config.getInt("optimization-methods.workstation-optimization.optimize-cooldown-seconds", 600, """ Cooldown in seconds until a villager can be optimized again using a workstation.\s Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L; - this.onlyWhileSneaking = config.getBoolean("optimization-methods.workstation-optimization.only-when-sneaking", true, + this.only_while_sneaking = config.getBoolean("optimization-methods.workstation-optimization.only-when-sneaking", true, "Only optimize/unoptimize by workstation when player is sneaking during place or break"); - this.shouldNotifyPlayer = config.getBoolean("optimization-methods.workstation-optimization.notify-player", true, + this.notify_player = config.getBoolean("optimization-methods.workstation-optimization.notify-player", true, "Sends players a message when they successfully optimized a villager."); - this.shouldLog = config.getBoolean("optimization-methods.workstation-optimization.log", false); + this.log_enabled = config.getBoolean("optimization-methods.workstation-optimization.log", false); } @Override @@ -69,7 +69,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener if (workstationProfession.equals(Villager.Profession.NONE)) return; Player player = event.getPlayer(); if (!player.hasPermission(Permissions.Optimize.WORKSTATION.get())) return; - if (onlyWhileSneaking && !player.isSneaking()) return; + if (only_while_sneaking && !player.isSneaking()) return; final Location workstationLoc = placed.getLocation(); WrappedVillager closestOptimizableVillager = null; @@ -99,7 +99,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener closestOptimizableVillager.setOptimization(optimizeEvent.getOptimizationType()); closestOptimizableVillager.saveOptimizeTime(); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig vilProfession = TextReplacementConfig.builder() .matchLiteral("%vil_profession%") .replacement(closestOptimizableVillager.villager().getProfession().toString().toLowerCase()) @@ -113,10 +113,10 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener .replaceText(placedWorkstation) )); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info(player.getName() + " optimized a villager using workstation: '" + placed.getType().toString().toLowerCase() + "'"); } else { - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") .replacement(CommonUtil.formatTime(closestOptimizableVillager.getOptimizeCooldownMillis(cooldown))) @@ -135,7 +135,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener if (workstationProfession.equals(Villager.Profession.NONE)) return; Player player = event.getPlayer(); if (!player.hasPermission(Permissions.Optimize.WORKSTATION.get())) return; - if (onlyWhileSneaking && !player.isSneaking()) return; + if (only_while_sneaking && !player.isSneaking()) return; final Location workstationLoc = broken.getLocation(); WrappedVillager closestOptimizedVillager = null; @@ -163,7 +163,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener closestOptimizedVillager.setOptimization(OptimizationType.NONE); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig vilProfession = TextReplacementConfig.builder() .matchLiteral("%vil_profession%") .replacement(closestOptimizedVillager.villager().getProfession().toString().toLowerCase()) @@ -177,7 +177,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener .replaceText(brokenWorkstation) )); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info(player.getName() + " unoptimized a villager by breaking workstation: '" + broken.getType().toString().toLowerCase() + "'"); } diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/commands/optimizevillagers/OptVillagersRadius.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/commands/optimizevillagers/OptVillagersRadius.java index 39f28cc..d7516c2 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/commands/optimizevillagers/OptVillagersRadius.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/commands/optimizevillagers/OptVillagersRadius.java @@ -28,11 +28,11 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete private final List tabCompletes = List.of("5", "10", "25", "50"); private final long cooldown; - private final int maxRadius; + private final int max_radius; public OptVillagersRadius() { Config config = VillagerOptimizer.getConfiguration(); - this.maxRadius = config.getInt("optimization-methods.commands.optimizevillagers.max-block-radius", 100); + this.max_radius = config.getInt("optimization-methods.commands.optimizevillagers.max-block-radius", 100); this.cooldown = config.getInt("optimization-methods.commands.optimizevillagers.cooldown-seconds", 600, """ Cooldown in seconds until a villager can be optimized again using the command.\s Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L; @@ -65,10 +65,10 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete try { int specifiedRadius = Integer.parseInt(args[0]); - if (specifiedRadius > maxRadius) { + if (specifiedRadius > max_radius) { final TextReplacementConfig limit = TextReplacementConfig.builder() .matchLiteral("%distance%") - .replacement(Integer.toString(maxRadius)) + .replacement(Integer.toString(max_radius)) .build(); VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit))); return true; diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/commands/unoptimizevillagers/UnOptVillagersRadius.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/commands/unoptimizevillagers/UnOptVillagersRadius.java index bef847f..f91ca7e 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/commands/unoptimizevillagers/UnOptVillagersRadius.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/commands/unoptimizevillagers/UnOptVillagersRadius.java @@ -26,10 +26,10 @@ import java.util.List; public class UnOptVillagersRadius implements VillagerOptimizerCommand, TabCompleter { private final List tabCompletes = List.of("5", "10", "25", "50"); - private final int maxRadius; + private final int max_radius; public UnOptVillagersRadius() { - this.maxRadius = VillagerOptimizer.getConfiguration().getInt("optimization-methods.commands.unoptimizevillagers.max-block-radius", 100); + this.max_radius = VillagerOptimizer.getConfiguration().getInt("optimization-methods.commands.unoptimizevillagers.max-block-radius", 100); } @Override @@ -59,10 +59,10 @@ public class UnOptVillagersRadius implements VillagerOptimizerCommand, TabComple try { int specifiedRadius = Integer.parseInt(args[0]); - if (specifiedRadius > maxRadius) { + if (specifiedRadius > max_radius) { final TextReplacementConfig limit = TextReplacementConfig.builder() .matchLiteral("%distance%") - .replacement(Integer.toString(maxRadius)) + .replacement(Integer.toString(max_radius)) .build(); VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit))); return true; diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/VillagerChunkLimit.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/VillagerChunkLimit.java index b3e55cb..b490cd2 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/VillagerChunkLimit.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/VillagerChunkLimit.java @@ -6,6 +6,8 @@ import me.xginko.villageroptimizer.VillagerOptimizer; import me.xginko.villageroptimizer.config.Config; import me.xginko.villageroptimizer.utils.LogUtil; import org.bukkit.Chunk; +import org.bukkit.Server; +import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Villager; @@ -23,17 +25,17 @@ import java.util.logging.Level; public class VillagerChunkLimit implements VillagerOptimizerModule, Listener { - private final VillagerOptimizer plugin; + private final Server server; private final VillagerCache villagerCache; - private ScheduledTask scheduledTask; - private final List removalPriority = new ArrayList<>(16); + private ScheduledTask periodic_chunk_check; + private final List removal_priority = new ArrayList<>(16); private final long check_period; private final int max_unoptimized_per_chunk, max_optimized_per_chunk; - private final boolean logIsEnabled; + private final boolean log_enabled; protected VillagerChunkLimit() { shouldEnable(); - this.plugin = VillagerOptimizer.getInstance(); + this.server = VillagerOptimizer.getInstance().getServer(); this.villagerCache = VillagerOptimizer.getCache(); Config config = VillagerOptimizer.getConfiguration(); config.addComment("villager-chunk-limit.enable", """ @@ -48,7 +50,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener { Check all loaded chunks every X ticks. 1 second = 20 ticks\s A shorter delay in between checks is more efficient but is also more resource intense.\s A larger delay is less resource intense but could become inefficient."""); - this.logIsEnabled = config.getBoolean("villager-chunk-limit.log-removals", false); + this.log_enabled = config.getBoolean("villager-chunk-limit.log-removals", false); config.getList("villager-chunk-limit.removal-priority", List.of( "NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER", "FLETCHER", "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN" @@ -58,7 +60,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener { ).forEach(configuredProfession -> { try { Villager.Profession profession = Villager.Profession.valueOf(configuredProfession); - this.removalPriority.add(profession); + this.removal_priority.add(profession); } catch (IllegalArgumentException e) { LogUtil.moduleLog(Level.WARNING, "villager-chunk-limit", "Villager profession '"+configuredProfession+"' not recognized. Make sure you're using the correct profession enums."); @@ -68,12 +70,16 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener { @Override public void enable() { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - this.scheduledTask = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, periodic_chunk_check -> { - plugin.getServer().getWorlds().forEach(world -> { - for (Chunk chunk : world.getLoadedChunks()) - plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), check_chunk -> checkVillagersInChunk(chunk)); - }); + VillagerOptimizer plugin = VillagerOptimizer.getInstance(); + server.getPluginManager().registerEvents(this, plugin); + this.periodic_chunk_check = server.getGlobalRegionScheduler().runAtFixedRate(plugin, periodic_chunk_check -> { + for (World world : server.getWorlds()) { + for (Chunk chunk : world.getLoadedChunks()) { + plugin.getServer().getRegionScheduler().run( + plugin, world, chunk.getX(), chunk.getZ(), check_chunk -> checkVillagersInChunk(chunk) + ); + } + } }, check_period, check_period); } @@ -85,7 +91,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener { @Override public void disable() { HandlerList.unregisterAll(this); - if (scheduledTask != null) scheduledTask.cancel(); + if (periodic_chunk_check != null) periodic_chunk_check.cancel(); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -130,8 +136,9 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener { for (int i = 0; i < unoptimized_vils_too_many; i++) { Villager villager = unoptimized_villagers.get(i); villager.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit", - "Removed unoptimized villager of profession type '"+villager.getProfession().name()+"' at "+villager.getLocation()); + if (log_enabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit", + "Removed unoptimized villager of profession type '"+villager.getProfession().name()+"' at "+villager.getLocation() + ); } } @@ -144,14 +151,15 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener { for (int i = 0; i < optimized_vils_too_many; i++) { Villager villager = optimized_villagers.get(i); villager.remove(); - if (logIsEnabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit", - "Removed optimized villager of profession type '"+villager.getProfession().name()+"' at "+villager.getLocation()); + if (log_enabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit", + "Removed optimized villager of profession type '"+villager.getProfession().name()+"' at "+villager.getLocation() + ); } } } private int getProfessionPriority(Villager villager) { final Villager.Profession profession = villager.getProfession(); - return removalPriority.contains(profession) ? removalPriority.indexOf(profession) : Integer.MAX_VALUE; + return removal_priority.contains(profession) ? removal_priority.indexOf(profession) : Integer.MAX_VALUE; } } \ No newline at end of file diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/extras/PreventUnoptimizedTrading.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/extras/PreventUnoptimizedTrading.java index 54fb7ac..0407147 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/extras/PreventUnoptimizedTrading.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/extras/PreventUnoptimizedTrading.java @@ -18,7 +18,7 @@ import org.bukkit.event.inventory.TradeSelectEvent; public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Listener { private final VillagerCache villagerCache; - private final boolean notifyPlayer; + private final boolean notify_player; public PreventUnoptimizedTrading() { shouldEnable(); @@ -28,7 +28,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste Will prevent players from selecting and using trades of unoptimized villagers.\s Use this if you have a lot of villagers and therefore want to force your players to optimize them.\s Inventories can still be opened so players can move villagers around."""); - this.notifyPlayer = config.getBoolean("gameplay.prevent-trading-with-unoptimized.notify-player", true, + this.notify_player = config.getBoolean("gameplay.prevent-trading-with-unoptimized.notify-player", true, "Sends players a message when they try to trade with an unoptimized villager."); } @@ -58,7 +58,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste && !villagerCache.getOrAdd(villager).isOptimized() ) { event.setCancelled(true); - if (notifyPlayer) + if (notify_player) VillagerOptimizer.getLang(player.locale()).optimize_for_trading.forEach(player::sendMessage); } } @@ -73,7 +73,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste && !villagerCache.getOrAdd(villager).isOptimized() ) { event.setCancelled(true); - if (notifyPlayer) + if (notify_player) VillagerOptimizer.getLang(player.locale()).optimize_for_trading.forEach(player::sendMessage); } } diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/mechanics/LevelVillagers.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/mechanics/LevelVillagers.java index 85c7217..659d323 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/mechanics/LevelVillagers.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/mechanics/LevelVillagers.java @@ -22,7 +22,7 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener { private final VillagerOptimizer plugin; private final VillagerCache villagerCache; - private final boolean shouldNotify; + private final boolean notify_player; private final long cooldown; public LevelVillagers() { @@ -36,7 +36,7 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener { this.cooldown = config.getInt("gameplay.villager-leveling.level-check-cooldown-seconds", 5, """ Cooldown in seconds until the level of a villager will be checked and updated again.\s Recommended to leave as is.""") * 1000L; - this.shouldNotify = config.getBoolean("gameplay.villager-leveling.notify-player", true, + this.notify_player = config.getBoolean("gameplay.villager-leveling.notify-player", true, "Tell players to wait when a villager is leveling up."); } @@ -77,7 +77,7 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener { }, null, 100L); } } else { - if (shouldNotify) { + if (notify_player) { Player player = (Player) event.getPlayer(); final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/mechanics/RestockTrades.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/mechanics/RestockTrades.java index 594db8f..d6ee427 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/mechanics/RestockTrades.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/mechanics/RestockTrades.java @@ -21,7 +21,7 @@ public class RestockTrades implements VillagerOptimizerModule, Listener { private final VillagerCache villagerCache; private final long restock_delay_millis; - private final boolean shouldLog, notifyPlayer; + private final boolean log_enabled, notify_player; public RestockTrades() { shouldEnable(); @@ -32,9 +32,9 @@ public class RestockTrades implements VillagerOptimizerModule, Listener { Don't have enough AI to do trade restocks themselves, so this needs to always be enabled."""); this.restock_delay_millis = config.getInt("gameplay.trade-restocking.delay-in-ticks", 1000, "1 second = 20 ticks. There are 24.000 ticks in a single minecraft day.") * 50L; - this.notifyPlayer = config.getBoolean("gameplay.trade-restocking.notify-player", true, + this.notify_player = config.getBoolean("gameplay.trade-restocking.notify-player", true, "Sends the player a message when the trades were restocked on a clicked villager."); - this.shouldLog = config.getBoolean("gameplay.trade-restocking.log", false); + this.log_enabled = config.getBoolean("gameplay.trade-restocking.log", false); } @Override @@ -66,14 +66,14 @@ public class RestockTrades implements VillagerOptimizerModule, Listener { if (wVillager.canRestock(restock_delay_millis) || player_bypassing) { wVillager.restock(); wVillager.saveRestockTime(); - if (notifyPlayer && !player_bypassing) { + if (notify_player && !player_bypassing) { final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") .replacement(CommonUtil.formatTime(wVillager.getRestockCooldownMillis(restock_delay_millis))) .build(); VillagerOptimizer.getLang(player.locale()).trades_restocked.forEach(line -> player.sendMessage(line.replaceText(timeLeft))); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info("Restocked optimized villager at "+ wVillager.villager().getLocation()); } } diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByBlock.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByBlock.java index 6fcdd83..f76730d 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByBlock.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByBlock.java @@ -35,7 +35,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { private final HashSet blocks_that_disable = new HashSet<>(4); private final long cooldown; private final double search_radius; - private final boolean onlyWhileSneaking, shouldNotifyPlayer, shouldLog; + private final boolean only_while_sneaking, notify_player, log_enabled; public OptimizeByBlock() { shouldEnable(); @@ -61,11 +61,11 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { this.search_radius = config.getDouble("optimization-methods.block-optimization.search-radius-in-blocks", 2.0, """ The radius in blocks a villager can be away from the player when he places an optimize block.\s The closest unoptimized villager to the player will be optimized.""") / 2; - this.onlyWhileSneaking = config.getBoolean("optimization-methods.block-optimization.only-when-sneaking", true, + this.only_while_sneaking = config.getBoolean("optimization-methods.block-optimization.only-when-sneaking", true, "Only optimize/unoptimize by workstation when player is sneaking during place or break."); - this.shouldNotifyPlayer = config.getBoolean("optimization-methods.block-optimization.notify-player", true, + this.notify_player = config.getBoolean("optimization-methods.block-optimization.notify-player", true, "Sends players a message when they successfully optimized or unoptimized a villager."); - this.shouldLog = config.getBoolean("optimization-methods.block-optimization.log", false); + this.log_enabled = config.getBoolean("optimization-methods.block-optimization.log", false); } @Override @@ -90,7 +90,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { if (!blocks_that_disable.contains(placed.getType())) return; Player player = event.getPlayer(); if (!player.hasPermission(Permissions.Optimize.BLOCK.get())) return; - if (onlyWhileSneaking && !player.isSneaking()) return; + if (only_while_sneaking && !player.isSneaking()) return; final Location blockLoc = placed.getLocation(); WrappedVillager closestOptimizableVillager = null; @@ -121,7 +121,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { closestOptimizableVillager.setOptimization(optimizeEvent.getOptimizationType()); closestOptimizableVillager.saveOptimizeTime(); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig vilProfession = TextReplacementConfig.builder() .matchLiteral("%vil_profession%") .replacement(closestOptimizableVillager.villager().getProfession().toString().toLowerCase()) @@ -135,11 +135,11 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { .replaceText(placedMaterial) )); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info("Villager was optimized by block at "+closestOptimizableVillager.villager().getLocation()); } else { closestOptimizableVillager.villager().shakeHead(); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") .replacement(CommonUtil.formatTime(closestOptimizableVillager.getOptimizeCooldownMillis(cooldown))) @@ -155,7 +155,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { if (!blocks_that_disable.contains(broken.getType())) return; Player player = event.getPlayer(); if (!player.hasPermission(Permissions.Optimize.BLOCK.get())) return; - if (onlyWhileSneaking && !player.isSneaking()) return; + if (only_while_sneaking && !player.isSneaking()) return; final Location blockLoc = broken.getLocation(); WrappedVillager closestOptimizedVillager = null; @@ -182,7 +182,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { closestOptimizedVillager.setOptimization(OptimizationType.NONE); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig vilProfession = TextReplacementConfig.builder() .matchLiteral("%vil_profession%") .replacement(closestOptimizedVillager.villager().getProfession().toString().toLowerCase()) @@ -196,7 +196,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener { .replaceText(brokenMaterial) )); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info("Villager unoptimized because nearby optimization block broken at: "+closestOptimizedVillager.villager().getLocation()); } } \ No newline at end of file diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByNametag.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByNametag.java index 32caff6..b9efc80 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByNametag.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByNametag.java @@ -33,7 +33,7 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { private final VillagerCache villagerCache; private final HashSet nametags = new HashSet<>(4); private final long cooldown; - private final boolean consumeNametag, shouldNotifyPlayer, shouldLog; + private final boolean consume_nametag, notify_player, log_enabled; public OptimizeByNametag() { shouldEnable(); @@ -44,14 +44,14 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { Nametag optimized villagers will be unoptimized again when they are renamed to something else."""); this.nametags.addAll(config.getList("optimization-methods.nametag-optimization.names", List.of("Optimize", "DisableAI"), "Names are case insensitive, capital letters won't matter.").stream().map(String::toLowerCase).toList()); - this.consumeNametag = config.getBoolean("optimization-methods.nametag-optimization.nametags-get-consumed", true, + this.consume_nametag = config.getBoolean("optimization-methods.nametag-optimization.nametags-get-consumed", true, "Enable or disable consumption of the used nametag item."); this.cooldown = config.getInt("optimization-methods.nametag-optimization.optimize-cooldown-seconds", 600, """ Cooldown in seconds until a villager can be optimized again using a nametag.\s Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L; - this.shouldNotifyPlayer = config.getBoolean("optimization-methods.nametag-optimization.notify-player", true, + this.notify_player = config.getBoolean("optimization-methods.nametag-optimization.notify-player", true, "Sends players a message when they successfully optimized a villager."); - this.shouldLog = config.getBoolean("optimization-methods.nametag-optimization.log", false); + this.log_enabled = config.getBoolean("optimization-methods.nametag-optimization.log", false); } @Override @@ -94,7 +94,7 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { VillagerOptimizer.callEvent(optimizeEvent); if (optimizeEvent.isCancelled()) return; - if (!consumeNametag) { + if (!consume_nametag) { event.setCancelled(true); villager.customName(newVillagerName); } @@ -102,14 +102,14 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { wVillager.setOptimization(optimizeEvent.getOptimizationType()); wVillager.saveOptimizeTime(); - if (shouldNotifyPlayer) + if (notify_player) VillagerOptimizer.getLang(player.locale()).nametag_optimize_success.forEach(player::sendMessage); - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info(player.getName() + " optimized a villager using nametag: '" + name + "'"); } else { event.setCancelled(true); villager.shakeHead(); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") .replacement(CommonUtil.formatTime(wVillager.getOptimizeCooldownMillis(cooldown))) @@ -125,9 +125,9 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener { wVillager.setOptimization(OptimizationType.NONE); - if (shouldNotifyPlayer) + if (notify_player) VillagerOptimizer.getLang(player.locale()).nametag_unoptimize_success.forEach(player::sendMessage); - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info(event.getPlayer().getName() + " disabled optimizations for a villager using nametag: '" + name + "'"); } } diff --git a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByWorkstation.java b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByWorkstation.java index 1bf14a4..65ef2fa 100644 --- a/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByWorkstation.java +++ b/VillagerOptimizer-1.20.2/src/main/java/me/xginko/villageroptimizer/modules/optimizations/OptimizeByWorkstation.java @@ -30,7 +30,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener private final VillagerCache villagerCache; private final long cooldown; private final double search_radius; - private final boolean onlyWhileSneaking, shouldLog, shouldNotifyPlayer; + private final boolean only_while_sneaking, log_enabled, notify_player; public OptimizeByWorkstation() { shouldEnable(); @@ -45,11 +45,11 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener this.cooldown = config.getInt("optimization-methods.workstation-optimization.optimize-cooldown-seconds", 600, """ Cooldown in seconds until a villager can be optimized again using a workstation.\s Here for configuration freedom. Recommended to leave as is to not enable any exploitable behavior.""") * 1000L; - this.onlyWhileSneaking = config.getBoolean("optimization-methods.workstation-optimization.only-when-sneaking", true, + this.only_while_sneaking = config.getBoolean("optimization-methods.workstation-optimization.only-when-sneaking", true, "Only optimize/unoptimize by workstation when player is sneaking during place or break"); - this.shouldNotifyPlayer = config.getBoolean("optimization-methods.workstation-optimization.notify-player", true, + this.notify_player = config.getBoolean("optimization-methods.workstation-optimization.notify-player", true, "Sends players a message when they successfully optimized a villager."); - this.shouldLog = config.getBoolean("optimization-methods.workstation-optimization.log", false); + this.log_enabled = config.getBoolean("optimization-methods.workstation-optimization.log", false); } @Override @@ -75,7 +75,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener if (workstationProfession.equals(Villager.Profession.NONE)) return; Player player = event.getPlayer(); if (!player.hasPermission(Permissions.Optimize.WORKSTATION.get())) return; - if (onlyWhileSneaking && !player.isSneaking()) return; + if (only_while_sneaking && !player.isSneaking()) return; final Location workstationLoc = placed.getLocation(); WrappedVillager closestOptimizableVillager = null; @@ -105,7 +105,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener closestOptimizableVillager.setOptimization(optimizeEvent.getOptimizationType()); closestOptimizableVillager.saveOptimizeTime(); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig vilProfession = TextReplacementConfig.builder() .matchLiteral("%vil_profession%") .replacement(closestOptimizableVillager.villager().getProfession().toString().toLowerCase()) @@ -119,11 +119,11 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener .replaceText(placedWorkstation) )); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info(player.getName() + " optimized a villager using workstation: '" + placed.getType().toString().toLowerCase() + "'"); } else { closestOptimizableVillager.villager().shakeHead(); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig timeLeft = TextReplacementConfig.builder() .matchLiteral("%time%") .replacement(CommonUtil.formatTime(closestOptimizableVillager.getOptimizeCooldownMillis(cooldown))) @@ -142,7 +142,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener if (workstationProfession.equals(Villager.Profession.NONE)) return; Player player = event.getPlayer(); if (!player.hasPermission(Permissions.Optimize.WORKSTATION.get())) return; - if (onlyWhileSneaking && !player.isSneaking()) return; + if (only_while_sneaking && !player.isSneaking()) return; final Location workstationLoc = broken.getLocation(); WrappedVillager closestOptimizedVillager = null; @@ -170,7 +170,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener closestOptimizedVillager.setOptimization(OptimizationType.NONE); - if (shouldNotifyPlayer) { + if (notify_player) { final TextReplacementConfig vilProfession = TextReplacementConfig.builder() .matchLiteral("%vil_profession%") .replacement(closestOptimizedVillager.villager().getProfession().toString().toLowerCase()) @@ -184,7 +184,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener .replaceText(brokenWorkstation) )); } - if (shouldLog) + if (log_enabled) VillagerOptimizer.getLog().info(player.getName() + " unoptimized a villager by breaking workstation: '" + broken.getType().toString().toLowerCase() + "'"); }