some refactoring
This commit is contained in:
parent
a07d743198
commit
e78d79ee41
@ -11,11 +11,11 @@ import java.time.Duration;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
public final class CachedVillagers {
|
public final class VillagerCache {
|
||||||
|
|
||||||
private final @NotNull Cache<UUID, WrappedVillager> villagerCache;
|
private final @NotNull Cache<UUID, WrappedVillager> villagerCache;
|
||||||
|
|
||||||
CachedVillagers(long expireAfterWriteSeconds) {
|
VillagerCache(long expireAfterWriteSeconds) {
|
||||||
this.villagerCache = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(expireAfterWriteSeconds)).build();
|
this.villagerCache = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(expireAfterWriteSeconds)).build();
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
|||||||
public final class VillagerOptimizer extends JavaPlugin {
|
public final class VillagerOptimizer extends JavaPlugin {
|
||||||
|
|
||||||
private static VillagerOptimizer instance;
|
private static VillagerOptimizer instance;
|
||||||
private static CachedVillagers cachedVillagers;
|
private static VillagerCache villagerCache;
|
||||||
private static HashMap<String, LanguageCache> languageCacheMap;
|
private static HashMap<String, LanguageCache> languageCacheMap;
|
||||||
private static Config config;
|
private static Config config;
|
||||||
private static Logger logger;
|
private static Logger logger;
|
||||||
@ -74,17 +74,17 @@ public final class VillagerOptimizer extends JavaPlugin {
|
|||||||
public static VillagerOptimizer getInstance() {
|
public static VillagerOptimizer getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
public static CachedVillagers getCachedVillagers() {
|
public static NamespacedKey getKey(String key) {
|
||||||
return cachedVillagers;
|
return new NamespacedKey(instance, key);
|
||||||
}
|
}
|
||||||
public static Config getConfiguration() {
|
public static Config getConfiguration() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
public static NamespacedKey getKey(String key) {
|
public static VillagerCache getCache() {
|
||||||
return new NamespacedKey(instance, key);
|
return villagerCache;
|
||||||
}
|
}
|
||||||
public static LanguageCache getLang(String lang) {
|
public static Logger getLog() {
|
||||||
return config.auto_lang ? languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase())) : languageCacheMap.get(config.default_lang.toString().toLowerCase());
|
return logger;
|
||||||
}
|
}
|
||||||
public static LanguageCache getLang(Locale locale) {
|
public static LanguageCache getLang(Locale locale) {
|
||||||
return getLang(locale.toString().toLowerCase());
|
return getLang(locale.toString().toLowerCase());
|
||||||
@ -92,8 +92,8 @@ public final class VillagerOptimizer extends JavaPlugin {
|
|||||||
public static LanguageCache getLang(CommandSender commandSender) {
|
public static LanguageCache getLang(CommandSender commandSender) {
|
||||||
return commandSender instanceof Player player ? getLang(player.locale()) : getLang(config.default_lang);
|
return commandSender instanceof Player player ? getLang(player.locale()) : getLang(config.default_lang);
|
||||||
}
|
}
|
||||||
public static Logger getLog() {
|
public static LanguageCache getLang(String lang) {
|
||||||
return logger;
|
return config.auto_lang ? languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase())) : languageCacheMap.get(config.default_lang.toString().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadPlugin() {
|
public void reloadPlugin() {
|
||||||
@ -105,11 +105,11 @@ public final class VillagerOptimizer extends JavaPlugin {
|
|||||||
private void reloadConfiguration() {
|
private void reloadConfiguration() {
|
||||||
try {
|
try {
|
||||||
config = new Config();
|
config = new Config();
|
||||||
cachedVillagers = new CachedVillagers(config.cache_keep_time_seconds);
|
villagerCache = new VillagerCache(config.cache_keep_time_seconds);
|
||||||
VillagerOptimizerModule.reloadModules();
|
VillagerOptimizerModule.reloadModules();
|
||||||
config.saveConfig();
|
config.saveConfig();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.severe("Error while loading config! - " + e.getLocalizedMessage());
|
logger.severe("Error loading config! - " + e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public final class WrappedVillager {
|
|||||||
* @param type OptimizationType the villager should be set to.
|
* @param type OptimizationType the villager should be set to.
|
||||||
*/
|
*/
|
||||||
public void setOptimization(OptimizationType type) {
|
public void setOptimization(OptimizationType type) {
|
||||||
if (type.equals(OptimizationType.OFF) && isOptimized()) {
|
if (type.equals(OptimizationType.NONE) && isOptimized()) {
|
||||||
dataContainer.remove(Keys.OPTIMIZATION_TYPE.key());
|
dataContainer.remove(Keys.OPTIMIZATION_TYPE.key());
|
||||||
villager.getScheduler().run(VillagerOptimizer.getInstance(), enableAI -> {
|
villager.getScheduler().run(VillagerOptimizer.getInstance(), enableAI -> {
|
||||||
villager.setAware(true);
|
villager.setAware(true);
|
||||||
@ -61,7 +61,7 @@ public final class WrappedVillager {
|
|||||||
* @return The current OptimizationType of the villager.
|
* @return The current OptimizationType of the villager.
|
||||||
*/
|
*/
|
||||||
public @NotNull OptimizationType getOptimizationType() {
|
public @NotNull OptimizationType getOptimizationType() {
|
||||||
return isOptimized() ? OptimizationType.valueOf(dataContainer.get(Keys.OPTIMIZATION_TYPE.key(), PersistentDataType.STRING)) : OptimizationType.OFF;
|
return isOptimized() ? OptimizationType.valueOf(dataContainer.get(Keys.OPTIMIZATION_TYPE.key(), PersistentDataType.STRING)) : OptimizationType.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.xginko.villageroptimizer.commands.optimizevillagers;
|
package me.xginko.villageroptimizer.commands.optimizevillagers;
|
||||||
|
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import me.xginko.villageroptimizer.commands.VillagerOptimizerCommand;
|
import me.xginko.villageroptimizer.commands.VillagerOptimizerCommand;
|
||||||
import me.xginko.villageroptimizer.enums.OptimizationType;
|
import me.xginko.villageroptimizer.enums.OptimizationType;
|
||||||
import me.xginko.villageroptimizer.enums.Permissions;
|
import me.xginko.villageroptimizer.enums.Permissions;
|
||||||
@ -20,6 +20,7 @@ import org.bukkit.entity.Villager;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class OptVillagersRadius implements VillagerOptimizerCommand, TabCompleter {
|
public class OptVillagersRadius implements VillagerOptimizerCommand, TabCompleter {
|
||||||
@ -29,6 +30,8 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
private final List<String> tabCompletes = List.of("5", "10", "25", "50");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String label() {
|
public String label() {
|
||||||
return "optimizevillagers";
|
return "optimizevillagers";
|
||||||
@ -36,7 +39,7 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
return List.of("5", "10", "25", "50");
|
return args.length == 1 ? tabCompletes : Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,7 +59,7 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
try {
|
try {
|
||||||
int specifiedRadius = Integer.parseInt(args[0]) / 2;
|
int specifiedRadius = Integer.parseInt(args[0]) / 2;
|
||||||
|
|
||||||
CachedVillagers cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
||||||
int successCount = 0;
|
int successCount = 0;
|
||||||
int failCount = 0;
|
int failCount = 0;
|
||||||
|
|
||||||
@ -66,7 +69,7 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
Villager.Profession profession = villager.getProfession();
|
Villager.Profession profession = villager.getProfession();
|
||||||
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
||||||
|
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd(villager);
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
|
|
||||||
if (!wVillager.isOptimized()) {
|
if (!wVillager.isOptimized()) {
|
||||||
wVillager.setOptimization(OptimizationType.COMMAND);
|
wVillager.setOptimization(OptimizationType.COMMAND);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.xginko.villageroptimizer.commands.unoptimizevillagers;
|
package me.xginko.villageroptimizer.commands.unoptimizevillagers;
|
||||||
|
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import me.xginko.villageroptimizer.commands.VillagerOptimizerCommand;
|
import me.xginko.villageroptimizer.commands.VillagerOptimizerCommand;
|
||||||
import me.xginko.villageroptimizer.enums.OptimizationType;
|
import me.xginko.villageroptimizer.enums.OptimizationType;
|
||||||
import me.xginko.villageroptimizer.enums.Permissions;
|
import me.xginko.villageroptimizer.enums.Permissions;
|
||||||
@ -12,24 +12,36 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Villager;
|
import org.bukkit.entity.Villager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class UnOptVillagersRadius implements VillagerOptimizerCommand {
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UnOptVillagersRadius implements VillagerOptimizerCommand, TabCompleter {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: Radius limit, Cooldown, Compatibility with other types
|
* TODO: Radius limit, Cooldown, Compatibility with other types
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
private final List<String> tabCompletes = List.of("5", "10", "25", "50");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String label() {
|
public String label() {
|
||||||
return "unoptimizevillagers";
|
return "unoptimizevillagers";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
return args.length == 1 ? tabCompletes : Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
if (sender.hasPermission(Permissions.Commands.UNOPTIMIZE_RADIUS.get())) {
|
if (sender.hasPermission(Permissions.Commands.UNOPTIMIZE_RADIUS.get())) {
|
||||||
@ -47,7 +59,7 @@ public class UnOptVillagersRadius implements VillagerOptimizerCommand {
|
|||||||
try {
|
try {
|
||||||
int specifiedRadius = Integer.parseInt(args[0]) / 2;
|
int specifiedRadius = Integer.parseInt(args[0]) / 2;
|
||||||
|
|
||||||
CachedVillagers cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
||||||
int successCount = 0;
|
int successCount = 0;
|
||||||
|
|
||||||
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
||||||
@ -56,10 +68,10 @@ public class UnOptVillagersRadius implements VillagerOptimizerCommand {
|
|||||||
Villager.Profession profession = villager.getProfession();
|
Villager.Profession profession = villager.getProfession();
|
||||||
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
||||||
|
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd(villager);
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
|
|
||||||
if (wVillager.isOptimized()) {
|
if (wVillager.isOptimized()) {
|
||||||
wVillager.setOptimization(OptimizationType.OFF);
|
wVillager.setOptimization(OptimizationType.NONE);
|
||||||
successCount++;
|
successCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ public enum OptimizationType {
|
|||||||
NAMETAG,
|
NAMETAG,
|
||||||
WORKSTATION,
|
WORKSTATION,
|
||||||
BLOCK,
|
BLOCK,
|
||||||
OFF
|
NONE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package me.xginko.villageroptimizer.modules;
|
|||||||
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.enums.OptimizationType;
|
import me.xginko.villageroptimizer.enums.OptimizationType;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import me.xginko.villageroptimizer.enums.Permissions;
|
import me.xginko.villageroptimizer.enums.Permissions;
|
||||||
import me.xginko.villageroptimizer.WrappedVillager;
|
import me.xginko.villageroptimizer.WrappedVillager;
|
||||||
import me.xginko.villageroptimizer.utils.CommonUtils;
|
import me.xginko.villageroptimizer.utils.CommonUtils;
|
||||||
@ -35,7 +35,7 @@ public class BlockOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
* -> use workstation optimization logic
|
* -> use workstation optimization logic
|
||||||
* */
|
* */
|
||||||
|
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
private final HashSet<Material> blocks_that_disable = new HashSet<>(4);
|
private final HashSet<Material> blocks_that_disable = new HashSet<>(4);
|
||||||
private final boolean shouldLog, shouldNotifyPlayer;
|
private final boolean shouldLog, shouldNotifyPlayer;
|
||||||
private final int maxVillagers;
|
private final int maxVillagers;
|
||||||
@ -43,7 +43,7 @@ public class BlockOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
|
|
||||||
protected BlockOptimization() {
|
protected BlockOptimization() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization-methods.block-optimization.enable", """
|
config.addComment("optimization-methods.block-optimization.enable", """
|
||||||
When enabled, villagers standing on the configured specific blocks will become optimized once a\s
|
When enabled, villagers standing on the configured specific blocks will become optimized once a\s
|
||||||
@ -98,9 +98,9 @@ public class BlockOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
if (counter >= maxVillagers) return;
|
if (counter >= maxVillagers) return;
|
||||||
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
||||||
|
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd((Villager) entity);
|
WrappedVillager wVillager = villagerCache.getOrAdd((Villager) entity);
|
||||||
final OptimizationType type = wVillager.getOptimizationType();
|
final OptimizationType type = wVillager.getOptimizationType();
|
||||||
if (!type.equals(OptimizationType.OFF) && !type.equals(OptimizationType.COMMAND)) continue;
|
if (!type.equals(OptimizationType.NONE) && !type.equals(OptimizationType.COMMAND)) continue;
|
||||||
|
|
||||||
if (wVillager.canOptimize(cooldown) || player.hasPermission(Permissions.Bypass.BLOCK_COOLDOWN.get())) {
|
if (wVillager.canOptimize(cooldown) || player.hasPermission(Permissions.Bypass.BLOCK_COOLDOWN.get())) {
|
||||||
wVillager.setOptimization(OptimizationType.BLOCK);
|
wVillager.setOptimization(OptimizationType.BLOCK);
|
||||||
@ -138,12 +138,12 @@ public class BlockOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
for (Entity entity : broken.getRelative(BlockFace.UP).getLocation().getNearbyEntities(0.5,1,0.5)) {
|
for (Entity entity : broken.getRelative(BlockFace.UP).getLocation().getNearbyEntities(0.5,1,0.5)) {
|
||||||
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
||||||
|
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd((Villager) entity);
|
WrappedVillager wVillager = villagerCache.getOrAdd((Villager) entity);
|
||||||
|
|
||||||
if (wVillager.getOptimizationType().equals(OptimizationType.BLOCK)) {
|
if (wVillager.getOptimizationType().equals(OptimizationType.BLOCK)) {
|
||||||
if (counter >= maxVillagers) return;
|
if (counter >= maxVillagers) return;
|
||||||
|
|
||||||
wVillager.setOptimization(OptimizationType.OFF);
|
wVillager.setOptimization(OptimizationType.NONE);
|
||||||
|
|
||||||
if (shouldNotifyPlayer) {
|
if (shouldNotifyPlayer) {
|
||||||
final String villagerType = wVillager.villager().getProfession().toString().toLowerCase();
|
final String villagerType = wVillager.villager().getProfession().toString().toLowerCase();
|
||||||
@ -166,7 +166,7 @@ public class BlockOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (!player.hasPermission(Permissions.Optimize.BLOCK.get())) return;
|
if (!player.hasPermission(Permissions.Optimize.BLOCK.get())) return;
|
||||||
|
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd((Villager) interacted);
|
WrappedVillager wVillager = villagerCache.getOrAdd((Villager) interacted);
|
||||||
final Location entityLegs = interacted.getLocation();
|
final Location entityLegs = interacted.getLocation();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -199,7 +199,7 @@ public class BlockOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (wVillager.getOptimizationType().equals(OptimizationType.BLOCK)) {
|
if (wVillager.getOptimizationType().equals(OptimizationType.BLOCK)) {
|
||||||
wVillager.setOptimization(OptimizationType.OFF);
|
wVillager.setOptimization(OptimizationType.NONE);
|
||||||
if (shouldNotifyPlayer) {
|
if (shouldNotifyPlayer) {
|
||||||
final String villagerType = wVillager.villager().getProfession().toString().toLowerCase();
|
final String villagerType = wVillager.villager().getProfession().toString().toLowerCase();
|
||||||
final String blockType = entityLegs.getBlock().getType().toString().toLowerCase();
|
final String blockType = entityLegs.getBlock().getType().toString().toLowerCase();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.xginko.villageroptimizer.modules;
|
package me.xginko.villageroptimizer.modules;
|
||||||
|
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import me.xginko.villageroptimizer.config.Config;
|
import me.xginko.villageroptimizer.config.Config;
|
||||||
import me.xginko.villageroptimizer.WrappedVillager;
|
import me.xginko.villageroptimizer.WrappedVillager;
|
||||||
import me.xginko.villageroptimizer.utils.CommonUtils;
|
import me.xginko.villageroptimizer.utils.CommonUtils;
|
||||||
@ -20,14 +20,14 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
public class LevelVillagers implements VillagerOptimizerModule, Listener {
|
public class LevelVillagers implements VillagerOptimizerModule, Listener {
|
||||||
|
|
||||||
private final VillagerOptimizer plugin;
|
private final VillagerOptimizer plugin;
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
private final boolean shouldNotify;
|
private final boolean shouldNotify;
|
||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
|
|
||||||
public LevelVillagers() {
|
public LevelVillagers() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
this.plugin = VillagerOptimizer.getInstance();
|
this.plugin = VillagerOptimizer.getInstance();
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("gameplay.villager-leveling.enable", """
|
config.addComment("gameplay.villager-leveling.enable", """
|
||||||
This is needed to allow optimized villagers to level up.\s
|
This is needed to allow optimized villagers to level up.\s
|
||||||
@ -61,7 +61,7 @@ public class LevelVillagers implements VillagerOptimizerModule, Listener {
|
|||||||
event.getInventory().getType().equals(InventoryType.MERCHANT)
|
event.getInventory().getType().equals(InventoryType.MERCHANT)
|
||||||
&& event.getInventory().getHolder() instanceof Villager villager
|
&& event.getInventory().getHolder() instanceof Villager villager
|
||||||
) {
|
) {
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd(villager);
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
if (!wVillager.isOptimized()) return;
|
if (!wVillager.isOptimized()) return;
|
||||||
|
|
||||||
if (wVillager.canLevelUp(cooldown)) {
|
if (wVillager.canLevelUp(cooldown)) {
|
||||||
|
@ -2,7 +2,7 @@ package me.xginko.villageroptimizer.modules;
|
|||||||
|
|
||||||
import io.papermc.paper.event.player.PlayerNameEntityEvent;
|
import io.papermc.paper.event.player.PlayerNameEntityEvent;
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import me.xginko.villageroptimizer.config.Config;
|
import me.xginko.villageroptimizer.config.Config;
|
||||||
import me.xginko.villageroptimizer.enums.OptimizationType;
|
import me.xginko.villageroptimizer.enums.OptimizationType;
|
||||||
import me.xginko.villageroptimizer.enums.Permissions;
|
import me.xginko.villageroptimizer.enums.Permissions;
|
||||||
@ -26,14 +26,14 @@ import java.util.List;
|
|||||||
|
|
||||||
public class NametagOptimization implements VillagerOptimizerModule, Listener {
|
public class NametagOptimization implements VillagerOptimizerModule, Listener {
|
||||||
|
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
private final HashSet<String> nametags = new HashSet<>(4);
|
private final HashSet<String> nametags = new HashSet<>(4);
|
||||||
private final boolean shouldLog, shouldNotifyPlayer, consumeNametag;
|
private final boolean shouldLog, shouldNotifyPlayer, consumeNametag;
|
||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
|
|
||||||
protected NametagOptimization() {
|
protected NametagOptimization() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization-methods.nametag-optimization.enable", """
|
config.addComment("optimization-methods.nametag-optimization.enable", """
|
||||||
Enable optimization by naming villagers to one of the names configured below.\s
|
Enable optimization by naming villagers to one of the names configured below.\s
|
||||||
@ -75,7 +75,7 @@ public class NametagOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
if (name == null) return;
|
if (name == null) return;
|
||||||
|
|
||||||
final String nameTag = PlainTextComponentSerializer.plainText().serialize(name);
|
final String nameTag = PlainTextComponentSerializer.plainText().serialize(name);
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd((Villager) event.getEntity());
|
WrappedVillager wVillager = villagerCache.getOrAdd((Villager) event.getEntity());
|
||||||
|
|
||||||
if (nametags.contains(nameTag.toLowerCase())) {
|
if (nametags.contains(nameTag.toLowerCase())) {
|
||||||
if (wVillager.isOptimized()) return;
|
if (wVillager.isOptimized()) return;
|
||||||
@ -104,7 +104,7 @@ public class NametagOptimization implements VillagerOptimizerModule, Listener {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (wVillager.getOptimizationType().equals(OptimizationType.NAMETAG)) {
|
if (wVillager.getOptimizationType().equals(OptimizationType.NAMETAG)) {
|
||||||
wVillager.setOptimization(OptimizationType.OFF);
|
wVillager.setOptimization(OptimizationType.NONE);
|
||||||
if (shouldNotifyPlayer)
|
if (shouldNotifyPlayer)
|
||||||
VillagerOptimizer.getLang(player.locale()).nametag_unoptimize_success.forEach(player::sendMessage);
|
VillagerOptimizer.getLang(player.locale()).nametag_unoptimize_success.forEach(player::sendMessage);
|
||||||
if (shouldLog)
|
if (shouldLog)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.xginko.villageroptimizer.modules;
|
package me.xginko.villageroptimizer.modules;
|
||||||
|
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
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 org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -16,12 +16,12 @@ import org.bukkit.event.inventory.TradeSelectEvent;
|
|||||||
|
|
||||||
public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Listener {
|
public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Listener {
|
||||||
|
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
private final boolean notifyPlayer;
|
private final boolean notifyPlayer;
|
||||||
|
|
||||||
protected PreventUnoptimizedTrading() {
|
protected PreventUnoptimizedTrading() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("gameplay.prevent-trading-with-unoptimized.enable", """
|
config.addComment("gameplay.prevent-trading-with-unoptimized.enable", """
|
||||||
Will prevent players from selecting and using trades of unoptimized villagers.\s
|
Will prevent players from selecting and using trades of unoptimized villagers.\s
|
||||||
@ -54,7 +54,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste
|
|||||||
if (
|
if (
|
||||||
event.getInventory().getType().equals(InventoryType.MERCHANT)
|
event.getInventory().getType().equals(InventoryType.MERCHANT)
|
||||||
&& event.getInventory().getHolder() instanceof Villager villager
|
&& event.getInventory().getHolder() instanceof Villager villager
|
||||||
&& !cachedVillagers.getOrAdd(villager).isOptimized()
|
&& !villagerCache.getOrAdd(villager).isOptimized()
|
||||||
) {
|
) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (notifyPlayer)
|
if (notifyPlayer)
|
||||||
@ -69,7 +69,7 @@ public class PreventUnoptimizedTrading implements VillagerOptimizerModule, Liste
|
|||||||
if (
|
if (
|
||||||
event.getInventory().getType().equals(InventoryType.MERCHANT)
|
event.getInventory().getType().equals(InventoryType.MERCHANT)
|
||||||
&& event.getInventory().getHolder() instanceof Villager villager
|
&& event.getInventory().getHolder() instanceof Villager villager
|
||||||
&& !cachedVillagers.getOrAdd(villager).isOptimized()
|
&& !villagerCache.getOrAdd(villager).isOptimized()
|
||||||
) {
|
) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (notifyPlayer)
|
if (notifyPlayer)
|
||||||
|
@ -2,7 +2,7 @@ package me.xginko.villageroptimizer.modules;
|
|||||||
|
|
||||||
import io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent;
|
import io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent;
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import me.xginko.villageroptimizer.config.Config;
|
import me.xginko.villageroptimizer.config.Config;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -17,12 +17,12 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
|||||||
|
|
||||||
public class PreventVillagerDamage implements VillagerOptimizerModule, Listener {
|
public class PreventVillagerDamage implements VillagerOptimizerModule, Listener {
|
||||||
|
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
private final boolean block, player, mob, other, push;
|
private final boolean block, player, mob, other, push;
|
||||||
|
|
||||||
protected PreventVillagerDamage() {
|
protected PreventVillagerDamage() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("gameplay.prevent-damage.enable",
|
config.addComment("gameplay.prevent-damage.enable",
|
||||||
"Configure what kind of damage you want to cancel for optimized villagers here.");
|
"Configure what kind of damage you want to cancel for optimized villagers here.");
|
||||||
@ -58,7 +58,7 @@ public class PreventVillagerDamage implements VillagerOptimizerModule, Listener
|
|||||||
private void onDamageReceive(EntityDamageByEntityEvent event) {
|
private void onDamageReceive(EntityDamageByEntityEvent event) {
|
||||||
if (
|
if (
|
||||||
event.getEntityType().equals(EntityType.VILLAGER)
|
event.getEntityType().equals(EntityType.VILLAGER)
|
||||||
&& cachedVillagers.getOrAdd((Villager) event.getEntity()).isOptimized()
|
&& villagerCache.getOrAdd((Villager) event.getEntity()).isOptimized()
|
||||||
) {
|
) {
|
||||||
Entity damager = event.getDamager();
|
Entity damager = event.getDamager();
|
||||||
if (damager.getType().equals(EntityType.PLAYER)) {
|
if (damager.getType().equals(EntityType.PLAYER)) {
|
||||||
@ -82,7 +82,7 @@ public class PreventVillagerDamage implements VillagerOptimizerModule, Listener
|
|||||||
if (
|
if (
|
||||||
block
|
block
|
||||||
&& event.getEntityType().equals(EntityType.VILLAGER)
|
&& event.getEntityType().equals(EntityType.VILLAGER)
|
||||||
&& cachedVillagers.getOrAdd((Villager) event.getEntity()).isOptimized()
|
&& villagerCache.getOrAdd((Villager) event.getEntity()).isOptimized()
|
||||||
) {
|
) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ public class PreventVillagerDamage implements VillagerOptimizerModule, Listener
|
|||||||
if (
|
if (
|
||||||
push
|
push
|
||||||
&& event.getEntityType().equals(EntityType.VILLAGER)
|
&& event.getEntityType().equals(EntityType.VILLAGER)
|
||||||
&& cachedVillagers.getOrAdd((Villager) event.getEntity()).isOptimized()
|
&& villagerCache.getOrAdd((Villager) event.getEntity()).isOptimized()
|
||||||
) {
|
) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package me.xginko.villageroptimizer.modules;
|
|||||||
|
|
||||||
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
|
import com.destroystokyo.paper.event.entity.EntityPathfindEvent;
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Mob;
|
import org.bukkit.entity.Mob;
|
||||||
@ -16,10 +16,10 @@ import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
|||||||
|
|
||||||
public class PreventVillagerTargetting implements VillagerOptimizerModule, Listener {
|
public class PreventVillagerTargetting implements VillagerOptimizerModule, Listener {
|
||||||
|
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
|
|
||||||
protected PreventVillagerTargetting() {
|
protected PreventVillagerTargetting() {
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,7 +46,7 @@ public class PreventVillagerTargetting implements VillagerOptimizerModule, Liste
|
|||||||
if (
|
if (
|
||||||
target != null
|
target != null
|
||||||
&& target.getType().equals(EntityType.VILLAGER)
|
&& target.getType().equals(EntityType.VILLAGER)
|
||||||
&& cachedVillagers.getOrAdd((Villager) target).isOptimized()
|
&& villagerCache.getOrAdd((Villager) target).isOptimized()
|
||||||
) {
|
) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ public class PreventVillagerTargetting implements VillagerOptimizerModule, Liste
|
|||||||
if (
|
if (
|
||||||
target != null
|
target != null
|
||||||
&& target.getType().equals(EntityType.VILLAGER)
|
&& target.getType().equals(EntityType.VILLAGER)
|
||||||
&& cachedVillagers.getOrAdd((Villager) target).isOptimized()
|
&& villagerCache.getOrAdd((Villager) target).isOptimized()
|
||||||
) {
|
) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ public class PreventVillagerTargetting implements VillagerOptimizerModule, Liste
|
|||||||
if (
|
if (
|
||||||
event.getEntityType().equals(EntityType.VILLAGER)
|
event.getEntityType().equals(EntityType.VILLAGER)
|
||||||
&& event.getDamager() instanceof Mob attacker
|
&& event.getDamager() instanceof Mob attacker
|
||||||
&& cachedVillagers.getOrAdd((Villager) event.getEntity()).isOptimized()
|
&& villagerCache.getOrAdd((Villager) event.getEntity()).isOptimized()
|
||||||
) {
|
) {
|
||||||
attacker.setTarget(null);
|
attacker.setTarget(null);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.xginko.villageroptimizer.modules;
|
package me.xginko.villageroptimizer.modules;
|
||||||
|
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
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.WrappedVillager;
|
import me.xginko.villageroptimizer.WrappedVillager;
|
||||||
@ -22,13 +22,13 @@ public class RestockTrades implements VillagerOptimizerModule, Listener {
|
|||||||
* TODO: Disable notify message for cooldown bypassers
|
* TODO: Disable notify message for cooldown bypassers
|
||||||
* */
|
* */
|
||||||
|
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
private final long restock_delay_millis;
|
private final long restock_delay_millis;
|
||||||
private final boolean shouldLog, notifyPlayer;
|
private final boolean shouldLog, notifyPlayer;
|
||||||
|
|
||||||
protected RestockTrades() {
|
protected RestockTrades() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("gameplay.trade-restocking.enable", """
|
config.addComment("gameplay.trade-restocking.enable", """
|
||||||
This is for automatic restocking of trades for optimized villagers. Optimized Villagers\s
|
This is for automatic restocking of trades for optimized villagers. Optimized Villagers\s
|
||||||
@ -60,7 +60,7 @@ public class RestockTrades implements VillagerOptimizerModule, Listener {
|
|||||||
private void onInteract(PlayerInteractEntityEvent event) {
|
private void onInteract(PlayerInteractEntityEvent event) {
|
||||||
if (!event.getRightClicked().getType().equals(EntityType.VILLAGER)) return;
|
if (!event.getRightClicked().getType().equals(EntityType.VILLAGER)) return;
|
||||||
|
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd((Villager) event.getRightClicked());
|
WrappedVillager wVillager = villagerCache.getOrAdd((Villager) event.getRightClicked());
|
||||||
if (!wVillager.isOptimized()) return;
|
if (!wVillager.isOptimized()) return;
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package me.xginko.villageroptimizer.modules;
|
|||||||
|
|
||||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import me.xginko.villageroptimizer.config.Config;
|
import me.xginko.villageroptimizer.config.Config;
|
||||||
import me.xginko.villageroptimizer.utils.LogUtils;
|
import me.xginko.villageroptimizer.utils.LogUtils;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -28,7 +28,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
|||||||
* */
|
* */
|
||||||
|
|
||||||
private final VillagerOptimizer plugin;
|
private final VillagerOptimizer plugin;
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
private ScheduledTask scheduledTask;
|
private ScheduledTask scheduledTask;
|
||||||
private final List<Villager.Profession> removalPriority = new ArrayList<>(16);
|
private final List<Villager.Profession> removalPriority = new ArrayList<>(16);
|
||||||
private final int global_max_villagers_per_chunk, max_unoptimized_per_chunk, max_optimized_per_chunk;
|
private final int global_max_villagers_per_chunk, max_unoptimized_per_chunk, max_optimized_per_chunk;
|
||||||
@ -38,7 +38,7 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
|||||||
protected VillagerChunkLimit() {
|
protected VillagerChunkLimit() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
this.plugin = VillagerOptimizer.getInstance();
|
this.plugin = VillagerOptimizer.getInstance();
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("villager-chunk-limit.enable", """
|
config.addComment("villager-chunk-limit.enable", """
|
||||||
Checks chunks for too many villagers and removes excess villagers based on priority.\s
|
Checks chunks for too many villagers and removes excess villagers based on priority.\s
|
||||||
@ -137,6 +137,6 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
|||||||
|
|
||||||
private int getProfessionPriority(Villager villager) {
|
private int getProfessionPriority(Villager villager) {
|
||||||
final Villager.Profession profession = villager.getProfession();
|
final Villager.Profession profession = villager.getProfession();
|
||||||
return removalPriority.contains(profession) && !cachedVillagers.getOrAdd(villager).isOptimized() ? removalPriority.indexOf(profession) : Integer.MAX_VALUE;
|
return removalPriority.contains(profession) && !villagerCache.getOrAdd(villager).isOptimized() ? removalPriority.indexOf(profession) : Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.xginko.villageroptimizer.modules;
|
package me.xginko.villageroptimizer.modules;
|
||||||
|
|
||||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||||
import me.xginko.villageroptimizer.CachedVillagers;
|
import me.xginko.villageroptimizer.VillagerCache;
|
||||||
import me.xginko.villageroptimizer.config.Config;
|
import me.xginko.villageroptimizer.config.Config;
|
||||||
import me.xginko.villageroptimizer.enums.OptimizationType;
|
import me.xginko.villageroptimizer.enums.OptimizationType;
|
||||||
import me.xginko.villageroptimizer.enums.Permissions;
|
import me.xginko.villageroptimizer.enums.Permissions;
|
||||||
@ -31,7 +31,7 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
* TODO: Make placed workstation villager profession related.
|
* TODO: Make placed workstation villager profession related.
|
||||||
* */
|
* */
|
||||||
|
|
||||||
private final CachedVillagers cachedVillagers;
|
private final VillagerCache villagerCache;
|
||||||
private final HashSet<Material> workstations_that_disable = new HashSet<>(14);
|
private final HashSet<Material> workstations_that_disable = new HashSet<>(14);
|
||||||
private final boolean shouldLog, shouldNotifyPlayer;
|
private final boolean shouldLog, shouldNotifyPlayer;
|
||||||
private final long cooldown;
|
private final long cooldown;
|
||||||
@ -39,7 +39,7 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
|
|
||||||
protected WorkstationOptimization() {
|
protected WorkstationOptimization() {
|
||||||
shouldEnable();
|
shouldEnable();
|
||||||
this.cachedVillagers = VillagerOptimizer.getCachedVillagers();
|
this.villagerCache = VillagerOptimizer.getCache();
|
||||||
Config config = VillagerOptimizer.getConfiguration();
|
Config config = VillagerOptimizer.getConfiguration();
|
||||||
config.addComment("optimization-methods.workstation-optimization.enable", """
|
config.addComment("optimization-methods.workstation-optimization.enable", """
|
||||||
When enabled, villagers near a configured radius to a workstation specific to your config\s
|
When enabled, villagers near a configured radius to a workstation specific to your config\s
|
||||||
@ -100,12 +100,12 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
final Villager.Profession profession = villager.getProfession();
|
final Villager.Profession profession = villager.getProfession();
|
||||||
if (profession.equals(Villager.Profession.NONE) || profession.equals(Villager.Profession.NITWIT)) continue;
|
if (profession.equals(Villager.Profession.NONE) || profession.equals(Villager.Profession.NITWIT)) continue;
|
||||||
|
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd(villager);
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
final double distance = entity.getLocation().distance(workstationLoc);
|
final double distance = entity.getLocation().distance(workstationLoc);
|
||||||
|
|
||||||
if (distance < closestDistance) {
|
if (distance < closestDistance) {
|
||||||
final OptimizationType type = wVillager.getOptimizationType();
|
final OptimizationType type = wVillager.getOptimizationType();
|
||||||
if (type.equals(OptimizationType.OFF) || type.equals(OptimizationType.COMMAND)) {
|
if (type.equals(OptimizationType.NONE) || type.equals(OptimizationType.COMMAND)) {
|
||||||
closestOptimizableVillager = wVillager;
|
closestOptimizableVillager = wVillager;
|
||||||
closestDistance = distance;
|
closestDistance = distance;
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
||||||
Villager villager = (Villager) entity;
|
Villager villager = (Villager) entity;
|
||||||
|
|
||||||
WrappedVillager wVillager = cachedVillagers.getOrAdd(villager);
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
final double distance = entity.getLocation().distance(workstationLoc);
|
final double distance = entity.getLocation().distance(workstationLoc);
|
||||||
|
|
||||||
if (distance < closestDistance) {
|
if (distance < closestDistance) {
|
||||||
@ -166,7 +166,7 @@ public class WorkstationOptimization implements VillagerOptimizerModule, Listene
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (closestOptimizedVillager != null) {
|
if (closestOptimizedVillager != null) {
|
||||||
closestOptimizedVillager.setOptimization(OptimizationType.OFF);
|
closestOptimizedVillager.setOptimization(OptimizationType.NONE);
|
||||||
if (shouldNotifyPlayer) {
|
if (shouldNotifyPlayer) {
|
||||||
final String villagerType = closestOptimizedVillager.villager().getProfession().toString().toLowerCase();
|
final String villagerType = closestOptimizedVillager.villager().getProfession().toString().toLowerCase();
|
||||||
final String workstation = placed.getType().toString().toLowerCase();
|
final String workstation = placed.getType().toString().toLowerCase();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user