more hologram stuff

This commit is contained in:
Brianna 2019-08-22 01:43:26 -04:00
parent 95288fd8b0
commit a5a855787d
2 changed files with 11 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import com.songoda.core.library.hologram.holograms.Hologram;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.*;
@ -15,15 +16,17 @@ public class HologramManager {
/**
* Load all supported hologram plugins. <br />
* Note: This method should be called in your plugin's onEnable() section
*
* @param javaPlugin the plugin owning the holograms
*/
public static void load() {
public static void load(JavaPlugin javaPlugin) {
if (!registeredHolograms.isEmpty()) return;
PluginManager pluginManager = Bukkit.getPluginManager();
for (HologramType type : HologramType.values()) {
if (pluginManager.isPluginEnabled(type.plugin)) {
Hologram holo = type.getInstance();
Hologram holo = type.getInstance(javaPlugin);
registeredHolograms.put(type, holo);
if (defaultHolo == null)
defaultHolo = holo;

View File

@ -1,18 +1,16 @@
package com.songoda.core.library.hologram;
import com.songoda.core.library.economy.economies.Economy;
import com.songoda.core.library.economy.economies.PlayerPointsEconomy;
import com.songoda.core.library.economy.economies.ReserveEconomy;
import com.songoda.core.library.economy.economies.VaultEconomy;
import com.songoda.core.library.hologram.holograms.Hologram;
import com.songoda.core.library.hologram.holograms.HolographicDisplaysHologram;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
public enum HologramType {
VAULT("HolographicDisplays", HolographicDisplaysHologram.class);
HOLOGRAPHIC_DISPLAYS("HolographicDisplays", HolographicDisplaysHologram.class);
public final String plugin;
protected final Class managerClass;
@ -22,10 +20,10 @@ public enum HologramType {
this.managerClass = managerClass;
}
protected Hologram getInstance() {
protected Hologram getInstance(JavaPlugin javaPlugin) {
try {
return (Hologram) managerClass.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
return (Hologram) managerClass.getDeclaredConstructor(JavaPlugin.class).newInstance(javaPlugin);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Unexpected Error while creating a new Hologram Manager for " + name(), ex);
}
return null;