Fix NoClassDefFoundError on < 1.12 with Discord execute command (#4478)

This commit is contained in:
Josh Roy 2021-08-26 13:12:52 -07:00 committed by GitHub
parent df88a89c14
commit 69850d82c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 23 deletions

View File

@ -1,7 +1,5 @@
package net.ess3.provider.providers; package net.ess3.provider.providers;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
@ -60,27 +58,13 @@ public class BukkitSenderProvider implements CommandSender {
@Override @Override
public Spigot spigot() { public Spigot spigot() {
return new Spigot() { try {
@Override Class.forName("org.bukkit.command.CommandSender$Spigot");
public void sendMessage(BaseComponent component) { return ModernCommandSenderSpigotCreator.stupidDumbHackToMakeTheJvmHappy(this);
BukkitSenderProvider.this.sendMessage(component.toLegacyText()); } catch (ClassNotFoundException ignored) {
//noinspection ConstantConditions
return null;
} }
@Override
public void sendMessage(BaseComponent... components) {
sendMessage(new TextComponent(components));
}
@Override
public void sendMessage(UUID sender, BaseComponent... components) {
sendMessage(components);
}
@Override
public void sendMessage(UUID sender, BaseComponent component) {
sendMessage(component);
}
};
} }
@Override @Override

View File

@ -0,0 +1,40 @@
package net.ess3.provider.providers;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender;
import java.util.UUID;
public final class ModernCommandSenderSpigotCreator {
private ModernCommandSenderSpigotCreator() {
}
/**
* The JVM will FOR SOME REASON try to load inner classes even BEFORE THE CODE WHICH REFERENCE THEM IS CALLED.
* This dumbass hack postpones the class lookup to until we know for sure the class exists.
*/
public static CommandSender.Spigot stupidDumbHackToMakeTheJvmHappy(BukkitSenderProvider provider) {
return new CommandSender.Spigot() {
@Override
public void sendMessage(BaseComponent component) {
provider.sendMessage(component.toLegacyText());
}
@Override
public void sendMessage(BaseComponent... components) {
sendMessage(new TextComponent(components));
}
@Override
public void sendMessage(UUID sender, BaseComponent... components) {
sendMessage(components);
}
@Override
public void sendMessage(UUID sender, BaseComponent component) {
sendMessage(component);
}
};
}
}