first commit
Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s
Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s
This commit is contained in:
commit
bbccd4a815
454 files changed
+45050
No files matched your search
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.annotation.Nullable
|
||||
* org.bukkit.Bukkit
|
||||
* org.bukkit.entity.Player
|
||||
* org.bukkit.event.EventPriority
|
||||
* org.bukkit.event.Listener
|
||||
* org.bukkit.event.player.PlayerEvent
|
||||
* org.bukkit.plugin.Plugin
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import de.maxhenkel.voicechat.Voicechat;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.CompatibilityReflectionException;
|
||||
import de.maxhenkel.voicechat.compatibility.PlayerHideEvent;
|
||||
import de.maxhenkel.voicechat.compatibility.PlayerShowEvent;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import de.maxhenkel.voicechat.util.Key;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Consumer;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class BaseCompatibility
|
||||
implements Compatibility {
|
||||
private String baseBukkitPackage;
|
||||
private String baseServerPackage;
|
||||
private Method addChannel;
|
||||
private Method removeChannel;
|
||||
@Nullable
|
||||
private Class<? extends PlayerEvent> playerHideEntityEvent;
|
||||
@Nullable
|
||||
private Method playerHideEntityEventGetEntity;
|
||||
@Nullable
|
||||
private Class<? extends PlayerEvent> playerShowEntityEvent;
|
||||
@Nullable
|
||||
private Method playerShowEntityEventGetEntity;
|
||||
private Consumer<Runnable> runTask;
|
||||
private TaskScheduler taskScheduler;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
Compatibility.super.init();
|
||||
this.baseBukkitPackage = Bukkit.getServer().getClass().getPackage().getName();
|
||||
this.baseServerPackage = ReflectionUtils.callMethod((Object)Bukkit.getServer(), "getServer").getClass().getPackage().getName();
|
||||
Class<?> craftPlayer = this.getBukkitClass("entity.CraftPlayer");
|
||||
this.addChannel = ReflectionUtils.getMethod(craftPlayer, new String[]{"addChannel"}, new Class[]{String.class});
|
||||
this.removeChannel = ReflectionUtils.getMethod(craftPlayer, new String[]{"removeChannel"}, new Class[]{String.class});
|
||||
try {
|
||||
if (ReflectionUtils.doesClassExist("org.bukkit.event.player.PlayerHideEntityEvent") && ReflectionUtils.doesClassExist("org.bukkit.event.player.PlayerShowEntityEvent")) {
|
||||
Class<?> hide = ReflectionUtils.getClazz("org.bukkit.event.player.PlayerHideEntityEvent");
|
||||
if (!PlayerEvent.class.isAssignableFrom(hide)) {
|
||||
throw new CompatibilityReflectionException("PlayerHideEntityEvent is not a subclass of PlayerEvent");
|
||||
}
|
||||
Class<?> show = ReflectionUtils.getClazz("org.bukkit.event.player.PlayerShowEntityEvent");
|
||||
if (!PlayerEvent.class.isAssignableFrom(show)) {
|
||||
throw new CompatibilityReflectionException("PlayerShowEntityEvent is not a subclass of PlayerEvent");
|
||||
}
|
||||
this.playerShowEntityEventGetEntity = ReflectionUtils.getMethod(show, "getEntity");
|
||||
this.playerHideEntityEventGetEntity = ReflectionUtils.getMethod(hide, "getEntity");
|
||||
this.playerShowEntityEvent = show;
|
||||
this.playerHideEntityEvent = hide;
|
||||
} else {
|
||||
Voicechat.LOGGER.warn("Vanish plugin integration is not supported", new Object[0]);
|
||||
}
|
||||
}
|
||||
catch (CompatibilityReflectionException e) {
|
||||
Voicechat.LOGGER.warn("Vanish plugin integration is disabled", new Object[0]);
|
||||
Voicechat.LOGGER.warn("Failed to load vanish compatibility", e);
|
||||
this.playerHideEntityEvent = null;
|
||||
this.playerShowEntityEvent = null;
|
||||
}
|
||||
this.runTask = runnable -> Bukkit.getScheduler().runTask((Plugin)Voicechat.INSTANCE, runnable);
|
||||
this.taskScheduler = new TaskScheduler(){
|
||||
|
||||
@Override
|
||||
public void scheduleSyncRepeatingTask(Runnable runnable, long delay, long period) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask((Plugin)Voicechat.INSTANCE, runnable, delay, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTaskLater(Runnable runnable, long delay) {
|
||||
Bukkit.getScheduler().runTaskLater((Plugin)Voicechat.INSTANCE, runnable, delay);
|
||||
}
|
||||
};
|
||||
if (ReflectionUtils.doesMethodExist(Bukkit.class, "getGlobalRegionScheduler", new Class[0])) {
|
||||
final Object globalRegionScheduler = ReflectionUtils.callMethod(Bukkit.class, "getGlobalRegionScheduler");
|
||||
Method run = ReflectionUtils.getMethod(globalRegionScheduler.getClass(), new String[]{"run"}, new Class[]{Plugin.class, Consumer.class});
|
||||
this.runTask = runnable -> ReflectionUtils.call(run, globalRegionScheduler, new Object[]{Voicechat.INSTANCE, task -> runnable.run()});
|
||||
if (ReflectionUtils.doesMethodExist(globalRegionScheduler.getClass(), "runAtFixedRate", Plugin.class, Consumer.class, Long.TYPE, Long.TYPE) && ReflectionUtils.doesMethodExist(globalRegionScheduler.getClass(), "runDelayed", Plugin.class, Consumer.class, Long.TYPE)) {
|
||||
final Method runAtFixedRate = ReflectionUtils.getMethod(globalRegionScheduler.getClass(), new String[]{"runAtFixedRate"}, new Class[]{Plugin.class, Consumer.class, Long.TYPE, Long.TYPE});
|
||||
final Method runDelayed = ReflectionUtils.getMethod(globalRegionScheduler.getClass(), new String[]{"runDelayed"}, new Class[]{Plugin.class, Consumer.class, Long.TYPE});
|
||||
this.taskScheduler = new TaskScheduler(){
|
||||
final /* synthetic */ BaseCompatibility this$0;
|
||||
{
|
||||
this.this$0 = this$0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleSyncRepeatingTask(Runnable runnable, long delay, long period) {
|
||||
ReflectionUtils.call(runAtFixedRate, globalRegionScheduler, new Object[]{Voicechat.INSTANCE, task -> runnable.run(), delay <= 0L ? 1L : delay, period});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTaskLater(Runnable runnable, long delay) {
|
||||
ReflectionUtils.call(runDelayed, globalRegionScheduler, new Object[]{Voicechat.INSTANCE, task -> runnable.run(), delay <= 0L ? 1L : delay});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChannel(Player player, String channel) {
|
||||
ReflectionUtils.call(this.addChannel, player, channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChannel(Player player, String channel) {
|
||||
ReflectionUtils.call(this.removeChannel, player, channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key createNamespacedKey(String key) {
|
||||
return Key.of(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable runnable) {
|
||||
this.runTask.accept(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleSyncRepeatingTask(Runnable runnable, long delay, long period) {
|
||||
this.taskScheduler.scheduleSyncRepeatingTask(runnable, delay, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTaskLater(Runnable runnable, long delay) {
|
||||
this.taskScheduler.runTaskLater(runnable, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSee(Player player, Player other) {
|
||||
if (this.playerHideEntityEvent == null || this.playerShowEntityEvent == null) {
|
||||
return true;
|
||||
}
|
||||
return player.canSee(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlayerHideEvent(Consumer<PlayerHideEvent> event) {
|
||||
if (this.playerHideEntityEvent == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvent(this.playerHideEntityEvent, new Listener(){}, EventPriority.NORMAL, (listener, evt) -> {
|
||||
if (!evt.getClass().isAssignableFrom(this.playerHideEntityEvent)) {
|
||||
return;
|
||||
}
|
||||
PlayerEvent playerEvent = (PlayerEvent)evt;
|
||||
Object entityObj = ReflectionUtils.call(this.playerHideEntityEventGetEntity, playerEvent, new Object[0]);
|
||||
if (!(entityObj instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
event.accept(new PlayerHideEvent((Player)entityObj, playerEvent.getPlayer()));
|
||||
}, (Plugin)Voicechat.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPlayerShowEvent(Consumer<PlayerShowEvent> event) {
|
||||
if (this.playerShowEntityEvent == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvent(this.playerShowEntityEvent, new Listener(){}, EventPriority.NORMAL, (listener, evt) -> {
|
||||
if (!evt.getClass().isAssignableFrom(this.playerShowEntityEvent)) {
|
||||
return;
|
||||
}
|
||||
PlayerEvent playerEvent = (PlayerEvent)evt;
|
||||
Object entityObj = ReflectionUtils.call(this.playerShowEntityEventGetEntity, playerEvent, new Object[0]);
|
||||
if (!(entityObj instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
event.accept(new PlayerShowEvent((Player)entityObj, playerEvent.getPlayer()));
|
||||
}, (Plugin)Voicechat.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseBukkitPackage() {
|
||||
return this.baseBukkitPackage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseServerPackage() {
|
||||
return this.baseServerPackage;
|
||||
}
|
||||
|
||||
private static interface TaskScheduler {
|
||||
public void scheduleSyncRepeatingTask(Runnable var1, long var2, long var4);
|
||||
|
||||
public void runTaskLater(Runnable var1, long var2);
|
||||
}
|
||||
}
|
||||
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.annotation.Nullable
|
||||
* org.bukkit.Bukkit
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import de.maxhenkel.voicechat.Version;
|
||||
import de.maxhenkel.voicechat.Voicechat;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_12;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_16;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_17;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_18;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_19;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_19_1;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_20;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_20_2;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_20_3;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_21_5;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.CompatibilityReflectionException;
|
||||
import de.maxhenkel.voicechat.compatibility.FallbackCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.SpigotCompatibility;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class BukkitCompatibilityManager {
|
||||
private static final Map<Version, Compatibility> COMPATIBILITIES = new HashMap<Version, Compatibility>();
|
||||
|
||||
@Nullable
|
||||
public static Compatibility loadCompatibility() {
|
||||
Version forcedVersion = BukkitCompatibilityManager.getForcedVersion();
|
||||
Version version = forcedVersion != null ? forcedVersion : Version.getVersion();
|
||||
if (version == null) {
|
||||
Voicechat.LOGGER.info("Failed to parse version {}, trying to fall back to Spigot API compatibility mode", Bukkit.getBukkitVersion());
|
||||
return BukkitCompatibilityManager.tryLoadSpigot();
|
||||
}
|
||||
Voicechat.LOGGER.info("Initializing compatibility for version {}", version);
|
||||
if (version.getMajor() == 1 && version.getMinor() <= 7) {
|
||||
Voicechat.LOGGER.fatal("You are running a server that's too old to be able to join with any voice chat client", new Object[0]);
|
||||
return null;
|
||||
}
|
||||
Compatibility compatibility = COMPATIBILITIES.get(version);
|
||||
if (compatibility != null) {
|
||||
try {
|
||||
compatibility.init();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
compatibility = null;
|
||||
Voicechat.LOGGER.warn("Failed to load compatibility for version {}", version, t);
|
||||
}
|
||||
}
|
||||
if (compatibility == null) {
|
||||
Voicechat.LOGGER.warn("Incompatible version {}, trying to fall back to Spigot API compatibility mode", version);
|
||||
compatibility = BukkitCompatibilityManager.tryLoadSpigot();
|
||||
}
|
||||
if (compatibility == null) {
|
||||
compatibility = FallbackCompatibility.INSTANCE;
|
||||
try {
|
||||
compatibility.init();
|
||||
Voicechat.LOGGER.warn("Falling back to Bukkit compatibility mode, expect issues and lack of features", new Object[0]);
|
||||
Voicechat.LOGGER.warn("Chat messages won't be translatable", new Object[0]);
|
||||
}
|
||||
catch (CompatibilityReflectionException e) {
|
||||
compatibility = null;
|
||||
Voicechat.LOGGER.warn("Failed to load Bukkit compatibility mode: {}", e.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
compatibility = null;
|
||||
Voicechat.LOGGER.warn("Failed to load Bukkit compatibility mode", t);
|
||||
}
|
||||
}
|
||||
if (compatibility == null) {
|
||||
Voicechat.LOGGER.fatal("Could not load any compatibility for {}", version);
|
||||
}
|
||||
return compatibility;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Compatibility tryLoadSpigot() {
|
||||
if (!SpigotCompatibility.isSpigotCompatible()) {
|
||||
Voicechat.LOGGER.warn("Spigot API not found", new Object[0]);
|
||||
return null;
|
||||
}
|
||||
SpigotCompatibility compatibility = SpigotCompatibility.INSTANCE;
|
||||
try {
|
||||
compatibility.init();
|
||||
Voicechat.LOGGER.warn("Falling back to Spigot API compatibility mode, expect issues and lack of features", new Object[0]);
|
||||
}
|
||||
catch (CompatibilityReflectionException e) {
|
||||
compatibility = null;
|
||||
Voicechat.LOGGER.warn("Failed to load Spigot API compatibility mode: {}", e.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
compatibility = null;
|
||||
Voicechat.LOGGER.warn("Failed to load Spigot API compatibility mode", t);
|
||||
}
|
||||
return compatibility;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Version getForcedVersion() {
|
||||
String property = System.getProperty("voicechat.compatibility");
|
||||
if (property == null) {
|
||||
return null;
|
||||
}
|
||||
Version forcedVersion = Version.parse(property);
|
||||
if (forcedVersion == null) {
|
||||
Voicechat.LOGGER.warn("Failed to parse forced compatibility version: {}", property);
|
||||
return null;
|
||||
}
|
||||
Voicechat.LOGGER.info("Forcing compatibility for {}", forcedVersion);
|
||||
Voicechat.LOGGER.warn("Forcing version compatibility could lead to issues - use with caution!", new Object[0]);
|
||||
return forcedVersion;
|
||||
}
|
||||
|
||||
static {
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_PAPER_26_3, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_26_3, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_PAPER_26_2, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_26_2, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_PAPER_26_1_2, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_26_1_2, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_PAPER_26_1_1, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_26_1_1, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_26_1, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_1_21_11, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_1_21_10, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_1_21_9, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_1_21_8, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_1_21_7, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_1_21_6, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_21_5.VERSION_1_21_5, Compatibility1_21_5.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_21_4, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_21_3, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_21_2, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_21_1, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_21, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_20_6, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_20_5, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_20_4, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_3.VERSION_1_20_3, Compatibility1_20_3.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20_2.VERSION_1_20_2, Compatibility1_20_2.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20.VERSION_1_20_1, Compatibility1_20.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_20.VERSION_1_20, Compatibility1_20.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_19_1.VERSION_1_19_4, Compatibility1_19_1.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_19_1.VERSION_1_19_3, Compatibility1_19_1.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_19_1.VERSION_1_19_2, Compatibility1_19_1.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_19_1.VERSION_1_19_1, Compatibility1_19_1.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_19.VERSION_1_19, Compatibility1_19.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_18.VERSION_1_18_2, Compatibility1_18.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_18.VERSION_1_18_1, Compatibility1_18.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_18.VERSION_1_18, Compatibility1_18.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_17.VERSION_1_17_1, Compatibility1_17.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_17.VERSION_1_17, Compatibility1_17.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_16.VERSION_1_16_5, Compatibility1_16.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_16.VERSION_1_16_4, Compatibility1_16.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_16.VERSION_1_16_3, Compatibility1_16.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_16.VERSION_1_16_2, Compatibility1_16.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_16.VERSION_1_16_1, Compatibility1_16.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_16.VERSION_1_16, Compatibility1_16.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_12.VERSION_1_12_2, Compatibility1_12.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_12.VERSION_1_12_1, Compatibility1_12.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_12.VERSION_1_12, Compatibility1_12.INSTANCE);
|
||||
COMPATIBILITIES.put(Compatibility1_8.VERSION_1_8_8, Compatibility1_8.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* javax.annotation.Nullable
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.compatibility.CompatibilityReflectionException;
|
||||
import de.maxhenkel.voicechat.compatibility.PlayerHideEvent;
|
||||
import de.maxhenkel.voicechat.compatibility.PlayerShowEvent;
|
||||
import de.maxhenkel.voicechat.util.Key;
|
||||
import java.util.function.Consumer;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Compatibility {
|
||||
default public void init() throws Exception {
|
||||
}
|
||||
|
||||
public void addChannel(Player var1, String var2);
|
||||
|
||||
public void removeChannel(Player var1, String var2);
|
||||
|
||||
public Key createNamespacedKey(String var1);
|
||||
|
||||
public void sendTranslationMessage(Player var1, String var2, String ... var3);
|
||||
|
||||
public void sendStatusMessage(Player var1, String var2, String ... var3);
|
||||
|
||||
public void sendInviteMessage(Player var1, Player var2, String var3, String var4);
|
||||
|
||||
public void sendIncompatibleMessage(Player var1, String var2, String var3);
|
||||
|
||||
public void runTask(Runnable var1);
|
||||
|
||||
public void scheduleSyncRepeatingTask(Runnable var1, long var2, long var4);
|
||||
|
||||
public void runTaskLater(Runnable var1, long var2);
|
||||
|
||||
public boolean canSee(Player var1, Player var2);
|
||||
|
||||
public void registerPlayerHideEvent(Consumer<PlayerHideEvent> var1);
|
||||
|
||||
public void registerPlayerShowEvent(Consumer<PlayerShowEvent> var1);
|
||||
|
||||
@Nullable
|
||||
public ArgumentType<?> playerArgument();
|
||||
|
||||
@Nullable
|
||||
public ArgumentType<?> uuidArgument();
|
||||
|
||||
public String getBaseBukkitPackage();
|
||||
|
||||
public String getBaseServerPackage();
|
||||
|
||||
default public Class<?> getBukkitClass(String ... classNames) {
|
||||
for (String className : classNames) {
|
||||
try {
|
||||
return Class.forName(String.format("%s.%s", this.getBaseBukkitPackage(), className));
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
throw new CompatibilityReflectionException(String.format("Could not find any of the following classes: %s", String.join((CharSequence)", ", classNames)));
|
||||
}
|
||||
|
||||
default public Class<?> getServerClass(String ... classNames) {
|
||||
for (String className : classNames) {
|
||||
try {
|
||||
return Class.forName(String.format("%s.%s", this.getBaseServerPackage(), className));
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
throw new CompatibilityReflectionException(String.format("Could not find any of the following classes: %s", String.join((CharSequence)", ", classNames)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import de.maxhenkel.voicechat.util.Key;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_12
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final String CHANNEL = "vc";
|
||||
public static final BukkitVersion VERSION_1_12_2 = BukkitVersion.parseBukkitVersion("1.12.2-R0.1");
|
||||
public static final BukkitVersion VERSION_1_12_1 = BukkitVersion.parseBukkitVersion("1.12.1-R0.1");
|
||||
public static final BukkitVersion VERSION_1_12 = BukkitVersion.parseBukkitVersion("1.12-R0.1");
|
||||
public static final Compatibility1_12 INSTANCE = new Compatibility1_12();
|
||||
|
||||
@Override
|
||||
public Key createNamespacedKey(String key) {
|
||||
return Key.of(CHANNEL, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
Class<?> chatMessageTypeClass = this.getServerClass("ChatMessageType");
|
||||
Object b = ReflectionUtils.getField(chatMessageTypeClass, "CHAT");
|
||||
this.send(player, json, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
Class<?> chatMessageTypeClass = this.getServerClass("ChatMessageType");
|
||||
Object b = ReflectionUtils.getField(chatMessageTypeClass, "GAME_INFO");
|
||||
this.send(player, json, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void send(Player player, String json, Object chatMessageType) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Object playerConnection = ReflectionUtils.getField(entityPlayer, "playerConnection");
|
||||
Class<?> packet = this.getServerClass("Packet");
|
||||
Class<?> chatSerializer = this.getServerClass("IChatBaseComponent$ChatSerializer");
|
||||
Class<?> iChatBaseComponentClass = this.getServerClass("IChatBaseComponent");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(chatSerializer, "a", new Class[]{String.class}, json);
|
||||
Class<?> packetPlayOutChatClass = this.getServerClass("PacketPlayOutChat");
|
||||
Class<?> chatMessageTypeClass = this.getServerClass("ChatMessageType");
|
||||
Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(packetPlayOutChatClass, new Class[]{iChatBaseComponentClass, chatMessageTypeClass}, iChatBaseComponent, chatMessageType);
|
||||
ReflectionUtils.callMethod(playerConnection, "sendPacket", new Class[]{packet}, clientboundSystemChatPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_16
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_16_5 = BukkitVersion.parseBukkitVersion("1.16.5-R0.1");
|
||||
public static final BukkitVersion VERSION_1_16_4 = BukkitVersion.parseBukkitVersion("1.16.4-R0.1");
|
||||
public static final BukkitVersion VERSION_1_16_3 = BukkitVersion.parseBukkitVersion("1.16.3-R0.1");
|
||||
public static final BukkitVersion VERSION_1_16_2 = BukkitVersion.parseBukkitVersion("1.16.2-R0.1");
|
||||
public static final BukkitVersion VERSION_1_16_1 = BukkitVersion.parseBukkitVersion("1.16.1-R0.1");
|
||||
public static final BukkitVersion VERSION_1_16 = BukkitVersion.parseBukkitVersion("1.16-R0.1");
|
||||
public static final Compatibility1_16 INSTANCE = new Compatibility1_16();
|
||||
private static final UUID NUL_UUID = new UUID(0L, 0L);
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
Class<?> chatMessageTypeClass = this.getServerClass("ChatMessageType");
|
||||
Object b = ReflectionUtils.getField(chatMessageTypeClass, "CHAT");
|
||||
this.send(player, json, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
Class<?> chatMessageTypeClass = this.getServerClass("ChatMessageType");
|
||||
Object b = ReflectionUtils.getField(chatMessageTypeClass, "GAME_INFO");
|
||||
this.send(player, json, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
Class<?> argumentEntity = this.getServerClass("ArgumentEntity");
|
||||
return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "c");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
Class<?> argumentEntity = this.getServerClass("ArgumentUUID");
|
||||
return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "a");
|
||||
}
|
||||
|
||||
private void send(Player player, String json, Object chatMessageType) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Object playerConnection = ReflectionUtils.getField(entityPlayer, "playerConnection");
|
||||
Class<?> packet = this.getServerClass("Packet");
|
||||
Class<?> chatSerializer = this.getServerClass("IChatBaseComponent$ChatSerializer");
|
||||
Class<?> iChatBaseComponentClass = this.getServerClass("IChatBaseComponent");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(chatSerializer, "a", new Class[]{String.class}, json);
|
||||
Class<?> packetPlayOutChatClass = this.getServerClass("PacketPlayOutChat");
|
||||
Class<?> chatMessageTypeClass = this.getServerClass("ChatMessageType");
|
||||
Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(packetPlayOutChatClass, new Class[]{iChatBaseComponentClass, chatMessageTypeClass, UUID.class}, iChatBaseComponent, chatMessageType, NUL_UUID);
|
||||
ReflectionUtils.callMethod(playerConnection, "sendPacket", new Class[]{packet}, clientboundSystemChatPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_19;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_17
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_17_1 = BukkitVersion.parseBukkitVersion("1.17.1-R0.1");
|
||||
public static final BukkitVersion VERSION_1_17 = BukkitVersion.parseBukkitVersion("1.17-R0.1");
|
||||
public static final Compatibility1_17 INSTANCE = new Compatibility1_17();
|
||||
private static final UUID NUL_UUID = new UUID(0L, 0L);
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
Class<?> chatMessageTypeClass = ReflectionUtils.getClazz("net.minecraft.network.chat.ChatMessageType");
|
||||
Object b = ReflectionUtils.getField(chatMessageTypeClass, "b");
|
||||
this.send(player, json, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
Class<?> chatMessageTypeClass = ReflectionUtils.getClazz("net.minecraft.network.chat.ChatMessageType");
|
||||
Object b = ReflectionUtils.getField(chatMessageTypeClass, "c");
|
||||
this.send(player, json, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
return Compatibility1_19.INSTANCE.playerArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
return Compatibility1_19.INSTANCE.uuidArgument();
|
||||
}
|
||||
|
||||
private void send(Player player, String json, Object chatMessageType) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Object playerConnection = ReflectionUtils.getField(entityPlayer, "b");
|
||||
Class<?> packet = ReflectionUtils.getClazz("net.minecraft.network.protocol.Packet");
|
||||
Class<?> craftChatMessage = this.getBukkitClass("util.CraftChatMessage");
|
||||
Class<?> iChatBaseComponentClass = ReflectionUtils.getClazz("net.minecraft.network.chat.IChatBaseComponent");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(craftChatMessage, "fromJSON", new Class[]{String.class}, json);
|
||||
Class<?> packetPlayOutChatClass = ReflectionUtils.getClazz("net.minecraft.network.protocol.game.PacketPlayOutChat");
|
||||
Class<?> chatMessageTypeClass = ReflectionUtils.getClazz("net.minecraft.network.chat.ChatMessageType");
|
||||
Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(packetPlayOutChatClass, new Class[]{iChatBaseComponentClass, chatMessageTypeClass, UUID.class}, iChatBaseComponent, chatMessageType, NUL_UUID);
|
||||
ReflectionUtils.callMethod(playerConnection, "sendPacket", new Class[]{packet}, clientboundSystemChatPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_19;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_18
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_18_2 = BukkitVersion.parseBukkitVersion("1.18.2-R0.1");
|
||||
public static final BukkitVersion VERSION_1_18_1 = BukkitVersion.parseBukkitVersion("1.18.1-R0.1");
|
||||
public static final BukkitVersion VERSION_1_18 = BukkitVersion.parseBukkitVersion("1.18-R0.1");
|
||||
public static final Compatibility1_18 INSTANCE = new Compatibility1_18();
|
||||
private static final UUID NUL_UUID = new UUID(0L, 0L);
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
Class<?> chatMessageTypeClass = ReflectionUtils.getClazz("net.minecraft.network.chat.ChatMessageType");
|
||||
Object b = ReflectionUtils.getField(chatMessageTypeClass, "b");
|
||||
this.send(player, json, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
Class<?> chatMessageTypeClass = ReflectionUtils.getClazz("net.minecraft.network.chat.ChatMessageType");
|
||||
Object b = ReflectionUtils.getField(chatMessageTypeClass, "c");
|
||||
this.send(player, json, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
return Compatibility1_19.INSTANCE.playerArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
return Compatibility1_19.INSTANCE.uuidArgument();
|
||||
}
|
||||
|
||||
private void send(Player player, String json, Object chatMessageType) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Object playerConnection = ReflectionUtils.getField(entityPlayer, "b");
|
||||
Class<?> packet = ReflectionUtils.getClazz("net.minecraft.network.protocol.Packet");
|
||||
Class<?> craftChatMessage = this.getBukkitClass("util.CraftChatMessage");
|
||||
Class<?> iChatBaseComponentClass = ReflectionUtils.getClazz("net.minecraft.network.chat.IChatBaseComponent");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(craftChatMessage, "fromJSON", new Class[]{String.class}, json);
|
||||
Class<?> packetPlayOutChatClass = ReflectionUtils.getClazz("net.minecraft.network.protocol.game.PacketPlayOutChat");
|
||||
Class<?> chatMessageTypeClass = ReflectionUtils.getClazz("net.minecraft.network.chat.ChatMessageType");
|
||||
Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(packetPlayOutChatClass, new Class[]{iChatBaseComponentClass, chatMessageTypeClass, UUID.class}, iChatBaseComponent, chatMessageType, NUL_UUID);
|
||||
ReflectionUtils.callMethod(playerConnection, "a", new Class[]{packet}, clientboundSystemChatPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_19_1;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_19
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_19 = BukkitVersion.parseBukkitVersion("1.19-R0.1");
|
||||
public static final Compatibility1_19 INSTANCE = new Compatibility1_19();
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
this.send(player, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
this.send(player, json, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
return Compatibility1_19_1.INSTANCE.playerArgument();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
return Compatibility1_19_1.INSTANCE.uuidArgument();
|
||||
}
|
||||
|
||||
private void send(Player player, String json, boolean status) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Object playerConnection = ReflectionUtils.getField(entityPlayer, "b");
|
||||
Class<?> packet = ReflectionUtils.getClazz("net.minecraft.network.protocol.Packet");
|
||||
Class<?> craftChatMessage = this.getBukkitClass("util.CraftChatMessage");
|
||||
Class<?> iChatBaseComponentClass = ReflectionUtils.getClazz("net.minecraft.network.chat.IChatBaseComponent");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(craftChatMessage, "fromJSON", new Class[]{String.class}, json);
|
||||
Class<?> clientboundSystemChatPacketClass = ReflectionUtils.getClazz("net.minecraft.network.protocol.game.ClientboundSystemChatPacket");
|
||||
Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(clientboundSystemChatPacketClass, new Class[]{iChatBaseComponentClass, Integer.TYPE}, iChatBaseComponent, this.getId(player, status));
|
||||
ReflectionUtils.callMethod(playerConnection, "a", new Class[]{packet}, clientboundSystemChatPacket);
|
||||
}
|
||||
|
||||
private int getId(Player player, boolean status) {
|
||||
Object world = ReflectionUtils.callMethod((Object)player.getWorld(), "getHandle");
|
||||
Class<?> iRegistryCustomClass = ReflectionUtils.getClazz("net.minecraft.core.IRegistryCustom");
|
||||
Object iRegistryCustom = ReflectionUtils.callMethod(world, "s");
|
||||
Class<?> resourceKeyClass = ReflectionUtils.getClazz("net.minecraft.resources.ResourceKey");
|
||||
Class<?> iRegistry = ReflectionUtils.getClazz("net.minecraft.core.IRegistry");
|
||||
Object resourceKey = ReflectionUtils.getField(iRegistry, "bI");
|
||||
Object registry = ReflectionUtils.callMethod(iRegistryCustomClass, iRegistryCustom, "d", new Class[]{resourceKeyClass}, resourceKey);
|
||||
Class<?> chatMessageTypeClass = ReflectionUtils.getClazz("net.minecraft.network.chat.ChatMessageType");
|
||||
Object chatMessageType = status ? ReflectionUtils.getField(chatMessageTypeClass, "d") : ReflectionUtils.getField(chatMessageTypeClass, "c");
|
||||
Object messageType = ReflectionUtils.callMethod(registry, "a", new Class[]{resourceKeyClass}, chatMessageType);
|
||||
return (Integer)ReflectionUtils.callMethod(registry, "a", new Class[]{Object.class}, messageType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_19_1
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_19_4 = BukkitVersion.parseBukkitVersion("1.19.4-R0.1");
|
||||
public static final BukkitVersion VERSION_1_19_3 = BukkitVersion.parseBukkitVersion("1.19.3-R0.1");
|
||||
public static final BukkitVersion VERSION_1_19_2 = BukkitVersion.parseBukkitVersion("1.19.2-R0.1");
|
||||
public static final BukkitVersion VERSION_1_19_1 = BukkitVersion.parseBukkitVersion("1.19.1-R0.1");
|
||||
public static final Compatibility1_19_1 INSTANCE = new Compatibility1_19_1();
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
this.send(player, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
this.send(player, json, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
Class<?> argumentEntity = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentEntity");
|
||||
return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "c");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
Class<?> argumentEntity = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentUUID");
|
||||
return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "a");
|
||||
}
|
||||
|
||||
private void send(Player player, String json, boolean status) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Object playerConnection = ReflectionUtils.getField(entityPlayer, "b");
|
||||
Class<?> packet = ReflectionUtils.getClazz("net.minecraft.network.protocol.Packet");
|
||||
Class<?> craftChatMessage = this.getBukkitClass("util.CraftChatMessage");
|
||||
Class<?> iChatBaseComponentClass = ReflectionUtils.getClazz("net.minecraft.network.chat.IChatBaseComponent");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(craftChatMessage, "fromJSON", new Class[]{String.class}, json);
|
||||
Class<?> clientboundSystemChatPacketClass = ReflectionUtils.getClazz("net.minecraft.network.protocol.game.ClientboundSystemChatPacket");
|
||||
Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(clientboundSystemChatPacketClass, new Class[]{iChatBaseComponentClass, Boolean.TYPE}, iChatBaseComponent, status);
|
||||
ReflectionUtils.callMethod(playerConnection, "a", new Class[]{packet}, clientboundSystemChatPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_20
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_20 = BukkitVersion.parseBukkitVersion("1.20-R0.1");
|
||||
public static final BukkitVersion VERSION_1_20_1 = BukkitVersion.parseBukkitVersion("1.20.1-R0.1");
|
||||
public static final Compatibility1_20 INSTANCE = new Compatibility1_20();
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
this.send(player, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
this.send(player, json, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
Class<?> argumentEntity = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentEntity");
|
||||
return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "c");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
Class<?> argumentEntity = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentUUID");
|
||||
return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "a");
|
||||
}
|
||||
|
||||
private void send(Player player, String json, boolean status) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Object playerConnection = ReflectionUtils.getField(entityPlayer, "c");
|
||||
Class<?> packet = ReflectionUtils.getClazz("net.minecraft.network.protocol.Packet");
|
||||
Class<?> craftChatMessage = this.getBukkitClass("util.CraftChatMessage");
|
||||
Class<?> iChatBaseComponentClass = ReflectionUtils.getClazz("net.minecraft.network.chat.IChatBaseComponent");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(craftChatMessage, "fromJSON", new Class[]{String.class}, json);
|
||||
Class<?> clientboundSystemChatPacketClass = ReflectionUtils.getClazz("net.minecraft.network.protocol.game.ClientboundSystemChatPacket");
|
||||
Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(clientboundSystemChatPacketClass, new Class[]{iChatBaseComponentClass, Boolean.TYPE}, iChatBaseComponent, status);
|
||||
ReflectionUtils.callMethod(playerConnection, "a", new Class[]{packet}, clientboundSystemChatPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_20_2
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_20_2 = BukkitVersion.parseBukkitVersion("1.20.2-R0.1");
|
||||
public static final Compatibility1_20_2 INSTANCE = new Compatibility1_20_2();
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
this.send(player, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
this.send(player, json, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
Class<?> argumentEntity = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentEntity");
|
||||
return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "c");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
Class<?> argumentEntity = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentUUID");
|
||||
return (ArgumentType)ReflectionUtils.callMethod(argumentEntity, "a");
|
||||
}
|
||||
|
||||
private void send(Player player, String json, boolean status) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Class<?> iChatBaseComponentClass = ReflectionUtils.getClazz("net.minecraft.network.chat.IChatBaseComponent");
|
||||
Class<?> craftChatMessage = this.getBukkitClass("util.CraftChatMessage");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(craftChatMessage, "fromJSON", new Class[]{String.class}, json);
|
||||
ReflectionUtils.callMethod(entityPlayer, "a", new Class[]{iChatBaseComponentClass, Boolean.TYPE}, iChatBaseComponent, status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_8;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_20_3
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_20_3 = BukkitVersion.parseBukkitVersion("1.20.3-R0.1");
|
||||
public static final BukkitVersion VERSION_1_20_4 = BukkitVersion.parseBukkitVersion("1.20.4-R0.1");
|
||||
public static final BukkitVersion VERSION_1_20_5 = BukkitVersion.parseBukkitVersion("1.20.5-R0.1");
|
||||
public static final BukkitVersion VERSION_1_20_6 = BukkitVersion.parseBukkitVersion("1.20.6-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21 = BukkitVersion.parseBukkitVersion("1.21-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_1 = BukkitVersion.parseBukkitVersion("1.21.1-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_2 = BukkitVersion.parseBukkitVersion("1.21.2-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_3 = BukkitVersion.parseBukkitVersion("1.21.3-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_4 = BukkitVersion.parseBukkitVersion("1.21.4-R0.1");
|
||||
public static final Compatibility1_20_3 INSTANCE = new Compatibility1_20_3();
|
||||
private Method playerArgument;
|
||||
private Method uuidArgument;
|
||||
private Method fromJson;
|
||||
private Method getHandle;
|
||||
private Method sendSystemMessage;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
super.init();
|
||||
Class<?> argumentEntityClass = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentEntity", "net.minecraft.commands.arguments.EntityArgument");
|
||||
this.playerArgument = ReflectionUtils.getMethod(argumentEntityClass, "c", "entity");
|
||||
Class<?> argumentUuidClass = ReflectionUtils.getClazz("net.minecraft.commands.arguments.ArgumentUUID", "net.minecraft.commands.arguments.UuidArgument");
|
||||
this.uuidArgument = ReflectionUtils.getMethod(argumentUuidClass, "a", "uuid");
|
||||
Class<?> craftPlayer = this.getBukkitClass("entity.CraftPlayer");
|
||||
this.getHandle = ReflectionUtils.getMethod(craftPlayer, "getHandle");
|
||||
Class<?> componentClass = ReflectionUtils.getClazz("net.minecraft.network.chat.IChatBaseComponent", "net.minecraft.network.chat.Component");
|
||||
Class<?> craftChatMessageClass = this.getBukkitClass("util.CraftChatMessage");
|
||||
this.fromJson = ReflectionUtils.getMethod(craftChatMessageClass, new String[]{"fromJSON"}, new Class[]{String.class});
|
||||
Class<?> player = ReflectionUtils.getClazz("net.minecraft.server.level.EntityPlayer", "net.minecraft.server.level.ServerPlayer");
|
||||
this.sendSystemMessage = ReflectionUtils.getMethod(player, new String[]{"a", "sendSystemMessage"}, new Class[]{componentClass, Boolean.TYPE});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
this.send(player, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
this.send(player, json, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
return (ArgumentType)ReflectionUtils.call(this.playerArgument, null, new Object[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
return (ArgumentType)ReflectionUtils.call(this.uuidArgument, null, new Object[0]);
|
||||
}
|
||||
|
||||
protected void send(Player player, String json, boolean status) {
|
||||
ReflectionUtils.call(this.sendSystemMessage, ReflectionUtils.call(this.getHandle, player, new Object[0]), ReflectionUtils.call(this.fromJson, null, json), status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.PaperVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.Compatibility1_20_3;
|
||||
import de.maxhenkel.voicechat.org.json.JSONArray;
|
||||
import de.maxhenkel.voicechat.org.json.JSONObject;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_21_5
|
||||
extends Compatibility1_20_3 {
|
||||
public static final BukkitVersion VERSION_1_21_5 = BukkitVersion.parseBukkitVersion("1.21.5-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_6 = BukkitVersion.parseBukkitVersion("1.21.6-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_7 = BukkitVersion.parseBukkitVersion("1.21.7-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_8 = BukkitVersion.parseBukkitVersion("1.21.8-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_9 = BukkitVersion.parseBukkitVersion("1.21.9-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_10 = BukkitVersion.parseBukkitVersion("1.21.10-R0.1");
|
||||
public static final BukkitVersion VERSION_1_21_11 = BukkitVersion.parseBukkitVersion("1.21.11-R0.1");
|
||||
public static final BukkitVersion VERSION_26_1 = BukkitVersion.parseBukkitVersion("26.1-R0.1");
|
||||
public static final BukkitVersion VERSION_26_1_1 = BukkitVersion.parseBukkitVersion("26.1.1-R0.1");
|
||||
public static final PaperVersion VERSION_PAPER_26_1_1 = PaperVersion.parsePaperVersion("26.1.1.build.0");
|
||||
public static final BukkitVersion VERSION_26_1_2 = BukkitVersion.parseBukkitVersion("26.1.2-R0.1");
|
||||
public static final PaperVersion VERSION_PAPER_26_1_2 = PaperVersion.parsePaperVersion("26.1.2.build.0");
|
||||
public static final BukkitVersion VERSION_26_2 = BukkitVersion.parseBukkitVersion("26.2-R0.1");
|
||||
public static final PaperVersion VERSION_PAPER_26_2 = PaperVersion.parsePaperVersion("26.2.build.0");
|
||||
public static final BukkitVersion VERSION_26_3 = BukkitVersion.parseBukkitVersion("26.3-R0.1");
|
||||
public static final PaperVersion VERSION_PAPER_26_3 = PaperVersion.parsePaperVersion("26.3.build.0");
|
||||
public static final Compatibility1_21_5 INSTANCE = new Compatibility1_21_5();
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_21_5.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
public static String constructInviteMessage(Player commandSender, String groupName, String joinCommand) {
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("translate", "message.voicechat.invite");
|
||||
JSONArray args = new JSONArray();
|
||||
args.put(commandSender.getName());
|
||||
JSONObject groupNameObj = new JSONObject();
|
||||
groupNameObj.put("color", "gray");
|
||||
groupNameObj.put("text", groupName);
|
||||
args.put(groupNameObj);
|
||||
JSONObject acceptInBrackets = new JSONObject();
|
||||
acceptInBrackets.put("translate", "chat.square_brackets");
|
||||
acceptInBrackets.put("color", "green");
|
||||
JSONArray withBrackets = new JSONArray();
|
||||
JSONObject accept = new JSONObject();
|
||||
accept.put("translate", "message.voicechat.accept_invite");
|
||||
JSONObject clickEvent = new JSONObject();
|
||||
clickEvent.put("action", "run_command");
|
||||
clickEvent.put("command", joinCommand);
|
||||
accept.put("click_event", clickEvent);
|
||||
JSONObject hoverEvent = new JSONObject();
|
||||
hoverEvent.put("action", "show_text");
|
||||
JSONObject contents = new JSONObject();
|
||||
contents.put("translate", "message.voicechat.accept_invite.hover");
|
||||
hoverEvent.put("value", contents);
|
||||
accept.put("hover_event", hoverEvent);
|
||||
withBrackets.put(accept);
|
||||
acceptInBrackets.put("with", withBrackets);
|
||||
args.put(acceptInBrackets);
|
||||
msg.put("with", args);
|
||||
return msg.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.BukkitVersion;
|
||||
import de.maxhenkel.voicechat.compatibility.JsonMessageBaseCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import de.maxhenkel.voicechat.org.json.JSONArray;
|
||||
import de.maxhenkel.voicechat.org.json.JSONObject;
|
||||
import de.maxhenkel.voicechat.util.Key;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Compatibility1_8
|
||||
extends JsonMessageBaseCompatibility {
|
||||
public static final BukkitVersion VERSION_1_8_8 = BukkitVersion.parseBukkitVersion("1.8.8-R0.1");
|
||||
public static final Compatibility1_8 INSTANCE = new Compatibility1_8();
|
||||
|
||||
@Override
|
||||
public Key createNamespacedKey(String key) {
|
||||
return Key.of("vc", key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonMessage(Player player, String json) {
|
||||
this.send(player, json, (byte)0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendJsonStatusMessage(Player player, String json) {
|
||||
this.send(player, json, (byte)2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createTranslationMessage(String key, String ... args) {
|
||||
return Compatibility1_8.constructTranslationMessage(key, args);
|
||||
}
|
||||
|
||||
public static String constructTranslationMessage(String key, String ... args) {
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("translate", key);
|
||||
msg.put("with", args);
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructInviteMessage(commandSender, groupName, joinCommand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendJsonMessage(player, Compatibility1_8.constructIncompatibleMessage(pluginVersion, pluginName));
|
||||
}
|
||||
|
||||
public static String constructInviteMessage(Player commandSender, String groupName, String joinCommand) {
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("translate", "message.voicechat.invite");
|
||||
JSONArray args = new JSONArray();
|
||||
args.put(commandSender.getName());
|
||||
JSONObject groupNameObj = new JSONObject();
|
||||
groupNameObj.put("color", "gray");
|
||||
groupNameObj.put("text", groupName);
|
||||
args.put(groupNameObj);
|
||||
JSONObject acceptInBrackets = new JSONObject();
|
||||
acceptInBrackets.put("text", "[");
|
||||
acceptInBrackets.put("color", "green");
|
||||
JSONArray extra = new JSONArray();
|
||||
JSONObject accept = new JSONObject();
|
||||
accept.put("translate", "message.voicechat.accept_invite");
|
||||
accept.put("color", "green");
|
||||
JSONObject clickEvent = new JSONObject();
|
||||
clickEvent.put("action", "run_command");
|
||||
clickEvent.put("value", joinCommand);
|
||||
accept.put("clickEvent", clickEvent);
|
||||
JSONObject hoverEvent = new JSONObject();
|
||||
hoverEvent.put("action", "show_text");
|
||||
JSONObject contents = new JSONObject();
|
||||
contents.put("translate", "message.voicechat.accept_invite.hover");
|
||||
hoverEvent.put("contents", contents);
|
||||
accept.put("hoverEvent", hoverEvent);
|
||||
extra.put(accept);
|
||||
extra.put("]");
|
||||
acceptInBrackets.put("extra", extra);
|
||||
args.put(acceptInBrackets);
|
||||
msg.put("with", args);
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
public static String constructIncompatibleMessage(String pluginVersion, String pluginName) {
|
||||
JSONObject msg = new JSONObject();
|
||||
msg.put("translate", "message.voicechat.incompatible_version");
|
||||
JSONArray with = new JSONArray();
|
||||
JSONObject version = new JSONObject();
|
||||
version.put("text", pluginVersion);
|
||||
version.put("bold", true);
|
||||
with.put(version);
|
||||
JSONObject name = new JSONObject();
|
||||
name.put("text", pluginName);
|
||||
name.put("bold", true);
|
||||
with.put(name);
|
||||
msg.put("with", with);
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> playerArgument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void send(Player player, String json, byte chatMessageType) {
|
||||
Object entityPlayer = ReflectionUtils.callMethod((Object)player, "getHandle");
|
||||
Object playerConnection = ReflectionUtils.getField(entityPlayer, "playerConnection");
|
||||
Class<?> packet = this.getServerClass("Packet");
|
||||
Class<?> chatSerializer = this.getServerClass("IChatBaseComponent$ChatSerializer");
|
||||
Class<?> iChatBaseComponentClass = this.getServerClass("IChatBaseComponent");
|
||||
Object iChatBaseComponent = ReflectionUtils.callMethod(chatSerializer, "a", new Class[]{String.class}, json);
|
||||
Class<?> packetPlayOutChatClass = this.getServerClass("PacketPlayOutChat");
|
||||
Object clientboundSystemChatPacket = ReflectionUtils.callConstructor(packetPlayOutChatClass, new Class[]{iChatBaseComponentClass, Byte.TYPE}, iChatBaseComponent, chatMessageType);
|
||||
ReflectionUtils.callMethod(playerConnection, "sendPacket", new Class[]{packet}, clientboundSystemChatPacket);
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
public class CompatibilityReflectionException
|
||||
extends RuntimeException {
|
||||
public CompatibilityReflectionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CompatibilityReflectionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* javax.annotation.Nullable
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.FallbackTranslations;
|
||||
import de.maxhenkel.voicechat.Version;
|
||||
import de.maxhenkel.voicechat.compatibility.BaseCompatibility;
|
||||
import de.maxhenkel.voicechat.util.Key;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FallbackCompatibility
|
||||
extends BaseCompatibility {
|
||||
public static final FallbackCompatibility INSTANCE = new FallbackCompatibility();
|
||||
|
||||
@Override
|
||||
public void sendTranslationMessage(Player player, String key, String ... args) {
|
||||
player.sendMessage(FallbackCompatibility.fallbackTranslation(key, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusMessage(Player player, String key, String ... args) {
|
||||
this.sendTranslationMessage(player, key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInviteMessage(Player player, Player commandSender, String groupName, String joinCommand) {
|
||||
this.sendTranslationMessage(player, "message.voicechat.invite", commandSender.getName(), groupName, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendIncompatibleMessage(Player player, String pluginVersion, String pluginName) {
|
||||
this.sendTranslationMessage(player, "message.voicechat.incompatible_version", pluginVersion, pluginName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key createNamespacedKey(String key) {
|
||||
Version version = Version.getVersion();
|
||||
if (version == null) {
|
||||
return super.createNamespacedKey(key);
|
||||
}
|
||||
if (version.getMajor() != 1) {
|
||||
return super.createNamespacedKey(key);
|
||||
}
|
||||
if (version.getMinor() > 12) {
|
||||
return super.createNamespacedKey(key);
|
||||
}
|
||||
return Key.of("vc", key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ArgumentType<?> playerArgument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String fallbackTranslation(String key, String ... args) {
|
||||
String rawTranslation = FallbackTranslations.FALLBACK_TRANSLATIONS.get(key);
|
||||
if (rawTranslation == null) {
|
||||
return key;
|
||||
}
|
||||
return String.format(rawTranslation, args);
|
||||
}
|
||||
}
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import de.maxhenkel.voicechat.compatibility.BaseCompatibility;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class JsonMessageBaseCompatibility
|
||||
extends BaseCompatibility {
|
||||
@Override
|
||||
public void sendTranslationMessage(Player player, String key, String ... args) {
|
||||
this.sendJsonMessage(player, this.createTranslationMessage(key, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusMessage(Player player, String key, String ... args) {
|
||||
this.sendJsonStatusMessage(player, this.createTranslationMessage(key, args));
|
||||
}
|
||||
|
||||
public abstract void sendJsonMessage(Player var1, String var2);
|
||||
|
||||
public abstract void sendJsonStatusMessage(Player var1, String var2);
|
||||
|
||||
public abstract String createTranslationMessage(String var1, String ... var2);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerHideEvent {
|
||||
private final Player hiddenPlayer;
|
||||
private final Player observer;
|
||||
|
||||
public PlayerHideEvent(Player hiddenPlayer, Player observer) {
|
||||
this.hiddenPlayer = hiddenPlayer;
|
||||
this.observer = observer;
|
||||
}
|
||||
|
||||
public Player getHiddenPlayer() {
|
||||
return this.hiddenPlayer;
|
||||
}
|
||||
|
||||
public Player getObserver() {
|
||||
return this.observer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerShowEvent {
|
||||
private final Player shownPlayer;
|
||||
private final Player observer;
|
||||
|
||||
public PlayerShowEvent(Player shownPlayer, Player observer) {
|
||||
this.shownPlayer = shownPlayer;
|
||||
this.observer = observer;
|
||||
}
|
||||
|
||||
public Player getShownPlayer() {
|
||||
return this.shownPlayer;
|
||||
}
|
||||
|
||||
public Player getObserver() {
|
||||
return this.observer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.annotation.Nullable
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import de.maxhenkel.voicechat.compatibility.CompatibilityReflectionException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ReflectionUtils {
|
||||
public static <T> T callMethod(Object object, String ... methodNames) {
|
||||
return ReflectionUtils.callMethod(object, methodNames, new Class[0], new Object[0]);
|
||||
}
|
||||
|
||||
public static <T> T callMethod(Object object, String[] methodNames, Class<?>[] parameterTypes, Object ... args) {
|
||||
return ReflectionUtils.callMethod(object.getClass(), object, methodNames, parameterTypes, args);
|
||||
}
|
||||
|
||||
public static <T> T callMethod(Object object, String methodName, Class<?>[] parameterTypes, Object ... args) {
|
||||
return ReflectionUtils.callMethod(object.getClass(), object, new String[]{methodName}, parameterTypes, args);
|
||||
}
|
||||
|
||||
public static <T> T callMethod(Class<?> clazz, Object object, String ... methodNames) {
|
||||
return ReflectionUtils.callMethod(clazz, object, methodNames, new Class[0], new Object[0]);
|
||||
}
|
||||
|
||||
public static <T> T callMethod(Class<?> clazz, Object object, String methodName, Class<?>[] parameterTypes, Object ... args) {
|
||||
return ReflectionUtils.callMethod(clazz, object, new String[]{methodName}, parameterTypes, args);
|
||||
}
|
||||
|
||||
public static <T> T callMethod(Class<?> clazz, Object object, String[] methodNames, Class<?>[] parameterTypes, Object ... args) {
|
||||
for (String name : methodNames) {
|
||||
try {
|
||||
Method method = clazz.getDeclaredMethod(name, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return (T)method.invoke(object, args);
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
try {
|
||||
Method method = clazz.getMethod(name, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return (T)method.invoke(object, args);
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new CompatibilityReflectionException(String.format("Could not find any of the following methods in the class %s: %s", clazz.getSimpleName(), String.join((CharSequence)", ", methodNames)));
|
||||
}
|
||||
|
||||
public static <T> T callMethod(Class<?> object, String ... methodNames) {
|
||||
return ReflectionUtils.callMethod(object, methodNames, new Class[0], new Object[0]);
|
||||
}
|
||||
|
||||
public static <T> T callMethod(Class<?> object, String[] methodNames, Class<?>[] parameterTypes, Object ... args) {
|
||||
return ReflectionUtils.callMethod(object, null, methodNames, parameterTypes, args);
|
||||
}
|
||||
|
||||
public static <T> T callMethod(Class<?> object, String methodName, Class<?>[] parameterTypes, Object ... args) {
|
||||
return ReflectionUtils.callMethod(object, null, new String[]{methodName}, parameterTypes, args);
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> clazz, String ... methodNames) {
|
||||
return ReflectionUtils.getMethod(clazz, methodNames, new Class[0]);
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> clazz, String[] methodNames, Class<?>[] parameterTypes) {
|
||||
for (String name : methodNames) {
|
||||
try {
|
||||
Method method = clazz.getDeclaredMethod(name, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
try {
|
||||
Method method = clazz.getMethod(name, parameterTypes);
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new CompatibilityReflectionException(String.format("Could not find any of the following methods in the class %s: %s", clazz.getSimpleName(), String.join((CharSequence)", ", methodNames)));
|
||||
}
|
||||
|
||||
public static <T> T call(Method method, @Nullable Object instance, Object ... args) {
|
||||
try {
|
||||
return (T)method.invoke(instance, args);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw new CompatibilityReflectionException(String.format("Failed to invoke method %s", method.getName()), t);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T callConstructor(Class<?> object) {
|
||||
return ReflectionUtils.callConstructor(object, new Class[0], new Object[0]);
|
||||
}
|
||||
|
||||
public static <T> T callConstructor(Class<?> object, Class<?>[] parameterTypes, Object ... args) {
|
||||
try {
|
||||
Constructor<?> constructor = object.getDeclaredConstructor(parameterTypes);
|
||||
constructor.setAccessible(true);
|
||||
return (T)constructor.newInstance(args);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw new CompatibilityReflectionException(String.format("Failed to invoke constructor of %s", object.getName()), t);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Constructor<T> getConstructor(Class<T> object, Class<?> ... parameterTypes) {
|
||||
try {
|
||||
Constructor<T> constructor = object.getDeclaredConstructor(parameterTypes);
|
||||
constructor.setAccessible(true);
|
||||
return constructor;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw new CompatibilityReflectionException(String.format("Failed to get constructor of %s", object.getName()), t);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T newInstance(Constructor<T> constructor, Object ... args) {
|
||||
try {
|
||||
return constructor.newInstance(args);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw new CompatibilityReflectionException(String.format("Failed to invoke constructor of %s", constructor.getDeclaringClass().getName()), t);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getField(Object object, String ... fieldNames) {
|
||||
for (String fieldName : fieldNames) {
|
||||
try {
|
||||
Field field = object.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T)field.get(object);
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
try {
|
||||
Field field = object.getClass().getField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T)field.get(object);
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new CompatibilityReflectionException(String.format("Could not find any of the following fields in the class %s: %s", object.getClass().getSimpleName(), String.join((CharSequence)", ", fieldNames)));
|
||||
}
|
||||
|
||||
public static <T> T getField(Class<?> clazz, String ... fieldNames) {
|
||||
for (String fieldName : fieldNames) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T)field.get(null);
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
try {
|
||||
Field field = clazz.getField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T)field.get(null);
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new CompatibilityReflectionException(String.format("Could not find any of the following fields in the class %s: %s", clazz.getSimpleName(), String.join((CharSequence)", ", fieldNames)));
|
||||
}
|
||||
|
||||
public static Class<?> getClazz(String ... classNames) {
|
||||
for (String className : classNames) {
|
||||
try {
|
||||
return Class.forName(className);
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
throw new CompatibilityReflectionException(String.format("Could not find any of the following classes: %s", String.join((CharSequence)", ", classNames)));
|
||||
}
|
||||
|
||||
public static boolean doesClassExist(String ... classNames) {
|
||||
for (String className : classNames) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean doesMethodExist(Class<?> clazz, String methodName, Class<?> ... parameterTypes) {
|
||||
try {
|
||||
clazz.getDeclaredMethod(methodName, parameterTypes);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
try {
|
||||
clazz.getMethod(methodName, parameterTypes);
|
||||
return true;
|
||||
}
|
||||
catch (Throwable throwable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* javax.annotation.Nullable
|
||||
* org.bukkit.Bukkit
|
||||
* org.bukkit.entity.Player
|
||||
*/
|
||||
package de.maxhenkel.voicechat.compatibility;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.compatibility.FallbackCompatibility;
|
||||
import de.maxhenkel.voicechat.compatibility.ReflectionUtils;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SpigotCompatibility
|
||||
extends FallbackCompatibility {
|
||||
public static final SpigotCompatibility INSTANCE = new SpigotCompatibility();
|
||||
private MessageSender messageSender;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
super.init();
|
||||
Class<?> playerSpigotClass = ReflectionUtils.getClazz("org.bukkit.entity.Player$Spigot");
|
||||
Class<?> baseComponentClass = ReflectionUtils.getClazz("net.md_5.bungee.api.chat.BaseComponent");
|
||||
Class<?> chatMessageTypeClass = ReflectionUtils.getClazz("net.md_5.bungee.api.ChatMessageType");
|
||||
Object systemType = ReflectionUtils.getField(chatMessageTypeClass, "SYSTEM");
|
||||
Object actionBarType = ReflectionUtils.getField(chatMessageTypeClass, "ACTION_BAR");
|
||||
Method playerSpigot = ReflectionUtils.getMethod(Player.class, "spigot");
|
||||
Method sendMessage = ReflectionUtils.getMethod(playerSpigotClass, new String[]{"sendMessage"}, new Class[]{chatMessageTypeClass, baseComponentClass});
|
||||
Class<?> translatableComponentClass = ReflectionUtils.getClazz("net.md_5.bungee.api.chat.TranslatableComponent");
|
||||
Constructor<?> translatableComponentConstructor = ReflectionUtils.getConstructor(translatableComponentClass, String.class, Object[].class);
|
||||
this.messageSender = (player, actionBar, key, args) -> {
|
||||
Object messageType = actionBar ? actionBarType : systemType;
|
||||
ReflectionUtils.call(sendMessage, ReflectionUtils.call(playerSpigot, player, new Object[0]), messageType, ReflectionUtils.newInstance(translatableComponentConstructor, key, args));
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean isSpigotCompatible() {
|
||||
return ReflectionUtils.doesMethodExist(Bukkit.class, "spigot", new Class[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTranslationMessage(Player player, String key, String ... args) {
|
||||
this.messageSender.send(player, false, key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStatusMessage(Player player, String key, String ... args) {
|
||||
this.messageSender.send(player, true, key, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ArgumentType<?> playerArgument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ArgumentType<?> uuidArgument() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static interface MessageSender {
|
||||
public void send(Player var1, boolean var2, String var3, String ... var4);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user