diff --git a/paper-api/src/main/java/org/bukkit/plugin/Plugin.java b/paper-api/src/main/java/org/bukkit/plugin/Plugin.java index 97c882aaaf..adec34a572 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/Plugin.java +++ b/paper-api/src/main/java/org/bukkit/plugin/Plugin.java @@ -13,22 +13,24 @@ import com.avaje.ebean.EbeanServer; /** * Represents a Plugin + *

+ * The use of {@link PluginBase} is recommended for actual Implementation */ -public abstract class Plugin implements CommandExecutor { +public interface Plugin extends CommandExecutor { /** * Returns the folder that the plugin data's files are located in. The * folder may not yet exist. * * @return The folder */ - public abstract File getDataFolder(); + public File getDataFolder(); /** * Returns the plugin.yaml file containing the details for this plugin * * @return Contents of the plugin.yaml file */ - public abstract PluginDescriptionFile getDescription(); + public PluginDescriptionFile getDescription(); /** * Gets a {@link FileConfiguration} for this plugin, read through "config.yml" @@ -38,7 +40,7 @@ public abstract class Plugin implements CommandExecutor { * * @return Plugin configuration */ - public abstract FileConfiguration getConfig(); + public FileConfiguration getConfig(); /** * Gets an embedded resource in this plugin @@ -46,18 +48,18 @@ public abstract class Plugin implements CommandExecutor { * @param filename Filename of the resource * @return File if found, otherwise null */ - public abstract InputStream getResource(String filename); + public InputStream getResource(String filename); /** * Saves the {@link FileConfiguration} retrievable by {@link #getConfig()}. */ - public abstract void saveConfig(); + public void saveConfig(); /** * Saves the raw contents of the default config.yml file to the location retrievable by {@link #getConfig()}. * If there is no default config.yml embedded in the plugin, an empty config.yml file is saved. */ - public abstract void saveDefaultConfig(); + public void saveDefaultConfig(); /** * Saves the raw contents of any resource embedded with a plugin's .jar file assuming it can be found using @@ -68,70 +70,70 @@ public abstract class Plugin implements CommandExecutor { * @param replace if true, the embedded resource will overwrite the contents of an existing file. * @throws IllegalArgumentException if the resource path is null, empty, or points to a nonexistent resource. */ - public abstract void saveResource(String resourcePath, boolean replace); + public void saveResource(String resourcePath, boolean replace); /** * Discards any data in {@link #getConfig()} and reloads from disk. */ - public abstract void reloadConfig(); + public void reloadConfig(); /** * Gets the associated PluginLoader responsible for this plugin * * @return PluginLoader that controls this plugin */ - public abstract PluginLoader getPluginLoader(); + public PluginLoader getPluginLoader(); /** * Returns the Server instance currently running this plugin * * @return Server running this plugin */ - public abstract Server getServer(); + public Server getServer(); /** * Returns a value indicating whether or not this plugin is currently enabled * * @return true if this plugin is enabled, otherwise false */ - public abstract boolean isEnabled(); + public boolean isEnabled(); /** * Called when this plugin is disabled */ - public abstract void onDisable(); + public void onDisable(); /** * Called after a plugin is loaded but before it has been enabled. * When mulitple plugins are loaded, the onLoad() for all plugins is called before any onEnable() is called. */ - public abstract void onLoad(); + public void onLoad(); /** * Called when this plugin is enabled */ - public abstract void onEnable(); + public void onEnable(); /** * Simple boolean if we can still nag to the logs about things * * @return boolean whether we can nag */ - public abstract boolean isNaggable(); + public boolean isNaggable(); /** * Set naggable state * * @param canNag is this plugin still naggable? */ - public abstract void setNaggable(boolean canNag); + public void setNaggable(boolean canNag); /** * Gets the {@link EbeanServer} tied to this plugin * * @return Ebean server instance */ - public abstract EbeanServer getDatabase(); + public EbeanServer getDatabase(); /** * Gets a {@link ChunkGenerator} for use in a default world, as specified in the server configuration @@ -140,7 +142,7 @@ public abstract class Plugin implements CommandExecutor { * @param id Unique ID, if any, that was specified to indicate which generator was requested * @return ChunkGenerator for use in the default world generation */ - public abstract ChunkGenerator getDefaultWorldGenerator(String worldName, String id); + public ChunkGenerator getDefaultWorldGenerator(String worldName, String id); /** * Returns the primary logger associated with this server instance. The returned logger automatically @@ -148,7 +150,7 @@ public abstract class Plugin implements CommandExecutor { * * @return Logger associated with this server */ - public abstract Logger getLogger(); + public Logger getLogger(); /** * Returns the name of the plugin. @@ -157,26 +159,5 @@ public abstract class Plugin implements CommandExecutor { * * @return name of the plugin */ - public String getName() { - return getDescription().getName(); - } - - @Override - public int hashCode() { - return getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof Plugin)) { - return false; - } - return getName().equals(((Plugin) obj).getName()); - } + public String getName(); } diff --git a/paper-api/src/main/java/org/bukkit/plugin/PluginBase.java b/paper-api/src/main/java/org/bukkit/plugin/PluginBase.java new file mode 100644 index 0000000000..8b825adb60 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/plugin/PluginBase.java @@ -0,0 +1,31 @@ +package org.bukkit.plugin; + +/** + * Represents a base {@link Plugin} + *

+ * Extend this class if your plugin is not a {@link org.bukkit.plugin.java.JavaPlugin} + */ +public abstract class PluginBase implements Plugin { + @Override + public final int hashCode() { + return getName().hashCode(); + } + + @Override + public final boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof Plugin)) { + return false; + } + return getName().equals(((Plugin) obj).getName()); + } + + public final String getName() { + return getDescription().getName(); + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java index 6cc7d9db42..f367b7f5fd 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java @@ -19,7 +19,7 @@ import org.bukkit.command.PluginCommand; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginBase; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.PluginLogger; @@ -34,7 +34,7 @@ import com.avaje.ebeaninternal.server.ddl.DdlGenerator; /** * Represents a Java plugin */ -public abstract class JavaPlugin extends Plugin { +public abstract class JavaPlugin extends PluginBase { private boolean isEnabled = false; private boolean initialized = false; private PluginLoader loader = null; diff --git a/paper-api/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java b/paper-api/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java index 0844f97576..405169bc0b 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/FixedMetadataValueTest.java @@ -3,7 +3,7 @@ package org.bukkit.metadata; import static org.junit.Assert.assertEquals; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.messaging.TestPlugin; +import org.bukkit.plugin.TestPlugin; import org.junit.Test; public class FixedMetadataValueTest { diff --git a/paper-api/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java b/paper-api/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java index ece6a0f445..a3172db70e 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/LazyMetadataValueTest.java @@ -1,6 +1,6 @@ package org.bukkit.metadata; -import org.bukkit.plugin.messaging.TestPlugin; +import org.bukkit.plugin.TestPlugin; import org.junit.Test; import java.util.concurrent.Callable; diff --git a/paper-api/src/test/java/org/bukkit/metadata/MetadataConversionTest.java b/paper-api/src/test/java/org/bukkit/metadata/MetadataConversionTest.java index 428768adda..a595cc8d67 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/MetadataConversionTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/MetadataConversionTest.java @@ -16,7 +16,7 @@ package org.bukkit.metadata; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.messaging.TestPlugin; +import org.bukkit.plugin.TestPlugin; import org.junit.Test; import static org.junit.Assert.assertEquals; diff --git a/paper-api/src/test/java/org/bukkit/metadata/MetadataStoreTest.java b/paper-api/src/test/java/org/bukkit/metadata/MetadataStoreTest.java index 98a9642321..255324b5bd 100644 --- a/paper-api/src/test/java/org/bukkit/metadata/MetadataStoreTest.java +++ b/paper-api/src/test/java/org/bukkit/metadata/MetadataStoreTest.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.concurrent.Callable; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.messaging.TestPlugin; +import org.bukkit.plugin.TestPlugin; import org.junit.Test; public class MetadataStoreTest { diff --git a/paper-api/src/test/java/org/bukkit/plugin/messaging/TestPlugin.java b/paper-api/src/test/java/org/bukkit/plugin/TestPlugin.java similarity index 80% rename from paper-api/src/test/java/org/bukkit/plugin/messaging/TestPlugin.java rename to paper-api/src/test/java/org/bukkit/plugin/TestPlugin.java index f14e2e7503..a435771aed 100644 --- a/paper-api/src/test/java/org/bukkit/plugin/messaging/TestPlugin.java +++ b/paper-api/src/test/java/org/bukkit/plugin/TestPlugin.java @@ -1,4 +1,4 @@ -package org.bukkit.plugin.messaging; +package org.bukkit.plugin; import java.io.File; import java.io.InputStream; @@ -8,14 +8,10 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.PluginLoader; -import org.bukkit.plugin.PluginLogger; import com.avaje.ebean.EbeanServer; -public class TestPlugin extends Plugin { +public class TestPlugin extends PluginBase { private boolean enabled = true; final private String pluginName; @@ -28,10 +24,6 @@ public class TestPlugin extends Plugin { this.enabled = enabled; } - public String getName() { - return pluginName; - } - public File getDataFolder() { throw new UnsupportedOperationException("Not supported."); } @@ -111,20 +103,4 @@ public class TestPlugin extends Plugin { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { throw new UnsupportedOperationException("Not supported."); } - - @Override - public int hashCode() { - return getName().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - return getName().equals(((TestPlugin) obj).getName()); - } } diff --git a/paper-api/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java b/paper-api/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java index ee3d8acf15..47bea47280 100644 --- a/paper-api/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java +++ b/paper-api/src/test/java/org/bukkit/plugin/messaging/StandardMessengerTest.java @@ -1,6 +1,6 @@ package org.bukkit.plugin.messaging; -import org.bukkit.plugin.messaging.ReservedChannelException; +import org.bukkit.plugin.TestPlugin; import java.util.Collection; import org.junit.Test; import static org.junit.Assert.*;