feat(global): downgrade project to jre1.8 for compatibility reasons

also fixed the impossibility to compile 1.13 to 1.16
because the PlayerInfoData class is NOT static
toying with NMS is not recommended and
i can see why but this is on another level
This commit is contained in:
aro 2023-01-31 18:11:05 +01:00
parent 5fa12e0ef7
commit 2bba64e521
31 changed files with 337 additions and 142 deletions

View file

@ -1,5 +1,6 @@
package net.artelnatif.nicko.impl;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
@ -14,8 +15,9 @@ import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.lang.reflect.InvocationTargetException;
public class v1_16_R3 implements Internals {
@Override
@ -73,7 +75,7 @@ public class v1_16_R3 implements Internals {
final MojangSkin skin = skinFetch.getResult();
final PropertyMap properties = gameProfile.getProperties();
properties.removeAll("textures");
properties.put("textures", new Property("textures", skin.value(), skin.signature()));
properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature()));
updateSelf(player);
}
}
@ -82,13 +84,18 @@ public class v1_16_R3 implements Internals {
final PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
final IChatBaseComponent name = new ChatComponentText(profileName);
// what the fuck? didn't even KNOW instantiating a new class from an existing object was possible in java
final PacketPlayOutPlayerInfo.PlayerInfoData data = remove.new PlayerInfoData(gameProfile,
player.getPing(),
EnumGamemode.getById(player.getGameMode().ordinal()), name);
final ArrayList<PacketPlayOutPlayerInfo.PlayerInfoData> list = new ArrayList<>();
list.add(data);
spoofPlayerInfoPacket(add, list);
// ok so what the actual fuck
// the PlayerDataInfo inner class is NOT public
// thus the compiler can't access it when compiling??????
// i swear this is so dumb that i have to resort to doing this
final Object infoData = yes(
add,
gameProfile,
entityPlayer.ping,
EnumGamemode.getById(player.getGameMode().ordinal()),
name
);
spoofPlayerInfoPacket(add, Lists.newArrayList(infoData));
Bukkit.getOnlinePlayers().forEach(online -> {
EntityPlayer onlineEntityPlayer = ((CraftPlayer) online).getHandle();
@ -108,4 +115,22 @@ public class v1_16_R3 implements Internals {
NickoBukkit.getInstance().getLogger().warning("Unable to spoof packet, that's bad! (" + e.getMessage() + ")");
}
}
public Object yes(PacketPlayOutPlayerInfo packet, GameProfile gameProfile, int ping, EnumGamemode gamemode, IChatBaseComponent name) {
try {
final Class<?> clazz = Class.forName("net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo$PlayerInfoData");
final Constructor<?> infoConstructor = clazz.getDeclaredConstructor(
PacketPlayOutPlayerInfo.class,
GameProfile.class,
int.class,
EnumGamemode.class,
IChatBaseComponent.class
);
return infoConstructor.newInstance(packet, gameProfile, ping, gamemode, name);
} catch (ClassNotFoundException | InvocationTargetException | NoSuchMethodException | InstantiationException |
IllegalAccessException e) {
NickoBukkit.getInstance().getLogger().warning("Unable to instantiate PlayerInfoData, that's bad! (" + e.getMessage() + ")");
return null;
}
}
}