mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-20 15:11:25 +01:00
fix issue w/FormattedCommandAliasProvider on 1.8 forks
This commit is contained in:
parent
c8d6f64deb
commit
5b146f8383
@ -15,14 +15,12 @@ import java.util.List;
|
||||
|
||||
@ProviderData(description = "Reflection Formatted Command Alias Provider")
|
||||
public class ReflFormattedCommandAliasProvider implements FormattedCommandAliasProvider {
|
||||
|
||||
private final boolean paper;
|
||||
private final boolean senderArg;
|
||||
private final Field formatStringsField;
|
||||
private final MethodHandle buildCommandMethodHandle;
|
||||
|
||||
public ReflFormattedCommandAliasProvider(final boolean paper) {
|
||||
this.paper = paper;
|
||||
|
||||
public ReflFormattedCommandAliasProvider() {
|
||||
boolean senderArg = true;
|
||||
final Class<? extends FormattedCommandAlias> formattedCommandAliasClass;
|
||||
Field formatStringsField = null;
|
||||
MethodHandle buildCommandMethodHandle = null;
|
||||
@ -30,14 +28,16 @@ public class ReflFormattedCommandAliasProvider implements FormattedCommandAliasP
|
||||
formattedCommandAliasClass = FormattedCommandAlias.class;
|
||||
formatStringsField = ReflUtil.getFieldCached(formattedCommandAliasClass, "formatStrings");
|
||||
|
||||
final Class<?>[] parameterTypes;
|
||||
if (paper) {
|
||||
parameterTypes = new Class[] {CommandSender.class, String.class, String[].class};
|
||||
} else {
|
||||
parameterTypes = new Class[] {String.class, String[].class};
|
||||
Method buildCommandMethod = ReflUtil.getMethodCached(formattedCommandAliasClass, "buildCommand", CommandSender.class, String.class, String[].class);
|
||||
if (buildCommandMethod == null) {
|
||||
senderArg = false;
|
||||
buildCommandMethod = ReflUtil.getMethodCached(formattedCommandAliasClass, "buildCommand", String.class, String[].class);
|
||||
}
|
||||
|
||||
if (buildCommandMethod == null) {
|
||||
throw new NoSuchMethodException("Could not find buildCommand method in FormattedCommandAlias");
|
||||
}
|
||||
|
||||
final Method buildCommandMethod = ReflUtil.getMethodCached(formattedCommandAliasClass, "buildCommand", parameterTypes);
|
||||
buildCommandMethod.setAccessible(true);
|
||||
buildCommandMethodHandle = MethodHandles.lookup().unreflect(buildCommandMethod);
|
||||
} catch (final Exception ex) {
|
||||
@ -45,6 +45,7 @@ public class ReflFormattedCommandAliasProvider implements FormattedCommandAliasP
|
||||
} finally {
|
||||
this.formatStringsField = formatStringsField;
|
||||
this.buildCommandMethodHandle = buildCommandMethodHandle;
|
||||
this.senderArg = senderArg;
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +78,7 @@ public class ReflFormattedCommandAliasProvider implements FormattedCommandAliasP
|
||||
@Override
|
||||
public String buildCommand(FormattedCommandAlias command, CommandSender sender, String formatString, String[] args) {
|
||||
try {
|
||||
if (paper) {
|
||||
if (senderArg) {
|
||||
return (String) buildCommandMethodHandle.invoke(command, sender, formatString, args);
|
||||
} else {
|
||||
return (String) buildCommandMethodHandle.invoke(command, formatString, args);
|
||||
|
Loading…
Reference in New Issue
Block a user