mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-15 10:25:15 +01:00
Finish addons v1 and add AddonLogger
This commit is contained in:
parent
7f9d14aaf3
commit
4cd3ec5505
@ -24,6 +24,7 @@
|
||||
|
||||
package com.dre.brewery;
|
||||
|
||||
import com.dre.brewery.api.addons.AddonManager;
|
||||
import com.dre.brewery.commands.CommandManager;
|
||||
|
||||
import com.dre.brewery.commands.CommandUtil;
|
||||
@ -57,6 +58,8 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BreweryPlugin extends JavaPlugin {
|
||||
AddonManager addonManager = new AddonManager(this);
|
||||
|
||||
public static BreweryPlugin breweryPlugin;
|
||||
public static boolean debug;
|
||||
public static boolean useUUID;
|
||||
@ -178,11 +181,14 @@ public class BreweryPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addonManager.loadAddons();
|
||||
this.log(this.getDescription().getName() + " enabled!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
addonManager.unloadAddons();
|
||||
|
||||
// Disable listeners
|
||||
HandlerList.unregisterAll(this);
|
||||
|
@ -5,9 +5,11 @@ import com.dre.brewery.BreweryPlugin;
|
||||
public abstract class Addon {
|
||||
|
||||
protected final BreweryPlugin plugin;
|
||||
protected final AddonLogger logger;
|
||||
|
||||
public Addon(BreweryPlugin plugin) {
|
||||
public Addon(BreweryPlugin plugin, AddonLogger logger) {
|
||||
this.plugin = plugin;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void onAddonEnable() {
|
||||
|
25
src/com/dre/brewery/api/addons/AddonLogger.java
Normal file
25
src/com/dre/brewery/api/addons/AddonLogger.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.dre.brewery.api.addons;
|
||||
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class AddonLogger {
|
||||
|
||||
private final String prefix;
|
||||
|
||||
public AddonLogger(Class<? extends Addon> addonUninstantiated) {
|
||||
this.prefix = "[BreweryAddon: " + addonUninstantiated.getSimpleName() + "] ";
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage(BUtil.color(prefix + message));
|
||||
}
|
||||
|
||||
public void warning(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage(BUtil.color("&e" + prefix + message));
|
||||
}
|
||||
|
||||
public void severe(String message) {
|
||||
Bukkit.getConsoleSender().sendMessage(BUtil.color("&c" + prefix + message));
|
||||
}
|
||||
}
|
@ -31,6 +31,14 @@ public class AddonManager {
|
||||
|
||||
public void loadAddons() {
|
||||
addons = getAllAddonClasses();
|
||||
plugin.getLogger().info("Loaded " + addons.size() + " addons");
|
||||
}
|
||||
|
||||
public void unloadAddons() {
|
||||
for (Addon addon : addons) {
|
||||
addon.onAddonDisable();
|
||||
}
|
||||
addons = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,7 +58,7 @@ public class AddonManager {
|
||||
for (CompletableFuture<Class<? extends Addon>> addonClass : addonClasses) {
|
||||
addonClass.thenAccept(clazz -> {
|
||||
try {
|
||||
Addon addon = clazz.getConstructor(BreweryPlugin.class).newInstance(plugin);
|
||||
Addon addon = clazz.getConstructor(BreweryPlugin.class, AddonLogger.class).newInstance(plugin, new AddonLogger(clazz));
|
||||
addon.onAddonEnable();
|
||||
addons.add(addon);
|
||||
} catch (Exception e) {
|
||||
|
Loading…
Reference in New Issue
Block a user