studio.magemonkey.divinity.nms.packets.versions.V1_19_R1 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of divinity Show documentation
Show all versions of divinity Show documentation
Custom items, combat, and more!
The newest version!
package studio.magemonkey.divinity.nms.packets.versions;
import com.mojang.datafixers.util.Pair;
import studio.magemonkey.codex.CodexEngine;
import studio.magemonkey.codex.hooks.Hooks;
import studio.magemonkey.codex.nms.packets.events.EnginePlayerPacketEvent;
import studio.magemonkey.codex.util.Reflex;
import studio.magemonkey.divinity.Divinity;
import studio.magemonkey.divinity.api.event.EntityEquipmentChangeEvent;
import studio.magemonkey.divinity.data.api.DivinityUser;
import studio.magemonkey.divinity.data.api.UserProfile;
import studio.magemonkey.divinity.manager.EntityManager;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Method;
import java.util.List;
import java.util.UUID;
public class V1_19_R1 extends V1_18_R2 {
public V1_19_R1(@NotNull Divinity plugin) {
super(plugin);
}
@Override
public void manageEquipmentChanges(@NotNull EnginePlayerPacketEvent e, @NotNull Object packet) {
Bukkit.getScheduler().runTask(plugin, () -> {
Class playoutUpdateAttributes = Reflex.getClass(PACKET_LOCATION, "PacketPlayOutUpdateAttributes");
Class craftServerClass = Reflex.getCraftClass("CraftServer");
Class nmsEntityClass = Reflex.getClass("net.minecraft.world.entity", "Entity");
Class worldServerClass = Reflex.getClass("net.minecraft.server.level", "WorldServer");
Object equip = playoutUpdateAttributes.cast(packet);
Integer entityId = (Integer) Reflex.getFieldValue(equip, "a");
if (entityId == null) return;
Object server = craftServerClass.cast(Bukkit.getServer());
Object nmsEntity = null;
Object dedicatedServer = Reflex.invokeMethod(
Reflex.getMethod(craftServerClass, "getServer"),
server
);
Iterable> worlds = (Iterable>) Reflex.invokeMethod(
Reflex.getMethod(dedicatedServer.getClass(), "E"), // Get worlds (getAllLevels)
dedicatedServer
);
Method getEntity = Reflex.getMethod(worldServerClass, "a", int.class);
for (Object worldServer : worlds) {
nmsEntity = Reflex.invokeMethod(getEntity, worldServer, entityId.intValue());
if (nmsEntity != null) {
break;
}
}
if (nmsEntity == null) return;
Entity bukkitEntity;
Method getUniqueId;
try {
getUniqueId = Reflex.getMethod(nmsEntityClass, "cp");
bukkitEntity =
CodexEngine.get().getServer().getEntity((UUID) Reflex.invokeMethod(getUniqueId, nmsEntity));
} catch (ClassCastException ex) {
getUniqueId = Reflex.getMethod(nmsEntityClass, "co");
bukkitEntity =
CodexEngine.get().getServer().getEntity((UUID) Reflex.invokeMethod(getUniqueId, nmsEntity));
}
if (!(bukkitEntity instanceof LivingEntity)) return;
if (EntityManager.isPacketDuplicatorFixed(bukkitEntity)
|| !EntityManager.isEquipmentNew((LivingEntity) bukkitEntity)) return;
EntityEquipmentChangeEvent event = new EntityEquipmentChangeEvent((LivingEntity) bukkitEntity);
plugin.getServer().getPluginManager().callEvent(event);
});
}
@Override
protected void managePlayerHelmet(@NotNull EnginePlayerPacketEvent e, @NotNull Object packet) {
Bukkit.getScheduler().runTask(Divinity.getInstance(), () -> {
Class playOutEntityEquipment = Reflex.getClass(PACKET_LOCATION, "PacketPlayOutEntityEquipment");
Class enumItemSlotClass = Reflex.getClass("net.minecraft.world.entity", "EnumItemSlot");
Object p = playOutEntityEquipment.cast(packet);
@SuppressWarnings("unchecked")
List> slots = (List>) Reflex.getFieldValue(p, "c");
Pair
© 2015 - 2024 Weber Informatics LLC | Privacy Policy