last round of optimizations before release

This commit is contained in:
xGinko 2024-04-28 19:39:43 +02:00
parent 2ab9dbeaf1
commit 034a270cfc
13 changed files with 115 additions and 104 deletions

View File

@ -5,7 +5,7 @@ import me.xginko.villageroptimizer.commands.VillagerOptimizerCommand;
import me.xginko.villageroptimizer.config.Config; import me.xginko.villageroptimizer.config.Config;
import me.xginko.villageroptimizer.config.LanguageCache; import me.xginko.villageroptimizer.config.LanguageCache;
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule; import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
@ -18,6 +18,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.*; import java.util.*;
import java.util.jar.JarFile; import java.util.jar.JarFile;
@ -45,6 +46,7 @@ public final class VillagerOptimizer extends JavaPlugin {
audiences = BukkitAudiences.create(this); audiences = BukkitAudiences.create(this);
logger = ComponentLogger.logger(getLogger().getName()); logger = ComponentLogger.logger(getLogger().getName());
bStats = new Metrics(this, 19954); bStats = new Metrics(this, 19954);
try { try {
getDataFolder().mkdirs(); getDataFolder().mkdirs();
} catch (Exception e) { } catch (Exception e) {
@ -52,48 +54,48 @@ public final class VillagerOptimizer extends JavaPlugin {
getServer().getPluginManager().disablePlugin(this); getServer().getPluginManager().disablePlugin(this);
} }
logger.info(Component.text("╭────────────────────────────────────────────────────────────╮").style(GenericUtil.STYLE)); logger.info(Component.text("╭────────────────────────────────────────────────────────────╮").style(Util.PL_STYLE));
logger.info(Component.text("│ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ │").style(Util.PL_STYLE));
logger.info(Component.text("│ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ │").style(Util.PL_STYLE));
logger.info(Component.text("│ _ __ _ __ __ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ _ __ _ __ __ │").style(Util.PL_STYLE));
logger.info(Component.text("│ | | / /(_)/ // /___ _ ___ _ ___ ____ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ | | / /(_)/ // /___ _ ___ _ ___ ____ │").style(Util.PL_STYLE));
logger.info(Component.text("│ | |/ // // // // _ `// _ `// -_)/ __/ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ | |/ // // // // _ `// _ `// -_)/ __/ │").style(Util.PL_STYLE));
logger.info(Component.text("│ |___//_//_//_/ \\_,_/ \\_, / \\__//_/ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ |___//_//_//_/ \\_,_/ \\_, / \\__//_/ │").style(Util.PL_STYLE));
logger.info(Component.text("│ ____ __ _ /___/_ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ ____ __ _ /___/_ │").style(Util.PL_STYLE));
logger.info(Component.text("│ / __ \\ ___ / /_ (_)__ _ (_)___ ___ ____ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ / __ \\ ___ / /_ (_)__ _ (_)___ ___ ____ │").style(Util.PL_STYLE));
logger.info(Component.text("│ / /_/ // _ \\/ __// // ' \\ / //_ // -_)/ __/ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ / /_/ // _ \\/ __// // ' \\ / //_ // -_)/ __/ │").style(Util.PL_STYLE));
logger.info(Component.text("\\____// .__/\\__//_//_/_/_//_/ /__/\\__//_/ │").style(GenericUtil.STYLE)); logger.info(Component.text("\\____// .__/\\__//_//_/_/_//_/ /__/\\__//_/ │").style(Util.PL_STYLE));
logger.info(Component.text("│ /_/ by xGinko │").style(GenericUtil.STYLE)); logger.info(Component.text("│ /_/ by xGinko │").style(Util.PL_STYLE));
logger.info(Component.text("│ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ │").style(Util.PL_STYLE));
logger.info(Component.text("│ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ │").style(Util.PL_STYLE));
logger.info(Component.text("") logger.info(Component.text("")
.style(GenericUtil.STYLE).append(Component.text("https://github.com/xGinko/VillagerOptimizer") .style(Util.PL_STYLE).append(Component.text("https://github.com/xGinko/VillagerOptimizer")
.color(NamedTextColor.GRAY)).append(Component.text("").style(GenericUtil.STYLE))); .color(NamedTextColor.GRAY)).append(Component.text("").style(Util.PL_STYLE)));
logger.info(Component.text("│ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ │").style(Util.PL_STYLE));
logger.info(Component.text("│ │").style(GenericUtil.STYLE)); logger.info(Component.text("│ │").style(Util.PL_STYLE));
logger.info(Component.text("") logger.info(Component.text("")
.style(GenericUtil.STYLE).append(Component.text(" ➤ Loading Translations...").style(GenericUtil.STYLE)) .style(Util.PL_STYLE).append(Component.text(" ➤ Loading Config...").style(Util.PL_STYLE))
.append(Component.text("").style(GenericUtil.STYLE))); .append(Component.text("").style(Util.PL_STYLE)));
reloadLang(true);
logger.info(Component.text("")
.style(GenericUtil.STYLE).append(Component.text(" ➤ Loading Config...").style(GenericUtil.STYLE))
.append(Component.text("").style(GenericUtil.STYLE)));
reloadConfiguration(); reloadConfiguration();
logger.info(Component.text("") logger.info(Component.text("")
.style(GenericUtil.STYLE).append(Component.text(" ✓ Done.").color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD)) .style(Util.PL_STYLE).append(Component.text(" ➤ Loading Translations...").style(Util.PL_STYLE))
.append(Component.text("").style(GenericUtil.STYLE))); .append(Component.text("").style(Util.PL_STYLE)));
logger.info(Component.text("│ │").style(GenericUtil.STYLE)); reloadLang(true);
logger.info(Component.text("│ │").style(GenericUtil.STYLE));
logger.info(Component.text("╰────────────────────────────────────────────────────────────╯").style(GenericUtil.STYLE)); logger.info(Component.text("")
.style(Util.PL_STYLE).append(Component.text(" ✓ Done.").color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
.append(Component.text("").style(Util.PL_STYLE)));
logger.info(Component.text("│ │").style(Util.PL_STYLE));
logger.info(Component.text("│ │").style(Util.PL_STYLE));
logger.info(Component.text("╰────────────────────────────────────────────────────────────╯").style(Util.PL_STYLE));
} }
@Override @Override
public void onDisable() { public void onDisable() {
VillagerOptimizerModule.modules.forEach(VillagerOptimizerModule::disable); VillagerOptimizerModule.MODULES.forEach(VillagerOptimizerModule::disable);
VillagerOptimizerModule.modules.clear(); VillagerOptimizerModule.MODULES.clear();
if (foliaLib != null) { if (foliaLib != null) {
foliaLib.getImpl().cancelAllTasks(); foliaLib.getImpl().cancelAllTasks();
foliaLib = null; foliaLib = null;
@ -166,17 +168,24 @@ public final class VillagerOptimizer extends JavaPlugin {
private void reloadLang(boolean logFancy) { private void reloadLang(boolean logFancy) {
languageCacheMap = new HashMap<>(); languageCacheMap = new HashMap<>();
try { try {
for (String localeString : getAvailableTranslations()) { final SortedSet<String> availableLocales = getAvailableTranslations();
if (logFancy) logger.info(Component.text("").style(GenericUtil.STYLE) if (!config.auto_lang) {
final String defaultLang = config.default_lang.toString().replace("-", "_").toLowerCase();
if (!availableLocales.contains(defaultLang))
throw new FileNotFoundException("Could not find any translation file for language '" + config.default_lang + "'");
availableLocales.removeIf(localeString -> !localeString.equalsIgnoreCase(defaultLang));
}
for (String localeString : availableLocales) {
if (logFancy) logger.info(Component.text("").style(Util.PL_STYLE)
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD)) .append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
.append(Component.text("").style(GenericUtil.STYLE))); .append(Component.text("").style(Util.PL_STYLE)));
else logger.info(String.format("Found language file for %s", localeString)); else logger.info(String.format("Found language file for %s", localeString));
languageCacheMap.put(localeString, new LanguageCache(localeString)); languageCacheMap.put(localeString, new LanguageCache(localeString));
} }
} catch (Throwable t) { } catch (Throwable t) {
if (logFancy) logger.error(Component.text("").style(GenericUtil.STYLE) if (logFancy) logger.error(Component.text("").style(Util.PL_STYLE)
.append(Component.text("LANG ERROR").color(NamedTextColor.RED).decorate(TextDecoration.BOLD)) .append(Component.text("LANG ERROR").color(NamedTextColor.RED).decorate(TextDecoration.BOLD))
.append(Component.text("").style(GenericUtil.STYLE)), t); .append(Component.text("").style(Util.PL_STYLE)), t);
else logger.error("Error while loading translation files!", t); else logger.error("Error while loading translation files!", t);
} }
} }

View File

@ -6,7 +6,7 @@ import me.xginko.villageroptimizer.commands.villageroptimizer.subcommands.Disabl
import me.xginko.villageroptimizer.commands.villageroptimizer.subcommands.ReloadSubCmd; import me.xginko.villageroptimizer.commands.villageroptimizer.subcommands.ReloadSubCmd;
import me.xginko.villageroptimizer.commands.villageroptimizer.subcommands.VersionSubCmd; import me.xginko.villageroptimizer.commands.villageroptimizer.subcommands.VersionSubCmd;
import me.xginko.villageroptimizer.enums.Permissions; import me.xginko.villageroptimizer.enums.Permissions;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
@ -59,17 +59,17 @@ public class VillagerOptimizerCmd implements VillagerOptimizerCommand {
private void sendCommandOverview(CommandSender sender) { private void sendCommandOverview(CommandSender sender) {
if (!sender.hasPermission(Permissions.Commands.RELOAD.get()) && !sender.hasPermission(Permissions.Commands.VERSION.get())) return; if (!sender.hasPermission(Permissions.Commands.RELOAD.get()) && !sender.hasPermission(Permissions.Commands.VERSION.get())) return;
KyoriUtil.sendMessage(sender, Component.text("-----------------------------------------------------").color(NamedTextColor.GRAY)); KyoriUtil.sendMessage(sender, Component.text("-----------------------------------------------------").color(NamedTextColor.GRAY));
KyoriUtil.sendMessage(sender, Component.text("VillagerOptimizer Commands").color(GenericUtil.COLOR)); KyoriUtil.sendMessage(sender, Component.text("VillagerOptimizer Commands").color(Util.PL_COLOR));
KyoriUtil.sendMessage(sender, Component.text("-----------------------------------------------------").color(NamedTextColor.GRAY)); KyoriUtil.sendMessage(sender, Component.text("-----------------------------------------------------").color(NamedTextColor.GRAY));
subCommands.forEach(subCommand -> KyoriUtil.sendMessage(sender, subCommands.forEach(subCommand -> KyoriUtil.sendMessage(sender,
subCommand.getSyntax().append(Component.text(" - ").color(NamedTextColor.DARK_GRAY)).append(subCommand.getDescription()))); subCommand.getSyntax().append(Component.text(" - ").color(NamedTextColor.DARK_GRAY)).append(subCommand.getDescription())));
KyoriUtil.sendMessage(sender, KyoriUtil.sendMessage(sender,
Component.text("/optimizevillagers <blockradius>").color(GenericUtil.COLOR) Component.text("/optimizevillagers <blockradius>").color(Util.PL_COLOR)
.append(Component.text(" - ").color(NamedTextColor.DARK_GRAY)) .append(Component.text(" - ").color(NamedTextColor.DARK_GRAY))
.append(Component.text("Optimize villagers in a radius").color(NamedTextColor.GRAY)) .append(Component.text("Optimize villagers in a radius").color(NamedTextColor.GRAY))
); );
KyoriUtil.sendMessage(sender, KyoriUtil.sendMessage(sender,
Component.text("/unoptmizevillagers <blockradius>").color(GenericUtil.COLOR) Component.text("/unoptmizevillagers <blockradius>").color(Util.PL_COLOR)
.append(Component.text(" - ").color(NamedTextColor.DARK_GRAY)) .append(Component.text(" - ").color(NamedTextColor.DARK_GRAY))
.append(Component.text("Unoptimize villagers in a radius").color(NamedTextColor.GRAY)) .append(Component.text("Unoptimize villagers in a radius").color(NamedTextColor.GRAY))
); );

View File

@ -4,7 +4,7 @@ import me.xginko.villageroptimizer.VillagerOptimizer;
import me.xginko.villageroptimizer.commands.SubCommand; import me.xginko.villageroptimizer.commands.SubCommand;
import me.xginko.villageroptimizer.enums.Permissions; import me.xginko.villageroptimizer.enums.Permissions;
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule; import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
@ -25,7 +25,7 @@ public class DisableSubCmd extends SubCommand {
@Override @Override
public TextComponent getSyntax() { public TextComponent getSyntax() {
return Component.text("/villageroptimizer disable").color(GenericUtil.COLOR); return Component.text("/villageroptimizer disable").color(Util.PL_COLOR);
} }
@Override @Override
@ -36,8 +36,8 @@ public class DisableSubCmd extends SubCommand {
} }
KyoriUtil.sendMessage(sender, Component.text("Disabling VillagerOptimizer...").color(NamedTextColor.RED)); KyoriUtil.sendMessage(sender, Component.text("Disabling VillagerOptimizer...").color(NamedTextColor.RED));
VillagerOptimizerModule.modules.forEach(VillagerOptimizerModule::disable); VillagerOptimizerModule.MODULES.forEach(VillagerOptimizerModule::disable);
VillagerOptimizerModule.modules.clear(); VillagerOptimizerModule.MODULES.clear();
VillagerOptimizer.getCache().cacheMap().clear(); VillagerOptimizer.getCache().cacheMap().clear();
KyoriUtil.sendMessage(sender, Component.text("Disabled all plugin listeners and tasks.").color(NamedTextColor.GREEN)); KyoriUtil.sendMessage(sender, Component.text("Disabled all plugin listeners and tasks.").color(NamedTextColor.GREEN));
KyoriUtil.sendMessage(sender, Component.text("You can enable the plugin again using the reload command.").color(NamedTextColor.YELLOW)); KyoriUtil.sendMessage(sender, Component.text("You can enable the plugin again using the reload command.").color(NamedTextColor.YELLOW));

View File

@ -3,7 +3,7 @@ package me.xginko.villageroptimizer.commands.villageroptimizer.subcommands;
import me.xginko.villageroptimizer.VillagerOptimizer; import me.xginko.villageroptimizer.VillagerOptimizer;
import me.xginko.villageroptimizer.commands.SubCommand; import me.xginko.villageroptimizer.commands.SubCommand;
import me.xginko.villageroptimizer.enums.Permissions; import me.xginko.villageroptimizer.enums.Permissions;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
@ -24,7 +24,7 @@ public class ReloadSubCmd extends SubCommand {
@Override @Override
public TextComponent getSyntax() { public TextComponent getSyntax() {
return Component.text("/villageroptimizer reload").color(GenericUtil.COLOR); return Component.text("/villageroptimizer reload").color(Util.PL_COLOR);
} }
@Override @Override

View File

@ -4,7 +4,7 @@ import io.papermc.paper.plugin.configuration.PluginMeta;
import me.xginko.villageroptimizer.VillagerOptimizer; import me.xginko.villageroptimizer.VillagerOptimizer;
import me.xginko.villageroptimizer.commands.SubCommand; import me.xginko.villageroptimizer.commands.SubCommand;
import me.xginko.villageroptimizer.enums.Permissions; import me.xginko.villageroptimizer.enums.Permissions;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
@ -27,7 +27,7 @@ public class VersionSubCmd extends SubCommand {
@Override @Override
public TextComponent getSyntax() { public TextComponent getSyntax() {
return Component.text("/villageroptimizer version").color(GenericUtil.COLOR); return Component.text("/villageroptimizer version").color(Util.PL_COLOR);
} }
@Override @Override
@ -57,7 +57,7 @@ public class VersionSubCmd extends SubCommand {
KyoriUtil.sendMessage(sender, Component.newline() KyoriUtil.sendMessage(sender, Component.newline()
.append( .append(
Component.text(name + " " + version) Component.text(name + " " + version)
.style(GenericUtil.STYLE) .style(Util.PL_STYLE)
.clickEvent(ClickEvent.openUrl(website)) .clickEvent(ClickEvent.openUrl(website))
) )
.append(Component.text(" by ").color(NamedTextColor.GRAY)) .append(Component.text(" by ").color(NamedTextColor.GRAY))

View File

@ -5,7 +5,7 @@ import com.tcoded.folialib.wrapper.task.WrappedTask;
import me.xginko.villageroptimizer.VillagerCache; import me.xginko.villageroptimizer.VillagerCache;
import me.xginko.villageroptimizer.VillagerOptimizer; import me.xginko.villageroptimizer.VillagerOptimizer;
import me.xginko.villageroptimizer.config.Config; import me.xginko.villageroptimizer.config.Config;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.LocationUtil; import me.xginko.villageroptimizer.utils.LocationUtil;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Server; import org.bukkit.Server;
@ -111,7 +111,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
this.periodic_chunk_check = scheduler.runTimer(() -> { this.periodic_chunk_check = scheduler.runTimer(() -> {
for (World world : server.getWorlds()) { for (World world : server.getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) { for (Chunk chunk : world.getLoadedChunks()) {
if (!skip_unloaded_entity_chunks || GenericUtil.isEntitiesLoaded(chunk)) { if (!skip_unloaded_entity_chunks || Util.isEntitiesLoaded(chunk)) {
this.manageVillagerCount(chunk); this.manageVillagerCount(chunk);
} }
} }
@ -174,7 +174,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
scheduler.runAtEntity(villager, kill -> { scheduler.runAtEntity(villager, kill -> {
villager.remove(); villager.remove();
if (log_enabled) { if (log_enabled) {
info("Removed unoptimized villager with profession '" + GenericUtil.formatEnum(villager.getProfession()) + "' at " + info("Removed unoptimized villager with profession '" + Util.formatEnum(villager.getProfession()) + "' at " +
LocationUtil.toString(villager.getLocation())); LocationUtil.toString(villager.getLocation()));
} }
}); });
@ -196,7 +196,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
villager.remove(); villager.remove();
if (log_enabled) { if (log_enabled) {
info("Removed optimized villager with profession '" + GenericUtil.formatEnum(villager.getProfession()) + "' at " + info("Removed optimized villager with profession '" + Util.formatEnum(villager.getProfession()) + "' at " +
LocationUtil.toString(villager.getLocation())); LocationUtil.toString(villager.getLocation()));
} }
}); });

View File

@ -5,6 +5,8 @@ import me.xginko.villageroptimizer.modules.gameplay.*;
import me.xginko.villageroptimizer.modules.optimization.OptimizeByBlock; import me.xginko.villageroptimizer.modules.optimization.OptimizeByBlock;
import me.xginko.villageroptimizer.modules.optimization.OptimizeByNametag; import me.xginko.villageroptimizer.modules.optimization.OptimizeByNametag;
import me.xginko.villageroptimizer.modules.optimization.OptimizeByWorkstation; import me.xginko.villageroptimizer.modules.optimization.OptimizeByWorkstation;
import me.xginko.villageroptimizer.utils.Util;
import net.kyori.adventure.text.Component;
import java.util.HashSet; import java.util.HashSet;
@ -15,48 +17,48 @@ public interface VillagerOptimizerModule {
void disable(); void disable();
boolean shouldEnable(); boolean shouldEnable();
HashSet<VillagerOptimizerModule> modules = new HashSet<>(); HashSet<VillagerOptimizerModule> MODULES = new HashSet<>(14);
static void reloadModules() { static void reloadModules() {
modules.forEach(VillagerOptimizerModule::disable); MODULES.forEach(VillagerOptimizerModule::disable);
modules.clear(); MODULES.clear();
modules.add(new OptimizeByNametag()); MODULES.add(new OptimizeByNametag());
modules.add(new OptimizeByBlock()); MODULES.add(new OptimizeByBlock());
modules.add(new OptimizeByWorkstation()); MODULES.add(new OptimizeByWorkstation());
modules.add(new EnableLeashingVillagers()); MODULES.add(new EnableLeashingVillagers());
modules.add(new FixOptimisationAfterCure()); MODULES.add(new FixOptimisationAfterCure());
modules.add(new RestockOptimizedTrades()); MODULES.add(new RestockOptimizedTrades());
modules.add(new LevelOptimizedProfession()); MODULES.add(new LevelOptimizedProfession());
modules.add(new VisuallyHighlightOptimized()); MODULES.add(new VisuallyHighlightOptimized());
modules.add(new MakeVillagersSpawnAdult()); MODULES.add(new MakeVillagersSpawnAdult());
modules.add(new PreventUnoptimizedTrading()); MODULES.add(new PreventUnoptimizedTrading());
modules.add(new PreventOptimizedTargeting()); MODULES.add(new PreventOptimizedTargeting());
modules.add(new PreventOptimizedDamage()); MODULES.add(new PreventOptimizedDamage());
modules.add(new UnoptimizeOnJobLoose()); MODULES.add(new UnoptimizeOnJobLoose());
modules.add(new VillagerChunkLimit()); MODULES.add(new VillagerChunkLimit());
modules.forEach(module -> { MODULES.forEach(module -> {
if (module.shouldEnable()) module.enable(); if (module.shouldEnable()) module.enable();
}); });
} }
default void trace(String message, Throwable throwable) { default void error(String message, Throwable t) {
VillagerOptimizer.getPrefixedLogger().trace(logPrefix() + message, throwable); VillagerOptimizer.getPrefixedLogger().error("{}{}", logPrefix(), message, t);
} }
default void error(String message) { default void error(String message) {
VillagerOptimizer.getPrefixedLogger().error(logPrefix() + message); VillagerOptimizer.getPrefixedLogger().error("{}{}", logPrefix(), message);
} }
default void warn(String message) { default void warn(String message) {
VillagerOptimizer.getPrefixedLogger().warn(logPrefix() + message); VillagerOptimizer.getPrefixedLogger().warn("{}{}", logPrefix(), message);
} }
default void info(String message) { default void info(String message) {
VillagerOptimizer.getPrefixedLogger().info(logPrefix() + message); VillagerOptimizer.getPrefixedLogger().info(Component.text(logPrefix() + message).color(Util.PL_COLOR));
} }
default String logPrefix() { default String logPrefix() {

View File

@ -6,7 +6,7 @@ import me.xginko.villageroptimizer.VillagerCache;
import me.xginko.villageroptimizer.config.Config; import me.xginko.villageroptimizer.config.Config;
import me.xginko.villageroptimizer.wrapper.WrappedVillager; import me.xginko.villageroptimizer.wrapper.WrappedVillager;
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule; import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -93,7 +93,7 @@ public class LevelOptimizedProfession implements VillagerOptimizerModule, Listen
Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
final TextReplacementConfig timeLeft = TextReplacementConfig.builder() final TextReplacementConfig timeLeft = TextReplacementConfig.builder()
.matchLiteral("%time%") .matchLiteral("%time%")
.replacement(GenericUtil.formatDuration(Duration.ofMillis(wVillager.getLevelCooldownMillis(cooldown_millis)))) .replacement(Util.formatDuration(Duration.ofMillis(wVillager.getLevelCooldownMillis(cooldown_millis))))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).villager_leveling_up VillagerOptimizer.getLang(player.locale()).villager_leveling_up
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft)));

View File

@ -7,7 +7,7 @@ import me.xginko.villageroptimizer.wrapper.WrappedVillager;
import me.xginko.villageroptimizer.config.Config; import me.xginko.villageroptimizer.config.Config;
import me.xginko.villageroptimizer.enums.Permissions; import me.xginko.villageroptimizer.enums.Permissions;
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule; import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -79,7 +79,7 @@ public class RestockOptimizedTrades implements VillagerOptimizerModule, Listener
if (notify_player && !player_bypassing) { if (notify_player && !player_bypassing) {
final TextReplacementConfig timeLeft = TextReplacementConfig.builder() final TextReplacementConfig timeLeft = TextReplacementConfig.builder()
.matchLiteral("%time%") .matchLiteral("%time%")
.replacement(GenericUtil.formatDuration(Duration.ofMillis(wVillager.getRestockCooldownMillis(restock_delay_millis)))) .replacement(Util.formatDuration(Duration.ofMillis(wVillager.getRestockCooldownMillis(restock_delay_millis))))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).trades_restocked VillagerOptimizer.getLang(player.locale()).trades_restocked
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft)));

View File

@ -8,7 +8,7 @@ import me.xginko.villageroptimizer.enums.Permissions;
import me.xginko.villageroptimizer.events.VillagerOptimizeEvent; import me.xginko.villageroptimizer.events.VillagerOptimizeEvent;
import me.xginko.villageroptimizer.events.VillagerUnoptimizeEvent; import me.xginko.villageroptimizer.events.VillagerUnoptimizeEvent;
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule; import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import me.xginko.villageroptimizer.utils.LocationUtil; import me.xginko.villageroptimizer.utils.LocationUtil;
import me.xginko.villageroptimizer.wrapper.WrappedVillager; import me.xginko.villageroptimizer.wrapper.WrappedVillager;
@ -141,11 +141,11 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
if (notify_player) { if (notify_player) {
final TextReplacementConfig vilProfession = TextReplacementConfig.builder() final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
.matchLiteral("%vil_profession%") .matchLiteral("%vil_profession%")
.replacement(GenericUtil.formatEnum(closestOptimizableVillager.villager().getProfession())) .replacement(Util.formatEnum(closestOptimizableVillager.villager().getProfession()))
.build(); .build();
final TextReplacementConfig placedMaterial = TextReplacementConfig.builder() final TextReplacementConfig placedMaterial = TextReplacementConfig.builder()
.matchLiteral("%blocktype%") .matchLiteral("%blocktype%")
.replacement(GenericUtil.formatEnum(placed.getType())) .replacement(Util.formatEnum(placed.getType()))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).block_optimize_success VillagerOptimizer.getLang(player.locale()).block_optimize_success
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(placedMaterial))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(placedMaterial)));
@ -160,7 +160,7 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
if (notify_player) { if (notify_player) {
final TextReplacementConfig timeLeft = TextReplacementConfig.builder() final TextReplacementConfig timeLeft = TextReplacementConfig.builder()
.matchLiteral("%time%") .matchLiteral("%time%")
.replacement(GenericUtil.formatDuration(Duration.ofMillis(closestOptimizableVillager.getOptimizeCooldownMillis(cooldown_millis)))) .replacement(Util.formatDuration(Duration.ofMillis(closestOptimizableVillager.getOptimizeCooldownMillis(cooldown_millis))))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).block_on_optimize_cooldown VillagerOptimizer.getLang(player.locale()).block_on_optimize_cooldown
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft)));
@ -206,18 +206,18 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
if (notify_player) { if (notify_player) {
final TextReplacementConfig vilProfession = TextReplacementConfig.builder() final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
.matchLiteral("%vil_profession%") .matchLiteral("%vil_profession%")
.replacement(GenericUtil.formatEnum(closestOptimizedVillager.villager().getProfession())) .replacement(Util.formatEnum(closestOptimizedVillager.villager().getProfession()))
.build(); .build();
final TextReplacementConfig brokenMaterial = TextReplacementConfig.builder() final TextReplacementConfig brokenMaterial = TextReplacementConfig.builder()
.matchLiteral("%blocktype%") .matchLiteral("%blocktype%")
.replacement(GenericUtil.formatEnum(broken.getType())) .replacement(Util.formatEnum(broken.getType()))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).block_unoptimize_success VillagerOptimizer.getLang(player.locale()).block_unoptimize_success
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(brokenMaterial))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(brokenMaterial)));
} }
if (log_enabled) { if (log_enabled) {
info(player.getName() + " unoptimized villager using " + GenericUtil.formatEnum(broken.getType()) + info(player.getName() + " unoptimized villager using " + Util.formatEnum(broken.getType()) +
LocationUtil.toString(closestOptimizedVillager.villager().getLocation())); LocationUtil.toString(closestOptimizedVillager.villager().getLocation()));
} }
} }

