|
37 | 37 | import org.bukkit.inventory.InventoryHolder; |
38 | 38 | import org.bukkit.inventory.ItemStack; |
39 | 39 | import org.bukkit.persistence.PersistentDataContainer; |
| 40 | +import org.bukkit.persistence.PersistentDataHolder; |
40 | 41 | import org.bukkit.persistence.PersistentDataType; |
41 | 42 | import org.bukkit.plugin.java.JavaPlugin; |
42 | 43 |
|
@@ -122,12 +123,12 @@ public void onPacketSending(PacketEvent event) { |
122 | 123 | PacketContainer packet = event.getPacket(); |
123 | 124 | Entity entity = packet.getEntityModifier(event).read(0); |
124 | 125 |
|
125 | | - if (entity instanceof Vehicle vehicle) { |
126 | | - PersistentDataContainer pdc = vehicle.getPersistentDataContainer(); |
| 126 | + if (entity instanceof InventoryHolder) { |
| 127 | + PersistentDataContainer pdc = entity.getPersistentDataContainer(); |
127 | 128 | String serializedCustomName = pdc.get(clientSideRenderTitleKey, PersistentDataType.STRING); |
128 | 129 |
|
129 | 130 | if (serializedCustomName != null) { |
130 | | - WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(vehicle).deepClone(); |
| 131 | + WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity).deepClone(); |
131 | 132 | WrappedDataWatcher.Serializer chatSerializer = WrappedDataWatcher.Registry.getChatComponentSerializer(true); |
132 | 133 | final WrappedDataWatcher.WrappedDataWatcherObject optChatFieldWatcher = new WrappedDataWatcher.WrappedDataWatcherObject(2, chatSerializer); |
133 | 134 |
|
@@ -217,21 +218,22 @@ public void onVehicleDestroy(VehicleDestroyEvent event) { |
217 | 218 | } |
218 | 219 | } |
219 | 220 |
|
220 | | - // This is mainly for donkeys |
| 221 | + // This is mainly for donkeys, villagers etc... |
221 | 222 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) |
222 | 223 | public void onVehicleInteract(PlayerInteractEntityEvent event) { |
223 | | - if (event.getRightClicked() instanceof Vehicle vehicle) { |
| 224 | + Entity rightClicked = event.getRightClicked(); |
| 225 | + if (rightClicked instanceof InventoryHolder) { |
224 | 226 | Player player = event.getPlayer(); |
225 | 227 | ItemStack itemInHand = player.getInventory().getItem(event.getHand()); |
226 | 228 |
|
227 | 229 | if (itemInHand.getType() == Material.NAME_TAG) { |
228 | 230 | // Not happy with how this works, but seems to be the only way :( Create a PR if you have a better idea |
229 | 231 | Bukkit.getScheduler().runTaskLater(this, () -> { |
230 | | - Component customName = vehicle.customName(); |
| 232 | + Component customName = rightClicked.customName(); |
231 | 233 |
|
232 | 234 | if (customName != null && canUseTitle(customName)) { |
233 | | - vehicle.customName(null); |
234 | | - PersistentDataContainer pdc = vehicle.getPersistentDataContainer(); |
| 235 | + rightClicked.customName(null); |
| 236 | + PersistentDataContainer pdc = rightClicked.getPersistentDataContainer(); |
235 | 237 | pdc.set(clientSideRenderTitleKey, PersistentDataType.STRING, GsonComponentSerializer.gson().serialize(customName)); |
236 | 238 | } |
237 | 239 | }, 1L); |
|
0 commit comments