diff --git a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java index 11d597ca..7c754080 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java +++ b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java @@ -51,8 +51,11 @@ public abstract class EcoPlugin extends JavaPlugin { /** * The name of the plugin. + * + * @deprecated Pointless, use getName instead. */ @Getter + @Deprecated private final String pluginName; /** @@ -163,6 +166,62 @@ public abstract class EcoPlugin extends JavaPlugin { @Getter private boolean outdated = false; + /** + * Create a new plugin without a specified color, proxy support, spigot, or bStats. + */ + protected EcoPlugin() { + this("&f"); + } + + /** + * Create a new plugin without proxy support, spigot, or bStats. + * + * @param color The color. + */ + protected EcoPlugin(@NotNull final String color) { + this("", color); + } + + + /** + * Create a new plugin unlinked to spigot and bStats. + * + * @param proxyPackage The package where proxy implementations are stored. + * @param color The color of the plugin (used in messages, such as &a, &b) + */ + protected EcoPlugin(@NotNull final String proxyPackage, + @NotNull final String color) { + this(0, 0, proxyPackage, color); + } + + /** + * Create a new plugin. + * + * @param resourceId The spigot resource ID for the plugin. + * @param bStatsId The bStats resource ID for the plugin. + * @param proxyPackage The package where proxy implementations are stored. + * @param color The color of the plugin (used in messages, such as &a, &b) + */ + protected EcoPlugin(final int resourceId, + final int bStatsId, + @NotNull final String proxyPackage, + @NotNull final String color) { + this("", resourceId, bStatsId, proxyPackage, color); + } + + /** + * Create a new plugin without proxy support. + * + * @param resourceId The spigot resource ID for the plugin. + * @param bStatsId The bStats resource ID for the plugin. + * @param color The color of the plugin (used in messages, such as &a, &b) + */ + protected EcoPlugin(final int resourceId, + final int bStatsId, + @NotNull final String color) { + this(resourceId, bStatsId, "", color); + } + /** * Create a new plugin. * @@ -171,13 +230,15 @@ public abstract class EcoPlugin extends JavaPlugin { * @param bStatsId The bStats resource ID for the plugin. * @param proxyPackage The package where proxy implementations are stored. * @param color The color of the plugin (used in messages, such as &a, &b) + * @deprecated pluginName is redundant. */ + @Deprecated protected EcoPlugin(@NotNull final String pluginName, final int resourceId, final int bStatsId, @NotNull final String proxyPackage, @NotNull final String color) { - this.pluginName = pluginName; + this.pluginName = this.getName(); this.resourceId = resourceId; this.bStatsId = bStatsId; this.proxyPackage = proxyPackage; @@ -210,20 +271,24 @@ public abstract class EcoPlugin extends JavaPlugin { this.getEventManager().registerListener(new ArrowDataListener(this)); - new UpdateChecker(this).getVersion(version -> { - DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion()); - DefaultArtifactVersion mostRecentVersion = new DefaultArtifactVersion(version); - if (!(currentVersion.compareTo(mostRecentVersion) > 0 || currentVersion.equals(mostRecentVersion))) { - this.outdated = true; - this.getScheduler().runTimer(() -> { - this.getLogger().info("&c " + this.pluginName + " is out of date! (Version " + this.getDescription().getVersion() + ")"); - this.getLogger().info("&cThe newest version is &f" + version); - this.getLogger().info("&cDownload the new version!"); - }, 0, 864000); - } - }); + if (this.getResourceId() != 0) { + new UpdateChecker(this).getVersion(version -> { + DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion()); + DefaultArtifactVersion mostRecentVersion = new DefaultArtifactVersion(version); + if (!(currentVersion.compareTo(mostRecentVersion) > 0 || currentVersion.equals(mostRecentVersion))) { + this.outdated = true; + this.getScheduler().runTimer(() -> { + this.getLogger().info("&c " + this.pluginName + " is out of date! (Version " + this.getDescription().getVersion() + ")"); + this.getLogger().info("&cThe newest version is &f" + version); + this.getLogger().info("&cDownload the new version!"); + }, 0, 864000); + } + }); + } - new Metrics(this, this.bStatsId); + if (this.getBStatsId() != 0) { + new Metrics(this, this.bStatsId); + } Set enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet()); diff --git a/eco-core/core-proxy/src/main/java/com/willfp/eco/proxy/util/ProxyFactory.java b/eco-core/core-proxy/src/main/java/com/willfp/eco/proxy/util/ProxyFactory.java index 2235595f..a85035f6 100644 --- a/eco-core/core-proxy/src/main/java/com/willfp/eco/proxy/util/ProxyFactory.java +++ b/eco-core/core-proxy/src/main/java/com/willfp/eco/proxy/util/ProxyFactory.java @@ -5,6 +5,7 @@ import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.proxy.AbstractProxy; import com.willfp.eco.core.proxy.ProxyConstants; import com.willfp.eco.core.proxy.UnsupportedVersionException; +import org.apache.commons.lang.Validate; import org.jetbrains.annotations.NotNull; import java.util.IdentityHashMap; @@ -30,6 +31,12 @@ public class ProxyFactory extends PluginDependent { public ProxyFactory(@NotNull final EcoPlugin plugin, @NotNull final Class proxyClass) { super(plugin); + + Validate.isTrue( + !plugin.getProxyPackage().equalsIgnoreCase(""), + "Specified plugin has no proxy support!" + ); + this.proxyClass = proxyClass; }