Updated proxy errors
This commit is contained in:
@@ -635,7 +635,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
|
|||||||
* @return The proxy.
|
* @return The proxy.
|
||||||
*/
|
*/
|
||||||
public final <T> T getProxy(@NotNull final Class<T> proxyClass) {
|
public final <T> T getProxy(@NotNull final Class<T> proxyClass) {
|
||||||
Validate.notNull(proxyFactory, "Plugin does not support proxy!");
|
Validate.notNull(proxyFactory, "Plugin does not support proxies!");
|
||||||
|
|
||||||
return proxyFactory.getProxy(proxyClass);
|
return proxyFactory.getProxy(proxyClass);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,26 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
/**
|
/**
|
||||||
* Generic error with proxy loading.
|
* Generic error with proxy loading.
|
||||||
*/
|
*/
|
||||||
public class ProxyError extends RuntimeException {
|
public class ProxyError extends Error {
|
||||||
/**
|
/**
|
||||||
* Thrown if there is an error getting a proxy.
|
* Thrown if there is an error getting a proxy.
|
||||||
*
|
*
|
||||||
* @param message The message to send.
|
* @param message The message to send.
|
||||||
|
* @param cause The cause.
|
||||||
*/
|
*/
|
||||||
|
public ProxyError(@NotNull final String message,
|
||||||
|
@NotNull final Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown if there is an error getting a proxy.
|
||||||
|
*
|
||||||
|
* @param message The message to send.
|
||||||
|
* @deprecated Proxy Errors should include a cause.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||||
public ProxyError(@NotNull final String message) {
|
public ProxyError(@NotNull final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.willfp.eco.core.proxy.exceptions;
|
package com.willfp.eco.core.proxy.exceptions;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.proxy.ProxyConstants;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,8 +11,17 @@ public class UnsupportedVersionException extends ProxyError {
|
|||||||
* Thrown if the server is running an unsupported NMS version.
|
* Thrown if the server is running an unsupported NMS version.
|
||||||
*
|
*
|
||||||
* @param message The message to send.
|
* @param message The message to send.
|
||||||
|
* @deprecated Use the default constructor.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.24.0")
|
||||||
public UnsupportedVersionException(@NotNull final String message) {
|
public UnsupportedVersionException(@NotNull final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown if the server is running an unsupported NMS version.
|
||||||
|
*/
|
||||||
|
public UnsupportedVersionException() {
|
||||||
|
super("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,21 +34,26 @@ class EcoProxyFactory(
|
|||||||
return proxy
|
return proxy
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throwError(e)
|
throw proxyErrorFrom(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
throwError(IllegalArgumentException())
|
throw proxyErrorFrom(IllegalArgumentException("Class doesn't seem to be a proxy."))
|
||||||
|
|
||||||
throw RuntimeException("Something went wrong.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun throwError(e: Exception?) {
|
private fun proxyErrorFrom(e: Exception): Throwable {
|
||||||
e?.printStackTrace()
|
plugin.logger.severe("Fatal error with proxies! This plugin can't load.")
|
||||||
|
|
||||||
if (!SUPPORTED_VERSIONS.contains(ProxyConstants.NMS_VERSION)) {
|
if (!SUPPORTED_VERSIONS.contains(ProxyConstants.NMS_VERSION)) {
|
||||||
throw UnsupportedVersionException("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION)
|
throw ProxyError(
|
||||||
|
"Could not initialize proxy.",
|
||||||
|
UnsupportedVersionException()
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
throw ProxyError("Error with proxies - here's a stacktrace. Only god can help you now.")
|
throw ProxyError(
|
||||||
|
"Could not initialize proxy. If you're seeing this error message"
|
||||||
|
+ ", something has gone badly wrong. This almost definitely isn't user error, blame the developer.",
|
||||||
|
e
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user