improve logging
This commit is contained in:
parent
ed285be593
commit
73eecd3f7f
@ -6,8 +6,9 @@ import me.xginko.villageroptimizer.VillagerCache;
|
||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||
import me.xginko.villageroptimizer.config.Config;
|
||||
import me.xginko.villageroptimizer.utils.CommonUtil;
|
||||
import me.xginko.villageroptimizer.utils.LogUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -20,9 +21,11 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
||||
|
||||
@ -61,9 +64,9 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
||||
try {
|
||||
return Villager.Profession.valueOf(configuredProfession);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LogUtil.moduleLog(Level.WARN, "villager-chunk-limit.unoptimized",
|
||||
"Villager profession '"+configuredProfession+"' not recognized. " +
|
||||
"Make sure you're using the correct profession enums from https://jd.papermc.io/paper/1.20/org/bukkit/entity/Villager.Profession.html.");
|
||||
VillagerOptimizer.getLog().warn("(villager-chunk-limit.unoptimized) Villager profession '"+configuredProfession +
|
||||
"' not recognized. Make sure you're using the correct profession enums from " +
|
||||
"https://jd.papermc.io/paper/1.20/org/bukkit/entity/Villager.Profession.html.");
|
||||
return null;
|
||||
}
|
||||
}).filter(Objects::nonNull).toList();
|
||||
@ -76,9 +79,9 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
||||
try {
|
||||
return Villager.Profession.valueOf(configuredProfession);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LogUtil.moduleLog(Level.WARN, "villager-chunk-limit.optimized",
|
||||
"Villager profession '"+configuredProfession+"' not recognized. " +
|
||||
"Make sure you're using the correct profession enums from https://jd.papermc.io/paper/1.20/org/bukkit/entity/Villager.Profession.html.");
|
||||
VillagerOptimizer.getLog().warn("(villager-chunk-limit.optimized) Villager profession '"+configuredProfession +
|
||||
"' not recognized. Make sure you're using the correct profession enums from " +
|
||||
"https://jd.papermc.io/paper/1.20/org/bukkit/entity/Villager.Profession.html.");
|
||||
return null;
|
||||
}
|
||||
}).filter(Objects::nonNull).toList();
|
||||
@ -154,9 +157,13 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
||||
Villager villager = not_optimized_villagers.get(i);
|
||||
scheduler.runAtEntity(villager, kill -> {
|
||||
villager.remove();
|
||||
if (log_enabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit",
|
||||
"Removed unoptimized villager of profession type '" + villager.getProfession().name()
|
||||
+ "' at " + villager.getLocation());
|
||||
if (log_enabled) {
|
||||
final Location location = villager.getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(
|
||||
"Removed unoptimized villager with profession '" + villager.getProfession().name() + "' at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -174,9 +181,14 @@ public class VillagerChunkLimit implements VillagerOptimizerModule, Listener {
|
||||
Villager villager = optimized_villagers.get(i);
|
||||
scheduler.runAtEntity(villager, kill -> {
|
||||
villager.remove();
|
||||
if (log_enabled) LogUtil.moduleLog(Level.INFO, "villager-chunk-limit",
|
||||
"Removed optimized villager of profession type '" + villager.getProfession().name()
|
||||
+ "' at " + villager.getLocation());
|
||||
|
||||
if (log_enabled) {
|
||||
final Location location = villager.getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(
|
||||
"Removed optimized villager with profession '" + villager.getProfession().name() + "' at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import me.xginko.villageroptimizer.VillagerCache;
|
||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||
import me.xginko.villageroptimizer.config.Config;
|
||||
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -21,7 +23,7 @@ public class EnableLeashingVillagers implements VillagerOptimizerModule, Listene
|
||||
|
||||
private final ServerImplementation scheduler;
|
||||
private final VillagerCache villagerCache;
|
||||
private final boolean only_optimized;
|
||||
private final boolean only_optimized, log_enabled;
|
||||
|
||||
public EnableLeashingVillagers() {
|
||||
shouldEnable();
|
||||
@ -32,6 +34,7 @@ public class EnableLeashingVillagers implements VillagerOptimizerModule, Listene
|
||||
Enable leashing of villagers, enabling players to easily move villagers to where they want them to be.""");
|
||||
this.only_optimized = config.getBoolean("gameplay.villagers-can-be-leashed.only-optimized", false,
|
||||
"If set to true, only optimized villagers can be leashed.");
|
||||
this.log_enabled = config.getBoolean("gameplay.villagers-can-be-leashed.log", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,8 +67,16 @@ public class EnableLeashingVillagers implements VillagerOptimizerModule, Listene
|
||||
if (villager.isLeashed()) {
|
||||
// If leash holder clicked leashed villager, unleash.
|
||||
try {
|
||||
if (villager.getLeashHolder().getUniqueId().equals(player.getUniqueId()))
|
||||
villager.setLeashHolder(null);
|
||||
if (
|
||||
villager.getLeashHolder().getUniqueId().equals(player.getUniqueId())
|
||||
&& villager.setLeashHolder(null)
|
||||
&& log_enabled
|
||||
) {
|
||||
final Location location = villager.getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(player.getName() + " leashed a villager at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
} catch (IllegalStateException ignored) {} // Shouldn't throw because we checked LivingEntity#isLeashed()
|
||||
// Otherwise do nothing. There should only ever be one leash holder
|
||||
return;
|
||||
@ -86,5 +97,12 @@ public class EnableLeashingVillagers implements VillagerOptimizerModule, Listene
|
||||
|
||||
// Legitimate to not use entities from the event object since they are final in PlayerLeashEntityEvent
|
||||
scheduler.runAtEntity(villager, leash -> villager.setLeashHolder(player));
|
||||
|
||||
if (log_enabled) {
|
||||
final Location location = villager.getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(player.getName() + " leashed a villager at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import me.xginko.villageroptimizer.VillagerCache;
|
||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||
import me.xginko.villageroptimizer.config.Config;
|
||||
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
||||
import me.xginko.villageroptimizer.utils.LogUtil;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -43,7 +42,9 @@ public class PreventOptimizedDamage implements VillagerOptimizerModule, Listener
|
||||
try {
|
||||
return EntityDamageEvent.DamageCause.valueOf(configuredDamageCause);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LogUtil.damageCauseNotRecognized("prevent-damage-to-optimized", configuredDamageCause);
|
||||
VillagerOptimizer.getLog().warn("(prevent-damage-to-optimized) DamageCause '"+configuredDamageCause +
|
||||
"' not recognized. Please use correct DamageCause enums from: " +
|
||||
"https://jd.papermc.io/paper/1.20/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html");
|
||||
return null;
|
||||
}
|
||||
}).filter(Objects::nonNull).collect(Collectors.toCollection(HashSet::new));
|
||||
|
@ -7,7 +7,9 @@ import me.xginko.villageroptimizer.enums.permissions.Bypass;
|
||||
import me.xginko.villageroptimizer.WrappedVillager;
|
||||
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
||||
import me.xginko.villageroptimizer.utils.CommonUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
@ -73,8 +75,12 @@ public class RestockOptimizedTrades implements VillagerOptimizerModule, Listener
|
||||
.build();
|
||||
VillagerOptimizer.getLang(player.locale()).trades_restocked.forEach(line -> player.sendMessage(line.replaceText(timeLeft)));
|
||||
}
|
||||
if (log_enabled)
|
||||
VillagerOptimizer.getLog().info("Restocked optimized villager at "+ wVillager.villager().getLocation());
|
||||
if (log_enabled) {
|
||||
final Location location = wVillager.villager().getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text("Restocked optimized villager at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import me.xginko.villageroptimizer.events.VillagerOptimizeEvent;
|
||||
import me.xginko.villageroptimizer.events.VillagerUnoptimizeEvent;
|
||||
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
||||
import me.xginko.villageroptimizer.utils.CommonUtil;
|
||||
import me.xginko.villageroptimizer.utils.LogUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -56,7 +56,9 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
|
||||
try {
|
||||
return Material.valueOf(configuredMaterial);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LogUtil.materialNotRecognized("block-optimization", configuredMaterial);
|
||||
VillagerOptimizer.getLog().warn("(block-optimization) Material '"+configuredMaterial +
|
||||
"' not recognized. Please use correct Material enums from: " +
|
||||
"https://jd.papermc.io/paper/1.20/org/bukkit/Material.html");
|
||||
return null;
|
||||
}
|
||||
}).filter(Objects::nonNull).collect(Collectors.toCollection(HashSet::new));
|
||||
@ -140,8 +142,12 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
|
||||
.replaceText(placedMaterial)
|
||||
));
|
||||
}
|
||||
if (log_enabled)
|
||||
VillagerOptimizer.getLog().info("Villager was optimized by block at "+closestOptimizableVillager.villager().getLocation());
|
||||
if (log_enabled) {
|
||||
final Location location = closestOptimizableVillager.villager().getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(player.getName() + " optimized villager by block at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
} else {
|
||||
CommonUtil.shakeHead(closestOptimizableVillager.villager());
|
||||
if (notify_player) {
|
||||
@ -200,7 +206,11 @@ public class OptimizeByBlock implements VillagerOptimizerModule, Listener {
|
||||
.replaceText(brokenMaterial)
|
||||
));
|
||||
}
|
||||
if (log_enabled)
|
||||
VillagerOptimizer.getLog().info("Villager unoptimized because nearby optimization block broken at: "+closestOptimizedVillager.villager().getLocation());
|
||||
if (log_enabled) {
|
||||
final Location location = closestOptimizedVillager.villager().getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(player.getName() + " unoptimized villager by block at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ import me.xginko.villageroptimizer.utils.CommonUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -107,8 +108,13 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener {
|
||||
|
||||
if (notify_player)
|
||||
VillagerOptimizer.getLang(player.locale()).nametag_optimize_success.forEach(player::sendMessage);
|
||||
if (log_enabled)
|
||||
VillagerOptimizer.getLog().info(player.getName() + " optimized a villager using nametag: '" + name + "'");
|
||||
if (log_enabled) {
|
||||
final Location location = wVillager.villager().getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(player.getName() +
|
||||
" optimized villager by nametag '" + name + "' at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
CommonUtil.shakeHead(villager);
|
||||
@ -129,8 +135,13 @@ public class OptimizeByNametag implements VillagerOptimizerModule, Listener {
|
||||
|
||||
if (notify_player)
|
||||
VillagerOptimizer.getLang(player.locale()).nametag_unoptimize_success.forEach(player::sendMessage);
|
||||
if (log_enabled)
|
||||
VillagerOptimizer.getLog().info(event.getPlayer().getName() + " disabled optimizations for a villager using nametag: '" + name + "'");
|
||||
if (log_enabled) {
|
||||
final Location location = wVillager.villager().getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(player.getName() +
|
||||
" unoptimized villager by nametag '" + name + "' at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import me.xginko.villageroptimizer.events.VillagerOptimizeEvent;
|
||||
import me.xginko.villageroptimizer.events.VillagerUnoptimizeEvent;
|
||||
import me.xginko.villageroptimizer.modules.VillagerOptimizerModule;
|
||||
import me.xginko.villageroptimizer.utils.CommonUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@ -159,8 +160,13 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
|
||||
));
|
||||
}
|
||||
|
||||
if (log_enabled) VillagerOptimizer.getLog().info(player.getName() + " optimized a villager using workstation: '" +
|
||||
placed.getType().toString().toLowerCase() + "'");
|
||||
if (log_enabled) {
|
||||
final Location location = finalToOptimize.villager().getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(player.getName() +
|
||||
" optimized villager by workstation (" + placed.getType().toString().toLowerCase() + ") at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
}, toOptimize.canLooseProfession() ? resettable_delay_millis : delay_millis, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@ -216,7 +222,13 @@ public class OptimizeByWorkstation implements VillagerOptimizerModule, Listener
|
||||
.replaceText(brokenWorkstation)
|
||||
));
|
||||
}
|
||||
if (log_enabled)
|
||||
VillagerOptimizer.getLog().info(player.getName() + " unoptimized a villager by breaking workstation: '" + broken.getType().toString().toLowerCase() + "'");
|
||||
|
||||
if (log_enabled) {
|
||||
final Location location = closestOptimizedVillager.villager().getLocation();
|
||||
VillagerOptimizer.getLog().info(Component.text(player.getName() +
|
||||
" unoptimized villager by workstation (" + broken.getType().toString().toLowerCase() + ") at " +
|
||||
"x=" + location.getX() + ", y=" + location.getY() + ", z=" + location.getZ() +
|
||||
" in world " + location.getWorld().getName()).style(VillagerOptimizer.plugin_style));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package me.xginko.villageroptimizer.utils;
|
||||
|
||||
import me.xginko.villageroptimizer.VillagerOptimizer;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
|
||||
public class LogUtil {
|
||||
|
||||
public static void moduleLog(Level logLevel, String path, String logMessage) {
|
||||
switch (logLevel) { // This is the safest way to do it while staying version compatible
|
||||
case ERROR -> VillagerOptimizer.getLog().error("(" + path + ") " + logMessage);
|
||||
case WARN -> VillagerOptimizer.getLog().warn("(" + path + ") " + logMessage);
|
||||
case INFO -> VillagerOptimizer.getLog().info("(" + path + ") " + logMessage);
|
||||
case DEBUG -> VillagerOptimizer.getLog().debug("(" + path + ") " + logMessage);
|
||||
case TRACE -> VillagerOptimizer.getLog().trace("(" + path + ") " + logMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void materialNotRecognized(String path, String material) {
|
||||
moduleLog(Level.WARN, path, "Material '" + material + "' not recognized. Please use correct Material enums from: " +
|
||||
"https://jd.papermc.io/paper/1.20/org/bukkit/Material.html");
|
||||
}
|
||||
|
||||
public static void damageCauseNotRecognized(String path, String cause) {
|
||||
moduleLog(Level.WARN, path, "DamageCause '" + cause + "' not recognized. Please use correct DamageCause enums from: " +
|
||||
"https://jd.papermc.io/paper/1.20/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html");
|
||||
}
|
||||
|
||||
public static void entityTypeNotRecognized(String path, String entityType) {
|
||||
moduleLog(Level.WARN, path, "EntityType '" + entityType + "' not recognized. Please use correct Spigot EntityType enums for your Minecraft version!");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user