diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/API/MinepacksPlugin.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/API/MinepacksPlugin.java index 66cc7ac..b88fd61 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/API/MinepacksPlugin.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/API/MinepacksPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 GeorgH93 + * Copyright (C) 2016, 2017 GeorgH93 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,13 +19,44 @@ import at.pcgamingfreaks.Version; +import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +@SuppressWarnings("unused") public interface MinepacksPlugin { + /** + * Gets the instance of the minepacks plugin. + * WARNING use this function at your own risk! If the plugin is not installed the MinepacksPlugin class will be unknown! + * + * @return The instance of the minepacks plugin. + */ + static @Nullable MinepacksPlugin getInstance() + { + Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("Minepacks"); + return (plugin != null && plugin instanceof MinepacksPlugin && plugin.isEnabled()) ? (MinepacksPlugin) plugin : null; + } + + /** + * Gets the currently running {@link Version} of the plugin. + * Version 0.0 if plugin is not loaded or enabled. + * + * @return The currently running version of the plugin. + */ + static @NotNull Version getVersion() + { + Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("Minepacks"); + if(plugin != null && plugin instanceof MinepacksPlugin && plugin.isEnabled()) + { + return new Version(plugin.getDescription().getVersion()); + } + return new Version("0.0"); + } + /** * Let a given player open the backpack of an other player. * @@ -36,13 +67,13 @@ public interface MinepacksPlugin void openBackpack(@NotNull final Player opener, @NotNull final OfflinePlayer owner, final boolean editable); /** - * Let a given player open a given {@link at.pcgamingfreaks.Minepacks.Bukkit.Backpack}. + * Let a given player open a given {@link Backpack}. * * @param opener The player who opens the backpack. * @param backpack The backpack to be opened. null will result in an error message for the player. * @param editable Defines if the player who has opened the backpack can change the items inside. */ - void openBackpack(@NotNull final Player opener, @Nullable final at.pcgamingfreaks.Minepacks.Bukkit.Backpack backpack, boolean editable); + void openBackpack(@NotNull final Player opener, @Nullable final Backpack backpack, boolean editable); /** * Retrieves the backpack for a given player. @@ -51,7 +82,7 @@ public interface MinepacksPlugin * @param owner The player who's backpack should be retrieved. * @return The backpack of the given player. */ - @Nullable at.pcgamingfreaks.Minepacks.Bukkit.Backpack getBackpack(@NotNull final OfflinePlayer owner); + @Nullable Backpack getBackpack(@NotNull final OfflinePlayer owner); /** * Retrieves the backpack for a given player. @@ -60,7 +91,7 @@ public interface MinepacksPlugin * @param owner The player who's backpack should be retrieved. * @return The backpack of the given player. null if the backpack is in the cache. */ - @Nullable at.pcgamingfreaks.Minepacks.Bukkit.Backpack getBackpackCachedOnly(@NotNull final OfflinePlayer owner); + @Nullable Backpack getBackpackCachedOnly(@NotNull final OfflinePlayer owner); /** * Retrieves the backpack for a given player. @@ -70,11 +101,4 @@ public interface MinepacksPlugin * @param callback The callback delivering the result of the request. */ void getBackpack(@NotNull final OfflinePlayer owner, @NotNull final Callback callback); - - /** - * Gets the currently running {@link Version} of the plugin. - * - * @return The currently running version of the plugin. - */ - Version getVersion(); } \ No newline at end of file diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/ItemsCollector.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/ItemsCollector.java index 7578da0..4e60bc1 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/ItemsCollector.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/ItemsCollector.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 GeorgH93 + * Copyright (C) 2016, 2017 GeorgH93 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,7 +46,7 @@ public void run() if(player.getInventory().firstEmpty() == -1 && (player.hasPermission("backpack.use") || player.hasPermission("backpack")) && player.hasPermission("backpack.fullpickup")) { // Only check loaded backpacks (loading them would take to much time for a repeating task, the backpack will be loaded async soon enough) - Backpack backpack = plugin.getBackpackCachedOnly(player); + Backpack backpack = (Backpack) plugin.getBackpackCachedOnly(player); if(backpack == null) { continue; diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java index bc407cc..34e376c 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java @@ -22,6 +22,7 @@ import at.pcgamingfreaks.Bukkit.Updater; import at.pcgamingfreaks.Bukkit.Utils; import at.pcgamingfreaks.ConsoleColor; +import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack; import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback; import at.pcgamingfreaks.Minepacks.Bukkit.API.MinepacksPlugin; import at.pcgamingfreaks.Minepacks.Bukkit.Commands.OnCommand; @@ -33,14 +34,12 @@ import at.pcgamingfreaks.Minepacks.Bukkit.Listener.EventListener; import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemFilter; import at.pcgamingfreaks.StringUtils; -import at.pcgamingfreaks.Version; import org.apache.commons.lang3.Validate; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,7 +50,6 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin { - private static Version version = new Version("2.0-SNAPSHOT"); private static Minepacks instance = null; public Config config; @@ -70,17 +68,10 @@ public static Minepacks getInstance() return instance; } - @Override - public Version getVersion() - { - return version; - } - @Override public void onEnable() { Utils.warnOnJava_1_7(getLogger()); - version = new Version(getDescription().getVersion()); //region Check compatibility with used minecraft version if(MCVersion.is(MCVersion.UNKNOWN) || MCVersion.isNewerThan(MCVersion.MC_NMS_1_12_R1)) { @@ -130,7 +121,6 @@ private void load() backpackTitle = StringUtils.limitLength(config.getBPTitle(), 32); messageNoPermission = lang.getMessage("Ingame.NoPermission"); messageInvalidBackpack = lang.getMessage("Ingame.InvalidBackpack"); - getServer().getServicesManager().register(Minepacks.class, this, this, ServicePriority.Normal); getCommand("backpack").setExecutor(new OnCommand(this)); //region register events @@ -183,10 +173,10 @@ public Database getDb() public void openBackpack(@NotNull final Player opener, @NotNull final OfflinePlayer owner, final boolean editable) { Validate.notNull(owner); - database.getBackpack(owner, new Callback() + database.getBackpack(owner, new Callback() { @Override - public void onResult(Backpack backpack) + public void onResult(at.pcgamingfreaks.Minepacks.Bukkit.Backpack backpack) { openBackpack(opener, backpack, editable); } @@ -221,7 +211,7 @@ public void openBackpack(@NotNull final Player opener, @Nullable final Backpack } @Override - public void getBackpack(@NotNull OfflinePlayer owner, @NotNull Callback callback) + public void getBackpack(@NotNull OfflinePlayer owner, @NotNull Callback callback) { database.getBackpack(owner, callback); }