Fixed ReflectionUtils code order
This commit is contained in:
parent
6d1dab78aa
commit
3ca16d49b8
3 changed files with 45 additions and 34 deletions
|
@ -24,20 +24,19 @@
|
||||||
package tech.sbdevelopment.mapreflectionapi;
|
package tech.sbdevelopment.mapreflectionapi;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.map.MapView;
|
import org.bukkit.map.MapView;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import tech.sbdevelopment.mapreflectionapi.api.MapManager;
|
import tech.sbdevelopment.mapreflectionapi.api.MapManager;
|
||||||
import tech.sbdevelopment.mapreflectionapi.listeners.MapListener;
|
import tech.sbdevelopment.mapreflectionapi.listeners.MapListener;
|
||||||
import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
import tech.sbdevelopment.mapreflectionapi.listeners.PacketListener;
|
||||||
|
import tech.sbdevelopment.mapreflectionapi.util.ReflectionUtils;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class MapReflectionAPI extends JavaPlugin {
|
public class MapReflectionAPI extends JavaPlugin {
|
||||||
private static MapReflectionAPI instance;
|
private static MapReflectionAPI instance;
|
||||||
private static MapManager mapManager;
|
private static MapManager mapManager;
|
||||||
private ProtocolManager protocolManager;
|
|
||||||
|
|
||||||
public static MapReflectionAPI getInstance() {
|
public static MapReflectionAPI getInstance() {
|
||||||
if (instance == null) throw new IllegalStateException("The plugin is not enabled yet!");
|
if (instance == null) throw new IllegalStateException("The plugin is not enabled yet!");
|
||||||
|
@ -57,14 +56,25 @@ public class MapReflectionAPI extends JavaPlugin {
|
||||||
getLogger().info("MapReflectionAPI v" + getDescription().getVersion() + "");
|
getLogger().info("MapReflectionAPI v" + getDescription().getVersion() + "");
|
||||||
getLogger().info("Made by © Copyright SBDevelopment 2022");
|
getLogger().info("Made by © Copyright SBDevelopment 2022");
|
||||||
|
|
||||||
|
if (!ReflectionUtils.supports(12)) {
|
||||||
|
getLogger().severe("MapReflectionAPI only supports Minecraft 1.12 - 1.19!");
|
||||||
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Bukkit.getPluginManager().isPluginEnabled("BKCommonLib")) {
|
if (!Bukkit.getPluginManager().isPluginEnabled("BKCommonLib")) {
|
||||||
getLogger().severe("MapReflectionAPI requires BKCommonLib to function!");
|
getLogger().severe("MapReflectionAPI requires BKCommonLib to function!");
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
if (!Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||||
protocolManager.addPacketListener(new PacketListener(this));
|
getLogger().severe("MapReflectionAPI requires ProtocolLib to function!");
|
||||||
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketListener(this));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapManager = new MapManager(this);
|
mapManager = new MapManager(this);
|
||||||
|
|
|
@ -62,6 +62,36 @@ public final class ReflectionUtils {
|
||||||
* Performance is not a concern for these specific statically initialized values.
|
* Performance is not a concern for these specific statically initialized values.
|
||||||
*/
|
*/
|
||||||
public static final String VERSION;
|
public static final String VERSION;
|
||||||
|
|
||||||
|
static { // This needs to be right below VERSION because of initialization order.
|
||||||
|
// This package loop is used to avoid implementation-dependant strings like Bukkit.getVersion() or Bukkit.getBukkitVersion()
|
||||||
|
// which allows easier testing as well.
|
||||||
|
String found = null;
|
||||||
|
for (Package pack : Package.getPackages()) {
|
||||||
|
String name = pack.getName();
|
||||||
|
|
||||||
|
// .v because there are other packages.
|
||||||
|
if (name.startsWith("org.bukkit.craftbukkit.v")) {
|
||||||
|
found = pack.getName().split("\\.")[3];
|
||||||
|
|
||||||
|
// Just a final guard to make sure it finds this important class.
|
||||||
|
// As a protection for forge+bukkit implementation that tend to mix versions.
|
||||||
|
// The real CraftPlayer should exist in the package.
|
||||||
|
// Note: Doesn't seem to function properly. Will need to separate the version
|
||||||
|
// handler for NMS and CraftBukkit for softwares like catmc.
|
||||||
|
try {
|
||||||
|
Class.forName("org.bukkit.craftbukkit." + found + ".entity.CraftPlayer");
|
||||||
|
break;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
found = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found == null)
|
||||||
|
throw new IllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
|
||||||
|
VERSION = found;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw minor version number.
|
* The raw minor version number.
|
||||||
* E.g. {@code v1_17_R1} to {@code 17}
|
* E.g. {@code v1_17_R1} to {@code 17}
|
||||||
|
@ -95,35 +125,6 @@ public final class ReflectionUtils {
|
||||||
*/
|
*/
|
||||||
private static final MethodHandle SEND_PACKET;
|
private static final MethodHandle SEND_PACKET;
|
||||||
|
|
||||||
static { // This needs to be right below VERSION because of initialization order.
|
|
||||||
// This package loop is used to avoid implementation-dependant strings like Bukkit.getVersion() or Bukkit.getBukkitVersion()
|
|
||||||
// which allows easier testing as well.
|
|
||||||
String found = null;
|
|
||||||
for (Package pack : Package.getPackages()) {
|
|
||||||
String name = pack.getName();
|
|
||||||
|
|
||||||
// .v because there are other packages.
|
|
||||||
if (name.startsWith("org.bukkit.craftbukkit.v")) {
|
|
||||||
found = pack.getName().split("\\.")[3];
|
|
||||||
|
|
||||||
// Just a final guard to make sure it finds this important class.
|
|
||||||
// As a protection for forge+bukkit implementation that tend to mix versions.
|
|
||||||
// The real CraftPlayer should exist in the package.
|
|
||||||
// Note: Doesn't seem to function properly. Will need to separate the version
|
|
||||||
// handler for NMS and CraftBukkit for softwares like catmc.
|
|
||||||
try {
|
|
||||||
Class.forName("org.bukkit.craftbukkit." + found + ".entity.CraftPlayer");
|
|
||||||
break;
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
found = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found == null)
|
|
||||||
throw new IllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
|
|
||||||
VERSION = found;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Class<?> entityPlayer = getNMSClass("server.level", "EntityPlayer");
|
Class<?> entityPlayer = getNMSClass("server.level", "EntityPlayer");
|
||||||
Class<?> worldServer = getNMSClass("server.level", "WorldServer");
|
Class<?> worldServer = getNMSClass("server.level", "WorldServer");
|
||||||
|
|
|
@ -5,4 +5,4 @@ api-version: 1.13
|
||||||
authors: [ inventivetalent, SBDeveloper ]
|
authors: [ inventivetalent, SBDeveloper ]
|
||||||
description: This API helps developer with viewing images on maps.
|
description: This API helps developer with viewing images on maps.
|
||||||
website: https://sbdevelopment.tech
|
website: https://sbdevelopment.tech
|
||||||
softdepend: [ BKCommonLib ]
|
softdepend: [ BKCommonLib, ProtocolLib ]
|
Loading…
Add table
Reference in a new issue