Implement logger
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-10-22 00:14:33 +02:00
parent a45b487868
commit a3b4b9ca98
3 changed files with 47 additions and 5 deletions

View File

@ -4,17 +4,19 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import wtf.beatrice.nounspicker.objects.PAPIManager;
import java.util.logging.Level;
import wtf.beatrice.nounspicker.utils.ConsoleLogger;
public class NounsPicker extends JavaPlugin
{
private static NounsPicker instance;
private PluginManager pluginManager;
private final ConsoleLogger logger = new ConsoleLogger(getClass());
@Override
public void onEnable()
{
logger.log("Loading plugin!");
pluginManager = getServer().getPluginManager();
instance = this;
@ -22,11 +24,14 @@ public class NounsPicker extends JavaPlugin
// register PlaceholderAPI
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PAPIManager(this).register();
logger.log("PlaceholderAPI integration loaded!");
} else {
logger.err("Missing PlaceholderAPI! The plugin cannot continue.");
pluginManager.disablePlugin(this);
return;
}
logger.log("Plugin loaded!");
}
public static NounsPicker getInstance()

View File

@ -0,0 +1,37 @@
package wtf.beatrice.nounspicker.utils;
import org.bukkit.Bukkit;
import wtf.beatrice.nounspicker.NounsPicker;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ConsoleLogger
{
private final String className;
private final Logger logger;
private final String format = "[%class%] %msg%";
public ConsoleLogger(Class callingClass)
{
className = callingClass.getSimpleName();
logger = Bukkit.getServer().getLogger();
}
public void log(String msg)
{
print(Level.INFO, msg);
}
public void err(String msg)
{
print(Level.SEVERE, msg);
}
private void print(Level lvl, String msg)
{
String message = format.replace("%msg%", msg)
.replace("%class%", className);
logger.log(lvl, message);
}
}

View File

@ -3,7 +3,7 @@ version: 1.0
author: astro_bea
main: wtf.beatrice.nounspicker.NounsPicker
api-version: 1.19
depend:
softdepend:
- PlaceholderAPI
commands: