Fix hologram interaction in 1.8.x

This commit is contained in:
Eric 2016-11-19 21:34:29 +01:00
parent 6dcedc9bff
commit 198f83c738
2 changed files with 9 additions and 8 deletions

View File

@ -341,7 +341,7 @@ public class ShopInteractListener implements Listener {
Entity entity = e.getRightClicked(); Entity entity = e.getRightClicked();
Player p = e.getPlayer(); Player p = e.getPlayer();
if (e.getHand() == EquipmentSlot.HAND) { if (Utils.getMajorVersion() == 8 || e.getHand() == EquipmentSlot.HAND) {
if (entity instanceof ArmorStand) { if (entity instanceof ArmorStand) {
ArmorStand armorStand = (ArmorStand) entity; ArmorStand armorStand = (ArmorStand) entity;
if (Hologram.isPartOfHologram(armorStand)) { if (Hologram.isPartOfHologram(armorStand)) {
@ -355,7 +355,7 @@ public class ShopInteractListener implements Listener {
} }
if (b != null) { if (b != null) {
PlayerInteractEvent interactEvent = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, Utils.getPreferredItemInHand(p), b, null, EquipmentSlot.HAND); PlayerInteractEvent interactEvent = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, Utils.getPreferredItemInHand(p), b, null);
handleInteractEvent(interactEvent, false); handleInteractEvent(interactEvent, false);
} }
@ -388,8 +388,9 @@ public class ShopInteractListener implements Listener {
} }
if (b != null) { if (b != null) {
PlayerInteractEvent interactEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, Utils.getPreferredItemInHand(p), b, null, EquipmentSlot.HAND); PlayerInteractEvent interactEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, Utils.getPreferredItemInHand(p), b, null);
handleInteractEvent(interactEvent, false); handleInteractEvent(interactEvent, false);
e.setCancelled(true);
} }
} }

View File

@ -64,7 +64,7 @@ public class Hologram {
} else { } else {
if (plugin.getShopChestConfig().enable_hologram_interaction) { if (plugin.getShopChestConfig().enable_hologram_interaction) {
loc = location.clone(); loc = location.clone();
loc.add(0, 1, 0); loc.add(0, 0.4, 0);
} else { } else {
continue; continue;
} }
@ -90,10 +90,10 @@ public class Hologram {
entityArmorStandClass.getMethod("setNoGravity", boolean.class).invoke(entityArmorStand, true); entityArmorStandClass.getMethod("setNoGravity", boolean.class).invoke(entityArmorStand, true);
} }
// Probably like an addEntity() method... // Adds the entity to some lists so it can call interact events
Method b = nmsWorldServer.getClass().getDeclaredMethod("b", entityClass); Method addEntityMethod = nmsWorldServer.getClass().getDeclaredMethod((Utils.getMajorVersion() == 8 ? "a" : "b"), entityClass);
b.setAccessible(true); addEntityMethod.setAccessible(true);
b.invoke(nmsWorldServer, entityArmorStand); addEntityMethod.invoke(nmsWorldServer, entityArmorStand);
Object uuid = entityClass.getMethod("getUniqueID").invoke(entityArmorStand); Object uuid = entityClass.getMethod("getUniqueID").invoke(entityArmorStand);