From be4821daf35cdc547df5972a2fe06cc9d27fa767 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Thu, 19 Nov 2020 12:49:09 +0100 Subject: [PATCH] Add own PlayerEntity to World entities --- .../protocol/protocol/PacketHandler.java | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java index 8ece786c2..e760f45b1 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -116,7 +116,9 @@ public class PacketHandler { connection.getPlayer().getWorld().setHardcore(pkg.isHardcore()); connection.getMapping().setDimensions(pkg.getDimensions()); connection.getPlayer().getWorld().setDimension(pkg.getDimension()); - connection.getPlayer().setEntity(new PlayerEntity(connection, pkg.getEntityId(), connection.getPlayer().getPlayerUUID(), null, null, connection.getPlayer().getPlayerName(), new PlayerPropertyData[]{}, null)); + PlayerEntity entity = new PlayerEntity(connection, pkg.getEntityId(), connection.getPlayer().getPlayerUUID(), null, null, connection.getPlayer().getPlayerName(), new PlayerPropertyData[]{}, null); + connection.getPlayer().setEntity(entity); + connection.getPlayer().getWorld().addEntity(entity); connection.getSender().sendChatMessage("I am alive! ~ Minosoft"); } @@ -374,13 +376,7 @@ public class PacketHandler { } public void handle(PacketEntityMetadata pkg) { - Entity entity; - if (pkg.getEntityId() == connection.getPlayer().getEntity().getEntityId()) { - // our own meta data...set it - entity = connection.getPlayer().getEntity(); - } else { - entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); - } + Entity entity= connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if(entity == null){ // thanks mojang return; @@ -466,13 +462,7 @@ public class PacketHandler { } public void handle(PacketEntityEffect pkg) { - Entity entity; - if (pkg.getEntityId() == connection.getPlayer().getEntity().getEntityId()) { - // that's us! - entity = connection.getPlayer().getEntity(); - } else { - entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); - } + Entity entity= connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if(entity == null){ // thanks mojang return; @@ -481,13 +471,7 @@ public class PacketHandler { } public void handle(PacketRemoveEntityEffect pkg) { - Entity entity; - if (pkg.getEntityId() == connection.getPlayer().getEntity().getEntityId()) { - // that's us! - entity = connection.getPlayer().getEntity(); - } else { - entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); - } + Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if(entity == null){ // thanks mojang return; @@ -525,13 +509,7 @@ public class PacketHandler { } public void handle(PacketAttachEntity pkg) { - Entity entity; - if (pkg.getEntityId() == connection.getPlayer().getEntity().getEntityId()) { - // that's us! - entity = connection.getPlayer().getEntity(); - } else { - entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); - } + Entity entity = connection.getPlayer().getWorld().getEntity(pkg.getEntityId()); if(entity == null){ // thanks mojang return;