View File

@ -10,7 +10,7 @@ import me.xginko.villageroptimizer.enums.Permissions;
import me.xginko.villageroptimizer.events.VillagerOptimizeEvent; import me.xginko.villageroptimizer.events.VillagerOptimizeEvent;
import me.xginko.villageroptimizer.events.VillagerUnoptimizeEvent; import me.xginko.villageroptimizer.events.VillagerUnoptimizeEvent;
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule; import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -132,7 +132,7 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener {
if (notify_player) { if (notify_player) {
final TextReplacementConfig timeLeft = TextReplacementConfig.builder() final TextReplacementConfig timeLeft = TextReplacementConfig.builder()
.matchLiteral("%time%") .matchLiteral("%time%")
.replacement(GenericUtil.formatDuration(Duration.ofMillis(wVillager.getOptimizeCooldownMillis(cooldown)))) .replacement(Util.formatDuration(Duration.ofMillis(wVillager.getOptimizeCooldownMillis(cooldown))))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).nametag_on_optimize_cooldown VillagerOptimizer.getLang(player.locale()).nametag_on_optimize_cooldown
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft)));

View File

@ -11,7 +11,7 @@ import me.xginko.villageroptimizer.enums.Permissions;
import me.xginko.villageroptimizer.events.VillagerOptimizeEvent; import me.xginko.villageroptimizer.events.VillagerOptimizeEvent;
import me.xginko.villageroptimizer.events.VillagerUnoptimizeEvent; import me.xginko.villageroptimizer.events.VillagerUnoptimizeEvent;
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule; import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
import me.xginko.villageroptimizer.utils.GenericUtil; import me.xginko.villageroptimizer.utils.Util;
import me.xginko.villageroptimizer.utils.KyoriUtil; import me.xginko.villageroptimizer.utils.KyoriUtil;
import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.Location; import org.bukkit.Location;
@ -88,7 +88,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockPlace(BlockPlaceEvent event) { private void onBlockPlace(BlockPlaceEvent event) {
final Block placed = event.getBlock(); final Block placed = event.getBlock();
final Villager.Profession workstationProfession = GenericUtil.getWorkstationProfession(placed.getType()); final Villager.Profession workstationProfession = Util.getWorkstationProfession(placed.getType());
if (workstationProfession == null) return; if (workstationProfession == null) return;
final Player player = event.getPlayer(); final Player player = event.getPlayer();
@ -117,7 +117,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
if (notify_player) { if (notify_player) {
final TextReplacementConfig timeLeft = TextReplacementConfig.builder() final TextReplacementConfig timeLeft = TextReplacementConfig.builder()
.matchLiteral("%time%") .matchLiteral("%time%")
.replacement(GenericUtil.formatDuration(Duration.ofMillis(wrapped.getOptimizeCooldownMillis(cooldown_millis)))) .replacement(Util.formatDuration(Duration.ofMillis(wrapped.getOptimizeCooldownMillis(cooldown_millis))))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).nametag_on_optimize_cooldown VillagerOptimizer.getLang(player.locale()).nametag_on_optimize_cooldown
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(timeLeft)));
@ -141,18 +141,18 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
if (notify_player) { if (notify_player) {
final TextReplacementConfig vilProfession = TextReplacementConfig.builder() final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
.matchLiteral("%vil_profession%") .matchLiteral("%vil_profession%")
.replacement(GenericUtil.formatEnum(wrapped.villager().getProfession())) .replacement(Util.formatEnum(wrapped.villager().getProfession()))
.build(); .build();
final TextReplacementConfig placedWorkstation = TextReplacementConfig.builder() final TextReplacementConfig placedWorkstation = TextReplacementConfig.builder()
.matchLiteral("%blocktype%") .matchLiteral("%blocktype%")
.replacement(GenericUtil.formatEnum(placed.getType())) .replacement(Util.formatEnum(placed.getType()))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).workstation_optimize_success VillagerOptimizer.getLang(player.locale()).workstation_optimize_success
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(placedWorkstation))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(placedWorkstation)));
} }
if (log_enabled) { if (log_enabled) {
info(player.getName() + " optimized villager using workstation " + GenericUtil.formatEnum(placed.getType()) + " at " + info(player.getName() + " optimized villager using workstation " + Util.formatEnum(placed.getType()) + " at " +
LocationUtil.toString(wrapped.villager().getLocation())); LocationUtil.toString(wrapped.villager().getLocation()));
} }
@ -165,7 +165,7 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockBreak(BlockBreakEvent event) { private void onBlockBreak(BlockBreakEvent event) {
final Block broken = event.getBlock(); final Block broken = event.getBlock();
final Villager.Profession workstationProfession = GenericUtil.getWorkstationProfession(broken.getType()); final Villager.Profession workstationProfession = Util.getWorkstationProfession(broken.getType());
if (workstationProfession == null) return; if (workstationProfession == null) return;
final Player player = event.getPlayer(); final Player player = event.getPlayer();
@ -205,18 +205,18 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
if (notify_player) { if (notify_player) {
final TextReplacementConfig vilProfession = TextReplacementConfig.builder() final TextReplacementConfig vilProfession = TextReplacementConfig.builder()
.matchLiteral("%vil_profession%") .matchLiteral("%vil_profession%")
.replacement(GenericUtil.formatEnum(closestOptimized.villager().getProfession())) .replacement(Util.formatEnum(closestOptimized.villager().getProfession()))
.build(); .build();
final TextReplacementConfig brokenWorkstation = TextReplacementConfig.builder() final TextReplacementConfig brokenWorkstation = TextReplacementConfig.builder()
.matchLiteral("%blocktype%") .matchLiteral("%blocktype%")
.replacement(GenericUtil.formatEnum(broken.getType())) .replacement(Util.formatEnum(broken.getType()))
.build(); .build();
VillagerOptimizer.getLang(player.locale()).workstation_unoptimize_success VillagerOptimizer.getLang(player.locale()).workstation_unoptimize_success
.forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(brokenWorkstation))); .forEach(line -> KyoriUtil.sendMessage(player, line.replaceText(vilProfession).replaceText(brokenWorkstation)));
} }
if (log_enabled) { if (log_enabled) {
info(player.getName() + " unoptimized villager using workstation " + GenericUtil.formatEnum(broken.getType()) + " at " + info(player.getName() + " unoptimized villager using workstation " + Util.formatEnum(broken.getType()) + " at " +
LocationUtil.toString(closestOptimized.villager().getLocation())); LocationUtil.toString(closestOptimized.villager().getLocation()));
} }
} }

View File

@ -12,10 +12,10 @@ import org.jetbrains.annotations.Nullable;
import java.time.Duration; import java.time.Duration;
import java.util.Locale; import java.util.Locale;
public class GenericUtil { public class Util {
public static final @NotNull TextColor COLOR = TextColor.color(102,255,230); public static final @NotNull TextColor PL_COLOR = TextColor.color(102,255,230);
public static final @NotNull Style STYLE = Style.style(COLOR, TextDecoration.BOLD); public static final @NotNull Style PL_STYLE = Style.style(PL_COLOR, TextDecoration.BOLD);
public static @NotNull String formatDuration(@NotNull Duration duration) { public static @NotNull String formatDuration(@NotNull Duration duration) {
if (duration.isNegative()) duration = duration.negated(); if (duration.isNegative()) duration = duration.negated();