#1740 has broken the PRIMED_TNT entity
Peng1104 opened this issue ยท 7 comments
- This issue is not solved in a development build
Describe the bug
The new way of getting the entitys, (#1740) has broken my plugin, Bukkit has a long problem of getting some entitys by their IDs, in special the PRIMED_TNT.
My Code:
@Override
public void onSend(PacketEvent event) {
if (event.getPacketType() == Server.SPAWN_ENTITY) {
PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(event.getPacket()); //PacketWrapper
if (packet.getEntityType() == EntityType.PRIMED_TNT) {
for (ProtectedRegion region : getRegionSet(getManager(event.getPlayer().getWorld()), packet.getLocation())) { // WorldGuard Stuff
if (region.getFlag(flag) == State.ALLOW) { // WorldGuard Stuff
event.setCancelled(true);
packet.getEntity(event).remove(); //Entity is null
break;
}
}
}
}
}
Expected behavior
Revert this commit.
Screenshots
If applicable, add screenshots to help explain your problem.
Version Info
ProtocolLib-5.0.0-SNAPSHOT-b576 to the latest one.
Idk what you want to say, but it seems to work for me?
I'm using this code:
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, PacketType.Play.Server.SPAWN_ENTITY) {
@Override
public void onPacketSending(PacketEvent event) {
EntityType type = event.getPacket().getEntityTypeModifier().read(0);
Entity resolved = event.getPacket().getEntityModifier(event).read(0);
event.getPlayer().sendMessage(type + " /// " + resolved);
}
});
git-Paper-86 (MC: 1.19.1)
Thx, I found it out now I affect the 1.8.X minecraft server version
Interesting, seems like there are different types of lists when an entity is added to the world. For TNT it kinda looks like this: addToAllEntity -> trackAndSendPacket -> addEntityById. Therefore you cannot find the entity using the outbound id.
I'm not happy with just using the old way (looping over all entities) to find the entity, there must be a better way to do that. Will take a look into that soonish.
Interesting, seems like there are different types of lists when an entity is added to the world. For TNT it kinda looks like this: addToAllEntity -> trackAndSendPacket -> addEntityById. Therefore you cannot find the entity using the outbound id.
I'm not happy with just using the old way (looping over all entities) to find the entity, there must be a better way to do that. Will take a look into that soonish.
Thx I am no specialist at the minecraft server inside workings, I have made a work around using the EntityExplodeEvent for my problem, but it has cause a side effect of a invisible PRIMED_TNT been pressent until it explodes, blocking any projectile from hitting the "behind" TNT.
@Override
public void onSend(PacketEvent event) {
if (event.getPacketType() == Server.SPAWN_ENTITY) {
PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(event.getPacket());
if (packet.getEntityType() == EntityType.PRIMED_TNT) {
for (ProtectedRegion region : getRegionSet(getManager(event.getPlayer().getWorld()),
packet.getLocation())) {
if (region.getFlag(flag) == State.ALLOW) {
event.setCancelled(true);
break;
}
}
}
}
}
@EventHandler
private void onTNTExplosion(@NotNull EntityExplodeEvent event) {
if (event.getEntityType() == EntityType.PRIMED_TNT) {
for (ProtectedRegion region : getRegionSet(getManager(event.getEntity().getWorld()),
event.getEntity().getLocation())) {
if (region.getFlag(flag) == State.ALLOW) {
event.getEntity().remove();
event.setCancelled(true);
break;
}
}
}
}