Fix invalid calls to 1.12 methods

This commit is contained in:
libraryaddict 2020-07-04 18:01:30 +12:00
parent 1a256855e2
commit 6565fc5f4f
3 changed files with 37 additions and 29 deletions

View File

@ -729,30 +729,7 @@ public class FlagWatcher {
return; return;
if (itemStack == null && getDisguise().getEntity() instanceof LivingEntity) { if (itemStack == null && getDisguise().getEntity() instanceof LivingEntity) {
EntityEquipment equip = ((LivingEntity) getDisguise().getEntity()).getEquipment(); itemStack = ReflectionManager.getEquipment(slot, getDisguise().getEntity());
switch (slot) {
case HAND:
itemStack = equip.getItemInMainHand();
break;
case OFF_HAND:
itemStack = equip.getItemInOffHand();
break;
case HEAD:
itemStack = equip.getHelmet();
break;
case CHEST:
itemStack = equip.getChestplate();
break;
case LEGS:
itemStack = equip.getLeggings();
break;
case FEET:
itemStack = equip.getBoots();
break;
default:
break;
}
} }
Object itemToSend = ReflectionManager.getNmsItem(itemStack); Object itemToSend = ReflectionManager.getNmsItem(itemStack);

View File

@ -46,8 +46,10 @@ import org.bukkit.*;
import org.bukkit.boss.KeyedBossBar; import org.bukkit.boss.KeyedBossBar;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -2024,6 +2026,28 @@ public class DisguiseUtilities {
return list.toArray(new String[0]); return list.toArray(new String[0]);
} }
public static ItemStack getSlot(PlayerInventory equip, EquipmentSlot slot) {
switch (slot) {
case HAND:
return equip.getItemInMainHand();
case OFF_HAND:
return equip.getItemInOffHand();
case HEAD:
return equip.getHelmet();
case CHEST:
return equip.getChestplate();
case LEGS:
return equip.getLeggings();
case FEET:
return equip.getBoots();
default:
break;
}
return null;
}
/** /**
* Sends the self disguise to the player * Sends the self disguise to the player
*/ */
@ -2122,11 +2146,11 @@ public class DisguiseUtilities {
manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, list).createPacket(0, list)); manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, list).createPacket(0, list));
} else { } else {
for (EquipmentSlot slot : EquipmentSlot.values()) { for (EquipmentSlot slot : EquipmentSlot.values()) {
Object item = ReflectionManager.getNmsItem(getSlot(player.getInventory(), slot));
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0, sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, 0,
ReflectionManager.createEnumItemSlot(slot), ReflectionManager.createEnumItemSlot(slot), item)
ReflectionManager.getNmsItem(player.getInventory().getItem(slot))) .createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(slot), item));
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(slot),
ReflectionManager.getNmsItem(player.getInventory().getItem(slot))));
} }
} }

View File

@ -1121,7 +1121,9 @@ public class ReflectionManager {
Method toMinecraft = getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName", Method toMinecraft = getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName",
String.class); String.class);
return (Material) toMinecraft.invoke(null, name); Object instance = toMinecraft.getDeclaringClass().getField("INSTANCE").get(null);
return (Material) toMinecraft.invoke(instance, name);
} }
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name); Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name);
@ -1140,7 +1142,12 @@ public class ReflectionManager {
return (Material) getMaterial.invoke(null, item); return (Material) getMaterial.invoke(null, item);
} }
catch (Exception ex) { catch (Exception ex) {
DisguiseUtilities.getLogger().severe("Error when trying to convert '" + name + "' into a Material");
ex.printStackTrace(); ex.printStackTrace();
if (ex.getCause() != null) {
ex.getCause().printStackTrace();
}
} }
return null; return null;