use of me.devtec.theapi.bukkit.bossbar.BossBar in project TheAPI by TheDevTec.
the class BukkitLoader method onLoad.
public void onLoad() {
initTheAPI(this);
new Metrics(this, 10581);
boolean mohist = false;
try {
if (Class.forName("com.mohistmc.MohistMC", true, getClassLoader()) != null)
mohist = true;
} catch (Exception | NoClassDefFoundError err) {
}
try {
nmsProvider = (NmsProvider) Class.forName("me.devtec.theapi.bukkit.nms." + Ref.serverVersion() + (mohist ? "_Mohist" : ""), true, getClassLoader()).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (nmsProvider != null)
nmsProvider.loadParticles();
if (new File("spigot.yml").exists() && new Config("spigot.yml").getBoolean("settings.late-bind")) {
new Thread(() -> {
// ASYNC
if (Ref.isNewerThan(7))
handler = new PacketHandler_New(true);
else
handler = (PacketHandler<?>) Ref.newInstanceByClass("me.devtec.theapi.bukkit.packetlistener.PacketHandler_Legacy", true);
}).start();
} else {
if (Ref.isNewerThan(7))
handler = new PacketHandler_New(false);
else
handler = (PacketHandler<?>) Ref.newInstanceByClass("me.devtec.theapi.bukkit.packetlistener.PacketHandler_Legacy", false);
}
resource = Ref.nmsOrOld("network.protocol.game.PacketPlayInResourcePackStatus", "PacketPlayInResourcePackStatus");
close = Ref.nmsOrOld("network.protocol.game.PacketPlayInCloseWindow", "PacketPlayInCloseWindow");
click = Ref.nmsOrOld("network.protocol.game.PacketPlayInWindowClick", "PacketPlayInWindowClick");
itemname = Ref.nmsOrOld("network.protocol.game.PacketPlayInItemName", "PacketPlayInItemName");
airBlock = Ref.invoke(Ref.getNulled(Ref.field(Ref.nmsOrOld("world.level.block.Block", "Block"), "AIR")), "getBlockData");
if (airBlock == null)
airBlock = Ref.getNulled(Ref.field(Ref.nmsOrOld("world.level.block.Blocks", "Blocks"), "AIR"));
if (airBlock == null && Ref.isNewerThan(12))
airBlock = Ref.invoke(Ref.get(Ref.cast(Ref.craft("block.data.CraftBlockData"), Bukkit.createBlockData(Material.AIR)), "state"), "getBlock");
// BOSSBAR API: 1.7.10 - 1.8.8
if (Ref.isOlderThan(9)) {
new Tasker() {
public void run() {
for (BossBar s : bossbars) s.move();
}
}.runRepeating(0, 20);
} else
bossbars = null;
new PacketListener() {
@Override
public boolean PacketPlayOut(String player, Object packet, Object channel) {
return false;
}
public boolean isAllowedChatCharacter(char var0) {
return var0 != 167 && var0 >= ' ' && var0 != 127;
}
public String buildText(String var0) {
StringBuilder var1 = new StringBuilder();
char[] var2 = var0.toCharArray();
int var3 = var2.length;
for (int var4 = 0; var4 < var3; ++var4) {
char var5 = var2[var4];
if (isAllowedChatCharacter(var5)) {
var1.append(var5);
}
}
return var1.toString();
}
public boolean PacketPlayIn(String nick, Object packet, Object channel) {
// NPC
if (nick == null)
return false;
// ResourcePackAPI
if (resource != null && packet.getClass() == resource) {
Player player = Bukkit.getPlayer(nick);
if (player == null)
return false;
if (ResourcePackAPI.getResourcePack(player) == null || ResourcePackAPI.getHandlingPlayer(player) == null)
return false;
ResourcePackAPI.getHandlingPlayer(player).onHandle(player, ResourcePackAPI.getResourcePack(player), ResourcePackResult.valueOf(Ref.isNewerThan(16) ? getLegacyNameOf(Ref.get(packet, Ref.isNewerThan(16) ? "a" : "status").toString()) : Ref.get(packet, Ref.isNewerThan(16) ? "a" : "status").toString()));
return false;
}
// GUIS
if (packet.getClass() == itemname) {
Player player = Bukkit.getPlayer(nick);
if (player == null)
return false;
HolderGUI gui = BukkitLoader.gui.get(player.getUniqueId());
if (gui != null && gui instanceof AnvilGUI) {
nmsProvider.postToMainThread(() -> {
((AnvilGUI) gui).setRepairText(buildText(Ref.get(packet, "a") + ""));
});
return true;
}
}
if (packet.getClass() == close) {
Player player = Bukkit.getPlayer(nick);
if (player == null)
return false;
HolderGUI gui = BukkitLoader.gui.remove(player.getUniqueId());
if (gui == null)
return false;
gui.closeWithoutPacket(player);
return true;
}
if (packet.getClass() == click) {
Player player = Bukkit.getPlayer(nick);
if (player == null)
return false;
HolderGUI gui = BukkitLoader.gui.get(player.getUniqueId());
return gui == null ? false : nmsProvider.processInvClickPacket(player, gui, packet);
}
return false;
}
private String getLegacyNameOf(String string) {
switch(string.charAt(0)) {
case 'a':
return "SUCCESSFULLY_LOADED";
case 'b':
return "DECLINED";
case 'c':
return "FAILED_DOWNLOAD";
case 'd':
return "ACCEPTED";
}
return null;
}
}.register();
}
Aggregations