From 7b0af4ed35f3eff29b8b4cdaebf481dd1c711d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Endre=C3=9F?= Date: Tue, 19 Jan 2021 19:26:02 +0100 Subject: [PATCH] Some code cleanup --- pom.xml | 31 +- .../versiontools/entity/Hologram.java | 713 +++++------ .../entity/attributes/Nameable.java | 4 +- .../entity/handler/CustomEntity.java | 84 +- .../entity/handler/DefaultEntityType.java | 12 +- .../entity/handler/EntityBuilder.java | 28 +- .../entity/handler/EntityManager.java | 98 +- .../entity/handler/EntityRegistry.java | 96 +- .../entity/handler/EntityType.java | 2 +- .../reflection/BukkitConversion.java | 28 +- .../versiontools/reflection/DataProvider.java | 51 +- .../reflection/EntityProvider.java | 14 +- .../reflection/PacketHandler.java | 6 +- .../reflection/PlayerProvider.java | 48 +- .../reflection/TextureProvider.java | 160 +-- .../versiontools/reflection/ToolProvider.java | 14 +- .../reflection/VersionControl.java | 44 +- .../reflection/VersionHandler.java | 14 +- .../reflection/data/WrapType.java | 46 +- .../reflection/data/WrappedContainer.java | 54 +- .../reflection/data/WrappedContext.java | 4 +- .../reflection/data/WrappedKey.java | 20 +- .../data/persistence/DataDistributor.java | 99 +- .../data/persistence/DataObserver.java | 190 +-- .../data/persistence/PersistentContainer.java | 276 ++--- .../reflection/data/type/ObjectType.java | 36 +- .../reflection/data/type/SkinDataType.java | 64 +- .../data/wrap/SimpleSyntaxContainer.java | 198 +-- .../data/wrap/SimpleSyntaxContext.java | 40 +- .../data/wrap/SimpleSyntaxType.java | 50 +- .../reflection/data/wrap/SimpleWrapType.java | 50 +- .../reflection/data/wrap/SyntaxKey.java | 94 +- .../reflection/entity/NmsArmorStand.java | 4 +- .../reflection/entity/NmsEntity.java | 50 +- .../reflection/entity/NmsEntityLiving.java | 2 +- .../reflection/entity/NmsEntityType.java | 2 +- .../reflection/entity/NmsPlayer.java | 40 +- .../v1_10_R1/BukkitConversion1_10_R1.java | 364 +++--- .../v1_10_R1/EntityProvider1_10_R1.java | 60 +- .../v1_10_R1/PacketHandler1_10_R1.java | 6 +- .../v1_10_R1/PlayerProvider1_10_R1.java | 24 +- .../v1_10_R1/TextureProvider1_10_R1.java | 150 +-- .../v1_10_R1/ToolProvider1_10_R1.java | 40 +- .../v1_10_R1/VersionControl1_10_R1.java | 92 +- .../v1_10_R1/entity/ArmorStand1_10_R1.java | 22 +- .../v1_10_R1/entity/Entity1_10_R1.java | 366 +++--- .../v1_10_R1/entity/EntityLiving1_10_R1.java | 14 +- .../v1_10_R1/entity/Player1_10_R1.java | 452 +++---- .../reflection/NmsReflection1_10_R1.java | 32 +- .../v1_10_R1/tools/BlockTools1_10_R1.java | 42 +- .../v1_10_R1/tools/ServerTools1_10_R1.java | 16 +- .../v1_10_R1/tools/SkinTools1_10_R1.java | 8 +- .../utils/EntityConstructors1_10_R1.java | 2 +- .../v1_11_R1/BukkitConversion1_11_R1.java | 358 +++--- .../v1_11_R1/EntityProvider1_11_R1.java | 60 +- .../v1_11_R1/PacketHandler1_11_R1.java | 6 +- .../v1_11_R1/PlayerProvider1_11_R1.java | 24 +- .../v1_11_R1/TextureProvider1_11_R1.java | 146 +-- .../v1_11_R1/ToolProvider1_11_R1.java | 48 +- .../v1_11_R1/VersionControl1_11_R1.java | 92 +- .../v1_11_R1/entity/ArmorStand1_11_R1.java | 22 +- .../v1_11_R1/entity/Entity1_11_R1.java | 366 +++--- .../v1_11_R1/entity/EntityLiving1_11_R1.java | 14 +- .../v1_11_R1/entity/Player1_11_R1.java | 452 +++---- .../reflection/NmsReflection1_11_R1.java | 32 +- .../v1_11_R1/tools/BlockTools1_11_R1.java | 42 +- .../v1_11_R1/tools/ServerTools1_11_R1.java | 16 +- .../v1_11_R1/tools/SkinTools1_11_R1.java | 8 +- .../utils/EntityConstructors1_11_R1.java | 2 +- .../v1_12_R1/BukkitConversion1_12_R1.java | 351 +++--- .../v1_12_R1/EntityProvider1_12_R1.java | 60 +- .../v1_12_R1/PacketHandler1_12_R1.java | 6 +- .../v1_12_R1/PlayerProvider1_12_R1.java | 24 +- .../v1_12_R1/TextureProvider1_12_R1.java | 152 +-- .../v1_12_R1/ToolProvider1_12_R1.java | 50 +- .../v1_12_R1/VersionControl1_12_R1.java | 92 +- .../v1_12_R1/entity/ArmorStand1_12_R1.java | 22 +- .../v1_12_R1/entity/Entity1_12_R1.java | 366 +++--- .../v1_12_R1/entity/EntityLiving1_12_R1.java | 14 +- .../v1_12_R1/entity/Player1_12_R1.java | 452 +++---- .../reflection/NmsReflection1_12_R1.java | 34 +- .../v1_12_R1/tools/BlockTools1_12_R1.java | 42 +- .../v1_12_R1/tools/ServerTools1_12_R1.java | 16 +- .../v1_12_R1/tools/SkinTools1_12_R1.java | 8 +- .../utils/EntityConstructors1_12_R1.java | 2 +- .../v1_13_R1/BukkitConversion1_13_R1.java | 338 +++--- .../v1_13_R1/EntityProvider1_13_R1.java | 60 +- .../v1_13_R1/PacketHandler1_13_R1.java | 6 +- .../v1_13_R1/PlayerProvider1_13_R1.java | 24 +- .../v1_13_R1/TextureProvider1_13_R1.java | 144 +-- .../v1_13_R1/ToolProvider1_13_R1.java | 50 +- .../v1_13_R1/VersionControl1_13_R1.java | 92 +- .../v1_13_R1/entity/ArmorStand1_13_R1.java | 22 +- .../v1_13_R1/entity/Entity1_13_R1.java | 366 +++--- .../v1_13_R1/entity/EntityLiving1_13_R1.java | 14 +- .../v1_13_R1/entity/Player1_13_R1.java | 450 +++---- .../v1_13_R1/tools/BlockTools1_13_R1.java | 42 +- .../v1_13_R1/tools/ServerTools1_13_R1.java | 16 +- .../v1_13_R1/tools/SkinTools1_13_R1.java | 8 +- .../utils/EntityConstructors1_13_R1.java | 2 +- .../v1_13_R2/BukkitConversion1_13_R2.java | 338 +++--- .../v1_13_R2/EntityProvider1_13_R2.java | 60 +- .../v1_13_R2/PacketHandler1_13_R2.java | 6 +- .../v1_13_R2/PlayerProvider1_13_R2.java | 24 +- .../v1_13_R2/TextureProvider1_13_R2.java | 144 +-- .../v1_13_R2/ToolProvider1_13_R2.java | 48 +- .../v1_13_R2/VersionControl1_13_R2.java | 92 +- .../v1_13_R2/entity/ArmorStand1_13_R2.java | 22 +- .../v1_13_R2/entity/Entity1_13_R2.java | 366 +++--- .../v1_13_R2/entity/EntityLiving1_13_R2.java | 14 +- .../v1_13_R2/entity/Player1_13_R2.java | 450 +++---- .../v1_13_R2/tools/BlockTools1_13_R2.java | 42 +- .../v1_13_R2/tools/ServerTools1_13_R2.java | 16 +- .../v1_13_R2/tools/SkinTools1_13_R2.java | 8 +- .../utils/EntityConstructors1_13_R2.java | 2 +- .../v1_14_R1/BukkitConversion1_14_R1.java | 338 +++--- .../v1_14_R1/EntityProvider1_14_R1.java | 60 +- .../v1_14_R1/PacketHandler1_14_R1.java | 6 +- .../v1_14_R1/PlayerProvider1_14_R1.java | 14 +- .../v1_14_R1/TextureProvider1_14_R1.java | 144 +-- .../v1_14_R1/ToolProvider1_14_R1.java | 48 +- .../v1_14_R1/VersionControl1_14_R1.java | 92 +- .../v1_14_R1/data/BukkitContainer1_14_R1.java | 274 ++--- .../v1_14_R1/data/BukkitContext1_14_R1.java | 50 +- .../v1_14_R1/data/BukkitKey1_14_R1.java | 82 +- .../v1_14_R1/data/BukkitType1_14_R1.java | 115 +- .../data/SimpleBukkitType1_14_R1.java | 50 +- .../v1_14_R1/data/SyntaxContainer1_14_R1.java | 340 +++--- .../v1_14_R1/data/SyntaxContext1_14_R1.java | 50 +- .../v1_14_R1/data/SyntaxType1_14_R1.java | 127 +- .../v1_14_R1/data/WrappedType1_14_R1.java | 264 ++-- .../v1_14_R1/entity/ArmorStand1_14_R1.java | 22 +- .../v1_14_R1/entity/Entity1_14_R1.java | 366 +++--- .../v1_14_R1/entity/EntityLiving1_14_R1.java | 14 +- .../v1_14_R1/entity/Player1_14_R1.java | 446 +++---- .../v1_14_R1/tools/BlockTools1_14_R1.java | 42 +- .../v1_14_R1/tools/ServerTools1_14_R1.java | 16 +- .../v1_14_R1/tools/SkinTools1_14_R1.java | 8 +- .../utils/EntityConstructors1_14_R1.java | 2 +- .../v1_15_R1/BukkitConversion1_15_R1.java | 338 +++--- .../v1_15_R1/EntityProvider1_15_R1.java | 60 +- .../v1_15_R1/PacketHandler1_15_R1.java | 6 +- .../v1_15_R1/PlayerProvider1_15_R1.java | 14 +- .../v1_15_R1/TextureProvider1_15_R1.java | 144 +-- .../v1_15_R1/ToolProvider1_15_R1.java | 48 +- .../v1_15_R1/VersionControl1_15_R1.java | 92 +- .../v1_15_R1/data/BukkitContainer1_15_R1.java | 274 ++--- .../v1_15_R1/data/BukkitContext1_15_R1.java | 50 +- .../v1_15_R1/data/BukkitKey1_15_R1.java | 82 +- .../v1_15_R1/data/BukkitType1_15_R1.java | 115 +- .../data/SimpleBukkitType1_15_R1.java | 50 +- .../v1_15_R1/data/SyntaxContainer1_15_R1.java | 340 +++--- .../v1_15_R1/data/SyntaxContext1_15_R1.java | 50 +- .../v1_15_R1/data/SyntaxType1_15_R1.java | 127 +- .../v1_15_R1/data/WrappedType1_15_R1.java | 264 ++-- .../v1_15_R1/entity/ArmorStand1_15_R1.java | 22 +- .../v1_15_R1/entity/Entity1_15_R1.java | 366 +++--- .../v1_15_R1/entity/EntityLiving1_15_R1.java | 14 +- .../v1_15_R1/entity/Player1_15_R1.java | 446 +++---- .../v1_15_R1/tools/BlockTools1_15_R1.java | 42 +- .../v1_15_R1/tools/ServerTools1_15_R1.java | 16 +- .../v1_15_R1/tools/SkinTools1_15_R1.java | 8 +- .../utils/EntityConstructors1_15_R1.java | 2 +- .../v1_16_R1/BukkitConversion1_16_R1.java | 338 +++--- .../v1_16_R1/EntityProvider1_16_R1.java | 60 +- .../v1_16_R1/PacketHandler1_16_R1.java | 6 +- .../v1_16_R1/PlayerProvider1_16_R1.java | 14 +- .../v1_16_R1/TextureProvider1_16_R1.java | 144 +-- .../v1_16_R1/ToolProvider1_16_R1.java | 48 +- .../v1_16_R1/VersionControl1_16_R1.java | 92 +- .../v1_16_R1/data/BukkitContainer1_16_R1.java | 276 ++--- .../v1_16_R1/data/BukkitContext1_16_R1.java | 50 +- .../v1_16_R1/data/BukkitKey1_16_R1.java | 82 +- .../v1_16_R1/data/BukkitType1_16_R1.java | 115 +- .../data/SimpleBukkitType1_16_R1.java | 50 +- .../v1_16_R1/data/SyntaxContainer1_16_R1.java | 334 ++--- .../v1_16_R1/data/SyntaxContext1_16_R1.java | 50 +- .../v1_16_R1/data/SyntaxType1_16_R1.java | 127 +- .../v1_16_R1/data/WrappedType1_16_R1.java | 264 ++-- .../v1_16_R1/entity/ArmorStand1_16_R1.java | 22 +- .../v1_16_R1/entity/Entity1_16_R1.java | 366 +++--- .../v1_16_R1/entity/EntityLiving1_16_R1.java | 14 +- .../v1_16_R1/entity/Player1_16_R1.java | 449 +++---- .../v1_16_R1/tools/BlockTools1_16_R1.java | 42 +- .../v1_16_R1/tools/ServerTools1_16_R1.java | 16 +- .../v1_16_R1/tools/SkinTools1_16_R1.java | 8 +- .../utils/EntityConstructors1_16_R1.java | 2 +- .../v1_16_R2/BukkitConversion1_16_R2.java | 338 +++--- .../v1_16_R2/EntityProvider1_16_R2.java | 60 +- .../v1_16_R2/PacketHandler1_16_R2.java | 6 +- .../v1_16_R2/PlayerProvider1_16_R2.java | 14 +- .../v1_16_R2/TextureProvider1_16_R2.java | 144 +-- .../v1_16_R2/ToolProvider1_16_R2.java | 40 +- .../v1_16_R2/VersionControl1_16_R2.java | 92 +- .../v1_16_R2/data/BukkitContainer1_16_R2.java | 276 ++--- .../v1_16_R2/data/BukkitContext1_16_R2.java | 50 +- .../v1_16_R2/data/BukkitKey1_16_R2.java | 82 +- .../v1_16_R2/data/BukkitType1_16_R2.java | 115 +- .../data/SimpleBukkitType1_16_R2.java | 50 +- .../v1_16_R2/data/SyntaxContainer1_16_R2.java | 336 ++--- .../v1_16_R2/data/SyntaxContext1_16_R2.java | 50 +- .../v1_16_R2/data/SyntaxType1_16_R2.java | 127 +- .../v1_16_R2/data/WrappedType1_16_R2.java | 264 ++-- .../v1_16_R2/entity/ArmorStand1_16_R2.java | 22 +- .../v1_16_R2/entity/Entity1_16_R2.java | 366 +++--- .../v1_16_R2/entity/EntityLiving1_16_R2.java | 14 +- .../v1_16_R2/entity/Player1_16_R2.java | 451 +++---- .../v1_16_R2/tools/BlockTools1_16_R2.java | 42 +- .../v1_16_R2/tools/ServerTools1_16_R2.java | 16 +- .../v1_16_R2/tools/SkinTools1_16_R2.java | 8 +- .../utils/EntityConstructors1_16_R2.java | 2 +- .../v1_16_R3/BukkitConversion1_16_R3.java | 338 +++--- .../v1_16_R3/EntityProvider1_16_R3.java | 60 +- .../v1_16_R3/PacketHandler1_16_R3.java | 6 +- .../v1_16_R3/PlayerProvider1_16_R3.java | 14 +- .../v1_16_R3/TextureProvider1_16_R3.java | 144 +-- .../v1_16_R3/ToolProvider1_16_R3.java | 50 +- .../v1_16_R3/VersionControl1_16_R3.java | 92 +- .../v1_16_R3/data/BukkitContainer1_16_R3.java | 276 ++--- .../v1_16_R3/data/BukkitContext1_16_R3.java | 50 +- .../v1_16_R3/data/BukkitKey1_16_R3.java | 82 +- .../v1_16_R3/data/BukkitType1_16_R3.java | 115 +- .../data/SimpleBukkitType1_16_R3.java | 50 +- .../v1_16_R3/data/SyntaxContainer1_16_R3.java | 336 ++--- .../v1_16_R3/data/SyntaxContext1_16_R3.java | 50 +- .../v1_16_R3/data/SyntaxType1_16_R3.java | 127 +- .../v1_16_R3/data/WrappedType1_16_R3.java | 264 ++-- .../v1_16_R3/entity/ArmorStand1_16_R3.java | 22 +- .../v1_16_R3/entity/Entity1_16_R3.java | 366 +++--- .../v1_16_R3/entity/EntityLiving1_16_R3.java | 14 +- .../v1_16_R3/entity/Player1_16_R3.java | 451 +++---- .../v1_16_R3/tools/BlockTools1_16_R3.java | 42 +- .../v1_16_R3/tools/ServerTools1_16_R3.java | 16 +- .../v1_16_R3/tools/SkinTools1_16_R3.java | 8 +- .../utils/EntityConstructors1_16_R3.java | 2 +- .../v1_8_R1/BukkitConversion1_8_R1.java | 366 +++--- .../v1_8_R1/EntityProvider1_8_R1.java | 60 +- .../provider/v1_8_R1/PacketHandler1_8_R1.java | 6 +- .../v1_8_R1/PlayerProvider1_8_R1.java | 24 +- .../v1_8_R1/TextureProvider1_8_R1.java | 152 +-- .../provider/v1_8_R1/ToolProvider1_8_R1.java | 50 +- .../v1_8_R1/VersionControl1_8_R1.java | 92 +- .../v1_8_R1/entity/ArmorStand1_8_R1.java | 46 +- .../provider/v1_8_R1/entity/Entity1_8_R1.java | 362 +++--- .../v1_8_R1/entity/EntityLiving1_8_R1.java | 14 +- .../provider/v1_8_R1/entity/Player1_8_R1.java | 452 +++---- .../reflection/NmsReflection1_8_R1.java | 32 +- .../v1_8_R1/tools/BlockTools1_8_R1.java | 42 +- .../v1_8_R1/tools/ServerTools1_8_R1.java | 16 +- .../v1_8_R1/tools/SkinTools1_8_R1.java | 8 +- .../utils/EntityConstructors1_8_R1.java | 2 +- .../v1_8_R2/BukkitConversion1_8_R2.java | 364 +++--- .../v1_8_R2/EntityProvider1_8_R2.java | 60 +- .../provider/v1_8_R2/PacketHandler1_8_R2.java | 6 +- .../v1_8_R2/PlayerProvider1_8_R2.java | 24 +- .../v1_8_R2/TextureProvider1_8_R2.java | 150 +-- .../provider/v1_8_R2/ToolProvider1_8_R2.java | 40 +- .../v1_8_R2/VersionControl1_8_R2.java | 92 +- .../v1_8_R2/entity/ArmorStand1_8_R2.java | 46 +- .../provider/v1_8_R2/entity/Entity1_8_R2.java | 360 +++--- .../v1_8_R2/entity/EntityLiving1_8_R2.java | 14 +- .../provider/v1_8_R2/entity/Player1_8_R2.java | 452 +++---- .../reflection/NmsReflection1_8_R2.java | 32 +- .../v1_8_R2/tools/BlockTools1_8_R2.java | 42 +- .../v1_8_R2/tools/ServerTools1_8_R2.java | 16 +- .../v1_8_R2/tools/SkinTools1_8_R2.java | 8 +- .../utils/EntityConstructors1_8_R2.java | 2 +- .../v1_8_R3/BukkitConversion1_8_R3.java | 364 +++--- .../v1_8_R3/EntityProvider1_8_R3.java | 60 +- .../provider/v1_8_R3/PacketHandler1_8_R3.java | 6 +- .../v1_8_R3/PlayerProvider1_8_R3.java | 24 +- .../v1_8_R3/TextureProvider1_8_R3.java | 150 +-- .../provider/v1_8_R3/ToolProvider1_8_R3.java | 40 +- .../v1_8_R3/VersionControl1_8_R3.java | 92 +- .../v1_8_R3/entity/ArmorStand1_8_R3.java | 46 +- .../provider/v1_8_R3/entity/Entity1_8_R3.java | 360 +++--- .../v1_8_R3/entity/EntityLiving1_8_R3.java | 14 +- .../provider/v1_8_R3/entity/Player1_8_R3.java | 452 +++---- .../reflection/NmsReflection1_8_R3.java | 32 +- .../v1_8_R3/tools/BlockTools1_8_R3.java | 42 +- .../v1_8_R3/tools/ServerTools1_8_R3.java | 16 +- .../v1_8_R3/tools/SkinTools1_8_R3.java | 8 +- .../utils/EntityConstructors1_8_R3.java | 2 +- .../v1_9_R1/BukkitConversion1_9_R1.java | 364 +++--- .../v1_9_R1/EntityProvider1_9_R1.java | 60 +- .../provider/v1_9_R1/PacketHandler1_9_R1.java | 6 +- .../v1_9_R1/PlayerProvider1_9_R1.java | 24 +- .../v1_9_R1/TextureProvider1_9_R1.java | 150 +-- .../provider/v1_9_R1/ToolProvider1_9_R1.java | 40 +- .../v1_9_R1/VersionControl1_9_R1.java | 92 +- .../v1_9_R1/entity/ArmorStand1_9_R1.java | 46 +- .../provider/v1_9_R1/entity/Entity1_9_R1.java | 362 +++--- .../v1_9_R1/entity/EntityLiving1_9_R1.java | 14 +- .../provider/v1_9_R1/entity/Player1_9_R1.java | 452 +++---- .../reflection/NmsReflection1_9_R1.java | 32 +- .../v1_9_R1/tools/BlockTools1_9_R1.java | 42 +- .../v1_9_R1/tools/ServerTools1_9_R1.java | 16 +- .../v1_9_R1/tools/SkinTools1_9_R1.java | 8 +- .../utils/EntityConstructors1_9_R1.java | 2 +- .../v1_9_R2/BukkitConversion1_9_R2.java | 364 +++--- .../v1_9_R2/EntityProvider1_9_R2.java | 60 +- .../provider/v1_9_R2/PacketHandler1_9_R2.java | 6 +- .../v1_9_R2/PlayerProvider1_9_R2.java | 24 +- .../v1_9_R2/TextureProvider1_9_R2.java | 150 +-- .../provider/v1_9_R2/ToolProvider1_9_R2.java | 48 +- .../v1_9_R2/VersionControl1_9_R2.java | 92 +- .../v1_9_R2/entity/ArmorStand1_9_R2.java | 46 +- .../provider/v1_9_R2/entity/Entity1_9_R2.java | 360 +++--- .../v1_9_R2/entity/EntityLiving1_9_R2.java | 14 +- .../provider/v1_9_R2/entity/Player1_9_R2.java | 452 +++---- .../reflection/NmsReflection1_9_R2.java | 32 +- .../v1_9_R2/tools/BlockTools1_9_R2.java | 42 +- .../v1_9_R2/tools/ServerTools1_9_R2.java | 16 +- .../v1_9_R2/tools/SkinTools1_9_R2.java | 8 +- .../utils/EntityConstructors1_9_R2.java | 2 +- .../reflection/reflect/FakeReflect.java | 446 +++---- .../reflect/ReflectionProvider.java | 160 +-- .../reflection/reflect/Reflections.java | 28 +- .../reflect/provider/GeneralReflections.java | 36 +- .../reflection/tools/BlockTools.java | 4 +- .../reflection/tools/ServerTools.java | 4 +- .../reflection/tools/SkinTools.java | 18 +- .../reflection/utils/NmsBoundingBox.java | 1078 +++++++++-------- .../reflection/utils/Tracker.java | 56 +- .../minecraft/versiontools/skin/Mojang.java | 316 ++--- .../versiontools/skin/MojangProvider.java | 6 +- .../minecraft/versiontools/skin/Profile.java | 192 +-- .../minecraft/versiontools/skin/Skin.java | 322 ++--- .../versiontools/skin/SkinModel.java | 46 +- .../versiontools/skin/SkinRequest.java | 54 +- .../utils/bukkit/BukkitColor.java | 54 +- .../utils/bukkit/MojangProfileServer.java | 96 +- .../versiontools/utils/bukkit/Players.java | 78 +- .../utils/bukkit/unsafe/KeyCache.java | 84 +- .../utils/constants/DefaultConstants.java | 4 +- .../utils/constants/MinecraftConstants.java | 2 +- .../versiontools/utils/java/ArrayTools.java | 30 +- .../versiontools/utils/java/OptionTools.java | 18 +- .../utils/java/ReflectionTools.java | 22 +- .../versiontools/utils/java/UUIDHelper.java | 62 +- .../utils/java/function/TriPredicate.java | 114 +- .../versiontools/utils/thread/PostAsync.java | 76 +- .../utils/validation/ValidationHelper.java | 12 +- .../versiontools/version/ServerVersion.java | 322 ++--- .../versiontools/version/Versions.java | 204 ++-- 345 files changed, 19379 insertions(+), 19081 deletions(-) diff --git a/pom.xml b/pom.xml index 295d2b2..e6d4c75 100644 --- a/pom.xml +++ b/pom.xml @@ -21,11 +21,11 @@ - - github - GitHub OWNER Apache Maven Packages - https://maven.pkg.github.com/SourceWriters/vCompat - + + github + GitHub OWNER Apache Maven Packages + https://maven.pkg.github.com/SourceWriters/vCompat + @@ -104,22 +104,11 @@ - + bukkit diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/Hologram.java b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/Hologram.java index 46818de..26b0adf 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/Hologram.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/Hologram.java @@ -19,361 +19,362 @@ public class Hologram extends CustomEntity { - public static final EntityBuilder BUILDER = new HologramBuilder(); - - private final ArrayList entities = new ArrayList<>(); - private final ArrayList lines = new ArrayList<>(); - - private Location location; - private boolean alive = false; - - private double height = 0.1D; - private double offset = 0.25D; - - private Hologram(UUID uniqueId) { - super(uniqueId); - } - - /* - * CustomEntity handle - */ - - @Override - public boolean spawn() { - if (alive || !isSpawnable() || !hasLines() || location == null) { - return false; - } - synchronized (lines) { - for (String line : lines) { - spawnEntity(line); - } - updateOrder(0); - } - alive = true; - return true; - } - - @Override - public boolean kill() { - if (!alive) { - return false; - } - synchronized (entities) { - for (NmsArmorStand entity : entities) { - entity.kill(); - } - entities.clear(); - } - alive = false; - return true; - } - - @Override - public boolean isAlive() { - return alive; - } - - @Override - public Location getLocation() { - return location == null ? null : location.clone(); - } - - @Override - public EntityType getType() { - return DefaultEntityType.HOLOGRAM; - } - - @Override - public org.bukkit.entity.EntityType getBukkitType() { - return org.bukkit.entity.EntityType.ARMOR_STAND; - } - - @Override - public void setGravity(boolean gravity) { - - } - - @Override - public void setInvisible(boolean invisible) { - - } - - @Override - public void setInvulnerable(boolean invulnerable) { - - } - - @Override - public void teleport(Location location) { - this.location = location; - if (!alive) { - return; - } - updateOrder(0); - } - - /* - * Entity handle - */ - - public Hologram show(Player... players) { - int amount; - synchronized (entities) { - amount = entities.size(); - } - for (int index = 0; index < amount; index++) { - NmsArmorStand entity; - synchronized (entities) { - entity = entities.get(index); - } - entity.show(players); - } - return this; - } - - public Hologram hide(Player... players) { - int amount; - synchronized (entities) { - amount = entities.size(); - } - for (int index = 0; index < amount; index++) { - NmsArmorStand entity; - synchronized (entities) { - entity = entities.get(index); - } - entity.hide(players); - } - return this; - } - - private void updateText(int amount) { - int entityAmount; - synchronized (entities) { - entityAmount = entities.size(); - } - for (int index = 0; index < amount; index++) { - String line; - synchronized (lines) { - line = lines.get(index); - } - if (index >= entityAmount) { - spawnEntity(line); - continue; - } - updateEntity(index, line); - } - updateOrder(0); - } - - private void updateOrder(int offset) { - int amount; - synchronized (entities) { - amount = entities.size(); - } - if (amount == offset) { - return; - } - for (int index = amount - offset - 1; index >= 0; index--) { - NmsArmorStand entity; - synchronized (entities) { - entity = entities.get(index); - } - entity.setLocation(new Location(null, location.getX(), location.getY() + (this.offset * (amount - index)), location.getZ())); - } - } - - private void spawnEntity(String line) { - - NmsArmorStand entity = (NmsArmorStand) VersionControl.get().getEntityProvider().createEntity(location.getWorld(), NmsEntityType.ARMOR_STAND); - - entity.setCustomName(line); - entity.setCustomNameVisible(true); - entity.setInvisible(true); - entity.setSmall(true); - - NmsArmorStand entity0; - synchronized (entities) { - entities.add(entity); - if (entities.size() == 1) { - return; - } - entity0 = entities.get(0); - } - - entity.show(entity0.getVisibleAsPlayer()); - - } - - private void updateEntity(int index, String line) { - NmsArmorStand entity; - synchronized (entities) { - entity = entities.get(index); - } - entity.setCustomName(line); - } - - private void killEntity(int index) { - NmsArmorStand entity; - synchronized (entities) { - entity = entities.remove(index); - } - entity.kill(); - } - - /* - * Text handle - */ - - public void setHeight(double height) { - this.height = height; - } - - public double getHeight() { - return height; - } - - public void setOffset(double offset) { - this.offset = offset; - } - - public double getOffset() { - return offset; - } - - public NmsArmorStand[] getEntities() { - synchronized (entities) { - return entities.toArray(new NmsArmorStand[0]); - } - } - - public int lineCount() { - synchronized (lines) { - return lines.size(); - } - } - - public int indexOfLine(String line) { - synchronized (lines) { - return lines.indexOf(line); - } - } - - public boolean containsLine(String line) { - synchronized (lines) { - return lines.contains(line); - } - } - - public boolean containsLine(int index) { - return index >= 0 && index < lineCount(); - } - - public Hologram setLines(String... lines) { - return setLines(Arrays.asList(Objects.requireNonNull(lines))); - } - - public Hologram setLines(Collection lines) { - Objects.requireNonNull(lines); - synchronized (this.lines) { - this.lines.clear(); - this.lines.addAll(lines); - } - if (alive) { - updateText(lines.size()); - } - return this; - } - - public Hologram setLine(int index, String line) { - Objects.requireNonNull(line); - if (!containsLine(index)) { - return this; - } - synchronized (lines) { - lines.set(index, line); - } - if (alive) { - updateEntity(index, line); - } - return this; - } - - public Hologram addLine(String line) { - Objects.requireNonNull(line); - synchronized (lines) { - lines.add(line); - } - if (alive) { - spawnEntity(line); - updateOrder(0); - } - return this; - } - - public Hologram addLine(int index, String line) { - Objects.requireNonNull(line); - int size = lineCount(); - index = index < 0 ? 0 : (index >= size ? size - 1 : index); - synchronized (lines) { - lines.add(index, line); - } - if (alive) { - spawnEntity(line); - updateOrder(0); - } - return this; - } - - public boolean removeLine(int index) { - if (!containsLine(index)) { - return false; - } - synchronized (lines) { - lines.remove(index); - } - if (alive) { - killEntity(index); - updateOrder(index); - } - return true; - } - - public boolean removeLine(String line) { - return removeLine(indexOfLine(line)); - } - - public String[] getLines() { - synchronized (lines) { - return lines.toArray(new String[0]); - } - } - - public boolean hasLines() { - synchronized (lines) { - return !lines.isEmpty(); - } - } - - /* - * EntityBuilder class - */ - - private static class HologramBuilder extends EntityBuilder { - - private HologramBuilder() { - super(Hologram.class); - } - - @Override - public EntityType getType() { - return DefaultEntityType.HOLOGRAM; - } - - @Override - protected Hologram build(UUID uniqueId, Object... arguments) { - return new Hologram(uniqueId); - } - - } + public static final EntityBuilder BUILDER = new HologramBuilder(); + + private final ArrayList entities = new ArrayList<>(); + private final ArrayList lines = new ArrayList<>(); + + private Location location; + private boolean alive = false; + + private double height = 0.1D; + private double offset = 0.25D; + + private Hologram(UUID uniqueId) { + super(uniqueId); + } + + /* + * CustomEntity handle + */ + + @Override + public boolean spawn() { + if (alive || !isSpawnable() || !hasLines() || location == null) { + return false; + } + synchronized (lines) { + for (String line : lines) { + spawnEntity(line); + } + updateOrder(0); + } + alive = true; + return true; + } + + @Override + public boolean kill() { + if (!alive) { + return false; + } + synchronized (entities) { + for (NmsArmorStand entity : entities) { + entity.kill(); + } + entities.clear(); + } + alive = false; + return true; + } + + @Override + public boolean isAlive() { + return alive; + } + + @Override + public Location getLocation() { + return location == null ? null : location.clone(); + } + + @Override + public EntityType getType() { + return DefaultEntityType.HOLOGRAM; + } + + @Override + public org.bukkit.entity.EntityType getBukkitType() { + return org.bukkit.entity.EntityType.ARMOR_STAND; + } + + @Override + public void setGravity(boolean gravity) { + + } + + @Override + public void setInvisible(boolean invisible) { + + } + + @Override + public void setInvulnerable(boolean invulnerable) { + + } + + @Override + public void teleport(Location location) { + this.location = location; + if (!alive) { + return; + } + updateOrder(0); + } + + /* + * Entity handle + */ + + public Hologram show(Player... players) { + int amount; + synchronized (entities) { + amount = entities.size(); + } + for (int index = 0; index < amount; index++) { + NmsArmorStand entity; + synchronized (entities) { + entity = entities.get(index); + } + entity.show(players); + } + return this; + } + + public Hologram hide(Player... players) { + int amount; + synchronized (entities) { + amount = entities.size(); + } + for (int index = 0; index < amount; index++) { + NmsArmorStand entity; + synchronized (entities) { + entity = entities.get(index); + } + entity.hide(players); + } + return this; + } + + private void updateText(int amount) { + int entityAmount; + synchronized (entities) { + entityAmount = entities.size(); + } + for (int index = 0; index < amount; index++) { + String line; + synchronized (lines) { + line = lines.get(index); + } + if (index >= entityAmount) { + spawnEntity(line); + continue; + } + updateEntity(index, line); + } + updateOrder(0); + } + + private void updateOrder(int offset) { + int amount; + synchronized (entities) { + amount = entities.size(); + } + if (amount == offset) { + return; + } + for (int index = amount - offset - 1; index >= 0; index--) { + NmsArmorStand entity; + synchronized (entities) { + entity = entities.get(index); + } + entity.setLocation(new Location(null, location.getX(), location.getY() + (this.offset * (amount - index)), location.getZ())); + } + } + + private void spawnEntity(String line) { + + NmsArmorStand entity = (NmsArmorStand) VersionControl.get().getEntityProvider().createEntity(location.getWorld(), + NmsEntityType.ARMOR_STAND); + + entity.setCustomName(line); + entity.setCustomNameVisible(true); + entity.setInvisible(true); + entity.setSmall(true); + + NmsArmorStand entity0; + synchronized (entities) { + entities.add(entity); + if (entities.size() == 1) { + return; + } + entity0 = entities.get(0); + } + + entity.show(entity0.getVisibleAsPlayer()); + + } + + private void updateEntity(int index, String line) { + NmsArmorStand entity; + synchronized (entities) { + entity = entities.get(index); + } + entity.setCustomName(line); + } + + private void killEntity(int index) { + NmsArmorStand entity; + synchronized (entities) { + entity = entities.remove(index); + } + entity.kill(); + } + + /* + * Text handle + */ + + public void setHeight(double height) { + this.height = height; + } + + public double getHeight() { + return height; + } + + public void setOffset(double offset) { + this.offset = offset; + } + + public double getOffset() { + return offset; + } + + public NmsArmorStand[] getEntities() { + synchronized (entities) { + return entities.toArray(new NmsArmorStand[0]); + } + } + + public int lineCount() { + synchronized (lines) { + return lines.size(); + } + } + + public int indexOfLine(String line) { + synchronized (lines) { + return lines.indexOf(line); + } + } + + public boolean containsLine(String line) { + synchronized (lines) { + return lines.contains(line); + } + } + + public boolean containsLine(int index) { + return index >= 0 && index < lineCount(); + } + + public Hologram setLines(String... lines) { + return setLines(Arrays.asList(Objects.requireNonNull(lines))); + } + + public Hologram setLines(Collection lines) { + Objects.requireNonNull(lines); + synchronized (this.lines) { + this.lines.clear(); + this.lines.addAll(lines); + } + if (alive) { + updateText(lines.size()); + } + return this; + } + + public Hologram setLine(int index, String line) { + Objects.requireNonNull(line); + if (!containsLine(index)) { + return this; + } + synchronized (lines) { + lines.set(index, line); + } + if (alive) { + updateEntity(index, line); + } + return this; + } + + public Hologram addLine(String line) { + Objects.requireNonNull(line); + synchronized (lines) { + lines.add(line); + } + if (alive) { + spawnEntity(line); + updateOrder(0); + } + return this; + } + + public Hologram addLine(int index, String line) { + Objects.requireNonNull(line); + int size = lineCount(); + index = index < 0 ? 0 : (index >= size ? size - 1 : index); + synchronized (lines) { + lines.add(index, line); + } + if (alive) { + spawnEntity(line); + updateOrder(0); + } + return this; + } + + public boolean removeLine(int index) { + if (!containsLine(index)) { + return false; + } + synchronized (lines) { + lines.remove(index); + } + if (alive) { + killEntity(index); + updateOrder(index); + } + return true; + } + + public boolean removeLine(String line) { + return removeLine(indexOfLine(line)); + } + + public String[] getLines() { + synchronized (lines) { + return lines.toArray(new String[0]); + } + } + + public boolean hasLines() { + synchronized (lines) { + return !lines.isEmpty(); + } + } + + /* + * EntityBuilder class + */ + + private static class HologramBuilder extends EntityBuilder { + + private HologramBuilder() { + super(Hologram.class); + } + + @Override + public EntityType getType() { + return DefaultEntityType.HOLOGRAM; + } + + @Override + protected Hologram build(UUID uniqueId, Object... arguments) { + return new Hologram(uniqueId); + } + + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/attributes/Nameable.java b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/attributes/Nameable.java index 8313f56..355853d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/attributes/Nameable.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/attributes/Nameable.java @@ -2,8 +2,8 @@ public interface Nameable { - public void setCustomName(String name); + public void setCustomName(String name); - public void setCustomNameVisible(boolean visible); + public void setCustomNameVisible(boolean visible); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/CustomEntity.java b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/CustomEntity.java index 7fe7c5a..59893df 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/CustomEntity.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/CustomEntity.java @@ -6,66 +6,66 @@ public abstract class CustomEntity { - private EntityManager hook; + private EntityManager hook; - protected final UUID uniqueId; - protected Location location; - protected boolean deleted = false; + protected final UUID uniqueId; + protected Location location; + protected boolean deleted = false; - public CustomEntity(UUID uniqueId) { - this.uniqueId = uniqueId; - } + public CustomEntity(UUID uniqueId) { + this.uniqueId = uniqueId; + } - /* - * Hook / Unhook - */ + /* + * Hook / Unhook + */ - protected final void hook(EntityManager manager) { - this.hook = manager; - } + protected final void hook(EntityManager manager) { + this.hook = manager; + } - public final boolean isSpawnable() { - return hook != null; - } + public final boolean isSpawnable() { + return hook != null; + } - public final void remove() { - kill(); - hook.unhook(this); - hook = null; - } + public final void remove() { + kill(); + hook.unhook(this); + hook = null; + } - /* - * Getter - */ + /* + * Getter + */ - public UUID getUniqueId() { - return uniqueId; - } + public UUID getUniqueId() { + return uniqueId; + } - public Location getLocation() { - return location; - } + public Location getLocation() { + return location; + } - /* - * Handle - */ + /* + * Handle + */ - public abstract boolean spawn(); + public abstract boolean spawn(); - public abstract boolean kill(); + public abstract boolean kill(); - public abstract boolean isAlive(); + public abstract boolean isAlive(); - public abstract EntityType getType(); + public abstract EntityType getType(); - public abstract org.bukkit.entity.EntityType getBukkitType(); + public abstract org.bukkit.entity.EntityType getBukkitType(); - public abstract void setGravity(boolean gravity); + public abstract void setGravity(boolean gravity); - public abstract void setInvisible(boolean invisible); + public abstract void setInvisible(boolean invisible); - public abstract void setInvulnerable(boolean invulnerable); + public abstract void setInvulnerable(boolean invulnerable); - public abstract void teleport(Location location); + public abstract void teleport(Location location); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/DefaultEntityType.java b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/DefaultEntityType.java index f19ec58..797d84d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/DefaultEntityType.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/DefaultEntityType.java @@ -2,12 +2,12 @@ public enum DefaultEntityType implements EntityType { - HOLOGRAM, - NPC; + HOLOGRAM, + NPC; - @Override - public String getName() { - return name(); - } + @Override + public String getName() { + return name(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityBuilder.java b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityBuilder.java index c4320c8..eec16a5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityBuilder.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityBuilder.java @@ -6,24 +6,24 @@ public abstract class EntityBuilder { - protected final Class owner; - protected final Reflect reference; + protected final Class owner; + protected final Reflect reference; - public EntityBuilder(Class owner) { - this.owner = owner; - this.reference = new Reflect(owner); - } + public EntityBuilder(Class owner) { + this.owner = owner; + this.reference = new Reflect(owner); + } - public final Class getOwner() { - return owner; - } + public final Class getOwner() { + return owner; + } - public final Reflect getReference() { - return reference; - } + public final Reflect getReference() { + return reference; + } - public abstract EntityType getType(); + public abstract EntityType getType(); - protected abstract E build(UUID uniqueId, Object... arguments); + protected abstract E build(UUID uniqueId, Object... arguments); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityManager.java b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityManager.java index d294776..3e81b8b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityManager.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityManager.java @@ -8,64 +8,64 @@ public class EntityManager { - private final ArrayList entities = new ArrayList<>(); + private final ArrayList entities = new ArrayList<>(); - public CustomEntity create(EntityType type) { - return create(REGISTRY.getBuilderOrNull(type)); - } + public CustomEntity create(EntityType type) { + return create(REGISTRY.getBuilderOrNull(type)); + } - public E create(EntityBuilder builder, Object... arguments) { - return builder == null ? null : hook(builder.build(generateId(), arguments)); - } + public E create(EntityBuilder builder, Object... arguments) { + return builder == null ? null : hook(builder.build(generateId(), arguments)); + } - public Optional getById(UUID uniqueId) { - synchronized (entities) { - return entities.stream().filter(entity -> entity.getUniqueId().equals(uniqueId)).findFirst(); - } - } + public Optional getById(UUID uniqueId) { + synchronized (entities) { + return entities.stream().filter(entity -> entity.getUniqueId().equals(uniqueId)).findFirst(); + } + } - public CustomEntity getByIdOrNull(UUID uniqueId) { - return getById(uniqueId).orElse(null); - } + public CustomEntity getByIdOrNull(UUID uniqueId) { + return getById(uniqueId).orElse(null); + } - public CustomEntity[] getByType(EntityType type) { - synchronized (entities) { - return entities.stream().filter(entity -> entity.getType().equals(type)).toArray(CustomEntity[]::new); - } - } + public CustomEntity[] getByType(EntityType type) { + synchronized (entities) { + return entities.stream().filter(entity -> entity.getType().equals(type)).toArray(CustomEntity[]::new); + } + } - public CustomEntity[] getByBukkitType(org.bukkit.entity.EntityType type) { - synchronized (entities) { - return entities.stream().filter(entity -> entity.getBukkitType() == type).toArray(CustomEntity[]::new); - } - } + public CustomEntity[] getByBukkitType(org.bukkit.entity.EntityType type) { + synchronized (entities) { + return entities.stream().filter(entity -> entity.getBukkitType() == type).toArray(CustomEntity[]::new); + } + } - public CustomEntity[] getAll() { - synchronized (entities) { - return entities.toArray(new CustomEntity[0]); - } - } + public CustomEntity[] getAll() { + synchronized (entities) { + return entities.toArray(new CustomEntity[0]); + } + } - protected E hook(E entity) { - entity.hook(this); - synchronized (entities) { - entities.add(entity); - } - return entity; - } + protected E hook(E entity) { + entity.hook(this); + synchronized (entities) { + entities.add(entity); + } + return entity; + } - protected void unhook(CustomEntity entity) { - synchronized (entities) { - entities.remove(entity); - } - } + protected void unhook(CustomEntity entity) { + synchronized (entities) { + entities.remove(entity); + } + } - protected UUID generateId() { - UUID current = UUID.randomUUID(); - while (getById(current).isPresent()) { - current = UUID.randomUUID(); - } - return current; - } + protected UUID generateId() { + UUID current = UUID.randomUUID(); + while (getById(current).isPresent()) { + current = UUID.randomUUID(); + } + return current; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityRegistry.java b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityRegistry.java index 5562d56..1826136 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityRegistry.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityRegistry.java @@ -5,64 +5,64 @@ public final class EntityRegistry { - public static final EntityRegistry REGISTRY = new EntityRegistry(); + public static final EntityRegistry REGISTRY = new EntityRegistry(); - private final HashMap> builders = new HashMap<>(); + private final HashMap> builders = new HashMap<>(); - private EntityRegistry() {} + private EntityRegistry() {} - public EntityType[] getTypes() { - synchronized (builders) { - return builders.keySet().toArray(new EntityType[0]); - } - } + public EntityType[] getTypes() { + synchronized (builders) { + return builders.keySet().toArray(new EntityType[0]); + } + } - public EntityBuilder[] getBuilders() { - synchronized (builders) { - return builders.values().toArray(new EntityBuilder[0]); - } - } + public EntityBuilder[] getBuilders() { + synchronized (builders) { + return builders.values().toArray(new EntityBuilder[0]); + } + } - public Optional getType(String name) { - synchronized (builders) { - return builders.keySet().stream().filter(type -> type.getName().equals(name)).findFirst(); - } - } + public Optional getType(String name) { + synchronized (builders) { + return builders.keySet().stream().filter(type -> type.getName().equals(name)).findFirst(); + } + } - public EntityType getTypeOrNull(String name) { - return getType(name).orElse(null); - } + public EntityType getTypeOrNull(String name) { + return getType(name).orElse(null); + } - public Optional> getBuilder(EntityType type) { - return Optional.ofNullable(getBuilderOrNull(type)); - } + public Optional> getBuilder(EntityType type) { + return Optional.ofNullable(getBuilderOrNull(type)); + } - public EntityBuilder getBuilderOrNull(EntityType type) { - synchronized (builders) { - return builders.get(type); - } - } + public EntityBuilder getBuilderOrNull(EntityType type) { + synchronized (builders) { + return builders.get(type); + } + } - public boolean register(EntityBuilder builder) { - synchronized (builders) { - if (builder != null && builders.containsKey(builder.getType())) { - return false; - } - builders.put(builder.getType(), builder); - return true; - } - } + public boolean register(EntityBuilder builder) { + synchronized (builders) { + if (builder != null && builders.containsKey(builder.getType())) { + return false; + } + builders.put(builder.getType(), builder); + return true; + } + } - public boolean unregister(EntityBuilder builder) { - synchronized (builders) { - return builder != null && builders.remove(builder.getType(), builder); - } - } + public boolean unregister(EntityBuilder builder) { + synchronized (builders) { + return builder != null && builders.remove(builder.getType(), builder); + } + } - public boolean unregister(EntityType type) { - synchronized (builders) { - return type != null && builders.remove(type) != null; - } - } + public boolean unregister(EntityType type) { + synchronized (builders) { + return type != null && builders.remove(type) != null; + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityType.java b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityType.java index a384e84..93ab417 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityType.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/entity/handler/EntityType.java @@ -2,6 +2,6 @@ public interface EntityType { - public String getName(); + public String getName(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/BukkitConversion.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/BukkitConversion.java index 3029d64..5baed15 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/BukkitConversion.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/BukkitConversion.java @@ -13,30 +13,30 @@ public abstract class BukkitConversion extends VersionHandler { - protected BukkitConversion(V versionControl) { - super(versionControl); - } + protected BukkitConversion(V versionControl) { + super(versionControl); + } - public abstract EntityType toEntityType(NmsEntityType type); + public abstract EntityType toEntityType(NmsEntityType type); - public abstract NmsEntityType fromEntityType(EntityType type); + public abstract NmsEntityType fromEntityType(EntityType type); - public abstract Object toMinecraftTag(NbtTag tag); + public abstract Object toMinecraftTag(NbtTag tag); - public abstract NbtTag fromMinecraftTag(Object tag); + public abstract NbtTag fromMinecraftTag(Object tag); - public abstract Object toMinecraftList(NbtList list); + public abstract Object toMinecraftList(NbtList list); - public abstract NbtList fromMinecraftList(Object list); + public abstract NbtList fromMinecraftList(Object list); - public abstract Object toMinecraftCompound(NbtCompound compound); + public abstract Object toMinecraftCompound(NbtCompound compound); - public abstract NbtCompound fromMinecraftCompound(Object compound); + public abstract NbtCompound fromMinecraftCompound(Object compound); - public abstract ItemStack itemFromCompound(NbtCompound compound); + public abstract ItemStack itemFromCompound(NbtCompound compound); - public abstract NbtCompound itemToCompound(ItemStack itemStack); + public abstract NbtCompound itemToCompound(ItemStack itemStack); - public abstract WrappedContext createContext(DataAdapterContext context); + public abstract WrappedContext createContext(DataAdapterContext context); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/DataProvider.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/DataProvider.java index cce05fc..c05ba59 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/DataProvider.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/DataProvider.java @@ -16,38 +16,39 @@ public class DataProvider extends VersionHandler { - public static final Function DEFAULT_NAMING = UUID::toString; - public static final Supplier DEFAULT_RANDOM = UUID::randomUUID; + public static final Function DEFAULT_NAMING = UUID::toString; + public static final Supplier DEFAULT_RANDOM = UUID::randomUUID; - protected final NbtAdapterRegistry registry = new NbtAdapterRegistry(); - protected final DataDistributor defaultDistributor = createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "pluginData")); + protected final NbtAdapterRegistry registry = new NbtAdapterRegistry(); + protected final DataDistributor defaultDistributor = createDistributor( + new File(Bukkit.getWorlds().get(0).getWorldFolder(), "pluginData")); - protected DataProvider(VersionControl versionControl) { - super(versionControl); - } + protected DataProvider(VersionControl versionControl) { + super(versionControl); + } - public final NbtAdapterRegistry getRegistry() { - return registry; - } + public final NbtAdapterRegistry getRegistry() { + return registry; + } - public WrappedContainer createContainer() { - return new SimpleSyntaxContainer<>(new NbtContainer(registry)); - } + public WrappedContainer createContainer() { + return new SimpleSyntaxContainer<>(new NbtContainer(registry)); + } - public WrappedContainer createPersistentContainer() { - return new SimpleSyntaxContainer<>(defaultDistributor.create()); - } + public WrappedContainer createPersistentContainer() { + return new SimpleSyntaxContainer<>(defaultDistributor.create()); + } - public DataDistributor getDefaultDistributor() { - return defaultDistributor; - } + public DataDistributor getDefaultDistributor() { + return defaultDistributor; + } - public DataDistributor createDistributor(File location) { - return new DataDistributor<>(this, location, DEFAULT_NAMING, DEFAULT_RANDOM); - } + public DataDistributor createDistributor(File location) { + return new DataDistributor<>(this, location, DEFAULT_NAMING, DEFAULT_RANDOM); + } - public DataDistributor createDistributor(File location, Function namingFunction, Supplier randomFunction) { - return new DataDistributor<>(this, location, namingFunction, randomFunction); - } + public DataDistributor createDistributor(File location, Function namingFunction, Supplier randomFunction) { + return new DataDistributor<>(this, location, namingFunction, randomFunction); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/EntityProvider.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/EntityProvider.java index 5694410..5544114 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/EntityProvider.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/EntityProvider.java @@ -8,14 +8,14 @@ public abstract class EntityProvider extends VersionHandler { - protected EntityProvider(V versionControl) { - super(versionControl); - } + protected EntityProvider(V versionControl) { + super(versionControl); + } - public NmsEntity createEntity(World world, EntityType type) { - return createEntity(world, versionControl.getBukkitConversion().fromEntityType(type)); - } + public NmsEntity createEntity(World world, EntityType type) { + return createEntity(world, versionControl.getBukkitConversion().fromEntityType(type)); + } - public abstract NmsEntity createEntity(World world, NmsEntityType type); + public abstract NmsEntity createEntity(World world, NmsEntityType type); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/PacketHandler.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/PacketHandler.java index c6ec279..f4d70d0 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/PacketHandler.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/PacketHandler.java @@ -2,8 +2,8 @@ public abstract class PacketHandler extends VersionHandler { - protected PacketHandler(V versionControl) { - super(versionControl); - } + protected PacketHandler(V versionControl) { + super(versionControl); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/PlayerProvider.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/PlayerProvider.java index d746788..dd1e191 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/PlayerProvider.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/PlayerProvider.java @@ -12,29 +12,29 @@ public abstract class PlayerProvider extends VersionHandler { - protected final Map players = Collections.synchronizedMap(new HashMap<>()); - - protected PlayerProvider(V versionControl) { - super(versionControl); - } - - public NmsPlayer getPlayer(UUID uniqueId) { - Player player = Bukkit.getPlayer(uniqueId); - if (player == null) { - return players.get(uniqueId); - } - return getPlayer(player); - } - - public NmsPlayer getPlayer(Player player) { - if (players.containsKey(player.getUniqueId())) { - return players.get(player.getUniqueId()); - } - NmsPlayer nmsPlayer = createPlayer(player); - players.put(player.getUniqueId(), nmsPlayer); - return nmsPlayer; - } - - protected abstract NmsPlayer createPlayer(Player player); + protected final Map players = Collections.synchronizedMap(new HashMap<>()); + + protected PlayerProvider(V versionControl) { + super(versionControl); + } + + public NmsPlayer getPlayer(UUID uniqueId) { + Player player = Bukkit.getPlayer(uniqueId); + if (player == null) { + return players.get(uniqueId); + } + return getPlayer(player); + } + + public NmsPlayer getPlayer(Player player) { + if (players.containsKey(player.getUniqueId())) { + return players.get(player.getUniqueId()); + } + NmsPlayer nmsPlayer = createPlayer(player); + players.put(player.getUniqueId(), nmsPlayer); + return nmsPlayer; + } + + protected abstract NmsPlayer createPlayer(Player player); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/TextureProvider.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/TextureProvider.java index a396d54..6ac7aef 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/TextureProvider.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/TextureProvider.java @@ -17,85 +17,85 @@ public abstract class TextureProvider extends VersionHandler { - protected final Map textures = Collections.synchronizedMap(new HashMap<>()); - protected final Keys random = new Keys(); - - protected TextureProvider(V versionControl) { - super(versionControl); - } - - protected final GameProfile generateProfile() { - return new GameProfile(UUID.randomUUID(), random.makeKey(12)); - } - - protected final void applyTexture(GameProfile profile, String texture) { - PropertyMap map = profile.getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", TEXTURE_SIGNATURE + texture)); - } - - public String textureFromProfile(GameProfile profile) { - return profile.getProperties().get("textures").iterator().next().getValue(); - } - - public String textureFromBlock(Block block) { - return textureFromProfile(profileFromBlock(block)); - } - - public String textureFromItem(ItemStack itemStack) { - return textureFromProfile(profileFromItem(itemStack)); - } - - public GameProfile getCacheProfile(String texture) { - texture = texture.replace(TEXTURE_SIGNATURE, ""); - if (textures.containsKey(texture)) { - return textures.get(texture); - } - GameProfile profile = profileFromTexture(texture); - textures.put(texture, profile); - return profile; - } - - public GameProfile getCacheProfile(Block block) { - GameProfile profile = profileFromBlock(block); - return textures.containsValue(profile) ? profile : getCacheProfile(textureFromProfile(profile)); - } - - public GameProfile getCacheProfile(ItemStack itemStack) { - GameProfile profile = profileFromItem(itemStack); - return textures.containsValue(profile) ? profile : getCacheProfile(textureFromProfile(profile)); - } - - public GameProfile profileFromTexture(String texture) { - GameProfile profile = generateProfile(); - applyTexture(profile, texture); - return profile; - } - - public abstract GameProfile profileFromBlock(Block block); - - public abstract GameProfile profileFromItem(ItemStack itemStack); - - public GameProfile removeProfile(String texture) { - return textures.remove(texture); - } - - public ItemStack getItem(String texture) { - return getItem(getCacheProfile(texture)); - } - - public abstract ItemStack getItem(GameProfile profile); - - public boolean applyItem(ItemStack itemStack, String texture) { - return applyItem(itemStack, getCacheProfile(texture)); - } - - public abstract boolean applyItem(ItemStack itemStack, GameProfile profile); - - public boolean applyBlock(Block block, String texture) { - return applyBlock(block, getCacheProfile(texture)); - } - - public abstract boolean applyBlock(Block block, GameProfile profile); + protected final Map textures = Collections.synchronizedMap(new HashMap<>()); + protected final Keys random = new Keys(); + + protected TextureProvider(V versionControl) { + super(versionControl); + } + + protected final GameProfile generateProfile() { + return new GameProfile(UUID.randomUUID(), random.makeKey(12)); + } + + protected final void applyTexture(GameProfile profile, String texture) { + PropertyMap map = profile.getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", TEXTURE_SIGNATURE + texture)); + } + + public String textureFromProfile(GameProfile profile) { + return profile.getProperties().get("textures").iterator().next().getValue(); + } + + public String textureFromBlock(Block block) { + return textureFromProfile(profileFromBlock(block)); + } + + public String textureFromItem(ItemStack itemStack) { + return textureFromProfile(profileFromItem(itemStack)); + } + + public GameProfile getCacheProfile(String texture) { + texture = texture.replace(TEXTURE_SIGNATURE, ""); + if (textures.containsKey(texture)) { + return textures.get(texture); + } + GameProfile profile = profileFromTexture(texture); + textures.put(texture, profile); + return profile; + } + + public GameProfile getCacheProfile(Block block) { + GameProfile profile = profileFromBlock(block); + return textures.containsValue(profile) ? profile : getCacheProfile(textureFromProfile(profile)); + } + + public GameProfile getCacheProfile(ItemStack itemStack) { + GameProfile profile = profileFromItem(itemStack); + return textures.containsValue(profile) ? profile : getCacheProfile(textureFromProfile(profile)); + } + + public GameProfile profileFromTexture(String texture) { + GameProfile profile = generateProfile(); + applyTexture(profile, texture); + return profile; + } + + public abstract GameProfile profileFromBlock(Block block); + + public abstract GameProfile profileFromItem(ItemStack itemStack); + + public GameProfile removeProfile(String texture) { + return textures.remove(texture); + } + + public ItemStack getItem(String texture) { + return getItem(getCacheProfile(texture)); + } + + public abstract ItemStack getItem(GameProfile profile); + + public boolean applyItem(ItemStack itemStack, String texture) { + return applyItem(itemStack, getCacheProfile(texture)); + } + + public abstract boolean applyItem(ItemStack itemStack, GameProfile profile); + + public boolean applyBlock(Block block, String texture) { + return applyBlock(block, getCacheProfile(texture)); + } + + public abstract boolean applyBlock(Block block, GameProfile profile); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/ToolProvider.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/ToolProvider.java index 714caee..3142c7b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/ToolProvider.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/ToolProvider.java @@ -6,14 +6,14 @@ public abstract class ToolProvider extends VersionHandler { - protected ToolProvider(V versionControl) { - super(versionControl); - } + protected ToolProvider(V versionControl) { + super(versionControl); + } - public abstract SkinTools getSkinTools(); + public abstract SkinTools getSkinTools(); - public abstract ServerTools getServerTools(); - - public abstract BlockTools getBlockTools(); + public abstract ServerTools getServerTools(); + + public abstract BlockTools getBlockTools(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/VersionControl.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/VersionControl.java index b5fb827..d470d37 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/VersionControl.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/VersionControl.java @@ -7,36 +7,36 @@ public abstract class VersionControl { - public static final String CLASSPATH = "net.sourcewriters.minecraft.versiontools.reflection.provider.v$version.VersionControl$version"; - public static Container CURRENT = Container.of(); + public static final String CLASSPATH = "net.sourcewriters.minecraft.versiontools.reflection.provider.v$version.VersionControl$version"; + public static Container CURRENT = Container.of(); - public static VersionControl get() { - if (CURRENT.isPresent()) { - return CURRENT.get(); - } - Reflect reflect = new Reflect(CLASSPATH.replace("$version", Versions.getServerAsString().substring(1))); - if (reflect.getOwner() == null || !VersionControl.class.isAssignableFrom(reflect.getOwner())) { - return null; - } - return CURRENT.replace((VersionControl) reflect.searchMethod("init", "init").run("init")).lock().get(); - } + public static VersionControl get() { + if (CURRENT.isPresent()) { + return CURRENT.get(); + } + Reflect reflect = new Reflect(CLASSPATH.replace("$version", Versions.getServerAsString().substring(1))); + if (reflect.getOwner() == null || !VersionControl.class.isAssignableFrom(reflect.getOwner())) { + return null; + } + return CURRENT.replace((VersionControl) reflect.searchMethod("init", "init").run("init")).lock().get(); + } - protected final DataProvider dataProvider = new DataProvider(this); + protected final DataProvider dataProvider = new DataProvider(this); - public DataProvider getDataProvider() { - return dataProvider; - } + public DataProvider getDataProvider() { + return dataProvider; + } - public abstract ToolProvider getToolProvider(); + public abstract ToolProvider getToolProvider(); - public abstract EntityProvider getEntityProvider(); + public abstract EntityProvider getEntityProvider(); - public abstract PlayerProvider getPlayerProvider(); + public abstract PlayerProvider getPlayerProvider(); - public abstract TextureProvider getTextureProvider(); + public abstract TextureProvider getTextureProvider(); - public abstract PacketHandler getPacketHandler(); + public abstract PacketHandler getPacketHandler(); - public abstract BukkitConversion getBukkitConversion(); + public abstract BukkitConversion getBukkitConversion(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/VersionHandler.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/VersionHandler.java index 6d5cace..912ca02 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/VersionHandler.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/VersionHandler.java @@ -2,14 +2,14 @@ public abstract class VersionHandler { - protected final V versionControl; + protected final V versionControl; - protected VersionHandler(V versionControl) { - this.versionControl = versionControl; - } + protected VersionHandler(V versionControl) { + this.versionControl = versionControl; + } - public final V getVersionControl() { - return versionControl; - } + public final V getVersionControl() { + return versionControl; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrapType.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrapType.java index 476ad9b..b925168 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrapType.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrapType.java @@ -11,39 +11,39 @@ public interface WrapType { - public static final SimpleWrapType BYTE = new SimpleWrapType<>(PrimitiveDataType.BYTE); - public static final SimpleWrapType SHORT = new SimpleWrapType<>(PrimitiveDataType.SHORT); - public static final SimpleWrapType INTEGER = new SimpleWrapType<>(PrimitiveDataType.INTEGER); - public static final SimpleWrapType LONG = new SimpleWrapType<>(PrimitiveDataType.LONG); + public static final SimpleWrapType BYTE = new SimpleWrapType<>(PrimitiveDataType.BYTE); + public static final SimpleWrapType SHORT = new SimpleWrapType<>(PrimitiveDataType.SHORT); + public static final SimpleWrapType INTEGER = new SimpleWrapType<>(PrimitiveDataType.INTEGER); + public static final SimpleWrapType LONG = new SimpleWrapType<>(PrimitiveDataType.LONG); - public static final SimpleWrapType FLOAT = new SimpleWrapType<>(PrimitiveDataType.FLOAT); - public static final SimpleWrapType DOUBLE = new SimpleWrapType<>(PrimitiveDataType.DOUBLE); + public static final SimpleWrapType FLOAT = new SimpleWrapType<>(PrimitiveDataType.FLOAT); + public static final SimpleWrapType DOUBLE = new SimpleWrapType<>(PrimitiveDataType.DOUBLE); - public static final SimpleWrapType BIG_INTEGER = new SimpleWrapType<>(PrimitiveDataType.BIG_INTEGER); - public static final SimpleWrapType BIG_DECIMAL = new SimpleWrapType<>(PrimitiveDataType.BIG_DECIMAL); + public static final SimpleWrapType BIG_INTEGER = new SimpleWrapType<>(PrimitiveDataType.BIG_INTEGER); + public static final SimpleWrapType BIG_DECIMAL = new SimpleWrapType<>(PrimitiveDataType.BIG_DECIMAL); - public static final SimpleWrapType BOOLEAN = new SimpleWrapType<>(PrimitiveDataType.BOOLEAN); + public static final SimpleWrapType BOOLEAN = new SimpleWrapType<>(PrimitiveDataType.BOOLEAN); - public static final SimpleWrapType STRING = new SimpleWrapType<>(PrimitiveDataType.STRING); + public static final SimpleWrapType STRING = new SimpleWrapType<>(PrimitiveDataType.STRING); - public static final SimpleWrapType INT_ARRAY = new SimpleWrapType<>(PrimitiveDataType.INT_ARRAY); - public static final SimpleWrapType BYTE_ARRAY = new SimpleWrapType<>(PrimitiveDataType.BYTE_ARRAY); - public static final SimpleWrapType LONG_ARRAY = new SimpleWrapType<>(PrimitiveDataType.LONG_ARRAY); + public static final SimpleWrapType INT_ARRAY = new SimpleWrapType<>(PrimitiveDataType.INT_ARRAY); + public static final SimpleWrapType BYTE_ARRAY = new SimpleWrapType<>(PrimitiveDataType.BYTE_ARRAY); + public static final SimpleWrapType LONG_ARRAY = new SimpleWrapType<>(PrimitiveDataType.LONG_ARRAY); - /* - * Interface - */ + /* + * Interface + */ - Class

getPrimitiveWrapped(); + Class

getPrimitiveWrapped(); - Class getComplexWrapped(); + Class getComplexWrapped(); - P wrapToPrimitive(C complex, WrappedContext context); + P wrapToPrimitive(C complex, WrappedContext context); - C wrapToComplex(P primitive, WrappedContext context); + C wrapToComplex(P primitive, WrappedContext context); - public default DataType syntaxType() { - return new SimpleSyntaxType<>(this); - } + public default DataType syntaxType() { + return new SimpleSyntaxType<>(this); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedContainer.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedContainer.java index fe289cd..317c928 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedContainer.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedContainer.java @@ -13,52 +13,52 @@ public abstract class WrappedContainer { - public abstract Object getHandle(); + public abstract Object getHandle(); - public abstract WrappedContext getContext(); + public abstract WrappedContext getContext(); - public abstract IDataContainer getAsSyntaxContainer(); + public abstract IDataContainer getAsSyntaxContainer(); - public abstract boolean has(String key); + public abstract boolean has(String key); - public abstract boolean has(WrappedKey key); + public abstract boolean has(WrappedKey key); - public abstract boolean has(String key, WrapType type); + public abstract boolean has(String key, WrapType type); - public abstract boolean has(WrappedKey key, WrapType type); + public abstract boolean has(WrappedKey key, WrapType type); - public abstract Object get(String key); + public abstract Object get(String key); - public abstract Object get(WrappedKey key); + public abstract Object get(WrappedKey key); - public abstract C get(String key, WrapType type); + public abstract C get(String key, WrapType type); - public abstract C get(WrappedKey key, WrapType type); + public abstract C get(WrappedKey key, WrapType type); - public abstract void set(String key, B value, WrapType type); + public abstract void set(String key, B value, WrapType type); - public abstract void set(WrappedKey key, B value, WrapType type); + public abstract void set(WrappedKey key, B value, WrapType type); - public abstract boolean remove(String key); + public abstract boolean remove(String key); - public abstract boolean remove(WrappedKey key); + public abstract boolean remove(WrappedKey key); - public abstract Set keySet(); + public abstract Set keySet(); - public abstract boolean isEmpty(); + public abstract boolean isEmpty(); - public abstract int size(); + public abstract int size(); - protected SyntaxKey wrappedKey(String key) { - return new SyntaxKey(NamespacedKey.fromStringOrCompute(key, key0 -> Namespace.of(NAMESPACE_STRING).create(key0))); - } + protected SyntaxKey wrappedKey(String key) { + return new SyntaxKey(NamespacedKey.fromStringOrCompute(key, key0 -> Namespace.of(NAMESPACE_STRING).create(key0))); + } - public C getOrDefault(String key, WrapType type, C value) { - return Optional.ofNullable(get(key, type)).orElse(value); - } + public C getOrDefault(String key, WrapType type, C value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } - public C getOrDefault(WrappedKey key, WrapType type, C value) { - return Optional.ofNullable(get(key, type)).orElse(value); - } + public C getOrDefault(WrappedKey key, WrapType type, C value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedContext.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedContext.java index fdea09a..7fc4005 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedContext.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedContext.java @@ -4,8 +4,8 @@ public abstract class WrappedContext implements DataAdapterContext { - public abstract H getHandle(); + public abstract H getHandle(); - public abstract WrappedContainer newContainer(); + public abstract WrappedContainer newContainer(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedKey.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedKey.java index 9af4ae4..678e227 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedKey.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/WrappedKey.java @@ -5,20 +5,20 @@ public abstract class WrappedKey { - public abstract H getHandle(); + public abstract H getHandle(); - public abstract String getName(); + public abstract String getName(); - public abstract String getKey(); + public abstract String getKey(); - public abstract String toString(); + public abstract String toString(); - public Namespace getNamespace() { - return Namespace.of(getName()); - } + public Namespace getNamespace() { + return Namespace.of(getName()); + } - public NamespacedKey getNamespacedKey() { - return getNamespace().create(getKey()); - } + public NamespacedKey getNamespacedKey() { + return getNamespace().create(getKey()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/DataDistributor.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/DataDistributor.java index d229ce7..669f5a8 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/DataDistributor.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/DataDistributor.java @@ -11,64 +11,65 @@ public class DataDistributor { - protected final Map> containers = Collections.synchronizedMap(new HashMap<>()); + protected final Map> containers = Collections.synchronizedMap(new HashMap<>()); - protected final DataProvider dataProvider; + protected final DataProvider dataProvider; - protected final File parent; - protected final Function namingFunction; - protected final Supplier randomFunction; + protected final File parent; + protected final Function namingFunction; + protected final Supplier randomFunction; - public DataDistributor(DataProvider dataProvider, File parent, Supplier randomFunction) { - this(dataProvider, parent, Object::toString, randomFunction); - } + public DataDistributor(DataProvider dataProvider, File parent, Supplier randomFunction) { + this(dataProvider, parent, Object::toString, randomFunction); + } - public DataDistributor(DataProvider dataProvider, File parent, Function namingFunction, Supplier randomFunction) { - this.dataProvider = dataProvider; - this.parent = parent; - this.namingFunction = namingFunction; - this.randomFunction = randomFunction; - } + public DataDistributor(DataProvider dataProvider, File parent, Function namingFunction, Supplier randomFunction) { + this.dataProvider = dataProvider; + this.parent = parent; + this.namingFunction = namingFunction; + this.randomFunction = randomFunction; + } - /* - * - */ + /* + * + */ - public PersistentContainer create() { - K key = randomFunction.get(); - while (containers.containsKey(key)) { - key = randomFunction.get(); - } - PersistentContainer container = new PersistentContainer<>(key, new File(parent, namingFunction.apply(key) + ".nbt"), dataProvider.getRegistry()); - containers.put(key, container); - return container; - } + public PersistentContainer create() { + K key = randomFunction.get(); + while (containers.containsKey(key)) { + key = randomFunction.get(); + } + PersistentContainer container = new PersistentContainer<>(key, new File(parent, namingFunction.apply(key) + ".nbt"), + dataProvider.getRegistry()); + containers.put(key, container); + return container; + } - public PersistentContainer get(K key) { - return containers.computeIfAbsent(key, - (key0) -> new PersistentContainer<>(key0, new File(parent, namingFunction.apply(key0) + ".nbt"), dataProvider.getRegistry())); - } + public PersistentContainer get(K key) { + return containers.computeIfAbsent(key, + (key0) -> new PersistentContainer<>(key0, new File(parent, namingFunction.apply(key0) + ".nbt"), dataProvider.getRegistry())); + } - public boolean delete(K key) { - if (!containers.containsKey(key)) { - return false; - } - PersistentContainer container = containers.get(key); - File location = container.getLocation(); - container.delete(); - if (location.exists()) { - return location.delete(); - } - return true; - } + public boolean delete(K key) { + if (!containers.containsKey(key)) { + return false; + } + PersistentContainer container = containers.get(key); + File location = container.getLocation(); + container.delete(); + if (location.exists()) { + return location.delete(); + } + return true; + } - public void shutdown() { - containers.values().forEach(PersistentContainer::shutdown); - } + public void shutdown() { + containers.values().forEach(PersistentContainer::shutdown); + } - public void delete() { - containers.values().forEach(PersistentContainer::delete); - containers.clear(); - } + public void delete() { + containers.values().forEach(PersistentContainer::delete); + containers.clear(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/DataObserver.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/DataObserver.java index 8dac090..8dc2060 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/DataObserver.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/DataObserver.java @@ -11,100 +11,100 @@ public class DataObserver implements Runnable { - private final PersistentContainer container; - - private boolean alive = true; - private boolean stopIndicator = false; - - private long lastModified = 0L; - private boolean saving = false; - private Thread thread; - - private long wait = 700L; - - protected DataObserver(PersistentContainer container) { - this.container = container; - this.thread = new Thread(this); - this.thread.setDaemon(true); - this.thread.setName("Observer-" + container.getKey().toString()); - this.thread.start(); - } - - @Override - public void run() { - while (!stopIndicator) { - handle(); - try { - Thread.sleep(wait); - } catch (InterruptedException e) { - // IGNORE - } - } - } - - public long getWaitingTime() { - return wait; - } - - public void setWaitingTime(long wait) { - this.wait = wait; - } - - private void handle() { - if (saving) { - return; - } - if (!alive) { - stopIndicator = true; - } - if (alive && container.location.lastModified() != lastModified) { - load(); - } - if (container.changed) { - save(); - container.changed = false; - } - } - - public void load() { - container.lock.writeLock().lock(); - if (container.location.exists()) { - NbtNamedTag tag = null; - try { - tag = NbtDeserializer.COMPRESSED.fromFile(container.location); - } catch (IOException ignore) { - } - if (tag != null && tag.getTag().getType() == NbtType.COMPOUND) { - container.fromNbt((NbtCompound) tag.getTag()); - } - } - container.lock.writeLock().unlock(); - if (container.consumer != null) { - container.consumer.accept(container); - } - } - - public void save() { - saving = true; - try { - Files.createFile(container.location); - NbtSerializer.COMPRESSED.toFile(new NbtNamedTag("root", container.asNbt()), container.location); - lastModified = container.location.lastModified(); - } catch (IOException ignore) { - } - saving = false; - } - - public void shutdown() { - alive = false; - } - - public boolean isAlive() { - return alive; - } - - public long lastModified() { - return lastModified; - } + private final PersistentContainer container; + + private boolean alive = true; + private boolean stopIndicator = false; + + private long lastModified = 0L; + private boolean saving = false; + private Thread thread; + + private long wait = 700L; + + protected DataObserver(PersistentContainer container) { + this.container = container; + this.thread = new Thread(this); + this.thread.setDaemon(true); + this.thread.setName("Observer-" + container.getKey().toString()); + this.thread.start(); + } + + @Override + public void run() { + while (!stopIndicator) { + handle(); + try { + Thread.sleep(wait); + } catch (InterruptedException e) { + // IGNORE + } + } + } + + public long getWaitingTime() { + return wait; + } + + public void setWaitingTime(long wait) { + this.wait = wait; + } + + private void handle() { + if (saving) { + return; + } + if (!alive) { + stopIndicator = true; + } + if (alive && container.location.lastModified() != lastModified) { + load(); + } + if (container.changed) { + save(); + container.changed = false; + } + } + + public void load() { + container.lock.writeLock().lock(); + if (container.location.exists()) { + NbtNamedTag tag = null; + try { + tag = NbtDeserializer.COMPRESSED.fromFile(container.location); + } catch (IOException ignore) { + } + if (tag != null && tag.getTag().getType() == NbtType.COMPOUND) { + container.fromNbt((NbtCompound) tag.getTag()); + } + } + container.lock.writeLock().unlock(); + if (container.consumer != null) { + container.consumer.accept(container); + } + } + + public void save() { + saving = true; + try { + Files.createFile(container.location); + NbtSerializer.COMPRESSED.toFile(new NbtNamedTag("root", container.asNbt()), container.location); + lastModified = container.location.lastModified(); + } catch (IOException ignore) { + } + saving = false; + } + + public void shutdown() { + alive = false; + } + + public boolean isAlive() { + return alive; + } + + public long lastModified() { + return lastModified; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/PersistentContainer.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/PersistentContainer.java index 5ab0cae..0b03728 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/PersistentContainer.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/persistence/PersistentContainer.java @@ -15,143 +15,143 @@ public class PersistentContainer extends NbtContainer { - protected final ReadWriteLock lock = new ReentrantReadWriteLock(); - protected final DataObserver observer; - - protected final K key; - - protected final File location; - protected boolean changed; - - @SuppressWarnings("rawtypes") - protected Consumer consumer; - - public PersistentContainer(K key, File location, NbtAdapterRegistry registry) { - super(registry); - this.key = key; - this.location = location; - this.observer = new DataObserver(this); - } - - public final DataObserver getObserver() { - return observer; - } - - @SuppressWarnings("rawtypes") - public final void setLoadingAction(Consumer consumer) { - this.consumer = consumer; - } - - public final void forceLoad() { - observer.load(); - } - - public final K getKey() { - return key; - } - - public final File getLocation() { - return location; - } - - @Override - public Object get(String key) { - lock.readLock().lock(); - Object value = super.get(key); - lock.readLock().unlock(); - return value; - } - - @Override - public void set(String key, NbtTag tag) { - lock.writeLock().lock(); - super.set(key, tag); - changed = true; - lock.writeLock().unlock(); - } - - @Override - public boolean remove(String key) { - lock.writeLock().lock(); - boolean state = super.remove(key); - changed = true; - lock.writeLock().unlock(); - return state; - } - - @Override - public Set getKeyspaces() { - lock.readLock().lock(); - Set keys = new LinkedHashSet<>(super.getKeyspaces()); - lock.readLock().unlock(); - return keys; - } - - @Override - public IKey[] getKeys() { - lock.readLock().lock(); - IKey[] keys = super.getKeys(); - lock.readLock().unlock(); - return keys; - } - - @Override - public int size() { - lock.readLock().lock(); - int size = super.size(); - lock.readLock().unlock(); - return size; - } - - @Override - public NbtCompound getRoot() { - return asNbt(); - } - - @Override - public void fromNbt(NbtCompound nbt) { - lock.writeLock().lock(); - super.fromNbt(nbt); - changed = true; - lock.writeLock().unlock(); - } - - @Override - public NbtCompound asNbt() { - lock.readLock().lock(); - NbtCompound compound = super.asNbt(); - lock.readLock().unlock(); - return compound; - } - - public boolean isPersistent() { - return observer.isAlive(); - } - - public void clear() { - lock.writeLock().lock(); - super.getRoot().clear(); - changed = true; - lock.writeLock().unlock(); - } - - protected void read(NbtCompound compound) { - if (observer.isAlive()) { - return; - } - super.fromNbt(compound); - } - - protected void shutdown() { - observer.shutdown(); - } - - protected void delete() { - lock.writeLock().lock(); - observer.save(); - super.getRoot().clear(); - observer.shutdown(); - lock.writeLock().unlock(); - } + protected final ReadWriteLock lock = new ReentrantReadWriteLock(); + protected final DataObserver observer; + + protected final K key; + + protected final File location; + protected boolean changed; + + @SuppressWarnings("rawtypes") + protected Consumer consumer; + + public PersistentContainer(K key, File location, NbtAdapterRegistry registry) { + super(registry); + this.key = key; + this.location = location; + this.observer = new DataObserver(this); + } + + public final DataObserver getObserver() { + return observer; + } + + @SuppressWarnings("rawtypes") + public final void setLoadingAction(Consumer consumer) { + this.consumer = consumer; + } + + public final void forceLoad() { + observer.load(); + } + + public final K getKey() { + return key; + } + + public final File getLocation() { + return location; + } + + @Override + public Object get(String key) { + lock.readLock().lock(); + Object value = super.get(key); + lock.readLock().unlock(); + return value; + } + + @Override + public void set(String key, NbtTag tag) { + lock.writeLock().lock(); + super.set(key, tag); + changed = true; + lock.writeLock().unlock(); + } + + @Override + public boolean remove(String key) { + lock.writeLock().lock(); + boolean state = super.remove(key); + changed = true; + lock.writeLock().unlock(); + return state; + } + + @Override + public Set getKeyspaces() { + lock.readLock().lock(); + Set keys = new LinkedHashSet<>(super.getKeyspaces()); + lock.readLock().unlock(); + return keys; + } + + @Override + public IKey[] getKeys() { + lock.readLock().lock(); + IKey[] keys = super.getKeys(); + lock.readLock().unlock(); + return keys; + } + + @Override + public int size() { + lock.readLock().lock(); + int size = super.size(); + lock.readLock().unlock(); + return size; + } + + @Override + public NbtCompound getRoot() { + return asNbt(); + } + + @Override + public void fromNbt(NbtCompound nbt) { + lock.writeLock().lock(); + super.fromNbt(nbt); + changed = true; + lock.writeLock().unlock(); + } + + @Override + public NbtCompound asNbt() { + lock.readLock().lock(); + NbtCompound compound = super.asNbt(); + lock.readLock().unlock(); + return compound; + } + + public boolean isPersistent() { + return observer.isAlive(); + } + + public void clear() { + lock.writeLock().lock(); + super.getRoot().clear(); + changed = true; + lock.writeLock().unlock(); + } + + protected void read(NbtCompound compound) { + if (observer.isAlive()) { + return; + } + super.fromNbt(compound); + } + + protected void shutdown() { + observer.shutdown(); + } + + protected void delete() { + lock.writeLock().lock(); + observer.save(); + super.getRoot().clear(); + observer.shutdown(); + lock.writeLock().unlock(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/type/ObjectType.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/type/ObjectType.java index bee29a9..11356dc 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/type/ObjectType.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/type/ObjectType.java @@ -5,28 +5,28 @@ public final class ObjectType implements WrapType { - public static final ObjectType INSTANCE = new ObjectType(); + public static final ObjectType INSTANCE = new ObjectType(); - private ObjectType() {} + private ObjectType() {} - @Override - public Class getPrimitiveWrapped() { - return Object.class; - } + @Override + public Class getPrimitiveWrapped() { + return Object.class; + } - @Override - public Class getComplexWrapped() { - return Object.class; - } + @Override + public Class getComplexWrapped() { + return Object.class; + } - @Override - public Object wrapToPrimitive(Object complex, WrappedContext context) { - return complex; - } + @Override + public Object wrapToPrimitive(Object complex, WrappedContext context) { + return complex; + } - @Override - public Object wrapToComplex(Object primitive, WrappedContext context) { - return primitive; - } + @Override + public Object wrapToComplex(Object primitive, WrappedContext context) { + return primitive; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/type/SkinDataType.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/type/SkinDataType.java index f84b5d0..1bbdc9b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/type/SkinDataType.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/type/SkinDataType.java @@ -10,37 +10,37 @@ public final class SkinDataType implements WrapType { - public static final SkinDataType INSTANCE = new SkinDataType(); - - private SkinDataType() {} - - @Override - public Class getComplexWrapped() { - return Skin.class; - } - - @Override - public Class getPrimitiveWrapped() { - return WrappedContainer.class; - } - - @Override - public Skin wrapToComplex(WrappedContainer primitive, WrappedContext context) { - IDataContainer container = primitive.getAsSyntaxContainer(); - String name = container.get("name", PrimitiveDataType.STRING); - String value = container.get("value", PrimitiveDataType.STRING); - String signature = container.get("signature", PrimitiveDataType.STRING); - return new Skin(name, value, signature, false); - } - - @Override - public WrappedContainer wrapToPrimitive(Skin complex, WrappedContext context) { - WrappedContainer wrapped = context.newContainer(); - IDataContainer container = wrapped.getAsSyntaxContainer(); - container.set("name", complex.getName(), PrimitiveDataType.STRING); - container.set("value", complex.getValue(), PrimitiveDataType.STRING); - container.set("signature", complex.getSignature(), PrimitiveDataType.STRING); - return wrapped; - } + public static final SkinDataType INSTANCE = new SkinDataType(); + + private SkinDataType() {} + + @Override + public Class getComplexWrapped() { + return Skin.class; + } + + @Override + public Class getPrimitiveWrapped() { + return WrappedContainer.class; + } + + @Override + public Skin wrapToComplex(WrappedContainer primitive, WrappedContext context) { + IDataContainer container = primitive.getAsSyntaxContainer(); + String name = container.get("name", PrimitiveDataType.STRING); + String value = container.get("value", PrimitiveDataType.STRING); + String signature = container.get("signature", PrimitiveDataType.STRING); + return new Skin(name, value, signature, false); + } + + @Override + public WrappedContainer wrapToPrimitive(Skin complex, WrappedContext context) { + WrappedContainer wrapped = context.newContainer(); + IDataContainer container = wrapped.getAsSyntaxContainer(); + container.set("name", complex.getName(), PrimitiveDataType.STRING); + container.set("value", complex.getValue(), PrimitiveDataType.STRING); + container.set("signature", complex.getSignature(), PrimitiveDataType.STRING); + return wrapped; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxContainer.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxContainer.java index c71919b..306b122 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxContainer.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxContainer.java @@ -10,104 +10,104 @@ public final class SimpleSyntaxContainer extends WrappedContainer { - private final E container; - - public SimpleSyntaxContainer(E container) { - this.container = container; - } - - @Override - public E getHandle() { - return container; - } - - @Override - public E getAsSyntaxContainer() { - return container; - } - - /* - * - */ - - @Override - public SimpleSyntaxContext getContext() { - return new SimpleSyntaxContext(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(key.getNamespacedKey()); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public Object get(String key) { - return get(wrappedKey(key)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(key.getNamespacedKey()); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(key.getNamespacedKey(), value, type.syntaxType()); - } - - @Override - public boolean remove(String key) { - return false; - } - - @Override - public boolean remove(WrappedKey key) { - return container.remove(key.getNamespacedKey()); - } - - @Override - public Set keySet() { - return container.getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.size(); - } + private final E container; + + public SimpleSyntaxContainer(E container) { + this.container = container; + } + + @Override + public E getHandle() { + return container; + } + + @Override + public E getAsSyntaxContainer() { + return container; + } + + /* + * + */ + + @Override + public SimpleSyntaxContext getContext() { + return new SimpleSyntaxContext(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(key.getNamespacedKey()); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public Object get(String key) { + return get(wrappedKey(key)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(key.getNamespacedKey()); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(key.getNamespacedKey(), value, type.syntaxType()); + } + + @Override + public boolean remove(String key) { + return false; + } + + @Override + public boolean remove(WrappedKey key) { + return container.remove(key.getNamespacedKey()); + } + + @Override + public Set keySet() { + return container.getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.size(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxContext.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxContext.java index 547b688..39ec301 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxContext.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxContext.java @@ -8,25 +8,25 @@ public class SimpleSyntaxContext extends WrappedContext { - private final DataAdapterContext context; - - public SimpleSyntaxContext(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public WrappedContainer newContainer() { - return new SimpleSyntaxContainer<>(context.newDataContainer()); - } + private final DataAdapterContext context; + + public SimpleSyntaxContext(DataAdapterContext context) { + this.context = context; + } + + @Override + public DataAdapterContext getHandle() { + return context; + } + + @Override + public IDataContainer newDataContainer() { + return context.newDataContainer(); + } + + @Override + public WrappedContainer newContainer() { + return new SimpleSyntaxContainer<>(context.newDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxType.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxType.java index 9f955d0..1ed49ee 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxType.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleSyntaxType.java @@ -8,30 +8,30 @@ public class SimpleSyntaxType implements DataType { - private final WrapType type; - - public SimpleSyntaxType(WrapType type) { - this.type = type; - } - - @Override - public Class getComplex() { - return type.getComplexWrapped(); - } - - @Override - public Class

getPrimitive() { - return type.getPrimitiveWrapped(); - } - - @Override - public P toPrimitive(DataAdapterContext context, C complex) { - return type.wrapToPrimitive(complex, VersionControl.get().getBukkitConversion().createContext(context)); - } - - @Override - public C fromPrimitive(DataAdapterContext context, P primitive) { - return type.wrapToComplex(primitive, VersionControl.get().getBukkitConversion().createContext(context)); - } + private final WrapType type; + + public SimpleSyntaxType(WrapType type) { + this.type = type; + } + + @Override + public Class getComplex() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitive() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(DataAdapterContext context, C complex) { + return type.wrapToPrimitive(complex, VersionControl.get().getBukkitConversion().createContext(context)); + } + + @Override + public C fromPrimitive(DataAdapterContext context, P primitive) { + return type.wrapToComplex(primitive, VersionControl.get().getBukkitConversion().createContext(context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleWrapType.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleWrapType.java index 63eb384..733f8e6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleWrapType.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SimpleWrapType.java @@ -7,30 +7,30 @@ public class SimpleWrapType implements WrapType { - private final DataType type; - - public SimpleWrapType(DataType type) { - this.type = type; - } - - @Override - public Class getComplexWrapped() { - return type.getComplex(); - } - - @Override - public Class

getPrimitiveWrapped() { - return type.getPrimitive(); - } - - @Override - public P wrapToPrimitive(C complex, WrappedContext context) { - return type.toPrimitive(context, complex); - } - - @Override - public C wrapToComplex(P primitive, WrappedContext context) { - return type.fromPrimitive(context, primitive); - } + private final DataType type; + + public SimpleWrapType(DataType type) { + this.type = type; + } + + @Override + public Class getComplexWrapped() { + return type.getComplex(); + } + + @Override + public Class

getPrimitiveWrapped() { + return type.getPrimitive(); + } + + @Override + public P wrapToPrimitive(C complex, WrappedContext context) { + return type.toPrimitive(context, complex); + } + + @Override + public C wrapToComplex(P primitive, WrappedContext context) { + return type.fromPrimitive(context, primitive); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SyntaxKey.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SyntaxKey.java index fb9692f..9bb40b5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SyntaxKey.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/data/wrap/SyntaxKey.java @@ -12,52 +12,52 @@ public final class SyntaxKey extends WrappedKey { - private final NamespacedKey key; - - public SyntaxKey(Plugin plugin, String key) { - this.key = Namespace.of(plugin.getName().toLowerCase()).create(key); - } - - public SyntaxKey(String name, String key) { - this.key = Namespace.of(name).create(key); - } - - public SyntaxKey(NamespacedKey key) { - this.key = key; - } - - public SyntaxKey(IKey key) { - this.key = NamespacedKey.fromStringOrCompute(key.toString(), key0 -> Namespace.of(NAMESPACE_STRING).create(key0)); - } - - @Override - public NamespacedKey getHandle() { - return key; - } - - @Override - public Namespace getNamespace() { - return key.getNamespace(); - } - - @Override - public NamespacedKey getNamespacedKey() { - return key; - } - - @Override - public String getName() { - return key.getNamespace().getName(); - } - - @Override - public String getKey() { - return key.getKey(); - } - - @Override - public String toString() { - return key.toString(); - } + private final NamespacedKey key; + + public SyntaxKey(Plugin plugin, String key) { + this.key = Namespace.of(plugin.getName().toLowerCase()).create(key); + } + + public SyntaxKey(String name, String key) { + this.key = Namespace.of(name).create(key); + } + + public SyntaxKey(NamespacedKey key) { + this.key = key; + } + + public SyntaxKey(IKey key) { + this.key = NamespacedKey.fromStringOrCompute(key.toString(), key0 -> Namespace.of(NAMESPACE_STRING).create(key0)); + } + + @Override + public NamespacedKey getHandle() { + return key; + } + + @Override + public Namespace getNamespace() { + return key.getNamespace(); + } + + @Override + public NamespacedKey getNamespacedKey() { + return key; + } + + @Override + public String getName() { + return key.getNamespace().getName(); + } + + @Override + public String getKey() { + return key.getKey(); + } + + @Override + public String toString() { + return key.toString(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsArmorStand.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsArmorStand.java index c3c2392..9dfd0bb 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsArmorStand.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsArmorStand.java @@ -2,8 +2,8 @@ public interface NmsArmorStand extends NmsEntityLiving { - void setSmall(boolean small); + void setSmall(boolean small); - boolean isSmall(); + boolean isSmall(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntity.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntity.java index d85de8b..b5225f5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntity.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntity.java @@ -9,52 +9,52 @@ public interface NmsEntity { - Object getHandle(); + Object getHandle(); - int getId(); + int getId(); - UUID getUniqueId(); + UUID getUniqueId(); - void setCustomName(String name); + void setCustomName(String name); - String getCustomName(); + String getCustomName(); - void setGravity(boolean gravity); + void setGravity(boolean gravity); - boolean hasGravity(); + boolean hasGravity(); - void setCustomNameVisible(boolean visible); + void setCustomNameVisible(boolean visible); - boolean isCustomNameVisible(); + boolean isCustomNameVisible(); - boolean isInteractable(); + boolean isInteractable(); - boolean isCollidable(); + boolean isCollidable(); - void setInvisible(boolean invisible); + void setInvisible(boolean invisible); - boolean isInvisible(); + boolean isInvisible(); - void setInvulnerable(boolean invulnerable); + void setInvulnerable(boolean invulnerable); - boolean isInvulnerable(); + boolean isInvulnerable(); - void setLocation(Location location); + void setLocation(Location location); - Location getLocation(); + Location getLocation(); - boolean isShown(Player player); + boolean isShown(Player player); - void hide(Player... players); + void hide(Player... players); - void show(Player... players); + void show(Player... players); - UUID[] getVisible(); + UUID[] getVisible(); - Player[] getVisibleAsPlayer(); + Player[] getVisibleAsPlayer(); - void kill(); - - NmsBoundingBox getBoundingBox(); + void kill(); + + NmsBoundingBox getBoundingBox(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntityLiving.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntityLiving.java index 8f42a8e..09e7dfa 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntityLiving.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntityLiving.java @@ -2,6 +2,6 @@ public interface NmsEntityLiving extends NmsEntity { - void setCollidable(boolean collidable); + void setCollidable(boolean collidable); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntityType.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntityType.java index e2a75cf..7ea1945 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntityType.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsEntityType.java @@ -2,6 +2,6 @@ public enum NmsEntityType { - ARMOR_STAND; + ARMOR_STAND; } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsPlayer.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsPlayer.java index c5245e9..869576e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsPlayer.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/entity/NmsPlayer.java @@ -7,44 +7,44 @@ public interface NmsPlayer extends NmsEntityLiving { - Player getBukkitPlayer(); + Player getBukkitPlayer(); - WrappedContainer getDataAdapter(); + WrappedContainer getDataAdapter(); - void setSkin(Skin skin); + void setSkin(Skin skin); - Skin getSkin(); + Skin getSkin(); - void setName(String name); + void setName(String name); - String getName(); + String getName(); - String getRealName(); + String getRealName(); - void setPlayerListHeader(String text); + void setPlayerListHeader(String text); - String getPlayerListHeader(); + String getPlayerListHeader(); - void setPlayerListFooter(String text); + void setPlayerListFooter(String text); - String getPlayerListFooter(); + String getPlayerListFooter(); - int getPing(); + int getPing(); - void setTitleTimes(int fadeIn, int stay, int fadeOut); + void setTitleTimes(int fadeIn, int stay, int fadeOut); - void setPlayerListHeaderAndFooter(String header, String footer); + void setPlayerListHeaderAndFooter(String header, String footer); - void sendSubtitle(String text); + void sendSubtitle(String text); - void sendTitle(String text); + void sendTitle(String text); - void sendActionBar(String text); + void sendActionBar(String text); - void fakeRespawn(); + void fakeRespawn(); - void respawn(); + void respawn(); - void update(); + void update(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/BukkitConversion1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/BukkitConversion1_10_R1.java index 6d756df..5ec08ee 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/BukkitConversion1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/BukkitConversion1_10_R1.java @@ -7,7 +7,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_10_R1.ItemStack; import net.minecraft.server.v1_10_R1.NBTBase; @@ -31,179 +45,179 @@ public class BukkitConversion1_10_R1 extends BukkitConversion { - protected BukkitConversion1_10_R1(VersionControl1_10_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - NBTTagList list = new NBTTagList(); - for(long value : (long[]) tag.getValue()) { - list.add(new NBTTagLong(value)); - } - return list; - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTTagByte) tag).g()); - case SHORT: - return new NbtShort(((NBTTagShort) tag).f()); - case INT: - return new NbtInt(((NBTTagInt) tag).e()); - case LONG: - return new NbtLong(((NBTTagLong) tag).d()); - case FLOAT: - return new NbtFloat(((NBTTagFloat) tag).i()); - case DOUBLE: - return new NbtDouble(((NBTTagDouble) tag).h()); - case STRING: - return new NbtString(((NBTTagString) tag).c_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).d()); - case LONG_ARRAY: - return new NbtLongArray(new long[0]); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : content) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.c(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound stackTag; - if (!nmsStack.hasTag()) { - stackTag = nmsStack.save(new NBTTagCompound()); - } else { - stackTag = nmsStack.getTag(); - } - return fromMinecraftCompound(stackTag); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_10_R1(VersionControl1_10_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + NBTTagList list = new NBTTagList(); + for (long value : (long[]) tag.getValue()) { + list.add(new NBTTagLong(value)); + } + return list; + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTTagByte) tag).g()); + case SHORT: + return new NbtShort(((NBTTagShort) tag).f()); + case INT: + return new NbtInt(((NBTTagInt) tag).e()); + case LONG: + return new NbtLong(((NBTTagLong) tag).d()); + case FLOAT: + return new NbtFloat(((NBTTagFloat) tag).i()); + case DOUBLE: + return new NbtDouble(((NBTTagDouble) tag).h()); + case STRING: + return new NbtString(((NBTTagString) tag).c_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).d()); + case LONG_ARRAY: + return new NbtLongArray(new long[0]); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : content) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.c(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound stackTag; + if (!nmsStack.hasTag()) { + stackTag = nmsStack.save(new NBTTagCompound()); + } else { + stackTag = nmsStack.getTag(); + } + return fromMinecraftCompound(stackTag); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/EntityProvider1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/EntityProvider1_10_R1.java index 0f98572..a64a398 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/EntityProvider1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/EntityProvider1_10_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_10_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_10_R1(VersionControl1_10_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_10_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_10_R1(VersionControl1_10_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_10_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/PacketHandler1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/PacketHandler1_10_R1.java index 84519d0..bc30024 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/PacketHandler1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/PacketHandler1_10_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_10_R1 extends PacketHandler { - protected PacketHandler1_10_R1(VersionControl1_10_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_10_R1(VersionControl1_10_R1 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/PlayerProvider1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/PlayerProvider1_10_R1.java index 7fcc0ab..b5366bc 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/PlayerProvider1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/PlayerProvider1_10_R1.java @@ -14,17 +14,17 @@ public class PlayerProvider1_10_R1 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_10_R1(VersionControl1_10_R1 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_10_R1(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_10_R1(VersionControl1_10_R1 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_10_R1(player, distributor.get(player.getUniqueId())); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/TextureProvider1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/TextureProvider1_10_R1.java index 3f9a4f6..589c9a6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/TextureProvider1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/TextureProvider1_10_R1.java @@ -20,86 +20,86 @@ @SuppressWarnings("deprecation") public class TextureProvider1_10_R1 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_10_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final Material skullMaterial = Material.valueOf("SKULL"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_10_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final Material skullMaterial = Material.valueOf("SKULL"); - protected TextureProvider1_10_R1(VersionControl1_10_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_10_R1(VersionControl1_10_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - return ((CraftSkull) block).getTileEntity().getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + return ((CraftSkull) block).getTileEntity().getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag; - if (!stack.hasTag()) { - stackTag = stack.save(new NBTTagCompound()); - } else { - stackTag = stack.getTag(); - } - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag; + if (!stack.hasTag()) { + stackTag = stack.save(new NBTTagCompound()); + } else { + stackTag = stack.getTag(); + } + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - ((CraftSkull) block).getTileEntity().setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + ((CraftSkull) block).getTileEntity().setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/ToolProvider1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/ToolProvider1_10_R1.java index a418972..152a7b1 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/ToolProvider1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/ToolProvider1_10_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_10_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_10_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_10_R1.tools.BlockTools1_10_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_10_R1.tools.ServerTools1_10_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_10_R1.tools.SkinTools1_10_R1; public class ToolProvider1_10_R1 extends ToolProvider { - private final BlockTools1_10_R1 blockTools = new BlockTools1_10_R1(); - private final SkinTools1_10_R1 skinTools = new SkinTools1_10_R1(); - private final ServerTools1_10_R1 serverTools = new ServerTools1_10_R1(); + private final BlockTools1_10_R1 blockTools = new BlockTools1_10_R1(); + private final SkinTools1_10_R1 skinTools = new SkinTools1_10_R1(); + private final ServerTools1_10_R1 serverTools = new ServerTools1_10_R1(); - protected ToolProvider1_10_R1(VersionControl1_10_R1 versionControl) { - super(versionControl); - } + protected ToolProvider1_10_R1(VersionControl1_10_R1 versionControl) { + super(versionControl); + } - @Override - public SkinTools1_10_R1 getSkinTools() { - return skinTools; - } + @Override + public SkinTools1_10_R1 getSkinTools() { + return skinTools; + } - @Override - public ServerTools1_10_R1 getServerTools() { - return serverTools; - } + @Override + public ServerTools1_10_R1 getServerTools() { + return serverTools; + } - @Override - public BlockTools1_10_R1 getBlockTools() { - return blockTools; - } + @Override + public BlockTools1_10_R1 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/VersionControl1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/VersionControl1_10_R1.java index 0a6708e..b8310f9 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/VersionControl1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/VersionControl1_10_R1.java @@ -6,51 +6,51 @@ public class VersionControl1_10_R1 extends VersionControl { - public static VersionControl1_10_R1 INSTANCE; - - public static VersionControl1_10_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_10_R1()); - } - - private final ToolProvider1_10_R1 toolProvider = new ToolProvider1_10_R1(this); - private final TextureProvider1_10_R1 textureProvider = new TextureProvider1_10_R1(this); - private final PacketHandler1_10_R1 packetHandler = new PacketHandler1_10_R1(this); - private final EntityProvider1_10_R1 entityProvider = new EntityProvider1_10_R1(this); - private final PlayerProvider1_10_R1 playerProvider = new PlayerProvider1_10_R1(this); - private final BukkitConversion1_10_R1 bukkitConversion = new BukkitConversion1_10_R1(this); - - private VersionControl1_10_R1() { - NmsReflection1_10_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); - } - - @Override - public ToolProvider1_10_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_10_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_10_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_10_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_10_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_10_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_10_R1 INSTANCE; + + public static VersionControl1_10_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_10_R1()); + } + + private final ToolProvider1_10_R1 toolProvider = new ToolProvider1_10_R1(this); + private final TextureProvider1_10_R1 textureProvider = new TextureProvider1_10_R1(this); + private final PacketHandler1_10_R1 packetHandler = new PacketHandler1_10_R1(this); + private final EntityProvider1_10_R1 entityProvider = new EntityProvider1_10_R1(this); + private final PlayerProvider1_10_R1 playerProvider = new PlayerProvider1_10_R1(this); + private final BukkitConversion1_10_R1 bukkitConversion = new BukkitConversion1_10_R1(this); + + private VersionControl1_10_R1() { + NmsReflection1_10_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + } + + @Override + public ToolProvider1_10_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_10_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_10_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_10_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_10_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_10_R1 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/ArmorStand1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/ArmorStand1_10_R1.java index 2f572a1..2fbb3be 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/ArmorStand1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/ArmorStand1_10_R1.java @@ -6,18 +6,18 @@ public class ArmorStand1_10_R1 extends EntityLiving1_10_R1 implements NmsArmorStand { - public ArmorStand1_10_R1(World world) { - super(new EntityArmorStand(world)); - } + public ArmorStand1_10_R1(World world) { + super(new EntityArmorStand(world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/Entity1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/Entity1_10_R1.java index 7809080..c041903 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/Entity1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/Entity1_10_R1.java @@ -12,6 +12,7 @@ import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_10_R1.AxisAlignedBB; import net.minecraft.server.v1_10_R1.Entity; import net.minecraft.server.v1_10_R1.EntityTypes; import net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy; @@ -19,192 +20,193 @@ import net.minecraft.server.v1_10_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_10_R1.PlayerConnection; import net.minecraft.server.v1_10_R1.Vec3D; -import net.minecraft.server.v1_10_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_10_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_10_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(name); - } - - @Override - public String getCustomName() { - return handle.getCustomName(); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(null); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.d(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_10_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(name); + } + + @Override + public String getCustomName() { + return handle.getCustomName(); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(null); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.d(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/EntityLiving1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/EntityLiving1_10_R1.java index 87add2d..ba468c4 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/EntityLiving1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/EntityLiving1_10_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_10_R1 extends Entity1_10_R1 implements NmsEntityLiving { - public EntityLiving1_10_R1(E handle) { - super(handle); - } + public EntityLiving1_10_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/Player1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/Player1_10_R1.java index 8817f37..04c5e07 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/Player1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/entity/Player1_10_R1.java @@ -49,231 +49,231 @@ public class Player1_10_R1 extends EntityLiving1_10_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_10_R1(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); - reflect.setFieldValue(packet, "header", headerComponent); - reflect.setFieldValue(packet, "footer", footerComponent); - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_10_R1(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + reflect.setFieldValue(packet, "header", headerComponent); + reflect.setFieldValue(packet, "footer", footerComponent); + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/reflection/NmsReflection1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/reflection/NmsReflection1_10_R1.java index df8b54f..71df766 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/reflection/NmsReflection1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/reflection/NmsReflection1_10_R1.java @@ -8,27 +8,27 @@ public class NmsReflection1_10_R1 extends Reflections { - public static NmsReflection1_10_R1 INSTANCE = new NmsReflection1_10_R1(); + public static NmsReflection1_10_R1 INSTANCE = new NmsReflection1_10_R1(); - private NmsReflection1_10_R1() {} + private NmsReflection1_10_R1() {} - @Override - public void setup(ReflectionProvider provider) { + @Override + public void setup(ReflectionProvider provider) { - // - // - // Create Reflects - // + // + // + // Create Reflects + // - // - // Minecraft + // + // Minecraft - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class).searchField("header", "a") - .searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); - } + provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); + provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/BlockTools1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/BlockTools1_10_R1.java index 16b5bd5..184bc47 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/BlockTools1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/BlockTools1_10_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_10_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/ServerTools1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/ServerTools1_10_R1.java index 1890592..16a8918 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/ServerTools1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/ServerTools1_10_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_10_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/SkinTools1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/SkinTools1_10_R1.java index af1d28d..18c2d7f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/SkinTools1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/tools/SkinTools1_10_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_10_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/utils/EntityConstructors1_10_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/utils/EntityConstructors1_10_R1.java index e7efe67..e1ded4d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/utils/EntityConstructors1_10_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_10_R1/utils/EntityConstructors1_10_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_10_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_10_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_10_R1(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/BukkitConversion1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/BukkitConversion1_11_R1.java index ca6759c..02b48a6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/BukkitConversion1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/BukkitConversion1_11_R1.java @@ -7,7 +7,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_11_R1.ItemStack; import net.minecraft.server.v1_11_R1.NBTBase; @@ -31,176 +45,176 @@ public class BukkitConversion1_11_R1 extends BukkitConversion { - protected BukkitConversion1_11_R1(VersionControl1_11_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - NBTTagList list = new NBTTagList(); - for(long value : (long[]) tag.getValue()) { - list.add(new NBTTagLong(value)); - } - return list; - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTTagByte) tag).g()); - case SHORT: - return new NbtShort(((NBTTagShort) tag).f()); - case INT: - return new NbtInt(((NBTTagInt) tag).e()); - case LONG: - return new NbtLong(((NBTTagLong) tag).d()); - case FLOAT: - return new NbtFloat(((NBTTagFloat) tag).i()); - case DOUBLE: - return new NbtDouble(((NBTTagDouble) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).c_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).d()); - case LONG_ARRAY: - return new NbtLongArray(new long[0]); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : content) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.c(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(new ItemStack(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - if (!nmsStack.hasTag()) { - nmsStack.convertStack(); - } - return fromMinecraftCompound(nmsStack.getTag()); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_11_R1(VersionControl1_11_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + NBTTagList list = new NBTTagList(); + for (long value : (long[]) tag.getValue()) { + list.add(new NBTTagLong(value)); + } + return list; + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTTagByte) tag).g()); + case SHORT: + return new NbtShort(((NBTTagShort) tag).f()); + case INT: + return new NbtInt(((NBTTagInt) tag).e()); + case LONG: + return new NbtLong(((NBTTagLong) tag).d()); + case FLOAT: + return new NbtFloat(((NBTTagFloat) tag).i()); + case DOUBLE: + return new NbtDouble(((NBTTagDouble) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).c_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).d()); + case LONG_ARRAY: + return new NbtLongArray(new long[0]); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : content) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.c(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(new ItemStack(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); + if (!nmsStack.hasTag()) { + nmsStack.convertStack(); + } + return fromMinecraftCompound(nmsStack.getTag()); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/EntityProvider1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/EntityProvider1_11_R1.java index d9d70f2..cd1e27f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/EntityProvider1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/EntityProvider1_11_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_11_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_11_R1(VersionControl1_11_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_11_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_11_R1(VersionControl1_11_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_11_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/PacketHandler1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/PacketHandler1_11_R1.java index 49d8248..ef2ba2d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/PacketHandler1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/PacketHandler1_11_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_11_R1 extends PacketHandler { - protected PacketHandler1_11_R1(VersionControl1_11_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_11_R1(VersionControl1_11_R1 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/PlayerProvider1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/PlayerProvider1_11_R1.java index ba62fe2..6270e06 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/PlayerProvider1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/PlayerProvider1_11_R1.java @@ -14,17 +14,17 @@ public class PlayerProvider1_11_R1 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_11_R1(VersionControl1_11_R1 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_11_R1(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_11_R1(VersionControl1_11_R1 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_11_R1(player, distributor.get(player.getUniqueId())); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/TextureProvider1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/TextureProvider1_11_R1.java index d0ca609..4faa99f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/TextureProvider1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/TextureProvider1_11_R1.java @@ -20,84 +20,84 @@ @SuppressWarnings("deprecation") public class TextureProvider1_11_R1 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_11_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final Material skullMaterial = Material.valueOf("SKULL"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_11_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final Material skullMaterial = Material.valueOf("SKULL"); - protected TextureProvider1_11_R1(VersionControl1_11_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_11_R1(VersionControl1_11_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - return ((CraftSkull) block).getTileEntity().getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + return ((CraftSkull) block).getTileEntity().getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - if (!stack.hasTag()) { - stack.convertStack(); - } - NBTTagCompound stackTag = stack.getTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + if (!stack.hasTag()) { + stack.convertStack(); + } + NBTTagCompound stackTag = stack.getTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - ((CraftSkull) block).getTileEntity().setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + ((CraftSkull) block).getTileEntity().setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/ToolProvider1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/ToolProvider1_11_R1.java index 3cd7378..28d13df 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/ToolProvider1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/ToolProvider1_11_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_11_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_11_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_11_R1.tools.BlockTools1_11_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_11_R1.tools.ServerTools1_11_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_11_R1.tools.SkinTools1_11_R1; public class ToolProvider1_11_R1 extends ToolProvider { - private final BlockTools1_11_R1 blockTools = new BlockTools1_11_R1(); - private final SkinTools1_11_R1 skinTools = new SkinTools1_11_R1(); - private final ServerTools1_11_R1 serverTools = new ServerTools1_11_R1(); - - protected ToolProvider1_11_R1(VersionControl1_11_R1 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_11_R1 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_11_R1 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_11_R1 getBlockTools() { - return blockTools; - } + private final BlockTools1_11_R1 blockTools = new BlockTools1_11_R1(); + private final SkinTools1_11_R1 skinTools = new SkinTools1_11_R1(); + private final ServerTools1_11_R1 serverTools = new ServerTools1_11_R1(); + + protected ToolProvider1_11_R1(VersionControl1_11_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_11_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_11_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_11_R1 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/VersionControl1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/VersionControl1_11_R1.java index 3aa4505..72ecdde 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/VersionControl1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/VersionControl1_11_R1.java @@ -6,51 +6,51 @@ public class VersionControl1_11_R1 extends VersionControl { - public static VersionControl1_11_R1 INSTANCE; - - public static VersionControl1_11_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_11_R1()); - } - - private final ToolProvider1_11_R1 toolProvider = new ToolProvider1_11_R1(this); - private final TextureProvider1_11_R1 textureProvider = new TextureProvider1_11_R1(this); - private final PacketHandler1_11_R1 packetHandler = new PacketHandler1_11_R1(this); - private final EntityProvider1_11_R1 entityProvider = new EntityProvider1_11_R1(this); - private final PlayerProvider1_11_R1 playerProvider = new PlayerProvider1_11_R1(this); - private final BukkitConversion1_11_R1 bukkitConversion = new BukkitConversion1_11_R1(this); - - private VersionControl1_11_R1() { - NmsReflection1_11_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); - } - - @Override - public ToolProvider1_11_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_11_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_11_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_11_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_11_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_11_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_11_R1 INSTANCE; + + public static VersionControl1_11_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_11_R1()); + } + + private final ToolProvider1_11_R1 toolProvider = new ToolProvider1_11_R1(this); + private final TextureProvider1_11_R1 textureProvider = new TextureProvider1_11_R1(this); + private final PacketHandler1_11_R1 packetHandler = new PacketHandler1_11_R1(this); + private final EntityProvider1_11_R1 entityProvider = new EntityProvider1_11_R1(this); + private final PlayerProvider1_11_R1 playerProvider = new PlayerProvider1_11_R1(this); + private final BukkitConversion1_11_R1 bukkitConversion = new BukkitConversion1_11_R1(this); + + private VersionControl1_11_R1() { + NmsReflection1_11_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + } + + @Override + public ToolProvider1_11_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_11_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_11_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_11_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_11_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_11_R1 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/ArmorStand1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/ArmorStand1_11_R1.java index b74518d..42ac632 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/ArmorStand1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/ArmorStand1_11_R1.java @@ -6,18 +6,18 @@ public class ArmorStand1_11_R1 extends EntityLiving1_11_R1 implements NmsArmorStand { - public ArmorStand1_11_R1(World world) { - super(new EntityArmorStand(world)); - } + public ArmorStand1_11_R1(World world) { + super(new EntityArmorStand(world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/Entity1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/Entity1_11_R1.java index 8119ae7..6a05295 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/Entity1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/Entity1_11_R1.java @@ -12,6 +12,7 @@ import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_11_R1.AxisAlignedBB; import net.minecraft.server.v1_11_R1.Entity; import net.minecraft.server.v1_11_R1.EntityTypes; import net.minecraft.server.v1_11_R1.PacketPlayOutEntityDestroy; @@ -19,192 +20,193 @@ import net.minecraft.server.v1_11_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_11_R1.PlayerConnection; import net.minecraft.server.v1_11_R1.Vec3D; -import net.minecraft.server.v1_11_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_11_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_11_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(name); - } - - @Override - public String getCustomName() { - return handle.getCustomName(); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.aW(); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.d(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.b.a(handle.getClass())); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_11_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(name); + } + + @Override + public String getCustomName() { + return handle.getCustomName(); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.aW(); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.d(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.b.a(handle.getClass())); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/EntityLiving1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/EntityLiving1_11_R1.java index 4637b06..aa4e760 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/EntityLiving1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/EntityLiving1_11_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_11_R1 extends Entity1_11_R1 implements NmsEntityLiving { - public EntityLiving1_11_R1(E handle) { - super(handle); - } + public EntityLiving1_11_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/Player1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/Player1_11_R1.java index 03374d7..eb0366e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/Player1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/entity/Player1_11_R1.java @@ -48,231 +48,231 @@ public class Player1_11_R1 extends EntityLiving1_11_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_11_R1(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); - reflect.setFieldValue(packet, "header", headerComponent); - reflect.setFieldValue(packet, "footer", footerComponent); - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_11_R1(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + reflect.setFieldValue(packet, "header", headerComponent); + reflect.setFieldValue(packet, "footer", footerComponent); + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/reflection/NmsReflection1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/reflection/NmsReflection1_11_R1.java index 24d8d7e..0bd4da4 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/reflection/NmsReflection1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/reflection/NmsReflection1_11_R1.java @@ -8,27 +8,27 @@ public class NmsReflection1_11_R1 extends Reflections { - public static NmsReflection1_11_R1 INSTANCE = new NmsReflection1_11_R1(); + public static NmsReflection1_11_R1 INSTANCE = new NmsReflection1_11_R1(); - private NmsReflection1_11_R1() {} + private NmsReflection1_11_R1() {} - @Override - public void setup(ReflectionProvider provider) { + @Override + public void setup(ReflectionProvider provider) { - // - // - // Create Reflects - // + // + // + // Create Reflects + // - // - // Minecraft + // + // Minecraft - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class).searchField("header", "a") - .searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); - } + provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); + provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/BlockTools1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/BlockTools1_11_R1.java index e2ba7af..79076e7 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/BlockTools1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/BlockTools1_11_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_11_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/ServerTools1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/ServerTools1_11_R1.java index 62e90a7..a6c17da 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/ServerTools1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/ServerTools1_11_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_11_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/SkinTools1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/SkinTools1_11_R1.java index 856ab6f..da5fc77 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/SkinTools1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/tools/SkinTools1_11_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_11_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/utils/EntityConstructors1_11_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/utils/EntityConstructors1_11_R1.java index 7e6b9e2..ca4fee5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/utils/EntityConstructors1_11_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_11_R1/utils/EntityConstructors1_11_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_11_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_11_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_11_R1(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/BukkitConversion1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/BukkitConversion1_12_R1.java index 1a4cd31..e8fc7e5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/BukkitConversion1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/BukkitConversion1_12_R1.java @@ -7,7 +7,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_12_R1.ItemStack; import net.minecraft.server.v1_12_R1.NBTBase; @@ -32,172 +46,173 @@ public class BukkitConversion1_12_R1 extends BukkitConversion { - protected BukkitConversion1_12_R1(VersionControl1_12_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - return new NBTTagLongArray((long[]) tag.getValue()); - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTTagByte) tag).g()); - case SHORT: - return new NbtShort(((NBTTagShort) tag).f()); - case INT: - return new NbtInt(((NBTTagInt) tag).e()); - case LONG: - return new NbtLong(((NBTTagLong) tag).d()); - case FLOAT: - return new NbtFloat(((NBTTagFloat) tag).i()); - case DOUBLE: - return new NbtDouble(((NBTTagDouble) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).c_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).d()); - case LONG_ARRAY: - return new NbtLongArray((long[]) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagLongArray").getFieldValue("value", ((NBTTagLongArray) tag).c())); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : content) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.c(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(new ItemStack(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - if (!nmsStack.hasTag()) { - nmsStack.convertStack(); - } - return fromMinecraftCompound(nmsStack.getTag()); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_12_R1(VersionControl1_12_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + return new NBTTagLongArray((long[]) tag.getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTTagByte) tag).g()); + case SHORT: + return new NbtShort(((NBTTagShort) tag).f()); + case INT: + return new NbtInt(((NBTTagInt) tag).e()); + case LONG: + return new NbtLong(((NBTTagLong) tag).d()); + case FLOAT: + return new NbtFloat(((NBTTagFloat) tag).i()); + case DOUBLE: + return new NbtDouble(((NBTTagDouble) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).c_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).d()); + case LONG_ARRAY: + return new NbtLongArray( + (long[]) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagLongArray").getFieldValue("value", ((NBTTagLongArray) tag).c())); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : content) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.c(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(new ItemStack(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); + if (!nmsStack.hasTag()) { + nmsStack.convertStack(); + } + return fromMinecraftCompound(nmsStack.getTag()); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/EntityProvider1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/EntityProvider1_12_R1.java index 62b0e2b..58d527b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/EntityProvider1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/EntityProvider1_12_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_12_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_12_R1(VersionControl1_12_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_12_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_12_R1(VersionControl1_12_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_12_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/PacketHandler1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/PacketHandler1_12_R1.java index c242999..b90ce2c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/PacketHandler1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/PacketHandler1_12_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_12_R1 extends PacketHandler { - protected PacketHandler1_12_R1(VersionControl1_12_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_12_R1(VersionControl1_12_R1 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/PlayerProvider1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/PlayerProvider1_12_R1.java index 2ac1dc0..d360a9a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/PlayerProvider1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/PlayerProvider1_12_R1.java @@ -14,17 +14,17 @@ public class PlayerProvider1_12_R1 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_12_R1(VersionControl1_12_R1 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_12_R1(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_12_R1(VersionControl1_12_R1 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_12_R1(player, distributor.get(player.getUniqueId())); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/TextureProvider1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/TextureProvider1_12_R1.java index c3959e4..c5c616b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/TextureProvider1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/TextureProvider1_12_R1.java @@ -22,87 +22,87 @@ @SuppressWarnings("deprecation") public class TextureProvider1_12_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final Material skullMaterial = Material.valueOf("SKULL"); + private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_12_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final Material skullMaterial = Material.valueOf("SKULL"); - protected TextureProvider1_12_R1(VersionControl1_12_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_12_R1(VersionControl1_12_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - if (!stack.hasTag()) { - stack.convertStack(); - } - NBTTagCompound stackTag = stack.getTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + if (!stack.hasTag()) { + stack.convertStack(); + } + NBTTagCompound stackTag = stack.getTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - entitySkull.setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + entitySkull.setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/ToolProvider1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/ToolProvider1_12_R1.java index 75e9fc8..4e9eeae 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/ToolProvider1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/ToolProvider1_12_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_12_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_12_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_12_R1.tools.BlockTools1_12_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_12_R1.tools.ServerTools1_12_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_12_R1.tools.SkinTools1_12_R1; public class ToolProvider1_12_R1 extends ToolProvider { - - private final BlockTools1_12_R1 blockTools = new BlockTools1_12_R1(); - private final SkinTools1_12_R1 skinTools = new SkinTools1_12_R1(); - private final ServerTools1_12_R1 serverTools = new ServerTools1_12_R1(); - - protected ToolProvider1_12_R1(VersionControl1_12_R1 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_12_R1 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_12_R1 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_12_R1 getBlockTools() { - return blockTools; - } + + private final BlockTools1_12_R1 blockTools = new BlockTools1_12_R1(); + private final SkinTools1_12_R1 skinTools = new SkinTools1_12_R1(); + private final ServerTools1_12_R1 serverTools = new ServerTools1_12_R1(); + + protected ToolProvider1_12_R1(VersionControl1_12_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_12_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_12_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_12_R1 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/VersionControl1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/VersionControl1_12_R1.java index 5e7f48e..12bcf86 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/VersionControl1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/VersionControl1_12_R1.java @@ -6,51 +6,51 @@ public class VersionControl1_12_R1 extends VersionControl { - public static VersionControl1_12_R1 INSTANCE; - - public static VersionControl1_12_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_12_R1()); - } - - private final ToolProvider1_12_R1 toolProvider = new ToolProvider1_12_R1(this); - private final TextureProvider1_12_R1 textureProvider = new TextureProvider1_12_R1(this); - private final PacketHandler1_12_R1 packetHandler = new PacketHandler1_12_R1(this); - private final EntityProvider1_12_R1 entityProvider = new EntityProvider1_12_R1(this); - private final PlayerProvider1_12_R1 playerProvider = new PlayerProvider1_12_R1(this); - private final BukkitConversion1_12_R1 bukkitConversion = new BukkitConversion1_12_R1(this); - - private VersionControl1_12_R1() { - NmsReflection1_12_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); - } - - @Override - public ToolProvider1_12_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_12_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_12_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_12_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_12_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_12_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_12_R1 INSTANCE; + + public static VersionControl1_12_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_12_R1()); + } + + private final ToolProvider1_12_R1 toolProvider = new ToolProvider1_12_R1(this); + private final TextureProvider1_12_R1 textureProvider = new TextureProvider1_12_R1(this); + private final PacketHandler1_12_R1 packetHandler = new PacketHandler1_12_R1(this); + private final EntityProvider1_12_R1 entityProvider = new EntityProvider1_12_R1(this); + private final PlayerProvider1_12_R1 playerProvider = new PlayerProvider1_12_R1(this); + private final BukkitConversion1_12_R1 bukkitConversion = new BukkitConversion1_12_R1(this); + + private VersionControl1_12_R1() { + NmsReflection1_12_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + } + + @Override + public ToolProvider1_12_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_12_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_12_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_12_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_12_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_12_R1 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/ArmorStand1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/ArmorStand1_12_R1.java index 7971738..1fbefab 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/ArmorStand1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/ArmorStand1_12_R1.java @@ -6,18 +6,18 @@ public class ArmorStand1_12_R1 extends EntityLiving1_12_R1 implements NmsArmorStand { - public ArmorStand1_12_R1(World world) { - super(new EntityArmorStand(world)); - } + public ArmorStand1_12_R1(World world) { + super(new EntityArmorStand(world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/Entity1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/Entity1_12_R1.java index 944bd58..3e5497e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/Entity1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/Entity1_12_R1.java @@ -12,6 +12,7 @@ import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_12_R1.AxisAlignedBB; import net.minecraft.server.v1_12_R1.Entity; import net.minecraft.server.v1_12_R1.EntityTypes; import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy; @@ -19,192 +20,193 @@ import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_12_R1.PlayerConnection; import net.minecraft.server.v1_12_R1.Vec3D; -import net.minecraft.server.v1_12_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_12_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_12_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(name); - } - - @Override - public String getCustomName() { - return handle.getCustomName(); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.be(); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.d(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.b.a(handle.getClass())); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_12_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(name); + } + + @Override + public String getCustomName() { + return handle.getCustomName(); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.be(); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.d(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.b.a(handle.getClass())); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/EntityLiving1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/EntityLiving1_12_R1.java index dde79e5..5991c89 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/EntityLiving1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/EntityLiving1_12_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_12_R1 extends Entity1_12_R1 implements NmsEntityLiving { - public EntityLiving1_12_R1(E handle) { - super(handle); - } + public EntityLiving1_12_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/Player1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/Player1_12_R1.java index 6a570aa..6088ee2 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/Player1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/entity/Player1_12_R1.java @@ -48,231 +48,231 @@ public class Player1_12_R1 extends EntityLiving1_12_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_12_R1(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); - reflect.setFieldValue(packet, "header", headerComponent); - reflect.setFieldValue(packet, "footer", footerComponent); - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_12_R1(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + reflect.setFieldValue(packet, "header", headerComponent); + reflect.setFieldValue(packet, "footer", footerComponent); + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/reflection/NmsReflection1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/reflection/NmsReflection1_12_R1.java index 7c8360b..c599b1b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/reflection/NmsReflection1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/reflection/NmsReflection1_12_R1.java @@ -9,28 +9,28 @@ public class NmsReflection1_12_R1 extends Reflections { - public static NmsReflection1_12_R1 INSTANCE = new NmsReflection1_12_R1(); + public static NmsReflection1_12_R1 INSTANCE = new NmsReflection1_12_R1(); - private NmsReflection1_12_R1() {} + private NmsReflection1_12_R1() {} - @Override - public void setup(ReflectionProvider provider) { + @Override + public void setup(ReflectionProvider provider) { - // - // - // Create Reflects - // + // + // + // Create Reflects + // - // - // Minecraft + // + // Minecraft - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class).searchField("header", "a") - .searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagLongArray", NBTTagLongArray.class).searchField("value", "b"); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); - } + provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); + provider.createReflect("nmsNBTTagLongArray", NBTTagLongArray.class).searchField("value", "b"); + provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/BlockTools1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/BlockTools1_12_R1.java index 4ce2394..7028fb0 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/BlockTools1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/BlockTools1_12_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_12_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/ServerTools1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/ServerTools1_12_R1.java index 497b39e..317e4d3 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/ServerTools1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/ServerTools1_12_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_12_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/SkinTools1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/SkinTools1_12_R1.java index 84a9285..b096bf1 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/SkinTools1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/tools/SkinTools1_12_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_12_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/utils/EntityConstructors1_12_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/utils/EntityConstructors1_12_R1.java index 8367f81..caaa7f5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/utils/EntityConstructors1_12_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_12_R1/utils/EntityConstructors1_12_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_12_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_12_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_12_R1(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/BukkitConversion1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/BukkitConversion1_13_R1.java index 620e639..1cb6775 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/BukkitConversion1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/BukkitConversion1_13_R1.java @@ -6,7 +6,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_13_R1.ItemStack; import net.minecraft.server.v1_13_R1.NBTBase; @@ -31,166 +45,166 @@ public class BukkitConversion1_13_R1 extends BukkitConversion { - protected BukkitConversion1_13_R1(VersionControl1_13_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - return new NBTTagLongArray((long[]) tag.getValue()); - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return new NBTTagEnd(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTNumber) tag).g()); - case SHORT: - return new NbtShort(((NBTNumber) tag).f()); - case INT: - return new NbtInt(((NBTNumber) tag).e()); - case LONG: - return new NbtLong(((NBTNumber) tag).d()); - case FLOAT: - return new NbtFloat(((NBTNumber) tag).i()); - case DOUBLE: - return new NbtDouble(((NBTNumber) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).b_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).d()); - case LONG_ARRAY: - return new NbtLongArray(((NBTTagLongArray) tag).d()); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : list) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_13_R1(VersionControl1_13_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + return new NBTTagLongArray((long[]) tag.getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return new NBTTagEnd(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTNumber) tag).g()); + case SHORT: + return new NbtShort(((NBTNumber) tag).f()); + case INT: + return new NbtInt(((NBTNumber) tag).e()); + case LONG: + return new NbtLong(((NBTNumber) tag).d()); + case FLOAT: + return new NbtFloat(((NBTNumber) tag).i()); + case DOUBLE: + return new NbtDouble(((NBTNumber) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).b_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).d()); + case LONG_ARRAY: + return new NbtLongArray(((NBTTagLongArray) tag).d()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/EntityProvider1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/EntityProvider1_13_R1.java index 0592d9e..4b0fbe0 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/EntityProvider1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/EntityProvider1_13_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_13_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_13_R1(VersionControl1_13_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_13_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_13_R1(VersionControl1_13_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_13_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/PacketHandler1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/PacketHandler1_13_R1.java index f2fac75..b76a11c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/PacketHandler1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/PacketHandler1_13_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_13_R1 extends PacketHandler { - protected PacketHandler1_13_R1(VersionControl1_13_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_13_R1(VersionControl1_13_R1 versionControl) { + super(versionControl); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/PlayerProvider1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/PlayerProvider1_13_R1.java index af0eb56..aee2ffa 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/PlayerProvider1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/PlayerProvider1_13_R1.java @@ -14,17 +14,17 @@ public class PlayerProvider1_13_R1 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_13_R1(VersionControl1_13_R1 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_13_R1(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_13_R1(VersionControl1_13_R1 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_13_R1(player, distributor.get(player.getUniqueId())); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/TextureProvider1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/TextureProvider1_13_R1.java index 1cb3635..5739942 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/TextureProvider1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/TextureProvider1_13_R1.java @@ -20,83 +20,83 @@ public class TextureProvider1_13_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_13_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_13_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - protected TextureProvider1_13_R1(VersionControl1_13_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_13_R1(VersionControl1_13_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag = stack.getOrCreateTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag = stack.getOrCreateTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - entitySkull.setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + entitySkull.setGameProfile(profile); + return true; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/ToolProvider1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/ToolProvider1_13_R1.java index b5d15d7..4b54e2e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/ToolProvider1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/ToolProvider1_13_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R1.tools.BlockTools1_13_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R1.tools.ServerTools1_13_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R1.tools.SkinTools1_13_R1; public class ToolProvider1_13_R1 extends ToolProvider { - - private final BlockTools1_13_R1 blockTools = new BlockTools1_13_R1(); - private final SkinTools1_13_R1 skinTools = new SkinTools1_13_R1(); - private final ServerTools1_13_R1 serverTools = new ServerTools1_13_R1(); - - protected ToolProvider1_13_R1(VersionControl1_13_R1 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_13_R1 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_13_R1 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_13_R1 getBlockTools() { - return blockTools; - } + + private final BlockTools1_13_R1 blockTools = new BlockTools1_13_R1(); + private final SkinTools1_13_R1 skinTools = new SkinTools1_13_R1(); + private final ServerTools1_13_R1 serverTools = new ServerTools1_13_R1(); + + protected ToolProvider1_13_R1(VersionControl1_13_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_13_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_13_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_13_R1 getBlockTools() { + return blockTools; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/VersionControl1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/VersionControl1_13_R1.java index 3e78a81..fffa0e6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/VersionControl1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/VersionControl1_13_R1.java @@ -4,51 +4,51 @@ public class VersionControl1_13_R1 extends VersionControl { - public static VersionControl1_13_R1 INSTANCE; - - public static VersionControl1_13_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_13_R1()); - } - - private final ToolProvider1_13_R1 toolProvider = new ToolProvider1_13_R1(this); - private final TextureProvider1_13_R1 textureProvider = new TextureProvider1_13_R1(this); - private final PacketHandler1_13_R1 packetHandler = new PacketHandler1_13_R1(this); - private final EntityProvider1_13_R1 entityProvider = new EntityProvider1_13_R1(this); - private final PlayerProvider1_13_R1 playerProvider = new PlayerProvider1_13_R1(this); - private final BukkitConversion1_13_R1 bukkitConversion = new BukkitConversion1_13_R1(this); - - private VersionControl1_13_R1() { - - } - - @Override - public ToolProvider1_13_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_13_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_13_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_13_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_13_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_13_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_13_R1 INSTANCE; + + public static VersionControl1_13_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_13_R1()); + } + + private final ToolProvider1_13_R1 toolProvider = new ToolProvider1_13_R1(this); + private final TextureProvider1_13_R1 textureProvider = new TextureProvider1_13_R1(this); + private final PacketHandler1_13_R1 packetHandler = new PacketHandler1_13_R1(this); + private final EntityProvider1_13_R1 entityProvider = new EntityProvider1_13_R1(this); + private final PlayerProvider1_13_R1 playerProvider = new PlayerProvider1_13_R1(this); + private final BukkitConversion1_13_R1 bukkitConversion = new BukkitConversion1_13_R1(this); + + private VersionControl1_13_R1() { + + } + + @Override + public ToolProvider1_13_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_13_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_13_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_13_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_13_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_13_R1 getBukkitConversion() { + return bukkitConversion; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/ArmorStand1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/ArmorStand1_13_R1.java index 7420e2d..dc6e269 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/ArmorStand1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/ArmorStand1_13_R1.java @@ -6,18 +6,18 @@ public class ArmorStand1_13_R1 extends EntityLiving1_13_R1 implements NmsArmorStand { - public ArmorStand1_13_R1(World world) { - super(new EntityArmorStand(world)); - } + public ArmorStand1_13_R1(World world) { + super(new EntityArmorStand(world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/Entity1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/Entity1_13_R1.java index 297eba4..eecc22c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/Entity1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/Entity1_13_R1.java @@ -13,6 +13,7 @@ import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage; import org.bukkit.entity.Player; +import net.minecraft.server.v1_13_R1.AxisAlignedBB; import net.minecraft.server.v1_13_R1.Entity; import net.minecraft.server.v1_13_R1.EntityTypes; import net.minecraft.server.v1_13_R1.PacketPlayOutEntityDestroy; @@ -20,192 +21,193 @@ import net.minecraft.server.v1_13_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_13_R1.PlayerConnection; import net.minecraft.server.v1_13_R1.Vec3D; -import net.minecraft.server.v1_13_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_13_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_13_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); - } - - @Override - public String getCustomName() { - return CraftChatMessage.fromComponent(handle.getCustomName()); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.bl(); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(null); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.bI(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.REGISTRY.a(handle.P())); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_13_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.bl(); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(null); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.bI(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.REGISTRY.a(handle.P())); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/EntityLiving1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/EntityLiving1_13_R1.java index 33dd6bb..4e3bba9 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/EntityLiving1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/EntityLiving1_13_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_13_R1 extends Entity1_13_R1 implements NmsEntityLiving { - public EntityLiving1_13_R1(E handle) { - super(handle); - } + public EntityLiving1_13_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/Player1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/Player1_13_R1.java index 82be274..95d4014 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/Player1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/entity/Player1_13_R1.java @@ -47,230 +47,230 @@ public class Player1_13_R1 extends EntityLiving1_13_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_13_R1(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - packet.a = headerComponent; - packet.b = footerComponent; - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_13_R1(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + packet.a = headerComponent; + packet.b = footerComponent; + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/BlockTools1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/BlockTools1_13_R1.java index 31dcd02..b4053b1 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/BlockTools1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/BlockTools1_13_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_13_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/ServerTools1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/ServerTools1_13_R1.java index abd11cf..8a7aa06 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/ServerTools1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/ServerTools1_13_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_13_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/SkinTools1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/SkinTools1_13_R1.java index be8bca1..b309e9d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/SkinTools1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/tools/SkinTools1_13_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_13_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/utils/EntityConstructors1_13_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/utils/EntityConstructors1_13_R1.java index 41227e0..ab42e85 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/utils/EntityConstructors1_13_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R1/utils/EntityConstructors1_13_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_13_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_13_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_13_R1(world)); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/BukkitConversion1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/BukkitConversion1_13_R2.java index b123054..ce4357f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/BukkitConversion1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/BukkitConversion1_13_R2.java @@ -6,7 +6,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_13_R2.ItemStack; import net.minecraft.server.v1_13_R2.NBTBase; @@ -31,166 +45,166 @@ public class BukkitConversion1_13_R2 extends BukkitConversion { - protected BukkitConversion1_13_R2(VersionControl1_13_R2 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - return new NBTTagLongArray((long[]) tag.getValue()); - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return new NBTTagEnd(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTNumber) tag).asByte()); - case SHORT: - return new NbtShort(((NBTNumber) tag).asShort()); - case INT: - return new NbtInt(((NBTNumber) tag).asInt()); - case LONG: - return new NbtLong(((NBTNumber) tag).asLong()); - case FLOAT: - return new NbtFloat(((NBTNumber) tag).asFloat()); - case DOUBLE: - return new NbtDouble(((NBTNumber) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).asString()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).d()); - case LONG_ARRAY: - return new NbtLongArray(((NBTTagLongArray) tag).d()); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : list) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_13_R2(VersionControl1_13_R2 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + return new NBTTagLongArray((long[]) tag.getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return new NBTTagEnd(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTNumber) tag).asByte()); + case SHORT: + return new NbtShort(((NBTNumber) tag).asShort()); + case INT: + return new NbtInt(((NBTNumber) tag).asInt()); + case LONG: + return new NbtLong(((NBTNumber) tag).asLong()); + case FLOAT: + return new NbtFloat(((NBTNumber) tag).asFloat()); + case DOUBLE: + return new NbtDouble(((NBTNumber) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).asString()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).d()); + case LONG_ARRAY: + return new NbtLongArray(((NBTTagLongArray) tag).d()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/EntityProvider1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/EntityProvider1_13_R2.java index dfc8888..fa56d45 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/EntityProvider1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/EntityProvider1_13_R2.java @@ -13,35 +13,35 @@ public class EntityProvider1_13_R2 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_13_R2(VersionControl1_13_R2 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_13_R2.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_13_R2(VersionControl1_13_R2 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_13_R2.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/PacketHandler1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/PacketHandler1_13_R2.java index 88abc54..3479157 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/PacketHandler1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/PacketHandler1_13_R2.java @@ -4,8 +4,8 @@ public class PacketHandler1_13_R2 extends PacketHandler { - protected PacketHandler1_13_R2(VersionControl1_13_R2 versionControl) { - super(versionControl); - } + protected PacketHandler1_13_R2(VersionControl1_13_R2 versionControl) { + super(versionControl); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/PlayerProvider1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/PlayerProvider1_13_R2.java index 40fb2cc..7b2fecd 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/PlayerProvider1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/PlayerProvider1_13_R2.java @@ -14,17 +14,17 @@ public class PlayerProvider1_13_R2 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_13_R2(VersionControl1_13_R2 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_13_R2(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_13_R2(VersionControl1_13_R2 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_13_R2(player, distributor.get(player.getUniqueId())); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/TextureProvider1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/TextureProvider1_13_R2.java index 7a6c7d5..dc0d84e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/TextureProvider1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/TextureProvider1_13_R2.java @@ -20,83 +20,83 @@ public class TextureProvider1_13_R2 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_13_R2.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_13_R2.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - protected TextureProvider1_13_R2(VersionControl1_13_R2 versionControl) { - super(versionControl); - } + protected TextureProvider1_13_R2(VersionControl1_13_R2 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag = stack.getOrCreateTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag = stack.getOrCreateTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - entitySkull.setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + entitySkull.setGameProfile(profile); + return true; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/ToolProvider1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/ToolProvider1_13_R2.java index c0e3683..851dd3e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/ToolProvider1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/ToolProvider1_13_R2.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R2; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R2.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R2.tools.BlockTools1_13_R2; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R2.tools.ServerTools1_13_R2; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_13_R2.tools.SkinTools1_13_R2; public class ToolProvider1_13_R2 extends ToolProvider { - private final BlockTools1_13_R2 blockTools = new BlockTools1_13_R2(); - private final SkinTools1_13_R2 skinTools = new SkinTools1_13_R2(); - private final ServerTools1_13_R2 serverTools = new ServerTools1_13_R2(); - - protected ToolProvider1_13_R2(VersionControl1_13_R2 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_13_R2 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_13_R2 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_13_R2 getBlockTools() { - return blockTools; - } + private final BlockTools1_13_R2 blockTools = new BlockTools1_13_R2(); + private final SkinTools1_13_R2 skinTools = new SkinTools1_13_R2(); + private final ServerTools1_13_R2 serverTools = new ServerTools1_13_R2(); + + protected ToolProvider1_13_R2(VersionControl1_13_R2 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_13_R2 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_13_R2 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_13_R2 getBlockTools() { + return blockTools; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/VersionControl1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/VersionControl1_13_R2.java index 3db9c4e..fa33e3a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/VersionControl1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/VersionControl1_13_R2.java @@ -4,51 +4,51 @@ public class VersionControl1_13_R2 extends VersionControl { - public static VersionControl1_13_R2 INSTANCE; - - public static VersionControl1_13_R2 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_13_R2()); - } - - private final ToolProvider1_13_R2 toolProvider = new ToolProvider1_13_R2(this); - private final TextureProvider1_13_R2 textureProvider = new TextureProvider1_13_R2(this); - private final PacketHandler1_13_R2 packetHandler = new PacketHandler1_13_R2(this); - private final EntityProvider1_13_R2 entityProvider = new EntityProvider1_13_R2(this); - private final PlayerProvider1_13_R2 playerProvider = new PlayerProvider1_13_R2(this); - private final BukkitConversion1_13_R2 bukkitConversion = new BukkitConversion1_13_R2(this); - - private VersionControl1_13_R2() { - - } - - @Override - public ToolProvider1_13_R2 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_13_R2 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_13_R2 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_13_R2 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_13_R2 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_13_R2 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_13_R2 INSTANCE; + + public static VersionControl1_13_R2 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_13_R2()); + } + + private final ToolProvider1_13_R2 toolProvider = new ToolProvider1_13_R2(this); + private final TextureProvider1_13_R2 textureProvider = new TextureProvider1_13_R2(this); + private final PacketHandler1_13_R2 packetHandler = new PacketHandler1_13_R2(this); + private final EntityProvider1_13_R2 entityProvider = new EntityProvider1_13_R2(this); + private final PlayerProvider1_13_R2 playerProvider = new PlayerProvider1_13_R2(this); + private final BukkitConversion1_13_R2 bukkitConversion = new BukkitConversion1_13_R2(this); + + private VersionControl1_13_R2() { + + } + + @Override + public ToolProvider1_13_R2 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_13_R2 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_13_R2 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_13_R2 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_13_R2 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_13_R2 getBukkitConversion() { + return bukkitConversion; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/ArmorStand1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/ArmorStand1_13_R2.java index 6d12712..4dc55dc 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/ArmorStand1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/ArmorStand1_13_R2.java @@ -6,18 +6,18 @@ public class ArmorStand1_13_R2 extends EntityLiving1_13_R2 implements NmsArmorStand { - public ArmorStand1_13_R2(World world) { - super(new EntityArmorStand(world)); - } + public ArmorStand1_13_R2(World world) { + super(new EntityArmorStand(world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/Entity1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/Entity1_13_R2.java index b303ca5..ba505e8 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/Entity1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/Entity1_13_R2.java @@ -13,6 +13,7 @@ import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage; import org.bukkit.entity.Player; +import net.minecraft.server.v1_13_R2.AxisAlignedBB; import net.minecraft.server.v1_13_R2.Entity; import net.minecraft.server.v1_13_R2.IRegistry; import net.minecraft.server.v1_13_R2.PacketPlayOutEntityDestroy; @@ -20,192 +21,193 @@ import net.minecraft.server.v1_13_R2.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_13_R2.PlayerConnection; import net.minecraft.server.v1_13_R2.Vec3D; -import net.minecraft.server.v1_13_R2.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_13_R2 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_13_R2(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); - } - - @Override - public String getCustomName() { - return CraftChatMessage.fromComponent(handle.getCustomName()); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.bl(); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.bI(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, IRegistry.ENTITY_TYPE.a(handle.P())); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_13_R2(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.bl(); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.bI(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, IRegistry.ENTITY_TYPE.a(handle.P())); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/EntityLiving1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/EntityLiving1_13_R2.java index 5e2d7aa..d562f48 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/EntityLiving1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/EntityLiving1_13_R2.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_13_R2 extends Entity1_13_R2 implements NmsEntityLiving { - public EntityLiving1_13_R2(E handle) { - super(handle); - } + public EntityLiving1_13_R2(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/Player1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/Player1_13_R2.java index 62474d5..9622a86 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/Player1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/entity/Player1_13_R2.java @@ -47,230 +47,230 @@ public class Player1_13_R2 extends EntityLiving1_13_R2 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_13_R2(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - dataAdapter.set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - dataAdapter.remove("name"); - return; - } - dataAdapter.set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return dataAdapter.getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return dataAdapter.getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - dataAdapter.set("header", header, WrapType.STRING); - dataAdapter.set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - packet.header = headerComponent; - packet.footer = footerComponent; - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_13_R2(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + dataAdapter.set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + dataAdapter.remove("name"); + return; + } + dataAdapter.set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return dataAdapter.getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return dataAdapter.getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + dataAdapter.set("header", header, WrapType.STRING); + dataAdapter.set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + packet.header = headerComponent; + packet.footer = footerComponent; + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/BlockTools1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/BlockTools1_13_R2.java index a9b89a6..b95569c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/BlockTools1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/BlockTools1_13_R2.java @@ -14,26 +14,26 @@ public class BlockTools1_13_R2 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/ServerTools1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/ServerTools1_13_R2.java index 73c2b2e..58aa6be 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/ServerTools1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/ServerTools1_13_R2.java @@ -7,14 +7,14 @@ public class ServerTools1_13_R2 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/SkinTools1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/SkinTools1_13_R2.java index c3e2c36..90d203b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/SkinTools1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/tools/SkinTools1_13_R2.java @@ -8,9 +8,9 @@ public class SkinTools1_13_R2 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/utils/EntityConstructors1_13_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/utils/EntityConstructors1_13_R2.java index c0977d0..5bb8887 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/utils/EntityConstructors1_13_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_13_R2/utils/EntityConstructors1_13_R2.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_13_R2 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_13_R2(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_13_R2(world)); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/BukkitConversion1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/BukkitConversion1_14_R1.java index a719f93..6a61fef 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/BukkitConversion1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/BukkitConversion1_14_R1.java @@ -6,7 +6,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_14_R1.ItemStack; import net.minecraft.server.v1_14_R1.NBTBase; @@ -31,166 +45,166 @@ public class BukkitConversion1_14_R1 extends BukkitConversion { - protected BukkitConversion1_14_R1(VersionControl1_14_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - return new NBTTagLongArray((long[]) tag.getValue()); - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return new NBTTagEnd(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTNumber) tag).asByte()); - case SHORT: - return new NbtShort(((NBTNumber) tag).asShort()); - case INT: - return new NbtInt(((NBTNumber) tag).asInt()); - case LONG: - return new NbtLong(((NBTNumber) tag).asLong()); - case FLOAT: - return new NbtFloat(((NBTNumber) tag).asFloat()); - case DOUBLE: - return new NbtDouble(((NBTNumber) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).asString()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).getInts()); - case LONG_ARRAY: - return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : list) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new BukkitContext1_14_R1(context); - } + protected BukkitConversion1_14_R1(VersionControl1_14_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + return new NBTTagLongArray((long[]) tag.getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return new NBTTagEnd(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTNumber) tag).asByte()); + case SHORT: + return new NbtShort(((NBTNumber) tag).asShort()); + case INT: + return new NbtInt(((NBTNumber) tag).asInt()); + case LONG: + return new NbtLong(((NBTNumber) tag).asLong()); + case FLOAT: + return new NbtFloat(((NBTNumber) tag).asFloat()); + case DOUBLE: + return new NbtDouble(((NBTNumber) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).asString()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).getInts()); + case LONG_ARRAY: + return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new BukkitContext1_14_R1(context); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/EntityProvider1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/EntityProvider1_14_R1.java index 46fa28f..5ee496b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/EntityProvider1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/EntityProvider1_14_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_14_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_14_R1(VersionControl1_14_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_14_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_14_R1(VersionControl1_14_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_14_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/PacketHandler1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/PacketHandler1_14_R1.java index 720f366..4331df8 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/PacketHandler1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/PacketHandler1_14_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_14_R1 extends PacketHandler { - protected PacketHandler1_14_R1(VersionControl1_14_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_14_R1(VersionControl1_14_R1 versionControl) { + super(versionControl); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/PlayerProvider1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/PlayerProvider1_14_R1.java index 815671e..470edd0 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/PlayerProvider1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/PlayerProvider1_14_R1.java @@ -8,13 +8,13 @@ public class PlayerProvider1_14_R1 extends PlayerProvider { - protected PlayerProvider1_14_R1(VersionControl1_14_R1 versionControl) { - super(versionControl); - } + protected PlayerProvider1_14_R1(VersionControl1_14_R1 versionControl) { + super(versionControl); + } - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_14_R1(player); - } + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_14_R1(player); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/TextureProvider1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/TextureProvider1_14_R1.java index f8a9738..62b1ca6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/TextureProvider1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/TextureProvider1_14_R1.java @@ -20,83 +20,83 @@ public class TextureProvider1_14_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_14_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_14_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - protected TextureProvider1_14_R1(VersionControl1_14_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_14_R1(VersionControl1_14_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile; - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile; + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag = stack.getOrCreateTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag = stack.getOrCreateTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - entitySkull.setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + entitySkull.setGameProfile(profile); + return true; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/ToolProvider1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/ToolProvider1_14_R1.java index efaa8d1..1430a7b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/ToolProvider1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/ToolProvider1_14_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_14_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_14_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_14_R1.tools.BlockTools1_14_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_14_R1.tools.ServerTools1_14_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_14_R1.tools.SkinTools1_14_R1; public class ToolProvider1_14_R1 extends ToolProvider { - private final BlockTools1_14_R1 blockTools = new BlockTools1_14_R1(); - private final SkinTools1_14_R1 skinTools = new SkinTools1_14_R1(); - private final ServerTools1_14_R1 serverTools = new ServerTools1_14_R1(); - - protected ToolProvider1_14_R1(VersionControl1_14_R1 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_14_R1 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_14_R1 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_14_R1 getBlockTools() { - return blockTools; - } + private final BlockTools1_14_R1 blockTools = new BlockTools1_14_R1(); + private final SkinTools1_14_R1 skinTools = new SkinTools1_14_R1(); + private final ServerTools1_14_R1 serverTools = new ServerTools1_14_R1(); + + protected ToolProvider1_14_R1(VersionControl1_14_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_14_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_14_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_14_R1 getBlockTools() { + return blockTools; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/VersionControl1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/VersionControl1_14_R1.java index 8eab82c..3821143 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/VersionControl1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/VersionControl1_14_R1.java @@ -4,51 +4,51 @@ public class VersionControl1_14_R1 extends VersionControl { - public static VersionControl1_14_R1 INSTANCE; - - public static VersionControl1_14_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_14_R1()); - } - - private final ToolProvider1_14_R1 toolProvider = new ToolProvider1_14_R1(this); - private final TextureProvider1_14_R1 textureProvider = new TextureProvider1_14_R1(this); - private final PacketHandler1_14_R1 packetHandler = new PacketHandler1_14_R1(this); - private final EntityProvider1_14_R1 entityProvider = new EntityProvider1_14_R1(this); - private final PlayerProvider1_14_R1 playerProvider = new PlayerProvider1_14_R1(this); - private final BukkitConversion1_14_R1 bukkitConversion = new BukkitConversion1_14_R1(this); - - private VersionControl1_14_R1() { - - } - - @Override - public ToolProvider1_14_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_14_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_14_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_14_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_14_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_14_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_14_R1 INSTANCE; + + public static VersionControl1_14_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_14_R1()); + } + + private final ToolProvider1_14_R1 toolProvider = new ToolProvider1_14_R1(this); + private final TextureProvider1_14_R1 textureProvider = new TextureProvider1_14_R1(this); + private final PacketHandler1_14_R1 packetHandler = new PacketHandler1_14_R1(this); + private final EntityProvider1_14_R1 entityProvider = new EntityProvider1_14_R1(this); + private final PlayerProvider1_14_R1 playerProvider = new PlayerProvider1_14_R1(this); + private final BukkitConversion1_14_R1 bukkitConversion = new BukkitConversion1_14_R1(this); + + private VersionControl1_14_R1() { + + } + + @Override + public ToolProvider1_14_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_14_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_14_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_14_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_14_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_14_R1 getBukkitConversion() { + return bukkitConversion; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitContainer1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitContainer1_14_R1.java index b5a847d..356567b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitContainer1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitContainer1_14_R1.java @@ -19,142 +19,142 @@ public final class BukkitContainer1_14_R1 extends WrappedContainer implements PersistentDataContainer { - private final IDataContainer container; - - public BukkitContainer1_14_R1(IDataContainer container) { - this.container = container; - } - - @Override - public IDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return container; - } - - /* - * - */ - - @Override - public boolean has(NamespacedKey key, PersistentDataType type) { - return has(new BukkitKey1_14_R1(key), WrappedType1_14_R1.wrap(type)); - } - - @Override - public Z get(NamespacedKey key, PersistentDataType type) { - return get(new BukkitKey1_14_R1(key), WrappedType1_14_R1.wrap(type)); - } - - @Override - public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { - return Optional.ofNullable(get(key, type)).orElse(value); - } - - @Override - public void set(NamespacedKey key, PersistentDataType type, Z value) { - set(new BukkitKey1_14_R1(key), value, WrappedType1_14_R1.wrap(type)); - } - - @Override - public void remove(NamespacedKey key) { - remove(new BukkitKey1_14_R1(key)); - } - - public Set getKeys() { - return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_14_R1::asBukkit).collect(Collectors.toSet()); - } - - @Override - public PersistentDataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public BukkitContext1_14_R1 getContext() { - return new BukkitContext1_14_R1(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(key.getNamespacedKey()); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public Object get(String key) { - return get(wrappedKey(key)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(key.getNamespacedKey()); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(key.getNamespacedKey(), value, type.syntaxType()); - } - - @Override - public boolean remove(String key) { - return false; - } - - @Override - public boolean remove(WrappedKey key) { - return container.remove(key.getNamespacedKey()); - } - - @Override - public Set keySet() { - return container.getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.size(); - } + private final IDataContainer container; + + public BukkitContainer1_14_R1(IDataContainer container) { + this.container = container; + } + + @Override + public IDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return container; + } + + /* + * + */ + + @Override + public boolean has(NamespacedKey key, PersistentDataType type) { + return has(new BukkitKey1_14_R1(key), WrappedType1_14_R1.wrap(type)); + } + + @Override + public Z get(NamespacedKey key, PersistentDataType type) { + return get(new BukkitKey1_14_R1(key), WrappedType1_14_R1.wrap(type)); + } + + @Override + public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } + + @Override + public void set(NamespacedKey key, PersistentDataType type, Z value) { + set(new BukkitKey1_14_R1(key), value, WrappedType1_14_R1.wrap(type)); + } + + @Override + public void remove(NamespacedKey key) { + remove(new BukkitKey1_14_R1(key)); + } + + public Set getKeys() { + return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_14_R1::asBukkit).collect(Collectors.toSet()); + } + + @Override + public PersistentDataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public BukkitContext1_14_R1 getContext() { + return new BukkitContext1_14_R1(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(key.getNamespacedKey()); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public Object get(String key) { + return get(wrappedKey(key)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(key.getNamespacedKey()); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(key.getNamespacedKey(), value, type.syntaxType()); + } + + @Override + public boolean remove(String key) { + return false; + } + + @Override + public boolean remove(WrappedKey key) { + return container.remove(key.getNamespacedKey()); + } + + @Override + public Set keySet() { + return container.getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.size(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitContext1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitContext1_14_R1.java index 680c6e1..94e851b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitContext1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitContext1_14_R1.java @@ -10,30 +10,30 @@ public final class BukkitContext1_14_R1 extends WrappedContext implements PersistentDataAdapterContext { - private final DataAdapterContext context; - - public BukkitContext1_14_R1(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_14_R1 newContainer() { - return new BukkitContainer1_14_R1(context.newDataContainer()); - } + private final DataAdapterContext context; + + public BukkitContext1_14_R1(DataAdapterContext context) { + this.context = context; + } + + @Override + public DataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return context.newDataContainer(); + } + + @Override + public BukkitContainer1_14_R1 newContainer() { + return new BukkitContainer1_14_R1(context.newDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitKey1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitKey1_14_R1.java index 5689079..1deefee 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitKey1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitKey1_14_R1.java @@ -7,46 +7,46 @@ public final class BukkitKey1_14_R1 extends WrappedKey { - private final NamespacedKey key; - - public BukkitKey1_14_R1(Plugin plugin, String key) { - this.key = new NamespacedKey(plugin, key); - } - - @SuppressWarnings("deprecation") - public BukkitKey1_14_R1(String name, String key) { - this.key = new NamespacedKey(name, key); - } - - public BukkitKey1_14_R1(NamespacedKey key) { - this.key = key; - } - - @Override - public NamespacedKey getHandle() { - return key; - } - - @Override - public String getName() { - return key.getNamespace(); - } - - @Override - public String getKey() { - return key.getKey(); - } - - @Override - public String toString() { - return key.toString(); - } - - public static NamespacedKey asBukkit(WrappedKey key) { - if (key.getHandle() instanceof NamespacedKey) { - return (NamespacedKey) key.getHandle(); - } - return new BukkitKey1_14_R1(key.getName(), key.getKey()).getHandle(); - } + private final NamespacedKey key; + + public BukkitKey1_14_R1(Plugin plugin, String key) { + this.key = new NamespacedKey(plugin, key); + } + + @SuppressWarnings("deprecation") + public BukkitKey1_14_R1(String name, String key) { + this.key = new NamespacedKey(name, key); + } + + public BukkitKey1_14_R1(NamespacedKey key) { + this.key = key; + } + + @Override + public NamespacedKey getHandle() { + return key; + } + + @Override + public String getName() { + return key.getNamespace(); + } + + @Override + public String getKey() { + return key.getKey(); + } + + @Override + public String toString() { + return key.toString(); + } + + public static NamespacedKey asBukkit(WrappedKey key) { + if (key.getHandle() instanceof NamespacedKey) { + return (NamespacedKey) key.getHandle(); + } + return new BukkitKey1_14_R1(key.getName(), key.getKey()).getHandle(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitType1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitType1_14_R1.java index 7313c82..b7de07a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitType1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/BukkitType1_14_R1.java @@ -7,62 +7,63 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class BukkitType1_14_R1 extends WrappedType1_14_R1, P0, P1, C0, C1> implements PersistentDataType { - - private final DataType type; - - public BukkitType1_14_R1(DataType type) { - super(type.getPrimitive(), type.getComplex()); - this.type = type; - } - - @Override - public DataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitive(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplex(); - } - - /* - * - */ - - @Override - public Class getComplexType() { - return complexType; - } - - @Override - public Class getPrimitiveType() { - return primitiveType; - } - - @Override - public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { - return wrapToPrimitive(complex, new SyntaxContext1_14_R1(context)); - } - - @Override - public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { - return wrapToComplex(primitive, new SyntaxContext1_14_R1(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); - } +public class BukkitType1_14_R1 extends WrappedType1_14_R1, P0, P1, C0, C1> + implements PersistentDataType { + + private final DataType type; + + public BukkitType1_14_R1(DataType type) { + super(type.getPrimitive(), type.getComplex()); + this.type = type; + } + + @Override + public DataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitive(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplex(); + } + + /* + * + */ + + @Override + public Class getComplexType() { + return complexType; + } + + @Override + public Class getPrimitiveType() { + return primitiveType; + } + + @Override + public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { + return wrapToPrimitive(complex, new SyntaxContext1_14_R1(context)); + } + + @Override + public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { + return wrapToComplex(primitive, new SyntaxContext1_14_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SimpleBukkitType1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SimpleBukkitType1_14_R1.java index 7fc4f81..982b68d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SimpleBukkitType1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SimpleBukkitType1_14_R1.java @@ -7,30 +7,30 @@ public class SimpleBukkitType1_14_R1 implements PersistentDataType { - private final WrapType type; - - public SimpleBukkitType1_14_R1(WrapType type) { - this.type = type; - } - - @Override - public Class getComplexType() { - return type.getComplexWrapped(); - } - - @Override - public Class

getPrimitiveType() { - return type.getPrimitiveWrapped(); - } - - @Override - public P toPrimitive(C complex, PersistentDataAdapterContext context) { - return type.wrapToPrimitive(complex, new SyntaxContext1_14_R1(context)); - } - - @Override - public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { - return type.wrapToComplex(primitive, new SyntaxContext1_14_R1(context)); - } + private final WrapType type; + + public SimpleBukkitType1_14_R1(WrapType type) { + this.type = type; + } + + @Override + public Class getComplexType() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitiveType() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(C complex, PersistentDataAdapterContext context) { + return type.wrapToPrimitive(complex, new SyntaxContext1_14_R1(context)); + } + + @Override + public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { + return type.wrapToComplex(primitive, new SyntaxContext1_14_R1(context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxContainer1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxContainer1_14_R1.java index 5ccfa34..a6b4815 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxContainer1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxContainer1_14_R1.java @@ -21,175 +21,175 @@ public final class SyntaxContainer1_14_R1 extends WrappedContainer implements IDataContainer { - public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_14_R1<>(ObjectType.INSTANCE); - - private final PersistentDataContainer container; - - public SyntaxContainer1_14_R1(PersistentDataContainer container) { - this.container = container; - } - - @Override - public PersistentDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return new SyntaxContainer1_14_R1(container); - } - - /* - * - */ - - @Override - public boolean has(IKey key) { - return has(new SyntaxKey(key)); - } - - @Override - public boolean has(String key, DataType type) { - return has(NamespacedKey.fromString(key), type); - } - - @Override - public boolean has(IKey key, DataType type) { - return has(new SyntaxKey(key), WrappedType1_14_R1.wrap(type)); - } - - @Override - public C get(String key, DataType type) { - return get(NamespacedKey.fromString(key), type); - } - - @Override - public C get(IKey key, DataType type) { - return get(new SyntaxKey(key), WrappedType1_14_R1.wrap(type)); - } - - @Override - public Object get(String key) { - return get(NamespacedKey.fromString(key)); - } - - @Override - public Object get(IKey key) { - return get(new SyntaxKey(key)); - } - - @Override - public void set(String key, E value, DataType type) { - set(wrappedKey(key), value, WrappedType1_14_R1.wrap(type)); - } - - @Override - public void set(IKey key, E value, DataType type) { - set(new SyntaxKey(key), value, WrappedType1_14_R1.wrap(type)); - } - - @Override - public boolean remove(String key) { - return remove(wrappedKey(key)); - } - - @Override - public boolean remove(IKey key) { - return remove(new SyntaxKey(key)); - } - - @Override - public IKey[] getKeys() { - return getKeyspaces().stream().map(string -> NamespacedKey.fromString(string)).toArray(IKey[]::new); - } - - @Override - public Set getKeyspaces() { - if (container instanceof CraftPersistentDataContainer) { - return ((CraftPersistentDataContainer) container).getRaw().keySet(); - } - return Collections.emptySet(); - } - - @Override - public DataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public SyntaxContext1_14_R1 getContext() { - return new SyntaxContext1_14_R1(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(BukkitKey1_14_R1.asBukkit(key), OBJECT_TYPE); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(BukkitKey1_14_R1.asBukkit(key), new SimpleBukkitType1_14_R1<>(type)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(BukkitKey1_14_R1.asBukkit(key), OBJECT_TYPE); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(BukkitKey1_14_R1.asBukkit(key), new SimpleBukkitType1_14_R1<>(type)); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(BukkitKey1_14_R1.asBukkit(key), new SimpleBukkitType1_14_R1<>(type), value); - } - - @Override - public boolean remove(WrappedKey key) { - Object value = get(key); - container.remove(BukkitKey1_14_R1.asBukkit(key)); - return value != null && get(key) == null; - } - - @Override - public Set keySet() { - return getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return 0; - } + public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_14_R1<>(ObjectType.INSTANCE); + + private final PersistentDataContainer container; + + public SyntaxContainer1_14_R1(PersistentDataContainer container) { + this.container = container; + } + + @Override + public PersistentDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return new SyntaxContainer1_14_R1(container); + } + + /* + * + */ + + @Override + public boolean has(IKey key) { + return has(new SyntaxKey(key)); + } + + @Override + public boolean has(String key, DataType type) { + return has(NamespacedKey.fromString(key), type); + } + + @Override + public boolean has(IKey key, DataType type) { + return has(new SyntaxKey(key), WrappedType1_14_R1.wrap(type)); + } + + @Override + public C get(String key, DataType type) { + return get(NamespacedKey.fromString(key), type); + } + + @Override + public C get(IKey key, DataType type) { + return get(new SyntaxKey(key), WrappedType1_14_R1.wrap(type)); + } + + @Override + public Object get(String key) { + return get(NamespacedKey.fromString(key)); + } + + @Override + public Object get(IKey key) { + return get(new SyntaxKey(key)); + } + + @Override + public void set(String key, E value, DataType type) { + set(wrappedKey(key), value, WrappedType1_14_R1.wrap(type)); + } + + @Override + public void set(IKey key, E value, DataType type) { + set(new SyntaxKey(key), value, WrappedType1_14_R1.wrap(type)); + } + + @Override + public boolean remove(String key) { + return remove(wrappedKey(key)); + } + + @Override + public boolean remove(IKey key) { + return remove(new SyntaxKey(key)); + } + + @Override + public IKey[] getKeys() { + return getKeyspaces().stream().map(string -> NamespacedKey.fromString(string)).toArray(IKey[]::new); + } + + @Override + public Set getKeyspaces() { + if (container instanceof CraftPersistentDataContainer) { + return ((CraftPersistentDataContainer) container).getRaw().keySet(); + } + return Collections.emptySet(); + } + + @Override + public DataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public SyntaxContext1_14_R1 getContext() { + return new SyntaxContext1_14_R1(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(BukkitKey1_14_R1.asBukkit(key), OBJECT_TYPE); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(BukkitKey1_14_R1.asBukkit(key), new SimpleBukkitType1_14_R1<>(type)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(BukkitKey1_14_R1.asBukkit(key), OBJECT_TYPE); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(BukkitKey1_14_R1.asBukkit(key), new SimpleBukkitType1_14_R1<>(type)); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(BukkitKey1_14_R1.asBukkit(key), new SimpleBukkitType1_14_R1<>(type), value); + } + + @Override + public boolean remove(WrappedKey key) { + Object value = get(key); + container.remove(BukkitKey1_14_R1.asBukkit(key)); + return value != null && get(key) == null; + } + + @Override + public Set keySet() { + return getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return 0; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxContext1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxContext1_14_R1.java index 9852bb4..3381659 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxContext1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxContext1_14_R1.java @@ -9,30 +9,30 @@ public final class SyntaxContext1_14_R1 extends WrappedContext implements PersistentDataAdapterContext { - private final PersistentDataAdapterContext context; - - public SyntaxContext1_14_R1(PersistentDataAdapterContext context) { - this.context = context; - } - - @Override - public PersistentDataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return context.newPersistentDataContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return newContainer(); - } - - @Override - public SyntaxContainer1_14_R1 newContainer() { - return new SyntaxContainer1_14_R1(context.newPersistentDataContainer()); - } + private final PersistentDataAdapterContext context; + + public SyntaxContext1_14_R1(PersistentDataAdapterContext context) { + this.context = context; + } + + @Override + public PersistentDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return context.newPersistentDataContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return newContainer(); + } + + @Override + public SyntaxContainer1_14_R1 newContainer() { + return new SyntaxContainer1_14_R1(context.newPersistentDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxType1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxType1_14_R1.java index 6316710..0c43074 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxType1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/SyntaxType1_14_R1.java @@ -8,68 +8,69 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class SyntaxType1_14_R1 extends WrappedType1_14_R1, P0, P1, C0, C1> implements DataType { - - private final PersistentDataType type; - - public SyntaxType1_14_R1(PersistentDataType type) { - super(type.getPrimitiveType(), type.getComplexType()); - this.type = type; - } - - @Override - public PersistentDataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitiveType(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplexType(); - } - - /* - * - */ - - @Override - public Class getComplex() { - return complexType; - } - - @Override - public Class getPrimitive() { - return primitiveType; - } - - @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { - return wrapToPrimitive(complex, new BukkitContext1_14_R1(context)); - } - - @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { - return wrapToComplex(primitive, new BukkitContext1_14_R1(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); - } +public class SyntaxType1_14_R1 extends WrappedType1_14_R1, P0, P1, C0, C1> + implements DataType { + + private final PersistentDataType type; + + public SyntaxType1_14_R1(PersistentDataType type) { + super(type.getPrimitiveType(), type.getComplexType()); + this.type = type; + } + + @Override + public PersistentDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitiveType(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplexType(); + } + + /* + * + */ + + @Override + public Class getComplex() { + return complexType; + } + + @Override + public Class getPrimitive() { + return primitiveType; + } + + @Override + public P0 toPrimitive(DataAdapterContext context, C0 complex) { + return wrapToPrimitive(complex, new BukkitContext1_14_R1(context)); + } + + @Override + public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + return wrapToComplex(primitive, new BukkitContext1_14_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/WrappedType1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/WrappedType1_14_R1.java index 0e3e412..f0211b0 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/WrappedType1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/data/WrappedType1_14_R1.java @@ -12,135 +12,139 @@ public abstract class WrappedType1_14_R1 implements WrapType { - protected final Class primitiveType; - protected final Class complexType; - - private final int primitiveWrap; - private final int complexWrap; - - @SuppressWarnings("unchecked") - protected WrappedType1_14_R1(Class primitive, Class complex) { - this.primitiveWrap = WrappedType1_14_R1.internalState(primitive); - this.complexWrap = WrappedType1_14_R1.internalState(complex); - this.primitiveType = (Class) WrappedType1_14_R1.internalWrap(primitive, primitiveWrap); - this.complexType = (Class) WrappedType1_14_R1.internalWrap(complex, complexWrap); - } - - public abstract H getHandle(); - - public Class getPrimitiveWrapped() { - return primitiveType; - } - - public Class getComplexWrapped() { - return complexType; - } - - public abstract Class getPrimitiveOriginal(); - - public abstract Class getComplexOriginal(); - - @SuppressWarnings("unchecked") - public P0 toPrimitiveWrapped(P1 primitive) { - switch (primitiveWrap) { - case 1: - return (P0) new SyntaxContainer1_14_R1((PersistentDataContainer) primitive); - case 2: - return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_14_R1::new).toArray(IDataContainer[]::new); - case 3: - return (P0) new BukkitContainer1_14_R1((IDataContainer) primitive); - case 4: - return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_14_R1::new).toArray(PersistentDataContainer[]::new); - default: - return (P0) primitive; - } - } - - @SuppressWarnings("unchecked") - public C0 toComplexWrapped(C1 complex) { - switch (complexWrap) { - case 1: - return (C0) new SyntaxContainer1_14_R1((PersistentDataContainer) complex); - case 2: - return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_14_R1::new).toArray(IDataContainer[]::new); - case 3: - return (C0) new BukkitContainer1_14_R1((IDataContainer) complex); - case 4: - return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_14_R1::new).toArray(PersistentDataContainer[]::new); - default: - return (C0) complex; - } - } - - @SuppressWarnings("unchecked") - public P1 toPrimitiveOriginal(P0 primitive) { - switch (primitiveWrap) { - case 1: - return (P1) new BukkitContainer1_14_R1((IDataContainer) primitive); - case 2: - return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_14_R1::new).toArray(PersistentDataContainer[]::new); - case 3: - return (P1) new SyntaxContainer1_14_R1((PersistentDataContainer) primitive); - case 4: - return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_14_R1::new).toArray(IDataContainer[]::new); - default: - return (P1) primitive; - } - } - - @SuppressWarnings("unchecked") - public C1 toComplexOriginal(C0 complex) { - switch (complexWrap) { - case 1: - return (C1) new BukkitContainer1_14_R1((IDataContainer) complex); - case 2: - return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_14_R1::new).toArray(PersistentDataContainer[]::new); - case 3: - return (C1) new SyntaxContainer1_14_R1((PersistentDataContainer) complex); - case 4: - return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_14_R1::new).toArray(IDataContainer[]::new); - default: - return (C1) complex; - } - } - - protected static Class internalWrap(Class clazz, int state) { - switch (state) { - case 1: - return IDataContainer.class; - case 2: - return IDataContainer[].class; - case 3: - return PersistentDataContainer.class; - case 4: - return PersistentDataContainer[].class; - default: - return clazz; - } - } - - protected static int internalState(Class clazz) { - if (clazz.equals(PersistentDataContainer.class)) { - return 1; - } - if (clazz.equals(PersistentDataContainer[].class)) { - return 2; - } - if (clazz.equals(IDataContainer.class)) { - return 3; - } - if (clazz.equals(IDataContainer[].class)) { - return 4; - } - return 0; - } - - public static BukkitType1_14_R1 wrap(DataType type) { - return new BukkitType1_14_R1<>(type); - } - - public static SyntaxType1_14_R1 wrap(PersistentDataType type) { - return new SyntaxType1_14_R1<>(type); - } + protected final Class primitiveType; + protected final Class complexType; + + private final int primitiveWrap; + private final int complexWrap; + + @SuppressWarnings("unchecked") + protected WrappedType1_14_R1(Class primitive, Class complex) { + this.primitiveWrap = WrappedType1_14_R1.internalState(primitive); + this.complexWrap = WrappedType1_14_R1.internalState(complex); + this.primitiveType = (Class) WrappedType1_14_R1.internalWrap(primitive, primitiveWrap); + this.complexType = (Class) WrappedType1_14_R1.internalWrap(complex, complexWrap); + } + + public abstract H getHandle(); + + public Class getPrimitiveWrapped() { + return primitiveType; + } + + public Class getComplexWrapped() { + return complexType; + } + + public abstract Class getPrimitiveOriginal(); + + public abstract Class getComplexOriginal(); + + @SuppressWarnings("unchecked") + public P0 toPrimitiveWrapped(P1 primitive) { + switch (primitiveWrap) { + case 1: + return (P0) new SyntaxContainer1_14_R1((PersistentDataContainer) primitive); + case 2: + return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_14_R1::new) + .toArray(IDataContainer[]::new); + case 3: + return (P0) new BukkitContainer1_14_R1((IDataContainer) primitive); + case 4: + return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_14_R1::new) + .toArray(PersistentDataContainer[]::new); + default: + return (P0) primitive; + } + } + + @SuppressWarnings("unchecked") + public C0 toComplexWrapped(C1 complex) { + switch (complexWrap) { + case 1: + return (C0) new SyntaxContainer1_14_R1((PersistentDataContainer) complex); + case 2: + return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_14_R1::new).toArray(IDataContainer[]::new); + case 3: + return (C0) new BukkitContainer1_14_R1((IDataContainer) complex); + case 4: + return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_14_R1::new).toArray(PersistentDataContainer[]::new); + default: + return (C0) complex; + } + } + + @SuppressWarnings("unchecked") + public P1 toPrimitiveOriginal(P0 primitive) { + switch (primitiveWrap) { + case 1: + return (P1) new BukkitContainer1_14_R1((IDataContainer) primitive); + case 2: + return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_14_R1::new) + .toArray(PersistentDataContainer[]::new); + case 3: + return (P1) new SyntaxContainer1_14_R1((PersistentDataContainer) primitive); + case 4: + return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_14_R1::new) + .toArray(IDataContainer[]::new); + default: + return (P1) primitive; + } + } + + @SuppressWarnings("unchecked") + public C1 toComplexOriginal(C0 complex) { + switch (complexWrap) { + case 1: + return (C1) new BukkitContainer1_14_R1((IDataContainer) complex); + case 2: + return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_14_R1::new).toArray(PersistentDataContainer[]::new); + case 3: + return (C1) new SyntaxContainer1_14_R1((PersistentDataContainer) complex); + case 4: + return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_14_R1::new).toArray(IDataContainer[]::new); + default: + return (C1) complex; + } + } + + protected static Class internalWrap(Class clazz, int state) { + switch (state) { + case 1: + return IDataContainer.class; + case 2: + return IDataContainer[].class; + case 3: + return PersistentDataContainer.class; + case 4: + return PersistentDataContainer[].class; + default: + return clazz; + } + } + + protected static int internalState(Class clazz) { + if (clazz.equals(PersistentDataContainer.class)) { + return 1; + } + if (clazz.equals(PersistentDataContainer[].class)) { + return 2; + } + if (clazz.equals(IDataContainer.class)) { + return 3; + } + if (clazz.equals(IDataContainer[].class)) { + return 4; + } + return 0; + } + + public static BukkitType1_14_R1 wrap(DataType type) { + return new BukkitType1_14_R1<>(type); + } + + public static SyntaxType1_14_R1 wrap(PersistentDataType type) { + return new SyntaxType1_14_R1<>(type); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/ArmorStand1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/ArmorStand1_14_R1.java index cffcedd..646f593 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/ArmorStand1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/ArmorStand1_14_R1.java @@ -7,18 +7,18 @@ public class ArmorStand1_14_R1 extends EntityLiving1_14_R1 implements NmsArmorStand { - public ArmorStand1_14_R1(World world) { - super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); - } + public ArmorStand1_14_R1(World world) { + super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/Entity1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/Entity1_14_R1.java index b7c0a47..94d911c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/Entity1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/Entity1_14_R1.java @@ -13,198 +13,200 @@ import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage; import org.bukkit.entity.Player; +import net.minecraft.server.v1_14_R1.AxisAlignedBB; import net.minecraft.server.v1_14_R1.Entity; import net.minecraft.server.v1_14_R1.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata; import net.minecraft.server.v1_14_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_14_R1.PlayerConnection; import net.minecraft.server.v1_14_R1.Vec3D; -import net.minecraft.server.v1_14_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_14_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_14_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); - } - - @Override - public String getCustomName() { - return CraftChatMessage.fromComponent(handle.getCustomName()); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.bO(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_14_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.bO(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/EntityLiving1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/EntityLiving1_14_R1.java index 1484248..e91b6bb 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/EntityLiving1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/EntityLiving1_14_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_14_R1 extends Entity1_14_R1 implements NmsEntityLiving { - public EntityLiving1_14_R1(E handle) { - super(handle); - } + public EntityLiving1_14_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/Player1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/Player1_14_R1.java index cacd7b6..d9c6fa3 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/Player1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/entity/Player1_14_R1.java @@ -45,228 +45,228 @@ public class Player1_14_R1 extends EntityLiving1_14_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_14_R1(Player player) { - super(((CraftPlayer) player).getHandle()); - dataAdapter = new SyntaxContainer1_14_R1(getBukkitPlayer().getPersistentDataContainer()); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - dataAdapter.set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - dataAdapter.remove("name"); - return; - } - dataAdapter.set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return dataAdapter.getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return dataAdapter.getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - dataAdapter.set("header", header, WrapType.STRING); - dataAdapter.set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - packet.header = headerComponent; - packet.footer = footerComponent; - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_14_R1(Player player) { + super(((CraftPlayer) player).getHandle()); + dataAdapter = new SyntaxContainer1_14_R1(getBukkitPlayer().getPersistentDataContainer()); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + dataAdapter.set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + dataAdapter.remove("name"); + return; + } + dataAdapter.set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return dataAdapter.getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return dataAdapter.getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + dataAdapter.set("header", header, WrapType.STRING); + dataAdapter.set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + packet.header = headerComponent; + packet.footer = footerComponent; + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, handle.world.worldData.getType(), + handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/BlockTools1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/BlockTools1_14_R1.java index b1aa235..39b6150 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/BlockTools1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/BlockTools1_14_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_14_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.gameProfile.getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.gameProfile.getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/ServerTools1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/ServerTools1_14_R1.java index a652201..f3b9a71 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/ServerTools1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/ServerTools1_14_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_14_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/SkinTools1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/SkinTools1_14_R1.java index 1c41998..dd4bb9a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/SkinTools1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/tools/SkinTools1_14_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_14_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/utils/EntityConstructors1_14_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/utils/EntityConstructors1_14_R1.java index 3b56949..5058281 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/utils/EntityConstructors1_14_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_14_R1/utils/EntityConstructors1_14_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_14_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_14_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_14_R1(world)); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/BukkitConversion1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/BukkitConversion1_15_R1.java index 6ff802e..798b4e6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/BukkitConversion1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/BukkitConversion1_15_R1.java @@ -6,7 +6,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_15_R1.ItemStack; import net.minecraft.server.v1_15_R1.NBTBase; @@ -31,166 +45,166 @@ public class BukkitConversion1_15_R1 extends BukkitConversion { - protected BukkitConversion1_15_R1(VersionControl1_15_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return NBTTagByte.a((byte) tag.getValue()); - case SHORT: - return NBTTagShort.a((short) tag.getValue()); - case INT: - return NBTTagInt.a((int) tag.getValue()); - case LONG: - return NBTTagLong.a((long) tag.getValue()); - case FLOAT: - return NBTTagFloat.a((float) tag.getValue()); - case DOUBLE: - return NBTTagDouble.a((double) tag.getValue()); - case STRING: - return NBTTagString.a((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - return new NBTTagLongArray((long[]) tag.getValue()); - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return NBTTagEnd.b; - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTNumber) tag).asByte()); - case SHORT: - return new NbtShort(((NBTNumber) tag).asShort()); - case INT: - return new NbtInt(((NBTNumber) tag).asInt()); - case LONG: - return new NbtLong(((NBTNumber) tag).asLong()); - case FLOAT: - return new NbtFloat(((NBTNumber) tag).asFloat()); - case DOUBLE: - return new NbtDouble(((NBTNumber) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).asString()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).getInts()); - case LONG_ARRAY: - return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : list) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new BukkitContext1_15_R1(context); - } + protected BukkitConversion1_15_R1(VersionControl1_15_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return NBTTagByte.a((byte) tag.getValue()); + case SHORT: + return NBTTagShort.a((short) tag.getValue()); + case INT: + return NBTTagInt.a((int) tag.getValue()); + case LONG: + return NBTTagLong.a((long) tag.getValue()); + case FLOAT: + return NBTTagFloat.a((float) tag.getValue()); + case DOUBLE: + return NBTTagDouble.a((double) tag.getValue()); + case STRING: + return NBTTagString.a((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + return new NBTTagLongArray((long[]) tag.getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return NBTTagEnd.b; + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTNumber) tag).asByte()); + case SHORT: + return new NbtShort(((NBTNumber) tag).asShort()); + case INT: + return new NbtInt(((NBTNumber) tag).asInt()); + case LONG: + return new NbtLong(((NBTNumber) tag).asLong()); + case FLOAT: + return new NbtFloat(((NBTNumber) tag).asFloat()); + case DOUBLE: + return new NbtDouble(((NBTNumber) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).asString()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).getInts()); + case LONG_ARRAY: + return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new BukkitContext1_15_R1(context); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/EntityProvider1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/EntityProvider1_15_R1.java index 880c522..6076797 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/EntityProvider1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/EntityProvider1_15_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_15_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_15_R1(VersionControl1_15_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_15_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_15_R1(VersionControl1_15_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_15_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/PacketHandler1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/PacketHandler1_15_R1.java index e078218..30bf295 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/PacketHandler1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/PacketHandler1_15_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_15_R1 extends PacketHandler { - protected PacketHandler1_15_R1(VersionControl1_15_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_15_R1(VersionControl1_15_R1 versionControl) { + super(versionControl); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/PlayerProvider1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/PlayerProvider1_15_R1.java index d7c9f65..09a27de 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/PlayerProvider1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/PlayerProvider1_15_R1.java @@ -8,13 +8,13 @@ public class PlayerProvider1_15_R1 extends PlayerProvider { - protected PlayerProvider1_15_R1(VersionControl1_15_R1 versionControl) { - super(versionControl); - } + protected PlayerProvider1_15_R1(VersionControl1_15_R1 versionControl) { + super(versionControl); + } - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_15_R1(player); - } + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_15_R1(player); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/TextureProvider1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/TextureProvider1_15_R1.java index 79c0fe2..e007ac2 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/TextureProvider1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/TextureProvider1_15_R1.java @@ -20,83 +20,83 @@ public class TextureProvider1_15_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - protected TextureProvider1_15_R1(VersionControl1_15_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_15_R1(VersionControl1_15_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile; - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile; + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag = stack.getOrCreateTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag = stack.getOrCreateTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - entitySkull.setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + entitySkull.setGameProfile(profile); + return true; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/ToolProvider1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/ToolProvider1_15_R1.java index 94d4712..f531171 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/ToolProvider1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/ToolProvider1_15_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_15_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_15_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_15_R1.tools.BlockTools1_15_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_15_R1.tools.ServerTools1_15_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_15_R1.tools.SkinTools1_15_R1; public class ToolProvider1_15_R1 extends ToolProvider { - private final BlockTools1_15_R1 blockTools = new BlockTools1_15_R1(); - private final SkinTools1_15_R1 skinTools = new SkinTools1_15_R1(); - private final ServerTools1_15_R1 serverTools = new ServerTools1_15_R1(); - - protected ToolProvider1_15_R1(VersionControl1_15_R1 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_15_R1 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_15_R1 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_15_R1 getBlockTools() { - return blockTools; - } + private final BlockTools1_15_R1 blockTools = new BlockTools1_15_R1(); + private final SkinTools1_15_R1 skinTools = new SkinTools1_15_R1(); + private final ServerTools1_15_R1 serverTools = new ServerTools1_15_R1(); + + protected ToolProvider1_15_R1(VersionControl1_15_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_15_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_15_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_15_R1 getBlockTools() { + return blockTools; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/VersionControl1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/VersionControl1_15_R1.java index 1061389..1c61b1a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/VersionControl1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/VersionControl1_15_R1.java @@ -4,51 +4,51 @@ public class VersionControl1_15_R1 extends VersionControl { - public static VersionControl1_15_R1 INSTANCE; - - public static VersionControl1_15_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_15_R1()); - } - - private final ToolProvider1_15_R1 toolProvider = new ToolProvider1_15_R1(this); - private final TextureProvider1_15_R1 textureProvider = new TextureProvider1_15_R1(this); - private final PacketHandler1_15_R1 packetHandler = new PacketHandler1_15_R1(this); - private final EntityProvider1_15_R1 entityProvider = new EntityProvider1_15_R1(this); - private final PlayerProvider1_15_R1 playerProvider = new PlayerProvider1_15_R1(this); - private final BukkitConversion1_15_R1 bukkitConversion = new BukkitConversion1_15_R1(this); - - private VersionControl1_15_R1() { - - } - - @Override - public ToolProvider1_15_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_15_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_15_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_15_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_15_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_15_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_15_R1 INSTANCE; + + public static VersionControl1_15_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_15_R1()); + } + + private final ToolProvider1_15_R1 toolProvider = new ToolProvider1_15_R1(this); + private final TextureProvider1_15_R1 textureProvider = new TextureProvider1_15_R1(this); + private final PacketHandler1_15_R1 packetHandler = new PacketHandler1_15_R1(this); + private final EntityProvider1_15_R1 entityProvider = new EntityProvider1_15_R1(this); + private final PlayerProvider1_15_R1 playerProvider = new PlayerProvider1_15_R1(this); + private final BukkitConversion1_15_R1 bukkitConversion = new BukkitConversion1_15_R1(this); + + private VersionControl1_15_R1() { + + } + + @Override + public ToolProvider1_15_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_15_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_15_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_15_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_15_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_15_R1 getBukkitConversion() { + return bukkitConversion; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitContainer1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitContainer1_15_R1.java index 0dba970..c5e886d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitContainer1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitContainer1_15_R1.java @@ -19,142 +19,142 @@ public final class BukkitContainer1_15_R1 extends WrappedContainer implements PersistentDataContainer { - private final IDataContainer container; - - public BukkitContainer1_15_R1(IDataContainer container) { - this.container = container; - } - - @Override - public IDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return container; - } - - /* - * - */ - - @Override - public boolean has(NamespacedKey key, PersistentDataType type) { - return has(new BukkitKey1_15_R1(key), WrappedType1_15_R1.wrap(type)); - } - - @Override - public Z get(NamespacedKey key, PersistentDataType type) { - return get(new BukkitKey1_15_R1(key), WrappedType1_15_R1.wrap(type)); - } - - @Override - public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { - return Optional.ofNullable(get(key, type)).orElse(value); - } - - @Override - public void set(NamespacedKey key, PersistentDataType type, Z value) { - set(new BukkitKey1_15_R1(key), value, WrappedType1_15_R1.wrap(type)); - } - - @Override - public void remove(NamespacedKey key) { - remove(new BukkitKey1_15_R1(key)); - } - - public Set getKeys() { - return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_15_R1::asBukkit).collect(Collectors.toSet()); - } - - @Override - public PersistentDataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public BukkitContext1_15_R1 getContext() { - return new BukkitContext1_15_R1(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(key.getNamespacedKey()); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public Object get(String key) { - return get(wrappedKey(key)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(key.getNamespacedKey()); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(key.getNamespacedKey(), value, type.syntaxType()); - } - - @Override - public boolean remove(String key) { - return false; - } - - @Override - public boolean remove(WrappedKey key) { - return container.remove(key.getNamespacedKey()); - } - - @Override - public Set keySet() { - return container.getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.size(); - } + private final IDataContainer container; + + public BukkitContainer1_15_R1(IDataContainer container) { + this.container = container; + } + + @Override + public IDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return container; + } + + /* + * + */ + + @Override + public boolean has(NamespacedKey key, PersistentDataType type) { + return has(new BukkitKey1_15_R1(key), WrappedType1_15_R1.wrap(type)); + } + + @Override + public Z get(NamespacedKey key, PersistentDataType type) { + return get(new BukkitKey1_15_R1(key), WrappedType1_15_R1.wrap(type)); + } + + @Override + public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } + + @Override + public void set(NamespacedKey key, PersistentDataType type, Z value) { + set(new BukkitKey1_15_R1(key), value, WrappedType1_15_R1.wrap(type)); + } + + @Override + public void remove(NamespacedKey key) { + remove(new BukkitKey1_15_R1(key)); + } + + public Set getKeys() { + return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_15_R1::asBukkit).collect(Collectors.toSet()); + } + + @Override + public PersistentDataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public BukkitContext1_15_R1 getContext() { + return new BukkitContext1_15_R1(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(key.getNamespacedKey()); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public Object get(String key) { + return get(wrappedKey(key)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(key.getNamespacedKey()); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(key.getNamespacedKey(), value, type.syntaxType()); + } + + @Override + public boolean remove(String key) { + return false; + } + + @Override + public boolean remove(WrappedKey key) { + return container.remove(key.getNamespacedKey()); + } + + @Override + public Set keySet() { + return container.getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.size(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitContext1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitContext1_15_R1.java index 8a76c61..0d2c5c7 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitContext1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitContext1_15_R1.java @@ -10,30 +10,30 @@ public final class BukkitContext1_15_R1 extends WrappedContext implements PersistentDataAdapterContext { - private final DataAdapterContext context; - - public BukkitContext1_15_R1(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_15_R1 newContainer() { - return new BukkitContainer1_15_R1(context.newDataContainer()); - } + private final DataAdapterContext context; + + public BukkitContext1_15_R1(DataAdapterContext context) { + this.context = context; + } + + @Override + public DataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return context.newDataContainer(); + } + + @Override + public BukkitContainer1_15_R1 newContainer() { + return new BukkitContainer1_15_R1(context.newDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitKey1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitKey1_15_R1.java index 72ad95c..b0ddb19 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitKey1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitKey1_15_R1.java @@ -7,46 +7,46 @@ public final class BukkitKey1_15_R1 extends WrappedKey { - private final NamespacedKey key; - - public BukkitKey1_15_R1(Plugin plugin, String key) { - this.key = new NamespacedKey(plugin, key); - } - - @SuppressWarnings("deprecation") - public BukkitKey1_15_R1(String name, String key) { - this.key = new NamespacedKey(name, key); - } - - public BukkitKey1_15_R1(NamespacedKey key) { - this.key = key; - } - - @Override - public NamespacedKey getHandle() { - return key; - } - - @Override - public String getName() { - return key.getNamespace(); - } - - @Override - public String getKey() { - return key.getKey(); - } - - @Override - public String toString() { - return key.toString(); - } - - public static NamespacedKey asBukkit(WrappedKey key) { - if (key.getHandle() instanceof NamespacedKey) { - return (NamespacedKey) key.getHandle(); - } - return new BukkitKey1_15_R1(key.getName(), key.getKey()).getHandle(); - } + private final NamespacedKey key; + + public BukkitKey1_15_R1(Plugin plugin, String key) { + this.key = new NamespacedKey(plugin, key); + } + + @SuppressWarnings("deprecation") + public BukkitKey1_15_R1(String name, String key) { + this.key = new NamespacedKey(name, key); + } + + public BukkitKey1_15_R1(NamespacedKey key) { + this.key = key; + } + + @Override + public NamespacedKey getHandle() { + return key; + } + + @Override + public String getName() { + return key.getNamespace(); + } + + @Override + public String getKey() { + return key.getKey(); + } + + @Override + public String toString() { + return key.toString(); + } + + public static NamespacedKey asBukkit(WrappedKey key) { + if (key.getHandle() instanceof NamespacedKey) { + return (NamespacedKey) key.getHandle(); + } + return new BukkitKey1_15_R1(key.getName(), key.getKey()).getHandle(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitType1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitType1_15_R1.java index 079002e..335e7a7 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitType1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/BukkitType1_15_R1.java @@ -7,62 +7,63 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class BukkitType1_15_R1 extends WrappedType1_15_R1, P0, P1, C0, C1> implements PersistentDataType { - - private final DataType type; - - public BukkitType1_15_R1(DataType type) { - super(type.getPrimitive(), type.getComplex()); - this.type = type; - } - - @Override - public DataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitive(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplex(); - } - - /* - * - */ - - @Override - public Class getComplexType() { - return complexType; - } - - @Override - public Class getPrimitiveType() { - return primitiveType; - } - - @Override - public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { - return wrapToPrimitive(complex, new SyntaxContext1_15_R1(context)); - } - - @Override - public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { - return wrapToComplex(primitive, new SyntaxContext1_15_R1(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); - } +public class BukkitType1_15_R1 extends WrappedType1_15_R1, P0, P1, C0, C1> + implements PersistentDataType { + + private final DataType type; + + public BukkitType1_15_R1(DataType type) { + super(type.getPrimitive(), type.getComplex()); + this.type = type; + } + + @Override + public DataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitive(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplex(); + } + + /* + * + */ + + @Override + public Class getComplexType() { + return complexType; + } + + @Override + public Class getPrimitiveType() { + return primitiveType; + } + + @Override + public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { + return wrapToPrimitive(complex, new SyntaxContext1_15_R1(context)); + } + + @Override + public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { + return wrapToComplex(primitive, new SyntaxContext1_15_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SimpleBukkitType1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SimpleBukkitType1_15_R1.java index 873e3c3..74d6df5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SimpleBukkitType1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SimpleBukkitType1_15_R1.java @@ -7,30 +7,30 @@ public class SimpleBukkitType1_15_R1 implements PersistentDataType { - private final WrapType type; - - public SimpleBukkitType1_15_R1(WrapType type) { - this.type = type; - } - - @Override - public Class getComplexType() { - return type.getComplexWrapped(); - } - - @Override - public Class

getPrimitiveType() { - return type.getPrimitiveWrapped(); - } - - @Override - public P toPrimitive(C complex, PersistentDataAdapterContext context) { - return type.wrapToPrimitive(complex, new SyntaxContext1_15_R1(context)); - } - - @Override - public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { - return type.wrapToComplex(primitive, new SyntaxContext1_15_R1(context)); - } + private final WrapType type; + + public SimpleBukkitType1_15_R1(WrapType type) { + this.type = type; + } + + @Override + public Class getComplexType() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitiveType() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(C complex, PersistentDataAdapterContext context) { + return type.wrapToPrimitive(complex, new SyntaxContext1_15_R1(context)); + } + + @Override + public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { + return type.wrapToComplex(primitive, new SyntaxContext1_15_R1(context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxContainer1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxContainer1_15_R1.java index 28bc441..26fc625 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxContainer1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxContainer1_15_R1.java @@ -21,175 +21,175 @@ public final class SyntaxContainer1_15_R1 extends WrappedContainer implements IDataContainer { - public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_15_R1<>(ObjectType.INSTANCE); - - private final PersistentDataContainer container; - - public SyntaxContainer1_15_R1(PersistentDataContainer container) { - this.container = container; - } - - @Override - public PersistentDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return new SyntaxContainer1_15_R1(container); - } - - /* - * - */ - - @Override - public boolean has(IKey key) { - return has(new SyntaxKey(key)); - } - - @Override - public boolean has(String key, DataType type) { - return has(NamespacedKey.fromString(key), type); - } - - @Override - public boolean has(IKey key, DataType type) { - return has(new SyntaxKey(key), WrappedType1_15_R1.wrap(type)); - } - - @Override - public C get(String key, DataType type) { - return get(NamespacedKey.fromString(key), type); - } - - @Override - public C get(IKey key, DataType type) { - return get(new SyntaxKey(key), WrappedType1_15_R1.wrap(type)); - } - - @Override - public Object get(String key) { - return get(NamespacedKey.fromString(key)); - } - - @Override - public Object get(IKey key) { - return get(new SyntaxKey(key)); - } - - @Override - public void set(String key, E value, DataType type) { - set(wrappedKey(key), value, WrappedType1_15_R1.wrap(type)); - } - - @Override - public void set(IKey key, E value, DataType type) { - set(new SyntaxKey(key), value, WrappedType1_15_R1.wrap(type)); - } - - @Override - public boolean remove(String key) { - return remove(wrappedKey(key)); - } - - @Override - public boolean remove(IKey key) { - return remove(new SyntaxKey(key)); - } - - @Override - public IKey[] getKeys() { - return getKeyspaces().stream().map(string -> NamespacedKey.fromString(string)).toArray(IKey[]::new); - } - - @Override - public Set getKeyspaces() { - if (container instanceof CraftPersistentDataContainer) { - return ((CraftPersistentDataContainer) container).getRaw().keySet(); - } - return Collections.emptySet(); - } - - @Override - public DataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public SyntaxContext1_15_R1 getContext() { - return new SyntaxContext1_15_R1(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(BukkitKey1_15_R1.asBukkit(key), OBJECT_TYPE); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(BukkitKey1_15_R1.asBukkit(key), new SimpleBukkitType1_15_R1<>(type)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(BukkitKey1_15_R1.asBukkit(key), OBJECT_TYPE); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(BukkitKey1_15_R1.asBukkit(key), new SimpleBukkitType1_15_R1<>(type)); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(BukkitKey1_15_R1.asBukkit(key), new SimpleBukkitType1_15_R1<>(type), value); - } - - @Override - public boolean remove(WrappedKey key) { - Object value = get(key); - container.remove(BukkitKey1_15_R1.asBukkit(key)); - return value != null && get(key) == null; - } - - @Override - public Set keySet() { - return getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return 0; - } + public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_15_R1<>(ObjectType.INSTANCE); + + private final PersistentDataContainer container; + + public SyntaxContainer1_15_R1(PersistentDataContainer container) { + this.container = container; + } + + @Override + public PersistentDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return new SyntaxContainer1_15_R1(container); + } + + /* + * + */ + + @Override + public boolean has(IKey key) { + return has(new SyntaxKey(key)); + } + + @Override + public boolean has(String key, DataType type) { + return has(NamespacedKey.fromString(key), type); + } + + @Override + public boolean has(IKey key, DataType type) { + return has(new SyntaxKey(key), WrappedType1_15_R1.wrap(type)); + } + + @Override + public C get(String key, DataType type) { + return get(NamespacedKey.fromString(key), type); + } + + @Override + public C get(IKey key, DataType type) { + return get(new SyntaxKey(key), WrappedType1_15_R1.wrap(type)); + } + + @Override + public Object get(String key) { + return get(NamespacedKey.fromString(key)); + } + + @Override + public Object get(IKey key) { + return get(new SyntaxKey(key)); + } + + @Override + public void set(String key, E value, DataType type) { + set(wrappedKey(key), value, WrappedType1_15_R1.wrap(type)); + } + + @Override + public void set(IKey key, E value, DataType type) { + set(new SyntaxKey(key), value, WrappedType1_15_R1.wrap(type)); + } + + @Override + public boolean remove(String key) { + return remove(wrappedKey(key)); + } + + @Override + public boolean remove(IKey key) { + return remove(new SyntaxKey(key)); + } + + @Override + public IKey[] getKeys() { + return getKeyspaces().stream().map(string -> NamespacedKey.fromString(string)).toArray(IKey[]::new); + } + + @Override + public Set getKeyspaces() { + if (container instanceof CraftPersistentDataContainer) { + return ((CraftPersistentDataContainer) container).getRaw().keySet(); + } + return Collections.emptySet(); + } + + @Override + public DataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public SyntaxContext1_15_R1 getContext() { + return new SyntaxContext1_15_R1(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(BukkitKey1_15_R1.asBukkit(key), OBJECT_TYPE); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(BukkitKey1_15_R1.asBukkit(key), new SimpleBukkitType1_15_R1<>(type)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(BukkitKey1_15_R1.asBukkit(key), OBJECT_TYPE); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(BukkitKey1_15_R1.asBukkit(key), new SimpleBukkitType1_15_R1<>(type)); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(BukkitKey1_15_R1.asBukkit(key), new SimpleBukkitType1_15_R1<>(type), value); + } + + @Override + public boolean remove(WrappedKey key) { + Object value = get(key); + container.remove(BukkitKey1_15_R1.asBukkit(key)); + return value != null && get(key) == null; + } + + @Override + public Set keySet() { + return getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return 0; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxContext1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxContext1_15_R1.java index 4ff7696..dd21d97 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxContext1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxContext1_15_R1.java @@ -9,30 +9,30 @@ public final class SyntaxContext1_15_R1 extends WrappedContext implements PersistentDataAdapterContext { - private final PersistentDataAdapterContext context; - - public SyntaxContext1_15_R1(PersistentDataAdapterContext context) { - this.context = context; - } - - @Override - public PersistentDataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return context.newPersistentDataContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return newContainer(); - } - - @Override - public SyntaxContainer1_15_R1 newContainer() { - return new SyntaxContainer1_15_R1(context.newPersistentDataContainer()); - } + private final PersistentDataAdapterContext context; + + public SyntaxContext1_15_R1(PersistentDataAdapterContext context) { + this.context = context; + } + + @Override + public PersistentDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return context.newPersistentDataContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return newContainer(); + } + + @Override + public SyntaxContainer1_15_R1 newContainer() { + return new SyntaxContainer1_15_R1(context.newPersistentDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxType1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxType1_15_R1.java index ace4acf..6215dde 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxType1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/SyntaxType1_15_R1.java @@ -8,68 +8,69 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class SyntaxType1_15_R1 extends WrappedType1_15_R1, P0, P1, C0, C1> implements DataType { - - private final PersistentDataType type; - - public SyntaxType1_15_R1(PersistentDataType type) { - super(type.getPrimitiveType(), type.getComplexType()); - this.type = type; - } - - @Override - public PersistentDataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitiveType(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplexType(); - } - - /* - * - */ - - @Override - public Class getComplex() { - return complexType; - } - - @Override - public Class getPrimitive() { - return primitiveType; - } - - @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { - return wrapToPrimitive(complex, new BukkitContext1_15_R1(context)); - } - - @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { - return wrapToComplex(primitive, new BukkitContext1_15_R1(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); - } +public class SyntaxType1_15_R1 extends WrappedType1_15_R1, P0, P1, C0, C1> + implements DataType { + + private final PersistentDataType type; + + public SyntaxType1_15_R1(PersistentDataType type) { + super(type.getPrimitiveType(), type.getComplexType()); + this.type = type; + } + + @Override + public PersistentDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitiveType(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplexType(); + } + + /* + * + */ + + @Override + public Class getComplex() { + return complexType; + } + + @Override + public Class getPrimitive() { + return primitiveType; + } + + @Override + public P0 toPrimitive(DataAdapterContext context, C0 complex) { + return wrapToPrimitive(complex, new BukkitContext1_15_R1(context)); + } + + @Override + public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + return wrapToComplex(primitive, new BukkitContext1_15_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/WrappedType1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/WrappedType1_15_R1.java index d37e649..4830c98 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/WrappedType1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/data/WrappedType1_15_R1.java @@ -12,135 +12,139 @@ public abstract class WrappedType1_15_R1 implements WrapType { - protected final Class primitiveType; - protected final Class complexType; - - private final int primitiveWrap; - private final int complexWrap; - - @SuppressWarnings("unchecked") - protected WrappedType1_15_R1(Class primitive, Class complex) { - this.primitiveWrap = WrappedType1_15_R1.internalState(primitive); - this.complexWrap = WrappedType1_15_R1.internalState(complex); - this.primitiveType = (Class) WrappedType1_15_R1.internalWrap(primitive, primitiveWrap); - this.complexType = (Class) WrappedType1_15_R1.internalWrap(complex, complexWrap); - } - - public abstract H getHandle(); - - public Class getPrimitiveWrapped() { - return primitiveType; - } - - public Class getComplexWrapped() { - return complexType; - } - - public abstract Class getPrimitiveOriginal(); - - public abstract Class getComplexOriginal(); - - @SuppressWarnings("unchecked") - public P0 toPrimitiveWrapped(P1 primitive) { - switch (primitiveWrap) { - case 1: - return (P0) new SyntaxContainer1_15_R1((PersistentDataContainer) primitive); - case 2: - return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_15_R1::new).toArray(IDataContainer[]::new); - case 3: - return (P0) new BukkitContainer1_15_R1((IDataContainer) primitive); - case 4: - return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_15_R1::new).toArray(PersistentDataContainer[]::new); - default: - return (P0) primitive; - } - } - - @SuppressWarnings("unchecked") - public C0 toComplexWrapped(C1 complex) { - switch (complexWrap) { - case 1: - return (C0) new SyntaxContainer1_15_R1((PersistentDataContainer) complex); - case 2: - return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_15_R1::new).toArray(IDataContainer[]::new); - case 3: - return (C0) new BukkitContainer1_15_R1((IDataContainer) complex); - case 4: - return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_15_R1::new).toArray(PersistentDataContainer[]::new); - default: - return (C0) complex; - } - } - - @SuppressWarnings("unchecked") - public P1 toPrimitiveOriginal(P0 primitive) { - switch (primitiveWrap) { - case 1: - return (P1) new BukkitContainer1_15_R1((IDataContainer) primitive); - case 2: - return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_15_R1::new).toArray(PersistentDataContainer[]::new); - case 3: - return (P1) new SyntaxContainer1_15_R1((PersistentDataContainer) primitive); - case 4: - return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_15_R1::new).toArray(IDataContainer[]::new); - default: - return (P1) primitive; - } - } - - @SuppressWarnings("unchecked") - public C1 toComplexOriginal(C0 complex) { - switch (complexWrap) { - case 1: - return (C1) new BukkitContainer1_15_R1((IDataContainer) complex); - case 2: - return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_15_R1::new).toArray(PersistentDataContainer[]::new); - case 3: - return (C1) new SyntaxContainer1_15_R1((PersistentDataContainer) complex); - case 4: - return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_15_R1::new).toArray(IDataContainer[]::new); - default: - return (C1) complex; - } - } - - protected static Class internalWrap(Class clazz, int state) { - switch (state) { - case 1: - return IDataContainer.class; - case 2: - return IDataContainer[].class; - case 3: - return PersistentDataContainer.class; - case 4: - return PersistentDataContainer[].class; - default: - return clazz; - } - } - - protected static int internalState(Class clazz) { - if (clazz.equals(PersistentDataContainer.class)) { - return 1; - } - if (clazz.equals(PersistentDataContainer[].class)) { - return 2; - } - if (clazz.equals(IDataContainer.class)) { - return 3; - } - if (clazz.equals(IDataContainer[].class)) { - return 4; - } - return 0; - } - - public static BukkitType1_15_R1 wrap(DataType type) { - return new BukkitType1_15_R1<>(type); - } - - public static SyntaxType1_15_R1 wrap(PersistentDataType type) { - return new SyntaxType1_15_R1<>(type); - } + protected final Class primitiveType; + protected final Class complexType; + + private final int primitiveWrap; + private final int complexWrap; + + @SuppressWarnings("unchecked") + protected WrappedType1_15_R1(Class primitive, Class complex) { + this.primitiveWrap = WrappedType1_15_R1.internalState(primitive); + this.complexWrap = WrappedType1_15_R1.internalState(complex); + this.primitiveType = (Class) WrappedType1_15_R1.internalWrap(primitive, primitiveWrap); + this.complexType = (Class) WrappedType1_15_R1.internalWrap(complex, complexWrap); + } + + public abstract H getHandle(); + + public Class getPrimitiveWrapped() { + return primitiveType; + } + + public Class getComplexWrapped() { + return complexType; + } + + public abstract Class getPrimitiveOriginal(); + + public abstract Class getComplexOriginal(); + + @SuppressWarnings("unchecked") + public P0 toPrimitiveWrapped(P1 primitive) { + switch (primitiveWrap) { + case 1: + return (P0) new SyntaxContainer1_15_R1((PersistentDataContainer) primitive); + case 2: + return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_15_R1::new) + .toArray(IDataContainer[]::new); + case 3: + return (P0) new BukkitContainer1_15_R1((IDataContainer) primitive); + case 4: + return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_15_R1::new) + .toArray(PersistentDataContainer[]::new); + default: + return (P0) primitive; + } + } + + @SuppressWarnings("unchecked") + public C0 toComplexWrapped(C1 complex) { + switch (complexWrap) { + case 1: + return (C0) new SyntaxContainer1_15_R1((PersistentDataContainer) complex); + case 2: + return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_15_R1::new).toArray(IDataContainer[]::new); + case 3: + return (C0) new BukkitContainer1_15_R1((IDataContainer) complex); + case 4: + return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_15_R1::new).toArray(PersistentDataContainer[]::new); + default: + return (C0) complex; + } + } + + @SuppressWarnings("unchecked") + public P1 toPrimitiveOriginal(P0 primitive) { + switch (primitiveWrap) { + case 1: + return (P1) new BukkitContainer1_15_R1((IDataContainer) primitive); + case 2: + return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_15_R1::new) + .toArray(PersistentDataContainer[]::new); + case 3: + return (P1) new SyntaxContainer1_15_R1((PersistentDataContainer) primitive); + case 4: + return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_15_R1::new) + .toArray(IDataContainer[]::new); + default: + return (P1) primitive; + } + } + + @SuppressWarnings("unchecked") + public C1 toComplexOriginal(C0 complex) { + switch (complexWrap) { + case 1: + return (C1) new BukkitContainer1_15_R1((IDataContainer) complex); + case 2: + return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_15_R1::new).toArray(PersistentDataContainer[]::new); + case 3: + return (C1) new SyntaxContainer1_15_R1((PersistentDataContainer) complex); + case 4: + return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_15_R1::new).toArray(IDataContainer[]::new); + default: + return (C1) complex; + } + } + + protected static Class internalWrap(Class clazz, int state) { + switch (state) { + case 1: + return IDataContainer.class; + case 2: + return IDataContainer[].class; + case 3: + return PersistentDataContainer.class; + case 4: + return PersistentDataContainer[].class; + default: + return clazz; + } + } + + protected static int internalState(Class clazz) { + if (clazz.equals(PersistentDataContainer.class)) { + return 1; + } + if (clazz.equals(PersistentDataContainer[].class)) { + return 2; + } + if (clazz.equals(IDataContainer.class)) { + return 3; + } + if (clazz.equals(IDataContainer[].class)) { + return 4; + } + return 0; + } + + public static BukkitType1_15_R1 wrap(DataType type) { + return new BukkitType1_15_R1<>(type); + } + + public static SyntaxType1_15_R1 wrap(PersistentDataType type) { + return new SyntaxType1_15_R1<>(type); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/ArmorStand1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/ArmorStand1_15_R1.java index 1171364..e1328f2 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/ArmorStand1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/ArmorStand1_15_R1.java @@ -7,18 +7,18 @@ public class ArmorStand1_15_R1 extends EntityLiving1_15_R1 implements NmsArmorStand { - public ArmorStand1_15_R1(World world) { - super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); - } + public ArmorStand1_15_R1(World world) { + super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/Entity1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/Entity1_15_R1.java index e10bfb4..290123b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/Entity1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/Entity1_15_R1.java @@ -13,198 +13,200 @@ import org.bukkit.craftbukkit.v1_15_R1.util.CraftChatMessage; import org.bukkit.entity.Player; +import net.minecraft.server.v1_15_R1.AxisAlignedBB; import net.minecraft.server.v1_15_R1.Entity; import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata; import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_15_R1.PlayerConnection; import net.minecraft.server.v1_15_R1.Vec3D; -import net.minecraft.server.v1_15_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_15_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_15_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); - } - - @Override - public String getCustomName() { - return CraftChatMessage.fromComponent(handle.getCustomName()); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.getPositionVector(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_15_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.getPositionVector(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/EntityLiving1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/EntityLiving1_15_R1.java index eb0386b..432113f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/EntityLiving1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/EntityLiving1_15_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_15_R1 extends Entity1_15_R1 implements NmsEntityLiving { - public EntityLiving1_15_R1(E handle) { - super(handle); - } + public EntityLiving1_15_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/Player1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/Player1_15_R1.java index 5389762..4ae75c8 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/Player1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/entity/Player1_15_R1.java @@ -45,228 +45,228 @@ public class Player1_15_R1 extends EntityLiving1_15_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_15_R1(Player player) { - super(((CraftPlayer) player).getHandle()); - dataAdapter = new SyntaxContainer1_15_R1(getBukkitPlayer().getPersistentDataContainer()); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - dataAdapter.set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - dataAdapter.remove("name"); - return; - } - dataAdapter.set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return dataAdapter.getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return dataAdapter.getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - dataAdapter.set("header", header, WrapType.STRING); - dataAdapter.set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - packet.header = headerComponent; - packet.footer = footerComponent; - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, handle.world.getSeed(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX(), handle.locY(), handle.locZ(), handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_15_R1(Player player) { + super(((CraftPlayer) player).getHandle()); + dataAdapter = new SyntaxContainer1_15_R1(getBukkitPlayer().getPersistentDataContainer()); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + dataAdapter.set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + dataAdapter.remove("name"); + return; + } + dataAdapter.set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return dataAdapter.getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return dataAdapter.getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + dataAdapter.set("header", header, WrapType.STRING); + dataAdapter.set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + packet.header = headerComponent; + packet.footer = footerComponent; + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, handle.world.getSeed(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX(), handle.locY(), handle.locZ(), handle.yaw, + handle.pitch, Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/BlockTools1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/BlockTools1_15_R1.java index 9dbd307..a1fd9d3 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/BlockTools1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/BlockTools1_15_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_15_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.gameProfile.getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.gameProfile.getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/ServerTools1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/ServerTools1_15_R1.java index 114f51b..e820216 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/ServerTools1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/ServerTools1_15_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_15_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/SkinTools1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/SkinTools1_15_R1.java index 8b8bc89..b4c6a6d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/SkinTools1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/tools/SkinTools1_15_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_15_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/utils/EntityConstructors1_15_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/utils/EntityConstructors1_15_R1.java index 25e0f9c..9c2f256 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/utils/EntityConstructors1_15_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_15_R1/utils/EntityConstructors1_15_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_15_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_15_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_15_R1(world)); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/BukkitConversion1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/BukkitConversion1_16_R1.java index f51f454..4436b1f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/BukkitConversion1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/BukkitConversion1_16_R1.java @@ -6,7 +6,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_16_R1.ItemStack; import net.minecraft.server.v1_16_R1.NBTBase; @@ -31,166 +45,166 @@ public class BukkitConversion1_16_R1 extends BukkitConversion { - protected BukkitConversion1_16_R1(VersionControl1_16_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return NBTTagByte.a((byte) tag.getValue()); - case SHORT: - return NBTTagShort.a((short) tag.getValue()); - case INT: - return NBTTagInt.a((int) tag.getValue()); - case LONG: - return NBTTagLong.a((long) tag.getValue()); - case FLOAT: - return NBTTagFloat.a((float) tag.getValue()); - case DOUBLE: - return NBTTagDouble.a((double) tag.getValue()); - case STRING: - return NBTTagString.a((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - return new NBTTagLongArray((long[]) tag.getValue()); - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return NBTTagEnd.b; - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTNumber) tag).asByte()); - case SHORT: - return new NbtShort(((NBTNumber) tag).asShort()); - case INT: - return new NbtInt(((NBTNumber) tag).asInt()); - case LONG: - return new NbtLong(((NBTNumber) tag).asLong()); - case FLOAT: - return new NbtFloat(((NBTNumber) tag).asFloat()); - case DOUBLE: - return new NbtDouble(((NBTNumber) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).asString()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).getInts()); - case LONG_ARRAY: - return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : list) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new BukkitContext1_16_R1(context); - } + protected BukkitConversion1_16_R1(VersionControl1_16_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return NBTTagByte.a((byte) tag.getValue()); + case SHORT: + return NBTTagShort.a((short) tag.getValue()); + case INT: + return NBTTagInt.a((int) tag.getValue()); + case LONG: + return NBTTagLong.a((long) tag.getValue()); + case FLOAT: + return NBTTagFloat.a((float) tag.getValue()); + case DOUBLE: + return NBTTagDouble.a((double) tag.getValue()); + case STRING: + return NBTTagString.a((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + return new NBTTagLongArray((long[]) tag.getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return NBTTagEnd.b; + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTNumber) tag).asByte()); + case SHORT: + return new NbtShort(((NBTNumber) tag).asShort()); + case INT: + return new NbtInt(((NBTNumber) tag).asInt()); + case LONG: + return new NbtLong(((NBTNumber) tag).asLong()); + case FLOAT: + return new NbtFloat(((NBTNumber) tag).asFloat()); + case DOUBLE: + return new NbtDouble(((NBTNumber) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).asString()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).getInts()); + case LONG_ARRAY: + return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new BukkitContext1_16_R1(context); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/EntityProvider1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/EntityProvider1_16_R1.java index 5080174..e5a8827 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/EntityProvider1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/EntityProvider1_16_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_16_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_16_R1(VersionControl1_16_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_16_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_16_R1(VersionControl1_16_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_16_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/PacketHandler1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/PacketHandler1_16_R1.java index ed828af..b34b3e2 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/PacketHandler1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/PacketHandler1_16_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_16_R1 extends PacketHandler { - protected PacketHandler1_16_R1(VersionControl1_16_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_16_R1(VersionControl1_16_R1 versionControl) { + super(versionControl); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/PlayerProvider1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/PlayerProvider1_16_R1.java index ceff179..769689f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/PlayerProvider1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/PlayerProvider1_16_R1.java @@ -8,13 +8,13 @@ public class PlayerProvider1_16_R1 extends PlayerProvider { - protected PlayerProvider1_16_R1(VersionControl1_16_R1 versionControl) { - super(versionControl); - } + protected PlayerProvider1_16_R1(VersionControl1_16_R1 versionControl) { + super(versionControl); + } - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_16_R1(player); - } + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_16_R1(player); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/TextureProvider1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/TextureProvider1_16_R1.java index d4bf73a..420932b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/TextureProvider1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/TextureProvider1_16_R1.java @@ -20,83 +20,83 @@ public class TextureProvider1_16_R1 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - protected TextureProvider1_16_R1(VersionControl1_16_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_16_R1(VersionControl1_16_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile; - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile; + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag = stack.getOrCreateTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag = stack.getOrCreateTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - entitySkull.setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + entitySkull.setGameProfile(profile); + return true; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/ToolProvider1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/ToolProvider1_16_R1.java index f23e1ba..618a8b5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/ToolProvider1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/ToolProvider1_16_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R1.tools.BlockTools1_16_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R1.tools.ServerTools1_16_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R1.tools.SkinTools1_16_R1; public class ToolProvider1_16_R1 extends ToolProvider { - private final BlockTools1_16_R1 blockTools = new BlockTools1_16_R1(); - private final SkinTools1_16_R1 skinTools = new SkinTools1_16_R1(); - private final ServerTools1_16_R1 serverTools = new ServerTools1_16_R1(); - - protected ToolProvider1_16_R1(VersionControl1_16_R1 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_16_R1 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_16_R1 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_16_R1 getBlockTools() { - return blockTools; - } + private final BlockTools1_16_R1 blockTools = new BlockTools1_16_R1(); + private final SkinTools1_16_R1 skinTools = new SkinTools1_16_R1(); + private final ServerTools1_16_R1 serverTools = new ServerTools1_16_R1(); + + protected ToolProvider1_16_R1(VersionControl1_16_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_16_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_16_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_16_R1 getBlockTools() { + return blockTools; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/VersionControl1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/VersionControl1_16_R1.java index 05f2614..b68d715 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/VersionControl1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/VersionControl1_16_R1.java @@ -4,51 +4,51 @@ public class VersionControl1_16_R1 extends VersionControl { - public static VersionControl1_16_R1 INSTANCE; - - public static VersionControl1_16_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_16_R1()); - } - - private final ToolProvider1_16_R1 toolProvider = new ToolProvider1_16_R1(this); - private final TextureProvider1_16_R1 textureProvider = new TextureProvider1_16_R1(this); - private final PacketHandler1_16_R1 packetHandler = new PacketHandler1_16_R1(this); - private final EntityProvider1_16_R1 entityProvider = new EntityProvider1_16_R1(this); - private final PlayerProvider1_16_R1 playerProvider = new PlayerProvider1_16_R1(this); - private final BukkitConversion1_16_R1 bukkitConversion = new BukkitConversion1_16_R1(this); - - private VersionControl1_16_R1() { - - } - - @Override - public ToolProvider1_16_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_16_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_16_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_16_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_16_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_16_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_16_R1 INSTANCE; + + public static VersionControl1_16_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_16_R1()); + } + + private final ToolProvider1_16_R1 toolProvider = new ToolProvider1_16_R1(this); + private final TextureProvider1_16_R1 textureProvider = new TextureProvider1_16_R1(this); + private final PacketHandler1_16_R1 packetHandler = new PacketHandler1_16_R1(this); + private final EntityProvider1_16_R1 entityProvider = new EntityProvider1_16_R1(this); + private final PlayerProvider1_16_R1 playerProvider = new PlayerProvider1_16_R1(this); + private final BukkitConversion1_16_R1 bukkitConversion = new BukkitConversion1_16_R1(this); + + private VersionControl1_16_R1() { + + } + + @Override + public ToolProvider1_16_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_16_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_16_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_16_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_16_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_16_R1 getBukkitConversion() { + return bukkitConversion; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitContainer1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitContainer1_16_R1.java index 589e342..5a3916a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitContainer1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitContainer1_16_R1.java @@ -19,143 +19,143 @@ public final class BukkitContainer1_16_R1 extends WrappedContainer implements PersistentDataContainer { - private final IDataContainer container; - - public BukkitContainer1_16_R1(IDataContainer container) { - this.container = container; - } - - @Override - public IDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return container; - } - - /* - * - */ - - @Override - public boolean has(NamespacedKey key, PersistentDataType type) { - return has(new BukkitKey1_16_R1(key), WrappedType1_16_R1.wrap(type)); - } - - @Override - public Z get(NamespacedKey key, PersistentDataType type) { - return get(new BukkitKey1_16_R1(key), WrappedType1_16_R1.wrap(type)); - } - - @Override - public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { - return Optional.ofNullable(get(key, type)).orElse(value); - } - - @Override - public void set(NamespacedKey key, PersistentDataType type, Z value) { - set(new BukkitKey1_16_R1(key), value, WrappedType1_16_R1.wrap(type)); - } - - @Override - public void remove(NamespacedKey key) { - remove(new BukkitKey1_16_R1(key)); - } - - @Override - public Set getKeys() { - return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_16_R1::asBukkit).collect(Collectors.toSet()); - } - - @Override - public PersistentDataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public BukkitContext1_16_R1 getContext() { - return new BukkitContext1_16_R1(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(key.getNamespacedKey()); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public Object get(String key) { - return get(wrappedKey(key)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(key.getNamespacedKey()); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(key.getNamespacedKey(), value, type.syntaxType()); - } - - @Override - public boolean remove(String key) { - return false; - } - - @Override - public boolean remove(WrappedKey key) { - return container.remove(key.getNamespacedKey()); - } - - @Override - public Set keySet() { - return container.getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.size(); - } + private final IDataContainer container; + + public BukkitContainer1_16_R1(IDataContainer container) { + this.container = container; + } + + @Override + public IDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return container; + } + + /* + * + */ + + @Override + public boolean has(NamespacedKey key, PersistentDataType type) { + return has(new BukkitKey1_16_R1(key), WrappedType1_16_R1.wrap(type)); + } + + @Override + public Z get(NamespacedKey key, PersistentDataType type) { + return get(new BukkitKey1_16_R1(key), WrappedType1_16_R1.wrap(type)); + } + + @Override + public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } + + @Override + public void set(NamespacedKey key, PersistentDataType type, Z value) { + set(new BukkitKey1_16_R1(key), value, WrappedType1_16_R1.wrap(type)); + } + + @Override + public void remove(NamespacedKey key) { + remove(new BukkitKey1_16_R1(key)); + } + + @Override + public Set getKeys() { + return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_16_R1::asBukkit).collect(Collectors.toSet()); + } + + @Override + public PersistentDataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public BukkitContext1_16_R1 getContext() { + return new BukkitContext1_16_R1(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(key.getNamespacedKey()); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public Object get(String key) { + return get(wrappedKey(key)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(key.getNamespacedKey()); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(key.getNamespacedKey(), value, type.syntaxType()); + } + + @Override + public boolean remove(String key) { + return false; + } + + @Override + public boolean remove(WrappedKey key) { + return container.remove(key.getNamespacedKey()); + } + + @Override + public Set keySet() { + return container.getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.size(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitContext1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitContext1_16_R1.java index 1c4c18f..a9f982b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitContext1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitContext1_16_R1.java @@ -10,30 +10,30 @@ public final class BukkitContext1_16_R1 extends WrappedContext implements PersistentDataAdapterContext { - private final DataAdapterContext context; - - public BukkitContext1_16_R1(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_16_R1 newContainer() { - return new BukkitContainer1_16_R1(context.newDataContainer()); - } + private final DataAdapterContext context; + + public BukkitContext1_16_R1(DataAdapterContext context) { + this.context = context; + } + + @Override + public DataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return context.newDataContainer(); + } + + @Override + public BukkitContainer1_16_R1 newContainer() { + return new BukkitContainer1_16_R1(context.newDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitKey1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitKey1_16_R1.java index 6ef94c8..76dfda7 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitKey1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitKey1_16_R1.java @@ -7,46 +7,46 @@ public final class BukkitKey1_16_R1 extends WrappedKey { - private final NamespacedKey key; - - public BukkitKey1_16_R1(Plugin plugin, String key) { - this.key = new NamespacedKey(plugin, key); - } - - @SuppressWarnings("deprecation") - public BukkitKey1_16_R1(String name, String key) { - this.key = new NamespacedKey(name, key); - } - - public BukkitKey1_16_R1(NamespacedKey key) { - this.key = key; - } - - @Override - public NamespacedKey getHandle() { - return key; - } - - @Override - public String getName() { - return key.getNamespace(); - } - - @Override - public String getKey() { - return key.getKey(); - } - - @Override - public String toString() { - return key.toString(); - } - - public static NamespacedKey asBukkit(WrappedKey key) { - if (key.getHandle() instanceof NamespacedKey) { - return (NamespacedKey) key.getHandle(); - } - return new BukkitKey1_16_R1(key.getName(), key.getKey()).getHandle(); - } + private final NamespacedKey key; + + public BukkitKey1_16_R1(Plugin plugin, String key) { + this.key = new NamespacedKey(plugin, key); + } + + @SuppressWarnings("deprecation") + public BukkitKey1_16_R1(String name, String key) { + this.key = new NamespacedKey(name, key); + } + + public BukkitKey1_16_R1(NamespacedKey key) { + this.key = key; + } + + @Override + public NamespacedKey getHandle() { + return key; + } + + @Override + public String getName() { + return key.getNamespace(); + } + + @Override + public String getKey() { + return key.getKey(); + } + + @Override + public String toString() { + return key.toString(); + } + + public static NamespacedKey asBukkit(WrappedKey key) { + if (key.getHandle() instanceof NamespacedKey) { + return (NamespacedKey) key.getHandle(); + } + return new BukkitKey1_16_R1(key.getName(), key.getKey()).getHandle(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitType1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitType1_16_R1.java index 2e741d8..82b94af 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitType1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/BukkitType1_16_R1.java @@ -7,62 +7,63 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class BukkitType1_16_R1 extends WrappedType1_16_R1, P0, P1, C0, C1> implements PersistentDataType { - - private final DataType type; - - public BukkitType1_16_R1(DataType type) { - super(type.getPrimitive(), type.getComplex()); - this.type = type; - } - - @Override - public DataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitive(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplex(); - } - - /* - * - */ - - @Override - public Class getComplexType() { - return complexType; - } - - @Override - public Class getPrimitiveType() { - return primitiveType; - } - - @Override - public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { - return wrapToPrimitive(complex, new SyntaxContext1_16_R1(context)); - } - - @Override - public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { - return wrapToComplex(primitive, new SyntaxContext1_16_R1(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); - } +public class BukkitType1_16_R1 extends WrappedType1_16_R1, P0, P1, C0, C1> + implements PersistentDataType { + + private final DataType type; + + public BukkitType1_16_R1(DataType type) { + super(type.getPrimitive(), type.getComplex()); + this.type = type; + } + + @Override + public DataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitive(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplex(); + } + + /* + * + */ + + @Override + public Class getComplexType() { + return complexType; + } + + @Override + public Class getPrimitiveType() { + return primitiveType; + } + + @Override + public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { + return wrapToPrimitive(complex, new SyntaxContext1_16_R1(context)); + } + + @Override + public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { + return wrapToComplex(primitive, new SyntaxContext1_16_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SimpleBukkitType1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SimpleBukkitType1_16_R1.java index 0601da3..25b54f0 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SimpleBukkitType1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SimpleBukkitType1_16_R1.java @@ -7,30 +7,30 @@ public class SimpleBukkitType1_16_R1 implements PersistentDataType { - private final WrapType type; - - public SimpleBukkitType1_16_R1(WrapType type) { - this.type = type; - } - - @Override - public Class getComplexType() { - return type.getComplexWrapped(); - } - - @Override - public Class

getPrimitiveType() { - return type.getPrimitiveWrapped(); - } - - @Override - public P toPrimitive(C complex, PersistentDataAdapterContext context) { - return type.wrapToPrimitive(complex, new SyntaxContext1_16_R1(context)); - } - - @Override - public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { - return type.wrapToComplex(primitive, new SyntaxContext1_16_R1(context)); - } + private final WrapType type; + + public SimpleBukkitType1_16_R1(WrapType type) { + this.type = type; + } + + @Override + public Class getComplexType() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitiveType() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(C complex, PersistentDataAdapterContext context) { + return type.wrapToPrimitive(complex, new SyntaxContext1_16_R1(context)); + } + + @Override + public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { + return type.wrapToComplex(primitive, new SyntaxContext1_16_R1(context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxContainer1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxContainer1_16_R1.java index a6311fc..2288b82 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxContainer1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxContainer1_16_R1.java @@ -20,172 +20,172 @@ public final class SyntaxContainer1_16_R1 extends WrappedContainer implements IDataContainer { - public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_16_R1<>(ObjectType.INSTANCE); - - private final PersistentDataContainer container; - - public SyntaxContainer1_16_R1(PersistentDataContainer container) { - this.container = container; - } - - @Override - public PersistentDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return new SyntaxContainer1_16_R1(container); - } - - /* - * - */ - - @Override - public boolean has(IKey key) { - return has(new SyntaxKey(key)); - } - - @Override - public boolean has(String key, DataType type) { - return has(NamespacedKey.fromString(key), type); - } - - @Override - public boolean has(IKey key, DataType type) { - return has(new SyntaxKey(key), WrappedType1_16_R1.wrap(type)); - } - - @Override - public C get(String key, DataType type) { - return get(NamespacedKey.fromString(key), type); - } - - @Override - public C get(IKey key, DataType type) { - return get(new SyntaxKey(key), WrappedType1_16_R1.wrap(type)); - } - - @Override - public Object get(String key) { - return get(NamespacedKey.fromString(key)); - } - - @Override - public Object get(IKey key) { - return get(new SyntaxKey(key)); - } - - @Override - public void set(String key, E value, DataType type) { - set(wrappedKey(key), value, WrappedType1_16_R1.wrap(type)); - } - - @Override - public void set(IKey key, E value, DataType type) { - set(new SyntaxKey(key), value, WrappedType1_16_R1.wrap(type)); - } - - @Override - public boolean remove(String key) { - return remove(wrappedKey(key)); - } - - @Override - public boolean remove(IKey key) { - return remove(new SyntaxKey(key)); - } - - @Override - public IKey[] getKeys() { - return container.getKeys().stream().map(BukkitKey1_16_R1::new).map(WrappedKey::getNamespacedKey).toArray(IKey[]::new); - } - - @Override - public Set getKeyspaces() { - return container.getKeys().stream().map(org.bukkit.NamespacedKey::toString).collect(Collectors.toSet()); - } - - @Override - public DataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public SyntaxContext1_16_R1 getContext() { - return new SyntaxContext1_16_R1(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(BukkitKey1_16_R1.asBukkit(key), OBJECT_TYPE); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(BukkitKey1_16_R1.asBukkit(key), new SimpleBukkitType1_16_R1<>(type)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(BukkitKey1_16_R1.asBukkit(key), OBJECT_TYPE); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(BukkitKey1_16_R1.asBukkit(key), new SimpleBukkitType1_16_R1<>(type)); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(BukkitKey1_16_R1.asBukkit(key), new SimpleBukkitType1_16_R1<>(type), value); - } - - @Override - public boolean remove(WrappedKey key) { - Object value = get(key); - container.remove(BukkitKey1_16_R1.asBukkit(key)); - return value != null && get(key) == null; - } - - @Override - public Set keySet() { - return getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.getKeys().size(); - } + public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_16_R1<>(ObjectType.INSTANCE); + + private final PersistentDataContainer container; + + public SyntaxContainer1_16_R1(PersistentDataContainer container) { + this.container = container; + } + + @Override + public PersistentDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return new SyntaxContainer1_16_R1(container); + } + + /* + * + */ + + @Override + public boolean has(IKey key) { + return has(new SyntaxKey(key)); + } + + @Override + public boolean has(String key, DataType type) { + return has(NamespacedKey.fromString(key), type); + } + + @Override + public boolean has(IKey key, DataType type) { + return has(new SyntaxKey(key), WrappedType1_16_R1.wrap(type)); + } + + @Override + public C get(String key, DataType type) { + return get(NamespacedKey.fromString(key), type); + } + + @Override + public C get(IKey key, DataType type) { + return get(new SyntaxKey(key), WrappedType1_16_R1.wrap(type)); + } + + @Override + public Object get(String key) { + return get(NamespacedKey.fromString(key)); + } + + @Override + public Object get(IKey key) { + return get(new SyntaxKey(key)); + } + + @Override + public void set(String key, E value, DataType type) { + set(wrappedKey(key), value, WrappedType1_16_R1.wrap(type)); + } + + @Override + public void set(IKey key, E value, DataType type) { + set(new SyntaxKey(key), value, WrappedType1_16_R1.wrap(type)); + } + + @Override + public boolean remove(String key) { + return remove(wrappedKey(key)); + } + + @Override + public boolean remove(IKey key) { + return remove(new SyntaxKey(key)); + } + + @Override + public IKey[] getKeys() { + return container.getKeys().stream().map(BukkitKey1_16_R1::new).map(WrappedKey::getNamespacedKey).toArray(IKey[]::new); + } + + @Override + public Set getKeyspaces() { + return container.getKeys().stream().map(org.bukkit.NamespacedKey::toString).collect(Collectors.toSet()); + } + + @Override + public DataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public SyntaxContext1_16_R1 getContext() { + return new SyntaxContext1_16_R1(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(BukkitKey1_16_R1.asBukkit(key), OBJECT_TYPE); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(BukkitKey1_16_R1.asBukkit(key), new SimpleBukkitType1_16_R1<>(type)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(BukkitKey1_16_R1.asBukkit(key), OBJECT_TYPE); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(BukkitKey1_16_R1.asBukkit(key), new SimpleBukkitType1_16_R1<>(type)); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(BukkitKey1_16_R1.asBukkit(key), new SimpleBukkitType1_16_R1<>(type), value); + } + + @Override + public boolean remove(WrappedKey key) { + Object value = get(key); + container.remove(BukkitKey1_16_R1.asBukkit(key)); + return value != null && get(key) == null; + } + + @Override + public Set keySet() { + return getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.getKeys().size(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxContext1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxContext1_16_R1.java index 579c054..9eec183 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxContext1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxContext1_16_R1.java @@ -9,30 +9,30 @@ public final class SyntaxContext1_16_R1 extends WrappedContext implements PersistentDataAdapterContext { - private final PersistentDataAdapterContext context; - - public SyntaxContext1_16_R1(PersistentDataAdapterContext context) { - this.context = context; - } - - @Override - public PersistentDataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return context.newPersistentDataContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return newContainer(); - } - - @Override - public SyntaxContainer1_16_R1 newContainer() { - return new SyntaxContainer1_16_R1(context.newPersistentDataContainer()); - } + private final PersistentDataAdapterContext context; + + public SyntaxContext1_16_R1(PersistentDataAdapterContext context) { + this.context = context; + } + + @Override + public PersistentDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return context.newPersistentDataContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return newContainer(); + } + + @Override + public SyntaxContainer1_16_R1 newContainer() { + return new SyntaxContainer1_16_R1(context.newPersistentDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxType1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxType1_16_R1.java index 2d909a1..82da53e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxType1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/SyntaxType1_16_R1.java @@ -8,68 +8,69 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class SyntaxType1_16_R1 extends WrappedType1_16_R1, P0, P1, C0, C1> implements DataType { - - private final PersistentDataType type; - - public SyntaxType1_16_R1(PersistentDataType type) { - super(type.getPrimitiveType(), type.getComplexType()); - this.type = type; - } - - @Override - public PersistentDataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitiveType(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplexType(); - } - - /* - * - */ - - @Override - public Class getComplex() { - return complexType; - } - - @Override - public Class getPrimitive() { - return primitiveType; - } - - @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { - return wrapToPrimitive(complex, new BukkitContext1_16_R1(context)); - } - - @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { - return wrapToComplex(primitive, new BukkitContext1_16_R1(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); - } +public class SyntaxType1_16_R1 extends WrappedType1_16_R1, P0, P1, C0, C1> + implements DataType { + + private final PersistentDataType type; + + public SyntaxType1_16_R1(PersistentDataType type) { + super(type.getPrimitiveType(), type.getComplexType()); + this.type = type; + } + + @Override + public PersistentDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitiveType(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplexType(); + } + + /* + * + */ + + @Override + public Class getComplex() { + return complexType; + } + + @Override + public Class getPrimitive() { + return primitiveType; + } + + @Override + public P0 toPrimitive(DataAdapterContext context, C0 complex) { + return wrapToPrimitive(complex, new BukkitContext1_16_R1(context)); + } + + @Override + public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + return wrapToComplex(primitive, new BukkitContext1_16_R1(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/WrappedType1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/WrappedType1_16_R1.java index bb38aed..a41d676 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/WrappedType1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/data/WrappedType1_16_R1.java @@ -12,135 +12,139 @@ public abstract class WrappedType1_16_R1 implements WrapType { - protected final Class primitiveType; - protected final Class complexType; - - private final int primitiveWrap; - private final int complexWrap; - - @SuppressWarnings("unchecked") - protected WrappedType1_16_R1(Class primitive, Class complex) { - this.primitiveWrap = WrappedType1_16_R1.internalState(primitive); - this.complexWrap = WrappedType1_16_R1.internalState(complex); - this.primitiveType = (Class) WrappedType1_16_R1.internalWrap(primitive, primitiveWrap); - this.complexType = (Class) WrappedType1_16_R1.internalWrap(complex, complexWrap); - } - - public abstract H getHandle(); - - public Class getPrimitiveWrapped() { - return primitiveType; - } - - public Class getComplexWrapped() { - return complexType; - } - - public abstract Class getPrimitiveOriginal(); - - public abstract Class getComplexOriginal(); - - @SuppressWarnings("unchecked") - public P0 toPrimitiveWrapped(P1 primitive) { - switch (primitiveWrap) { - case 1: - return (P0) new SyntaxContainer1_16_R1((PersistentDataContainer) primitive); - case 2: - return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R1::new).toArray(IDataContainer[]::new); - case 3: - return (P0) new BukkitContainer1_16_R1((IDataContainer) primitive); - case 4: - return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R1::new).toArray(PersistentDataContainer[]::new); - default: - return (P0) primitive; - } - } - - @SuppressWarnings("unchecked") - public C0 toComplexWrapped(C1 complex) { - switch (complexWrap) { - case 1: - return (C0) new SyntaxContainer1_16_R1((PersistentDataContainer) complex); - case 2: - return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R1::new).toArray(IDataContainer[]::new); - case 3: - return (C0) new BukkitContainer1_16_R1((IDataContainer) complex); - case 4: - return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R1::new).toArray(PersistentDataContainer[]::new); - default: - return (C0) complex; - } - } - - @SuppressWarnings("unchecked") - public P1 toPrimitiveOriginal(P0 primitive) { - switch (primitiveWrap) { - case 1: - return (P1) new BukkitContainer1_16_R1((IDataContainer) primitive); - case 2: - return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R1::new).toArray(PersistentDataContainer[]::new); - case 3: - return (P1) new SyntaxContainer1_16_R1((PersistentDataContainer) primitive); - case 4: - return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R1::new).toArray(IDataContainer[]::new); - default: - return (P1) primitive; - } - } - - @SuppressWarnings("unchecked") - public C1 toComplexOriginal(C0 complex) { - switch (complexWrap) { - case 1: - return (C1) new BukkitContainer1_16_R1((IDataContainer) complex); - case 2: - return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R1::new).toArray(PersistentDataContainer[]::new); - case 3: - return (C1) new SyntaxContainer1_16_R1((PersistentDataContainer) complex); - case 4: - return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R1::new).toArray(IDataContainer[]::new); - default: - return (C1) complex; - } - } - - protected static Class internalWrap(Class clazz, int state) { - switch (state) { - case 1: - return IDataContainer.class; - case 2: - return IDataContainer[].class; - case 3: - return PersistentDataContainer.class; - case 4: - return PersistentDataContainer[].class; - default: - return clazz; - } - } - - protected static int internalState(Class clazz) { - if (clazz.equals(PersistentDataContainer.class)) { - return 1; - } - if (clazz.equals(PersistentDataContainer[].class)) { - return 2; - } - if (clazz.equals(IDataContainer.class)) { - return 3; - } - if (clazz.equals(IDataContainer[].class)) { - return 4; - } - return 0; - } - - public static BukkitType1_16_R1 wrap(DataType type) { - return new BukkitType1_16_R1<>(type); - } - - public static SyntaxType1_16_R1 wrap(PersistentDataType type) { - return new SyntaxType1_16_R1<>(type); - } + protected final Class primitiveType; + protected final Class complexType; + + private final int primitiveWrap; + private final int complexWrap; + + @SuppressWarnings("unchecked") + protected WrappedType1_16_R1(Class primitive, Class complex) { + this.primitiveWrap = WrappedType1_16_R1.internalState(primitive); + this.complexWrap = WrappedType1_16_R1.internalState(complex); + this.primitiveType = (Class) WrappedType1_16_R1.internalWrap(primitive, primitiveWrap); + this.complexType = (Class) WrappedType1_16_R1.internalWrap(complex, complexWrap); + } + + public abstract H getHandle(); + + public Class getPrimitiveWrapped() { + return primitiveType; + } + + public Class getComplexWrapped() { + return complexType; + } + + public abstract Class getPrimitiveOriginal(); + + public abstract Class getComplexOriginal(); + + @SuppressWarnings("unchecked") + public P0 toPrimitiveWrapped(P1 primitive) { + switch (primitiveWrap) { + case 1: + return (P0) new SyntaxContainer1_16_R1((PersistentDataContainer) primitive); + case 2: + return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R1::new) + .toArray(IDataContainer[]::new); + case 3: + return (P0) new BukkitContainer1_16_R1((IDataContainer) primitive); + case 4: + return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R1::new) + .toArray(PersistentDataContainer[]::new); + default: + return (P0) primitive; + } + } + + @SuppressWarnings("unchecked") + public C0 toComplexWrapped(C1 complex) { + switch (complexWrap) { + case 1: + return (C0) new SyntaxContainer1_16_R1((PersistentDataContainer) complex); + case 2: + return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R1::new).toArray(IDataContainer[]::new); + case 3: + return (C0) new BukkitContainer1_16_R1((IDataContainer) complex); + case 4: + return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R1::new).toArray(PersistentDataContainer[]::new); + default: + return (C0) complex; + } + } + + @SuppressWarnings("unchecked") + public P1 toPrimitiveOriginal(P0 primitive) { + switch (primitiveWrap) { + case 1: + return (P1) new BukkitContainer1_16_R1((IDataContainer) primitive); + case 2: + return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R1::new) + .toArray(PersistentDataContainer[]::new); + case 3: + return (P1) new SyntaxContainer1_16_R1((PersistentDataContainer) primitive); + case 4: + return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R1::new) + .toArray(IDataContainer[]::new); + default: + return (P1) primitive; + } + } + + @SuppressWarnings("unchecked") + public C1 toComplexOriginal(C0 complex) { + switch (complexWrap) { + case 1: + return (C1) new BukkitContainer1_16_R1((IDataContainer) complex); + case 2: + return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R1::new).toArray(PersistentDataContainer[]::new); + case 3: + return (C1) new SyntaxContainer1_16_R1((PersistentDataContainer) complex); + case 4: + return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R1::new).toArray(IDataContainer[]::new); + default: + return (C1) complex; + } + } + + protected static Class internalWrap(Class clazz, int state) { + switch (state) { + case 1: + return IDataContainer.class; + case 2: + return IDataContainer[].class; + case 3: + return PersistentDataContainer.class; + case 4: + return PersistentDataContainer[].class; + default: + return clazz; + } + } + + protected static int internalState(Class clazz) { + if (clazz.equals(PersistentDataContainer.class)) { + return 1; + } + if (clazz.equals(PersistentDataContainer[].class)) { + return 2; + } + if (clazz.equals(IDataContainer.class)) { + return 3; + } + if (clazz.equals(IDataContainer[].class)) { + return 4; + } + return 0; + } + + public static BukkitType1_16_R1 wrap(DataType type) { + return new BukkitType1_16_R1<>(type); + } + + public static SyntaxType1_16_R1 wrap(PersistentDataType type) { + return new SyntaxType1_16_R1<>(type); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/ArmorStand1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/ArmorStand1_16_R1.java index 2d165b5..7d930a5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/ArmorStand1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/ArmorStand1_16_R1.java @@ -7,18 +7,18 @@ public class ArmorStand1_16_R1 extends EntityLiving1_16_R1 implements NmsArmorStand { - public ArmorStand1_16_R1(World world) { - super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); - } + public ArmorStand1_16_R1(World world) { + super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/Entity1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/Entity1_16_R1.java index 013692b..3e456f5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/Entity1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/Entity1_16_R1.java @@ -13,198 +13,200 @@ import org.bukkit.craftbukkit.v1_16_R1.util.CraftChatMessage; import org.bukkit.entity.Player; +import net.minecraft.server.v1_16_R1.AxisAlignedBB; import net.minecraft.server.v1_16_R1.Entity; import net.minecraft.server.v1_16_R1.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_16_R1.PacketPlayOutEntityMetadata; import net.minecraft.server.v1_16_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_16_R1.PlayerConnection; import net.minecraft.server.v1_16_R1.Vec3D; -import net.minecraft.server.v1_16_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_16_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_16_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); - } - - @Override - public String getCustomName() { - return CraftChatMessage.fromComponent(handle.getCustomName()); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.getPositionVector(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_16_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.getPositionVector(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/EntityLiving1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/EntityLiving1_16_R1.java index 82efde7..2696328 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/EntityLiving1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/EntityLiving1_16_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_16_R1 extends Entity1_16_R1 implements NmsEntityLiving { - public EntityLiving1_16_R1(E handle) { - super(handle); - } + public EntityLiving1_16_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/Player1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/Player1_16_R1.java index 82c7896..8de1261 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/Player1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/entity/Player1_16_R1.java @@ -49,229 +49,230 @@ public class Player1_16_R1 extends EntityLiving1_16_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_16_R1(Player player) { - super(((CraftPlayer) player).getHandle()); - dataAdapter = new SyntaxContainer1_16_R1(getBukkitPlayer().getPersistentDataContainer()); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - dataAdapter.set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - dataAdapter.remove("name"); - return; - } - dataAdapter.set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return dataAdapter.getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return dataAdapter.getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - dataAdapter.set("header", header, WrapType.STRING); - dataAdapter.set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - packet.header = headerComponent; - packet.footer = footerComponent; - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList> list = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - list.add(Pair.of(slot, handle.getEquipment(slot))); - } - PacketPlayOutEntityEquipment equipmentPacket = new PacketPlayOutEntityEquipment(handle.getId(), list); - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - connection.sendPacket(equipmentPacket); - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(world.getTypeKey(), world.getDimensionKey(), BiomeManager.a(world.getSeed()), - handle.playerInteractManager.getGameMode(), handle.playerInteractManager.c(), world.isDebugWorld(), world.isFlatWorld(), true); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX(), handle.locY(), handle.locZ(), handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_16_R1(Player player) { + super(((CraftPlayer) player).getHandle()); + dataAdapter = new SyntaxContainer1_16_R1(getBukkitPlayer().getPersistentDataContainer()); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + dataAdapter.set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + dataAdapter.remove("name"); + return; + } + dataAdapter.set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return dataAdapter.getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return dataAdapter.getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + dataAdapter.set("header", header, WrapType.STRING); + dataAdapter.set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + packet.header = headerComponent; + packet.footer = footerComponent; + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList> list = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + list.add(Pair.of(slot, handle.getEquipment(slot))); + } + PacketPlayOutEntityEquipment equipmentPacket = new PacketPlayOutEntityEquipment(handle.getId(), list); + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + connection.sendPacket(equipmentPacket); + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(world.getTypeKey(), world.getDimensionKey(), + BiomeManager.a(world.getSeed()), handle.playerInteractManager.getGameMode(), handle.playerInteractManager.c(), + world.isDebugWorld(), world.isFlatWorld(), true); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX(), handle.locY(), handle.locZ(), handle.yaw, + handle.pitch, Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/BlockTools1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/BlockTools1_16_R1.java index 502a9e7..181bd51 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/BlockTools1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/BlockTools1_16_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_16_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.gameProfile.getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.gameProfile.getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/ServerTools1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/ServerTools1_16_R1.java index ff7edb0..3e27769 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/ServerTools1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/ServerTools1_16_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_16_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/SkinTools1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/SkinTools1_16_R1.java index 12de3ab..4db0f26 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/SkinTools1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/tools/SkinTools1_16_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_16_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/utils/EntityConstructors1_16_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/utils/EntityConstructors1_16_R1.java index 94882af..7f7cff4 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/utils/EntityConstructors1_16_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R1/utils/EntityConstructors1_16_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_16_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_16_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_16_R1(world)); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/BukkitConversion1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/BukkitConversion1_16_R2.java index c711951..fd77820 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/BukkitConversion1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/BukkitConversion1_16_R2.java @@ -6,7 +6,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_16_R2.ItemStack; import net.minecraft.server.v1_16_R2.NBTBase; @@ -31,166 +45,166 @@ public class BukkitConversion1_16_R2 extends BukkitConversion { - protected BukkitConversion1_16_R2(VersionControl1_16_R2 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return NBTTagByte.a((byte) tag.getValue()); - case SHORT: - return NBTTagShort.a((short) tag.getValue()); - case INT: - return NBTTagInt.a((int) tag.getValue()); - case LONG: - return NBTTagLong.a((long) tag.getValue()); - case FLOAT: - return NBTTagFloat.a((float) tag.getValue()); - case DOUBLE: - return NBTTagDouble.a((double) tag.getValue()); - case STRING: - return NBTTagString.a((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - return new NBTTagLongArray((long[]) tag.getValue()); - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return NBTTagEnd.b; - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTNumber) tag).asByte()); - case SHORT: - return new NbtShort(((NBTNumber) tag).asShort()); - case INT: - return new NbtInt(((NBTNumber) tag).asInt()); - case LONG: - return new NbtLong(((NBTNumber) tag).asLong()); - case FLOAT: - return new NbtFloat(((NBTNumber) tag).asFloat()); - case DOUBLE: - return new NbtDouble(((NBTNumber) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).asString()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).getInts()); - case LONG_ARRAY: - return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : list) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new BukkitContext1_16_R2(context); - } + protected BukkitConversion1_16_R2(VersionControl1_16_R2 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return NBTTagByte.a((byte) tag.getValue()); + case SHORT: + return NBTTagShort.a((short) tag.getValue()); + case INT: + return NBTTagInt.a((int) tag.getValue()); + case LONG: + return NBTTagLong.a((long) tag.getValue()); + case FLOAT: + return NBTTagFloat.a((float) tag.getValue()); + case DOUBLE: + return NBTTagDouble.a((double) tag.getValue()); + case STRING: + return NBTTagString.a((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + return new NBTTagLongArray((long[]) tag.getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return NBTTagEnd.b; + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTNumber) tag).asByte()); + case SHORT: + return new NbtShort(((NBTNumber) tag).asShort()); + case INT: + return new NbtInt(((NBTNumber) tag).asInt()); + case LONG: + return new NbtLong(((NBTNumber) tag).asLong()); + case FLOAT: + return new NbtFloat(((NBTNumber) tag).asFloat()); + case DOUBLE: + return new NbtDouble(((NBTNumber) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).asString()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).getInts()); + case LONG_ARRAY: + return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag()); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new BukkitContext1_16_R2(context); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/EntityProvider1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/EntityProvider1_16_R2.java index 2bf4812..bfa116c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/EntityProvider1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/EntityProvider1_16_R2.java @@ -13,35 +13,35 @@ public class EntityProvider1_16_R2 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_16_R2(VersionControl1_16_R2 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_16_R2.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_16_R2(VersionControl1_16_R2 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_16_R2.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/PacketHandler1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/PacketHandler1_16_R2.java index 8600939..ada2329 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/PacketHandler1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/PacketHandler1_16_R2.java @@ -4,8 +4,8 @@ public class PacketHandler1_16_R2 extends PacketHandler { - protected PacketHandler1_16_R2(VersionControl1_16_R2 versionControl) { - super(versionControl); - } + protected PacketHandler1_16_R2(VersionControl1_16_R2 versionControl) { + super(versionControl); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/PlayerProvider1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/PlayerProvider1_16_R2.java index d805c65..087f993 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/PlayerProvider1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/PlayerProvider1_16_R2.java @@ -8,13 +8,13 @@ public class PlayerProvider1_16_R2 extends PlayerProvider { - protected PlayerProvider1_16_R2(VersionControl1_16_R2 versionControl) { - super(versionControl); - } + protected PlayerProvider1_16_R2(VersionControl1_16_R2 versionControl) { + super(versionControl); + } - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_16_R2(player); - } + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_16_R2(player); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/TextureProvider1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/TextureProvider1_16_R2.java index 6bed464..4b7014e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/TextureProvider1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/TextureProvider1_16_R2.java @@ -20,83 +20,83 @@ public class TextureProvider1_16_R2 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - protected TextureProvider1_16_R2(VersionControl1_16_R2 versionControl) { - super(versionControl); - } + protected TextureProvider1_16_R2(VersionControl1_16_R2 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile; - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile; + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag = stack.getOrCreateTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag = stack.getOrCreateTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - entitySkull.setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + entitySkull.setGameProfile(profile); + return true; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/ToolProvider1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/ToolProvider1_16_R2.java index cb0320b..7e50802 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/ToolProvider1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/ToolProvider1_16_R2.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R2; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R2.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R2.tools.BlockTools1_16_R2; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R2.tools.ServerTools1_16_R2; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R2.tools.SkinTools1_16_R2; public class ToolProvider1_16_R2 extends ToolProvider { - private final BlockTools1_16_R2 blockTools = new BlockTools1_16_R2(); - private final SkinTools1_16_R2 skinTools = new SkinTools1_16_R2(); - private final ServerTools1_16_R2 serverTools = new ServerTools1_16_R2(); + private final BlockTools1_16_R2 blockTools = new BlockTools1_16_R2(); + private final SkinTools1_16_R2 skinTools = new SkinTools1_16_R2(); + private final ServerTools1_16_R2 serverTools = new ServerTools1_16_R2(); - protected ToolProvider1_16_R2(VersionControl1_16_R2 versionControl) { - super(versionControl); - } + protected ToolProvider1_16_R2(VersionControl1_16_R2 versionControl) { + super(versionControl); + } - @Override - public SkinTools1_16_R2 getSkinTools() { - return skinTools; - } + @Override + public SkinTools1_16_R2 getSkinTools() { + return skinTools; + } - @Override - public ServerTools1_16_R2 getServerTools() { - return serverTools; - } + @Override + public ServerTools1_16_R2 getServerTools() { + return serverTools; + } - @Override - public BlockTools1_16_R2 getBlockTools() { - return blockTools; - } + @Override + public BlockTools1_16_R2 getBlockTools() { + return blockTools; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/VersionControl1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/VersionControl1_16_R2.java index f92c3a7..9487bad 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/VersionControl1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/VersionControl1_16_R2.java @@ -4,51 +4,51 @@ public class VersionControl1_16_R2 extends VersionControl { - public static VersionControl1_16_R2 INSTANCE; - - public static VersionControl1_16_R2 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_16_R2()); - } - - private final ToolProvider1_16_R2 toolProvider = new ToolProvider1_16_R2(this); - private final TextureProvider1_16_R2 textureProvider = new TextureProvider1_16_R2(this); - private final PacketHandler1_16_R2 packetHandler = new PacketHandler1_16_R2(this); - private final EntityProvider1_16_R2 entityProvider = new EntityProvider1_16_R2(this); - private final PlayerProvider1_16_R2 playerProvider = new PlayerProvider1_16_R2(this); - private final BukkitConversion1_16_R2 bukkitConversion = new BukkitConversion1_16_R2(this); - - private VersionControl1_16_R2() { - - } - - @Override - public ToolProvider1_16_R2 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_16_R2 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_16_R2 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_16_R2 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_16_R2 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_16_R2 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_16_R2 INSTANCE; + + public static VersionControl1_16_R2 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_16_R2()); + } + + private final ToolProvider1_16_R2 toolProvider = new ToolProvider1_16_R2(this); + private final TextureProvider1_16_R2 textureProvider = new TextureProvider1_16_R2(this); + private final PacketHandler1_16_R2 packetHandler = new PacketHandler1_16_R2(this); + private final EntityProvider1_16_R2 entityProvider = new EntityProvider1_16_R2(this); + private final PlayerProvider1_16_R2 playerProvider = new PlayerProvider1_16_R2(this); + private final BukkitConversion1_16_R2 bukkitConversion = new BukkitConversion1_16_R2(this); + + private VersionControl1_16_R2() { + + } + + @Override + public ToolProvider1_16_R2 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_16_R2 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_16_R2 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_16_R2 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_16_R2 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_16_R2 getBukkitConversion() { + return bukkitConversion; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitContainer1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitContainer1_16_R2.java index 826476a..29a9ae4 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitContainer1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitContainer1_16_R2.java @@ -19,143 +19,143 @@ public final class BukkitContainer1_16_R2 extends WrappedContainer implements PersistentDataContainer { - private final IDataContainer container; - - public BukkitContainer1_16_R2(IDataContainer container) { - this.container = container; - } - - @Override - public IDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return container; - } - - /* - * - */ - - @Override - public boolean has(NamespacedKey key, PersistentDataType type) { - return has(new BukkitKey1_16_R2(key), WrappedType1_16_R2.wrap(type)); - } - - @Override - public Z get(NamespacedKey key, PersistentDataType type) { - return get(new BukkitKey1_16_R2(key), WrappedType1_16_R2.wrap(type)); - } - - @Override - public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { - return Optional.ofNullable(get(key, type)).orElse(value); - } - - @Override - public void set(NamespacedKey key, PersistentDataType type, Z value) { - set(new BukkitKey1_16_R2(key), value, WrappedType1_16_R2.wrap(type)); - } - - @Override - public void remove(NamespacedKey key) { - remove(new BukkitKey1_16_R2(key)); - } - - @Override - public Set getKeys() { - return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_16_R2::asBukkit).collect(Collectors.toSet()); - } - - @Override - public PersistentDataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public BukkitContext1_16_R2 getContext() { - return new BukkitContext1_16_R2(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(key.getNamespacedKey()); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public Object get(String key) { - return get(wrappedKey(key)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(key.getNamespacedKey()); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(key.getNamespacedKey(), value, type.syntaxType()); - } - - @Override - public boolean remove(String key) { - return false; - } - - @Override - public boolean remove(WrappedKey key) { - return container.remove(key.getNamespacedKey()); - } - - @Override - public Set keySet() { - return container.getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.size(); - } + private final IDataContainer container; + + public BukkitContainer1_16_R2(IDataContainer container) { + this.container = container; + } + + @Override + public IDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return container; + } + + /* + * + */ + + @Override + public boolean has(NamespacedKey key, PersistentDataType type) { + return has(new BukkitKey1_16_R2(key), WrappedType1_16_R2.wrap(type)); + } + + @Override + public Z get(NamespacedKey key, PersistentDataType type) { + return get(new BukkitKey1_16_R2(key), WrappedType1_16_R2.wrap(type)); + } + + @Override + public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } + + @Override + public void set(NamespacedKey key, PersistentDataType type, Z value) { + set(new BukkitKey1_16_R2(key), value, WrappedType1_16_R2.wrap(type)); + } + + @Override + public void remove(NamespacedKey key) { + remove(new BukkitKey1_16_R2(key)); + } + + @Override + public Set getKeys() { + return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_16_R2::asBukkit).collect(Collectors.toSet()); + } + + @Override + public PersistentDataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public BukkitContext1_16_R2 getContext() { + return new BukkitContext1_16_R2(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(key.getNamespacedKey()); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public Object get(String key) { + return get(wrappedKey(key)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(key.getNamespacedKey()); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(key.getNamespacedKey(), value, type.syntaxType()); + } + + @Override + public boolean remove(String key) { + return false; + } + + @Override + public boolean remove(WrappedKey key) { + return container.remove(key.getNamespacedKey()); + } + + @Override + public Set keySet() { + return container.getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.size(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitContext1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitContext1_16_R2.java index f308371..79b0f8e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitContext1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitContext1_16_R2.java @@ -10,30 +10,30 @@ public final class BukkitContext1_16_R2 extends WrappedContext implements PersistentDataAdapterContext { - private final DataAdapterContext context; - - public BukkitContext1_16_R2(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_16_R2 newContainer() { - return new BukkitContainer1_16_R2(context.newDataContainer()); - } + private final DataAdapterContext context; + + public BukkitContext1_16_R2(DataAdapterContext context) { + this.context = context; + } + + @Override + public DataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return context.newDataContainer(); + } + + @Override + public BukkitContainer1_16_R2 newContainer() { + return new BukkitContainer1_16_R2(context.newDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitKey1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitKey1_16_R2.java index 5f65131..c78f328 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitKey1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitKey1_16_R2.java @@ -7,46 +7,46 @@ public final class BukkitKey1_16_R2 extends WrappedKey { - private final NamespacedKey key; - - public BukkitKey1_16_R2(Plugin plugin, String key) { - this.key = new NamespacedKey(plugin, key); - } - - @SuppressWarnings("deprecation") - public BukkitKey1_16_R2(String name, String key) { - this.key = new NamespacedKey(name, key); - } - - public BukkitKey1_16_R2(NamespacedKey key) { - this.key = key; - } - - @Override - public NamespacedKey getHandle() { - return key; - } - - @Override - public String getName() { - return key.getNamespace(); - } - - @Override - public String getKey() { - return key.getKey(); - } - - @Override - public String toString() { - return key.toString(); - } - - public static NamespacedKey asBukkit(WrappedKey key) { - if (key.getHandle() instanceof NamespacedKey) { - return (NamespacedKey) key.getHandle(); - } - return new BukkitKey1_16_R2(key.getName(), key.getKey()).getHandle(); - } + private final NamespacedKey key; + + public BukkitKey1_16_R2(Plugin plugin, String key) { + this.key = new NamespacedKey(plugin, key); + } + + @SuppressWarnings("deprecation") + public BukkitKey1_16_R2(String name, String key) { + this.key = new NamespacedKey(name, key); + } + + public BukkitKey1_16_R2(NamespacedKey key) { + this.key = key; + } + + @Override + public NamespacedKey getHandle() { + return key; + } + + @Override + public String getName() { + return key.getNamespace(); + } + + @Override + public String getKey() { + return key.getKey(); + } + + @Override + public String toString() { + return key.toString(); + } + + public static NamespacedKey asBukkit(WrappedKey key) { + if (key.getHandle() instanceof NamespacedKey) { + return (NamespacedKey) key.getHandle(); + } + return new BukkitKey1_16_R2(key.getName(), key.getKey()).getHandle(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitType1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitType1_16_R2.java index b6db200..e19c414 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitType1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/BukkitType1_16_R2.java @@ -7,62 +7,63 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class BukkitType1_16_R2 extends WrappedType1_16_R2, P0, P1, C0, C1> implements PersistentDataType { - - private final DataType type; - - public BukkitType1_16_R2(DataType type) { - super(type.getPrimitive(), type.getComplex()); - this.type = type; - } - - @Override - public DataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitive(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplex(); - } - - /* - * - */ - - @Override - public Class getComplexType() { - return complexType; - } - - @Override - public Class getPrimitiveType() { - return primitiveType; - } - - @Override - public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { - return wrapToPrimitive(complex, new SyntaxContext1_16_R2(context)); - } - - @Override - public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { - return wrapToComplex(primitive, new SyntaxContext1_16_R2(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); - } +public class BukkitType1_16_R2 extends WrappedType1_16_R2, P0, P1, C0, C1> + implements PersistentDataType { + + private final DataType type; + + public BukkitType1_16_R2(DataType type) { + super(type.getPrimitive(), type.getComplex()); + this.type = type; + } + + @Override + public DataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitive(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplex(); + } + + /* + * + */ + + @Override + public Class getComplexType() { + return complexType; + } + + @Override + public Class getPrimitiveType() { + return primitiveType; + } + + @Override + public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { + return wrapToPrimitive(complex, new SyntaxContext1_16_R2(context)); + } + + @Override + public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { + return wrapToComplex(primitive, new SyntaxContext1_16_R2(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SimpleBukkitType1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SimpleBukkitType1_16_R2.java index f157d7f..bade1fa 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SimpleBukkitType1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SimpleBukkitType1_16_R2.java @@ -7,30 +7,30 @@ public class SimpleBukkitType1_16_R2 implements PersistentDataType { - private final WrapType type; - - public SimpleBukkitType1_16_R2(WrapType type) { - this.type = type; - } - - @Override - public Class getComplexType() { - return type.getComplexWrapped(); - } - - @Override - public Class

getPrimitiveType() { - return type.getPrimitiveWrapped(); - } - - @Override - public P toPrimitive(C complex, PersistentDataAdapterContext context) { - return type.wrapToPrimitive(complex, new SyntaxContext1_16_R2(context)); - } - - @Override - public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { - return type.wrapToComplex(primitive, new SyntaxContext1_16_R2(context)); - } + private final WrapType type; + + public SimpleBukkitType1_16_R2(WrapType type) { + this.type = type; + } + + @Override + public Class getComplexType() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitiveType() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(C complex, PersistentDataAdapterContext context) { + return type.wrapToPrimitive(complex, new SyntaxContext1_16_R2(context)); + } + + @Override + public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { + return type.wrapToComplex(primitive, new SyntaxContext1_16_R2(context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxContainer1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxContainer1_16_R2.java index 8bb3bf1..84fd2bf 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxContainer1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxContainer1_16_R2.java @@ -9,8 +9,8 @@ import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; import com.syntaxphoenix.syntaxapi.data.DataType; import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.utils.key.NamespacedKey; import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import com.syntaxphoenix.syntaxapi.utils.key.NamespacedKey; import net.sourcewriters.minecraft.versiontools.reflection.data.WrapType; import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContainer; @@ -20,172 +20,172 @@ public final class SyntaxContainer1_16_R2 extends WrappedContainer implements IDataContainer { - public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_16_R2<>(ObjectType.INSTANCE); - - private final PersistentDataContainer container; - - public SyntaxContainer1_16_R2(PersistentDataContainer container) { - this.container = container; - } - - @Override - public PersistentDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return new SyntaxContainer1_16_R2(container); - } - - /* - * - */ - - @Override - public boolean has(IKey key) { - return has(new SyntaxKey(key)); - } - - @Override - public boolean has(String key, DataType type) { - return has(NamespacedKey.fromString(key), type); - } - - @Override - public boolean has(IKey key, DataType type) { - return has(new SyntaxKey(key), WrappedType1_16_R2.wrap(type)); - } - - @Override - public C get(String key, DataType type) { - return get(NamespacedKey.fromString(key), type); - } - - @Override - public C get(IKey key, DataType type) { - return get(new SyntaxKey(key), WrappedType1_16_R2.wrap(type)); - } - - @Override - public Object get(String key) { - return get(NamespacedKey.fromString(key)); - } - - @Override - public Object get(IKey key) { - return get(new SyntaxKey(key)); - } - - @Override - public void set(String key, E value, DataType type) { - set(wrappedKey(key), value, WrappedType1_16_R2.wrap(type)); - } - - @Override - public void set(IKey key, E value, DataType type) { - set(new SyntaxKey(key), value, WrappedType1_16_R2.wrap(type)); - } - - @Override - public boolean remove(String key) { - return remove(wrappedKey(key)); - } - - @Override - public boolean remove(IKey key) { - return remove(new SyntaxKey(key)); - } - - @Override - public IKey[] getKeys() { - return container.getKeys().stream().map(BukkitKey1_16_R2::new).map(WrappedKey::getNamespacedKey).toArray(IKey[]::new); - } - - @Override - public Set getKeyspaces() { - return container.getKeys().stream().map(org.bukkit.NamespacedKey::toString).collect(Collectors.toSet()); - } - - @Override - public DataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public SyntaxContext1_16_R2 getContext() { - return new SyntaxContext1_16_R2(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(BukkitKey1_16_R2.asBukkit(key), OBJECT_TYPE); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(BukkitKey1_16_R2.asBukkit(key), new SimpleBukkitType1_16_R2<>(type)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(BukkitKey1_16_R2.asBukkit(key), OBJECT_TYPE); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(BukkitKey1_16_R2.asBukkit(key), new SimpleBukkitType1_16_R2<>(type)); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(BukkitKey1_16_R2.asBukkit(key), new SimpleBukkitType1_16_R2<>(type), value); - } - - @Override - public boolean remove(WrappedKey key) { - Object value = get(key); - container.remove(BukkitKey1_16_R2.asBukkit(key)); - return value != null && get(key) == null; - } - - @Override - public Set keySet() { - return getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.getKeys().size(); - } + public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_16_R2<>(ObjectType.INSTANCE); + + private final PersistentDataContainer container; + + public SyntaxContainer1_16_R2(PersistentDataContainer container) { + this.container = container; + } + + @Override + public PersistentDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return new SyntaxContainer1_16_R2(container); + } + + /* + * + */ + + @Override + public boolean has(IKey key) { + return has(new SyntaxKey(key)); + } + + @Override + public boolean has(String key, DataType type) { + return has(NamespacedKey.fromString(key), type); + } + + @Override + public boolean has(IKey key, DataType type) { + return has(new SyntaxKey(key), WrappedType1_16_R2.wrap(type)); + } + + @Override + public C get(String key, DataType type) { + return get(NamespacedKey.fromString(key), type); + } + + @Override + public C get(IKey key, DataType type) { + return get(new SyntaxKey(key), WrappedType1_16_R2.wrap(type)); + } + + @Override + public Object get(String key) { + return get(NamespacedKey.fromString(key)); + } + + @Override + public Object get(IKey key) { + return get(new SyntaxKey(key)); + } + + @Override + public void set(String key, E value, DataType type) { + set(wrappedKey(key), value, WrappedType1_16_R2.wrap(type)); + } + + @Override + public void set(IKey key, E value, DataType type) { + set(new SyntaxKey(key), value, WrappedType1_16_R2.wrap(type)); + } + + @Override + public boolean remove(String key) { + return remove(wrappedKey(key)); + } + + @Override + public boolean remove(IKey key) { + return remove(new SyntaxKey(key)); + } + + @Override + public IKey[] getKeys() { + return container.getKeys().stream().map(BukkitKey1_16_R2::new).map(WrappedKey::getNamespacedKey).toArray(IKey[]::new); + } + + @Override + public Set getKeyspaces() { + return container.getKeys().stream().map(org.bukkit.NamespacedKey::toString).collect(Collectors.toSet()); + } + + @Override + public DataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public SyntaxContext1_16_R2 getContext() { + return new SyntaxContext1_16_R2(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(BukkitKey1_16_R2.asBukkit(key), OBJECT_TYPE); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(BukkitKey1_16_R2.asBukkit(key), new SimpleBukkitType1_16_R2<>(type)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(BukkitKey1_16_R2.asBukkit(key), OBJECT_TYPE); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(BukkitKey1_16_R2.asBukkit(key), new SimpleBukkitType1_16_R2<>(type)); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(BukkitKey1_16_R2.asBukkit(key), new SimpleBukkitType1_16_R2<>(type), value); + } + + @Override + public boolean remove(WrappedKey key) { + Object value = get(key); + container.remove(BukkitKey1_16_R2.asBukkit(key)); + return value != null && get(key) == null; + } + + @Override + public Set keySet() { + return getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.getKeys().size(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxContext1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxContext1_16_R2.java index c8faa89..b92d198 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxContext1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxContext1_16_R2.java @@ -9,30 +9,30 @@ public final class SyntaxContext1_16_R2 extends WrappedContext implements PersistentDataAdapterContext { - private final PersistentDataAdapterContext context; - - public SyntaxContext1_16_R2(PersistentDataAdapterContext context) { - this.context = context; - } - - @Override - public PersistentDataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return context.newPersistentDataContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return newContainer(); - } - - @Override - public SyntaxContainer1_16_R2 newContainer() { - return new SyntaxContainer1_16_R2(context.newPersistentDataContainer()); - } + private final PersistentDataAdapterContext context; + + public SyntaxContext1_16_R2(PersistentDataAdapterContext context) { + this.context = context; + } + + @Override + public PersistentDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return context.newPersistentDataContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return newContainer(); + } + + @Override + public SyntaxContainer1_16_R2 newContainer() { + return new SyntaxContainer1_16_R2(context.newPersistentDataContainer()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxType1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxType1_16_R2.java index c99eb9b..5880c95 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxType1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/SyntaxType1_16_R2.java @@ -8,68 +8,69 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class SyntaxType1_16_R2 extends WrappedType1_16_R2, P0, P1, C0, C1> implements DataType { - - private final PersistentDataType type; - - public SyntaxType1_16_R2(PersistentDataType type) { - super(type.getPrimitiveType(), type.getComplexType()); - this.type = type; - } - - @Override - public PersistentDataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitiveType(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplexType(); - } - - /* - * - */ - - @Override - public Class getComplex() { - return complexType; - } - - @Override - public Class getPrimitive() { - return primitiveType; - } - - @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { - return wrapToPrimitive(complex, new BukkitContext1_16_R2(context)); - } - - @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { - return wrapToComplex(primitive, new BukkitContext1_16_R2(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); - } +public class SyntaxType1_16_R2 extends WrappedType1_16_R2, P0, P1, C0, C1> + implements DataType { + + private final PersistentDataType type; + + public SyntaxType1_16_R2(PersistentDataType type) { + super(type.getPrimitiveType(), type.getComplexType()); + this.type = type; + } + + @Override + public PersistentDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitiveType(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplexType(); + } + + /* + * + */ + + @Override + public Class getComplex() { + return complexType; + } + + @Override + public Class getPrimitive() { + return primitiveType; + } + + @Override + public P0 toPrimitive(DataAdapterContext context, C0 complex) { + return wrapToPrimitive(complex, new BukkitContext1_16_R2(context)); + } + + @Override + public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + return wrapToComplex(primitive, new BukkitContext1_16_R2(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/WrappedType1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/WrappedType1_16_R2.java index 3b0c9af..214e142 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/WrappedType1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/data/WrappedType1_16_R2.java @@ -12,135 +12,139 @@ public abstract class WrappedType1_16_R2 implements WrapType { - protected final Class primitiveType; - protected final Class complexType; - - private final int primitiveWrap; - private final int complexWrap; - - @SuppressWarnings("unchecked") - protected WrappedType1_16_R2(Class primitive, Class complex) { - this.primitiveWrap = WrappedType1_16_R2.internalState(primitive); - this.complexWrap = WrappedType1_16_R2.internalState(complex); - this.primitiveType = (Class) WrappedType1_16_R2.internalWrap(primitive, primitiveWrap); - this.complexType = (Class) WrappedType1_16_R2.internalWrap(complex, complexWrap); - } - - public abstract H getHandle(); - - public Class getPrimitiveWrapped() { - return primitiveType; - } - - public Class getComplexWrapped() { - return complexType; - } - - public abstract Class getPrimitiveOriginal(); - - public abstract Class getComplexOriginal(); - - @SuppressWarnings("unchecked") - public P0 toPrimitiveWrapped(P1 primitive) { - switch (primitiveWrap) { - case 1: - return (P0) new SyntaxContainer1_16_R2((PersistentDataContainer) primitive); - case 2: - return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R2::new).toArray(IDataContainer[]::new); - case 3: - return (P0) new BukkitContainer1_16_R2((IDataContainer) primitive); - case 4: - return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R2::new).toArray(PersistentDataContainer[]::new); - default: - return (P0) primitive; - } - } - - @SuppressWarnings("unchecked") - public C0 toComplexWrapped(C1 complex) { - switch (complexWrap) { - case 1: - return (C0) new SyntaxContainer1_16_R2((PersistentDataContainer) complex); - case 2: - return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R2::new).toArray(IDataContainer[]::new); - case 3: - return (C0) new BukkitContainer1_16_R2((IDataContainer) complex); - case 4: - return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R2::new).toArray(PersistentDataContainer[]::new); - default: - return (C0) complex; - } - } - - @SuppressWarnings("unchecked") - public P1 toPrimitiveOriginal(P0 primitive) { - switch (primitiveWrap) { - case 1: - return (P1) new BukkitContainer1_16_R2((IDataContainer) primitive); - case 2: - return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R2::new).toArray(PersistentDataContainer[]::new); - case 3: - return (P1) new SyntaxContainer1_16_R2((PersistentDataContainer) primitive); - case 4: - return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R2::new).toArray(IDataContainer[]::new); - default: - return (P1) primitive; - } - } - - @SuppressWarnings("unchecked") - public C1 toComplexOriginal(C0 complex) { - switch (complexWrap) { - case 1: - return (C1) new BukkitContainer1_16_R2((IDataContainer) complex); - case 2: - return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R2::new).toArray(PersistentDataContainer[]::new); - case 3: - return (C1) new SyntaxContainer1_16_R2((PersistentDataContainer) complex); - case 4: - return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R2::new).toArray(IDataContainer[]::new); - default: - return (C1) complex; - } - } - - protected static Class internalWrap(Class clazz, int state) { - switch (state) { - case 1: - return IDataContainer.class; - case 2: - return IDataContainer[].class; - case 3: - return PersistentDataContainer.class; - case 4: - return PersistentDataContainer[].class; - default: - return clazz; - } - } - - protected static int internalState(Class clazz) { - if (clazz.equals(PersistentDataContainer.class)) { - return 1; - } - if (clazz.equals(PersistentDataContainer[].class)) { - return 2; - } - if (clazz.equals(IDataContainer.class)) { - return 3; - } - if (clazz.equals(IDataContainer[].class)) { - return 4; - } - return 0; - } - - public static BukkitType1_16_R2 wrap(DataType type) { - return new BukkitType1_16_R2<>(type); - } - - public static SyntaxType1_16_R2 wrap(PersistentDataType type) { - return new SyntaxType1_16_R2<>(type); - } + protected final Class primitiveType; + protected final Class complexType; + + private final int primitiveWrap; + private final int complexWrap; + + @SuppressWarnings("unchecked") + protected WrappedType1_16_R2(Class primitive, Class complex) { + this.primitiveWrap = WrappedType1_16_R2.internalState(primitive); + this.complexWrap = WrappedType1_16_R2.internalState(complex); + this.primitiveType = (Class) WrappedType1_16_R2.internalWrap(primitive, primitiveWrap); + this.complexType = (Class) WrappedType1_16_R2.internalWrap(complex, complexWrap); + } + + public abstract H getHandle(); + + public Class getPrimitiveWrapped() { + return primitiveType; + } + + public Class getComplexWrapped() { + return complexType; + } + + public abstract Class getPrimitiveOriginal(); + + public abstract Class getComplexOriginal(); + + @SuppressWarnings("unchecked") + public P0 toPrimitiveWrapped(P1 primitive) { + switch (primitiveWrap) { + case 1: + return (P0) new SyntaxContainer1_16_R2((PersistentDataContainer) primitive); + case 2: + return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R2::new) + .toArray(IDataContainer[]::new); + case 3: + return (P0) new BukkitContainer1_16_R2((IDataContainer) primitive); + case 4: + return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R2::new) + .toArray(PersistentDataContainer[]::new); + default: + return (P0) primitive; + } + } + + @SuppressWarnings("unchecked") + public C0 toComplexWrapped(C1 complex) { + switch (complexWrap) { + case 1: + return (C0) new SyntaxContainer1_16_R2((PersistentDataContainer) complex); + case 2: + return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R2::new).toArray(IDataContainer[]::new); + case 3: + return (C0) new BukkitContainer1_16_R2((IDataContainer) complex); + case 4: + return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R2::new).toArray(PersistentDataContainer[]::new); + default: + return (C0) complex; + } + } + + @SuppressWarnings("unchecked") + public P1 toPrimitiveOriginal(P0 primitive) { + switch (primitiveWrap) { + case 1: + return (P1) new BukkitContainer1_16_R2((IDataContainer) primitive); + case 2: + return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R2::new) + .toArray(PersistentDataContainer[]::new); + case 3: + return (P1) new SyntaxContainer1_16_R2((PersistentDataContainer) primitive); + case 4: + return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R2::new) + .toArray(IDataContainer[]::new); + default: + return (P1) primitive; + } + } + + @SuppressWarnings("unchecked") + public C1 toComplexOriginal(C0 complex) { + switch (complexWrap) { + case 1: + return (C1) new BukkitContainer1_16_R2((IDataContainer) complex); + case 2: + return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R2::new).toArray(PersistentDataContainer[]::new); + case 3: + return (C1) new SyntaxContainer1_16_R2((PersistentDataContainer) complex); + case 4: + return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R2::new).toArray(IDataContainer[]::new); + default: + return (C1) complex; + } + } + + protected static Class internalWrap(Class clazz, int state) { + switch (state) { + case 1: + return IDataContainer.class; + case 2: + return IDataContainer[].class; + case 3: + return PersistentDataContainer.class; + case 4: + return PersistentDataContainer[].class; + default: + return clazz; + } + } + + protected static int internalState(Class clazz) { + if (clazz.equals(PersistentDataContainer.class)) { + return 1; + } + if (clazz.equals(PersistentDataContainer[].class)) { + return 2; + } + if (clazz.equals(IDataContainer.class)) { + return 3; + } + if (clazz.equals(IDataContainer[].class)) { + return 4; + } + return 0; + } + + public static BukkitType1_16_R2 wrap(DataType type) { + return new BukkitType1_16_R2<>(type); + } + + public static SyntaxType1_16_R2 wrap(PersistentDataType type) { + return new SyntaxType1_16_R2<>(type); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/ArmorStand1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/ArmorStand1_16_R2.java index 9d9ef8c..16ee74a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/ArmorStand1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/ArmorStand1_16_R2.java @@ -7,18 +7,18 @@ public class ArmorStand1_16_R2 extends EntityLiving1_16_R2 implements NmsArmorStand { - public ArmorStand1_16_R2(World world) { - super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); - } + public ArmorStand1_16_R2(World world) { + super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/Entity1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/Entity1_16_R2.java index 406d1cf..c9003a6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/Entity1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/Entity1_16_R2.java @@ -13,198 +13,200 @@ import org.bukkit.craftbukkit.v1_16_R2.util.CraftChatMessage; import org.bukkit.entity.Player; +import net.minecraft.server.v1_16_R2.AxisAlignedBB; import net.minecraft.server.v1_16_R2.Entity; import net.minecraft.server.v1_16_R2.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata; import net.minecraft.server.v1_16_R2.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_16_R2.PlayerConnection; import net.minecraft.server.v1_16_R2.Vec3D; -import net.minecraft.server.v1_16_R2.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_16_R2 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_16_R2(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); - } - - @Override - public String getCustomName() { - return CraftChatMessage.fromComponent(handle.getCustomName()); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.getPositionVector(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_16_R2(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.getPositionVector(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/EntityLiving1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/EntityLiving1_16_R2.java index fc06c0d..e220236 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/EntityLiving1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/EntityLiving1_16_R2.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_16_R2 extends Entity1_16_R2 implements NmsEntityLiving { - public EntityLiving1_16_R2(E handle) { - super(handle); - } + public EntityLiving1_16_R2(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/Player1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/Player1_16_R2.java index 29fc50e..60a8d44 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/Player1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/entity/Player1_16_R2.java @@ -36,8 +36,8 @@ import net.minecraft.server.v1_16_R2.PacketPlayOutTitle.EnumTitleAction; import net.minecraft.server.v1_16_R2.PlayerConnection; import net.minecraft.server.v1_16_R2.WorldServer; -import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContainer; import net.sourcewriters.minecraft.versiontools.reflection.data.WrapType; +import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContainer; import net.sourcewriters.minecraft.versiontools.reflection.data.type.SkinDataType; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsPlayer; import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R2.data.SyntaxContainer1_16_R2; @@ -49,229 +49,230 @@ public class Player1_16_R2 extends EntityLiving1_16_R2 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_16_R2(Player player) { - super(((CraftPlayer) player).getHandle()); - dataAdapter = new SyntaxContainer1_16_R2(getBukkitPlayer().getPersistentDataContainer()); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - dataAdapter.set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - dataAdapter.remove("name"); - return; - } - dataAdapter.set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return dataAdapter.getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return dataAdapter.getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - dataAdapter.set("header", header, WrapType.STRING); - dataAdapter.set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - packet.header = headerComponent; - packet.footer = footerComponent; - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList> list = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - list.add(Pair.of(slot, handle.getEquipment(slot))); - } - PacketPlayOutEntityEquipment equipmentPacket = new PacketPlayOutEntityEquipment(handle.getId(), list); - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - connection.sendPacket(equipmentPacket); - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(world.getDimensionManager(), world.getDimensionKey(), BiomeManager.a(world.getSeed()), - handle.playerInteractManager.getGameMode(), handle.playerInteractManager.c(), world.isDebugWorld(), world.isFlatWorld(), true); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX(), handle.locY(), handle.locZ(), handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_16_R2(Player player) { + super(((CraftPlayer) player).getHandle()); + dataAdapter = new SyntaxContainer1_16_R2(getBukkitPlayer().getPersistentDataContainer()); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + dataAdapter.set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + dataAdapter.remove("name"); + return; + } + dataAdapter.set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return dataAdapter.getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return dataAdapter.getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + dataAdapter.set("header", header, WrapType.STRING); + dataAdapter.set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + packet.header = headerComponent; + packet.footer = footerComponent; + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList> list = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + list.add(Pair.of(slot, handle.getEquipment(slot))); + } + PacketPlayOutEntityEquipment equipmentPacket = new PacketPlayOutEntityEquipment(handle.getId(), list); + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + connection.sendPacket(equipmentPacket); + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(world.getDimensionManager(), world.getDimensionKey(), + BiomeManager.a(world.getSeed()), handle.playerInteractManager.getGameMode(), handle.playerInteractManager.c(), + world.isDebugWorld(), world.isFlatWorld(), true); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX(), handle.locY(), handle.locZ(), handle.yaw, + handle.pitch, Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/BlockTools1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/BlockTools1_16_R2.java index 6ec826e..629225b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/BlockTools1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/BlockTools1_16_R2.java @@ -14,26 +14,26 @@ public class BlockTools1_16_R2 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.gameProfile.getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.gameProfile.getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/ServerTools1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/ServerTools1_16_R2.java index 5618f4b..0f46fbd 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/ServerTools1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/ServerTools1_16_R2.java @@ -7,14 +7,14 @@ public class ServerTools1_16_R2 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/SkinTools1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/SkinTools1_16_R2.java index a36b51d..6a4eec6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/SkinTools1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/tools/SkinTools1_16_R2.java @@ -8,9 +8,9 @@ public class SkinTools1_16_R2 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/utils/EntityConstructors1_16_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/utils/EntityConstructors1_16_R2.java index 289643a..5e2ee92 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/utils/EntityConstructors1_16_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R2/utils/EntityConstructors1_16_R2.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_16_R2 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_16_R2(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_16_R2(world)); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/BukkitConversion1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/BukkitConversion1_16_R3.java index 0ca728d..12d67bd 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/BukkitConversion1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/BukkitConversion1_16_R3.java @@ -6,7 +6,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_16_R3.ItemStack; import net.minecraft.server.v1_16_R3.NBTBase; @@ -31,166 +45,166 @@ public class BukkitConversion1_16_R3 extends BukkitConversion { - protected BukkitConversion1_16_R3(VersionControl1_16_R3 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return NBTTagByte.a((byte) tag.getValue()); - case SHORT: - return NBTTagShort.a((short) tag.getValue()); - case INT: - return NBTTagInt.a((int) tag.getValue()); - case LONG: - return NBTTagLong.a((long) tag.getValue()); - case FLOAT: - return NBTTagFloat.a((float) tag.getValue()); - case DOUBLE: - return NBTTagDouble.a((double) tag.getValue()); - case STRING: - return NBTTagString.a((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - return new NBTTagLongArray((long[]) tag.getValue()); - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return NBTTagEnd.b; - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTNumber) tag).asByte()); - case SHORT: - return new NbtShort(((NBTNumber) tag).asShort()); - case INT: - return new NbtInt(((NBTNumber) tag).asInt()); - case LONG: - return new NbtLong(((NBTNumber) tag).asLong()); - case FLOAT: - return new NbtFloat(((NBTNumber) tag).asFloat()); - case DOUBLE: - return new NbtDouble(((NBTNumber) tag).asDouble()); - case STRING: - return new NbtString(((NBTTagString) tag).asString()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).getInts()); - case LONG_ARRAY: - return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : list) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).save(new NBTTagCompound())); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new BukkitContext1_16_R3(context); - } + protected BukkitConversion1_16_R3(VersionControl1_16_R3 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return NBTTagByte.a((byte) tag.getValue()); + case SHORT: + return NBTTagShort.a((short) tag.getValue()); + case INT: + return NBTTagInt.a((int) tag.getValue()); + case LONG: + return NBTTagLong.a((long) tag.getValue()); + case FLOAT: + return NBTTagFloat.a((float) tag.getValue()); + case DOUBLE: + return NBTTagDouble.a((double) tag.getValue()); + case STRING: + return NBTTagString.a((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + return new NBTTagLongArray((long[]) tag.getValue()); + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return NBTTagEnd.b; + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTNumber) tag).asByte()); + case SHORT: + return new NbtShort(((NBTNumber) tag).asShort()); + case INT: + return new NbtInt(((NBTNumber) tag).asInt()); + case LONG: + return new NbtLong(((NBTNumber) tag).asLong()); + case FLOAT: + return new NbtFloat(((NBTNumber) tag).asFloat()); + case DOUBLE: + return new NbtDouble(((NBTNumber) tag).asDouble()); + case STRING: + return new NbtString(((NBTTagString) tag).asString()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).getBytes()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).getInts()); + case LONG_ARRAY: + return new NbtLongArray(((NBTTagLongArray) tag).getLongs()); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : list) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.a(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + return fromMinecraftCompound(CraftItemStack.asNMSCopy(itemStack).save(new NBTTagCompound())); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new BukkitContext1_16_R3(context); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/EntityProvider1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/EntityProvider1_16_R3.java index d9071a2..e81e218 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/EntityProvider1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/EntityProvider1_16_R3.java @@ -13,35 +13,35 @@ public class EntityProvider1_16_R3 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_16_R3(VersionControl1_16_R3 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_16_R3.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_16_R3(VersionControl1_16_R3 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_16_R3.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/PacketHandler1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/PacketHandler1_16_R3.java index 816e37c..0a1b144 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/PacketHandler1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/PacketHandler1_16_R3.java @@ -4,8 +4,8 @@ public class PacketHandler1_16_R3 extends PacketHandler { - protected PacketHandler1_16_R3(VersionControl1_16_R3 versionControl) { - super(versionControl); - } + protected PacketHandler1_16_R3(VersionControl1_16_R3 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/PlayerProvider1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/PlayerProvider1_16_R3.java index f89f239..7cfa092 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/PlayerProvider1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/PlayerProvider1_16_R3.java @@ -8,13 +8,13 @@ public class PlayerProvider1_16_R3 extends PlayerProvider { - protected PlayerProvider1_16_R3(VersionControl1_16_R3 versionControl) { - super(versionControl); - } + protected PlayerProvider1_16_R3(VersionControl1_16_R3 versionControl) { + super(versionControl); + } - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_16_R3(player); - } + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_16_R3(player); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/TextureProvider1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/TextureProvider1_16_R3.java index 6df8cc2..1f3af18 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/TextureProvider1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/TextureProvider1_16_R3.java @@ -20,83 +20,83 @@ public class TextureProvider1_16_R3 extends TextureProvider { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final AbstractReflect craftEntityStateRef = new Reflect(CraftBlockEntityState.class).searchField("tileEntity", "tileEntity"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - protected TextureProvider1_16_R3(VersionControl1_16_R3 versionControl) { - super(versionControl); - } + protected TextureProvider1_16_R3(VersionControl1_16_R3 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile; - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile; + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag = stack.getOrCreateTag(); - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag = stack.getOrCreateTag(); + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(Material.PLAYER_HEAD)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - entitySkull.setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + entitySkull.setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/ToolProvider1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/ToolProvider1_16_R3.java index d60d7b6..7506aa2 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/ToolProvider1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/ToolProvider1_16_R3.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R3; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R3.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R3.tools.BlockTools1_16_R3; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R3.tools.ServerTools1_16_R3; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R3.tools.SkinTools1_16_R3; public class ToolProvider1_16_R3 extends ToolProvider { - - private final BlockTools1_16_R3 blockTools = new BlockTools1_16_R3(); - private final SkinTools1_16_R3 skinTools = new SkinTools1_16_R3(); - private final ServerTools1_16_R3 serverTools = new ServerTools1_16_R3(); - - protected ToolProvider1_16_R3(VersionControl1_16_R3 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_16_R3 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_16_R3 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_16_R3 getBlockTools() { - return blockTools; - } + + private final BlockTools1_16_R3 blockTools = new BlockTools1_16_R3(); + private final SkinTools1_16_R3 skinTools = new SkinTools1_16_R3(); + private final ServerTools1_16_R3 serverTools = new ServerTools1_16_R3(); + + protected ToolProvider1_16_R3(VersionControl1_16_R3 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_16_R3 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_16_R3 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_16_R3 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/VersionControl1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/VersionControl1_16_R3.java index b706798..8ccbbbf 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/VersionControl1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/VersionControl1_16_R3.java @@ -4,51 +4,51 @@ public class VersionControl1_16_R3 extends VersionControl { - public static VersionControl1_16_R3 INSTANCE; - - public static VersionControl1_16_R3 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_16_R3()); - } - - private final ToolProvider1_16_R3 toolProvider = new ToolProvider1_16_R3(this); - private final TextureProvider1_16_R3 textureProvider = new TextureProvider1_16_R3(this); - private final PacketHandler1_16_R3 packetHandler = new PacketHandler1_16_R3(this); - private final EntityProvider1_16_R3 entityProvider = new EntityProvider1_16_R3(this); - private final PlayerProvider1_16_R3 playerProvider = new PlayerProvider1_16_R3(this); - private final BukkitConversion1_16_R3 bukkitConversion = new BukkitConversion1_16_R3(this); - - private VersionControl1_16_R3() { - - } - - @Override - public ToolProvider1_16_R3 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_16_R3 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_16_R3 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_16_R3 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_16_R3 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_16_R3 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_16_R3 INSTANCE; + + public static VersionControl1_16_R3 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_16_R3()); + } + + private final ToolProvider1_16_R3 toolProvider = new ToolProvider1_16_R3(this); + private final TextureProvider1_16_R3 textureProvider = new TextureProvider1_16_R3(this); + private final PacketHandler1_16_R3 packetHandler = new PacketHandler1_16_R3(this); + private final EntityProvider1_16_R3 entityProvider = new EntityProvider1_16_R3(this); + private final PlayerProvider1_16_R3 playerProvider = new PlayerProvider1_16_R3(this); + private final BukkitConversion1_16_R3 bukkitConversion = new BukkitConversion1_16_R3(this); + + private VersionControl1_16_R3() { + + } + + @Override + public ToolProvider1_16_R3 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_16_R3 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_16_R3 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_16_R3 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_16_R3 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_16_R3 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitContainer1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitContainer1_16_R3.java index 08f0575..63c0cfb 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitContainer1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitContainer1_16_R3.java @@ -19,143 +19,143 @@ public final class BukkitContainer1_16_R3 extends WrappedContainer implements PersistentDataContainer { - private final IDataContainer container; - - public BukkitContainer1_16_R3(IDataContainer container) { - this.container = container; - } - - @Override - public IDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return container; - } - - /* - * - */ - - @Override - public boolean has(NamespacedKey key, PersistentDataType type) { - return has(new BukkitKey1_16_R3(key), WrappedType1_16_R3.wrap(type)); - } - - @Override - public Z get(NamespacedKey key, PersistentDataType type) { - return get(new BukkitKey1_16_R3(key), WrappedType1_16_R3.wrap(type)); - } - - @Override - public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { - return Optional.ofNullable(get(key, type)).orElse(value); - } - - @Override - public void set(NamespacedKey key, PersistentDataType type, Z value) { - set(new BukkitKey1_16_R3(key), value, WrappedType1_16_R3.wrap(type)); - } - - @Override - public void remove(NamespacedKey key) { - remove(new BukkitKey1_16_R3(key)); - } - - @Override - public Set getKeys() { - return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_16_R3::asBukkit).collect(Collectors.toSet()); - } - - @Override - public PersistentDataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public BukkitContext1_16_R3 getContext() { - return new BukkitContext1_16_R3(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(key.getNamespacedKey()); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public Object get(String key) { - return get(wrappedKey(key)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(key.getNamespacedKey()); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(key.getNamespacedKey(), type.syntaxType()); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(key.getNamespacedKey(), value, type.syntaxType()); - } - - @Override - public boolean remove(String key) { - return false; - } - - @Override - public boolean remove(WrappedKey key) { - return container.remove(key.getNamespacedKey()); - } - - @Override - public Set keySet() { - return container.getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.size(); - } + private final IDataContainer container; + + public BukkitContainer1_16_R3(IDataContainer container) { + this.container = container; + } + + @Override + public IDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return container; + } + + /* + * + */ + + @Override + public boolean has(NamespacedKey key, PersistentDataType type) { + return has(new BukkitKey1_16_R3(key), WrappedType1_16_R3.wrap(type)); + } + + @Override + public Z get(NamespacedKey key, PersistentDataType type) { + return get(new BukkitKey1_16_R3(key), WrappedType1_16_R3.wrap(type)); + } + + @Override + public Z getOrDefault(NamespacedKey key, PersistentDataType type, Z value) { + return Optional.ofNullable(get(key, type)).orElse(value); + } + + @Override + public void set(NamespacedKey key, PersistentDataType type, Z value) { + set(new BukkitKey1_16_R3(key), value, WrappedType1_16_R3.wrap(type)); + } + + @Override + public void remove(NamespacedKey key) { + remove(new BukkitKey1_16_R3(key)); + } + + @Override + public Set getKeys() { + return Arrays.stream(container.getKeys()).map(SyntaxKey::new).map(BukkitKey1_16_R3::asBukkit).collect(Collectors.toSet()); + } + + @Override + public PersistentDataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public BukkitContext1_16_R3 getContext() { + return new BukkitContext1_16_R3(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(key.getNamespacedKey()); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public Object get(String key) { + return get(wrappedKey(key)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(key.getNamespacedKey()); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(key.getNamespacedKey(), type.syntaxType()); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(key.getNamespacedKey(), value, type.syntaxType()); + } + + @Override + public boolean remove(String key) { + return false; + } + + @Override + public boolean remove(WrappedKey key) { + return container.remove(key.getNamespacedKey()); + } + + @Override + public Set keySet() { + return container.getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.size(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitContext1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitContext1_16_R3.java index b89d793..7e05053 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitContext1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitContext1_16_R3.java @@ -10,30 +10,30 @@ public final class BukkitContext1_16_R3 extends WrappedContext implements PersistentDataAdapterContext { - private final DataAdapterContext context; - - public BukkitContext1_16_R3(DataAdapterContext context) { - this.context = context; - } - - @Override - public DataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return newContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return context.newDataContainer(); - } - - @Override - public BukkitContainer1_16_R3 newContainer() { - return new BukkitContainer1_16_R3(context.newDataContainer()); - } + private final DataAdapterContext context; + + public BukkitContext1_16_R3(DataAdapterContext context) { + this.context = context; + } + + @Override + public DataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return newContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return context.newDataContainer(); + } + + @Override + public BukkitContainer1_16_R3 newContainer() { + return new BukkitContainer1_16_R3(context.newDataContainer()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitKey1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitKey1_16_R3.java index 4b0e9be..6b6edf6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitKey1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitKey1_16_R3.java @@ -7,46 +7,46 @@ public final class BukkitKey1_16_R3 extends WrappedKey { - private final NamespacedKey key; - - public BukkitKey1_16_R3(Plugin plugin, String key) { - this.key = new NamespacedKey(plugin, key); - } - - @SuppressWarnings("deprecation") - public BukkitKey1_16_R3(String name, String key) { - this.key = new NamespacedKey(name, key); - } - - public BukkitKey1_16_R3(NamespacedKey key) { - this.key = key; - } - - @Override - public NamespacedKey getHandle() { - return key; - } - - @Override - public String getName() { - return key.getNamespace(); - } - - @Override - public String getKey() { - return key.getKey(); - } - - @Override - public String toString() { - return key.toString(); - } - - public static NamespacedKey asBukkit(WrappedKey key) { - if (key.getHandle() instanceof NamespacedKey) { - return (NamespacedKey) key.getHandle(); - } - return new BukkitKey1_16_R3(key.getName(), key.getKey()).getHandle(); - } + private final NamespacedKey key; + + public BukkitKey1_16_R3(Plugin plugin, String key) { + this.key = new NamespacedKey(plugin, key); + } + + @SuppressWarnings("deprecation") + public BukkitKey1_16_R3(String name, String key) { + this.key = new NamespacedKey(name, key); + } + + public BukkitKey1_16_R3(NamespacedKey key) { + this.key = key; + } + + @Override + public NamespacedKey getHandle() { + return key; + } + + @Override + public String getName() { + return key.getNamespace(); + } + + @Override + public String getKey() { + return key.getKey(); + } + + @Override + public String toString() { + return key.toString(); + } + + public static NamespacedKey asBukkit(WrappedKey key) { + if (key.getHandle() instanceof NamespacedKey) { + return (NamespacedKey) key.getHandle(); + } + return new BukkitKey1_16_R3(key.getName(), key.getKey()).getHandle(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitType1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitType1_16_R3.java index 2da3326..c4750d2 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitType1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/BukkitType1_16_R3.java @@ -7,62 +7,63 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class BukkitType1_16_R3 extends WrappedType1_16_R3, P0, P1, C0, C1> implements PersistentDataType { - - private final DataType type; - - public BukkitType1_16_R3(DataType type) { - super(type.getPrimitive(), type.getComplex()); - this.type = type; - } - - @Override - public DataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitive(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplex(); - } - - /* - * - */ - - @Override - public Class getComplexType() { - return complexType; - } - - @Override - public Class getPrimitiveType() { - return primitiveType; - } - - @Override - public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { - return wrapToPrimitive(complex, new SyntaxContext1_16_R3(context)); - } - - @Override - public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { - return wrapToComplex(primitive, new SyntaxContext1_16_R3(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); - } +public class BukkitType1_16_R3 extends WrappedType1_16_R3, P0, P1, C0, C1> + implements PersistentDataType { + + private final DataType type; + + public BukkitType1_16_R3(DataType type) { + super(type.getPrimitive(), type.getComplex()); + this.type = type; + } + + @Override + public DataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitive(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplex(); + } + + /* + * + */ + + @Override + public Class getComplexType() { + return complexType; + } + + @Override + public Class getPrimitiveType() { + return primitiveType; + } + + @Override + public P0 toPrimitive(C0 complex, PersistentDataAdapterContext context) { + return wrapToPrimitive(complex, new SyntaxContext1_16_R3(context)); + } + + @Override + public C0 fromPrimitive(P0 primitive, PersistentDataAdapterContext context) { + return wrapToComplex(primitive, new SyntaxContext1_16_R3(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + return toPrimitiveWrapped(type.toPrimitive(context, toComplexOriginal(complex))); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + return toComplexWrapped(type.fromPrimitive(context, toPrimitiveOriginal(primitive))); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SimpleBukkitType1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SimpleBukkitType1_16_R3.java index 5d2cb44..bd9b214 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SimpleBukkitType1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SimpleBukkitType1_16_R3.java @@ -7,30 +7,30 @@ public class SimpleBukkitType1_16_R3 implements PersistentDataType { - private final WrapType type; - - public SimpleBukkitType1_16_R3(WrapType type) { - this.type = type; - } - - @Override - public Class getComplexType() { - return type.getComplexWrapped(); - } - - @Override - public Class

getPrimitiveType() { - return type.getPrimitiveWrapped(); - } - - @Override - public P toPrimitive(C complex, PersistentDataAdapterContext context) { - return type.wrapToPrimitive(complex, new SyntaxContext1_16_R3(context)); - } - - @Override - public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { - return type.wrapToComplex(primitive, new SyntaxContext1_16_R3(context)); - } + private final WrapType type; + + public SimpleBukkitType1_16_R3(WrapType type) { + this.type = type; + } + + @Override + public Class getComplexType() { + return type.getComplexWrapped(); + } + + @Override + public Class

getPrimitiveType() { + return type.getPrimitiveWrapped(); + } + + @Override + public P toPrimitive(C complex, PersistentDataAdapterContext context) { + return type.wrapToPrimitive(complex, new SyntaxContext1_16_R3(context)); + } + + @Override + public C fromPrimitive(P primitive, PersistentDataAdapterContext context) { + return type.wrapToComplex(primitive, new SyntaxContext1_16_R3(context)); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxContainer1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxContainer1_16_R3.java index a1f9537..d876e63 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxContainer1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxContainer1_16_R3.java @@ -9,8 +9,8 @@ import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; import com.syntaxphoenix.syntaxapi.data.DataType; import com.syntaxphoenix.syntaxapi.data.IDataContainer; -import com.syntaxphoenix.syntaxapi.utils.key.NamespacedKey; import com.syntaxphoenix.syntaxapi.utils.key.IKey; +import com.syntaxphoenix.syntaxapi.utils.key.NamespacedKey; import net.sourcewriters.minecraft.versiontools.reflection.data.WrapType; import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContainer; @@ -20,172 +20,172 @@ public final class SyntaxContainer1_16_R3 extends WrappedContainer implements IDataContainer { - public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_16_R3<>(ObjectType.INSTANCE); - - private final PersistentDataContainer container; - - public SyntaxContainer1_16_R3(PersistentDataContainer container) { - this.container = container; - } - - @Override - public PersistentDataContainer getHandle() { - return container; - } - - @Override - public IDataContainer getAsSyntaxContainer() { - return new SyntaxContainer1_16_R3(container); - } - - /* - * - */ - - @Override - public boolean has(IKey key) { - return has(new SyntaxKey(key)); - } - - @Override - public boolean has(String key, DataType type) { - return has(NamespacedKey.fromString(key), type); - } - - @Override - public boolean has(IKey key, DataType type) { - return has(new SyntaxKey(key), WrappedType1_16_R3.wrap(type)); - } - - @Override - public C get(String key, DataType type) { - return get(NamespacedKey.fromString(key), type); - } - - @Override - public C get(IKey key, DataType type) { - return get(new SyntaxKey(key), WrappedType1_16_R3.wrap(type)); - } - - @Override - public Object get(String key) { - return get(NamespacedKey.fromString(key)); - } - - @Override - public Object get(IKey key) { - return get(new SyntaxKey(key)); - } - - @Override - public void set(String key, E value, DataType type) { - set(wrappedKey(key), value, WrappedType1_16_R3.wrap(type)); - } - - @Override - public void set(IKey key, E value, DataType type) { - set(new SyntaxKey(key), value, WrappedType1_16_R3.wrap(type)); - } - - @Override - public boolean remove(String key) { - return remove(wrappedKey(key)); - } - - @Override - public boolean remove(IKey key) { - return remove(new SyntaxKey(key)); - } - - @Override - public IKey[] getKeys() { - return container.getKeys().stream().map(BukkitKey1_16_R3::new).map(WrappedKey::getNamespacedKey).toArray(IKey[]::new); - } - - @Override - public Set getKeyspaces() { - return container.getKeys().stream().map(org.bukkit.NamespacedKey::toString).collect(Collectors.toSet()); - } - - @Override - public DataAdapterContext getAdapterContext() { - return getContext(); - } - - /* - * - */ - - @Override - public SyntaxContext1_16_R3 getContext() { - return new SyntaxContext1_16_R3(container.getAdapterContext()); - } - - @Override - public boolean has(String key) { - return has(wrappedKey(key)); - } - - @Override - public boolean has(WrappedKey key) { - return container.has(BukkitKey1_16_R3.asBukkit(key), OBJECT_TYPE); - } - - @Override - public boolean has(String key, WrapType type) { - return has(wrappedKey(key), type); - } - - @Override - public boolean has(WrappedKey key, WrapType type) { - return container.has(BukkitKey1_16_R3.asBukkit(key), new SimpleBukkitType1_16_R3<>(type)); - } - - @Override - public Object get(WrappedKey key) { - return container.get(BukkitKey1_16_R3.asBukkit(key), OBJECT_TYPE); - } - - @Override - public C get(String key, WrapType type) { - return get(wrappedKey(key), type); - } - - @Override - public C get(WrappedKey key, WrapType type) { - return container.get(BukkitKey1_16_R3.asBukkit(key), new SimpleBukkitType1_16_R3<>(type)); - } - - @Override - public void set(String key, B value, WrapType type) { - set(wrappedKey(key), value, type); - } - - @Override - public void set(WrappedKey key, B value, WrapType type) { - container.set(BukkitKey1_16_R3.asBukkit(key), new SimpleBukkitType1_16_R3<>(type), value); - } - - @Override - public boolean remove(WrappedKey key) { - Object value = get(key); - container.remove(BukkitKey1_16_R3.asBukkit(key)); - return value != null && get(key) == null; - } - - @Override - public Set keySet() { - return getKeyspaces(); - } - - @Override - public boolean isEmpty() { - return container.isEmpty(); - } - - @Override - public int size() { - return container.getKeys().size(); - } + public static final PersistentDataType OBJECT_TYPE = new SimpleBukkitType1_16_R3<>(ObjectType.INSTANCE); + + private final PersistentDataContainer container; + + public SyntaxContainer1_16_R3(PersistentDataContainer container) { + this.container = container; + } + + @Override + public PersistentDataContainer getHandle() { + return container; + } + + @Override + public IDataContainer getAsSyntaxContainer() { + return new SyntaxContainer1_16_R3(container); + } + + /* + * + */ + + @Override + public boolean has(IKey key) { + return has(new SyntaxKey(key)); + } + + @Override + public boolean has(String key, DataType type) { + return has(NamespacedKey.fromString(key), type); + } + + @Override + public boolean has(IKey key, DataType type) { + return has(new SyntaxKey(key), WrappedType1_16_R3.wrap(type)); + } + + @Override + public C get(String key, DataType type) { + return get(NamespacedKey.fromString(key), type); + } + + @Override + public C get(IKey key, DataType type) { + return get(new SyntaxKey(key), WrappedType1_16_R3.wrap(type)); + } + + @Override + public Object get(String key) { + return get(NamespacedKey.fromString(key)); + } + + @Override + public Object get(IKey key) { + return get(new SyntaxKey(key)); + } + + @Override + public void set(String key, E value, DataType type) { + set(wrappedKey(key), value, WrappedType1_16_R3.wrap(type)); + } + + @Override + public void set(IKey key, E value, DataType type) { + set(new SyntaxKey(key), value, WrappedType1_16_R3.wrap(type)); + } + + @Override + public boolean remove(String key) { + return remove(wrappedKey(key)); + } + + @Override + public boolean remove(IKey key) { + return remove(new SyntaxKey(key)); + } + + @Override + public IKey[] getKeys() { + return container.getKeys().stream().map(BukkitKey1_16_R3::new).map(WrappedKey::getNamespacedKey).toArray(IKey[]::new); + } + + @Override + public Set getKeyspaces() { + return container.getKeys().stream().map(org.bukkit.NamespacedKey::toString).collect(Collectors.toSet()); + } + + @Override + public DataAdapterContext getAdapterContext() { + return getContext(); + } + + /* + * + */ + + @Override + public SyntaxContext1_16_R3 getContext() { + return new SyntaxContext1_16_R3(container.getAdapterContext()); + } + + @Override + public boolean has(String key) { + return has(wrappedKey(key)); + } + + @Override + public boolean has(WrappedKey key) { + return container.has(BukkitKey1_16_R3.asBukkit(key), OBJECT_TYPE); + } + + @Override + public boolean has(String key, WrapType type) { + return has(wrappedKey(key), type); + } + + @Override + public boolean has(WrappedKey key, WrapType type) { + return container.has(BukkitKey1_16_R3.asBukkit(key), new SimpleBukkitType1_16_R3<>(type)); + } + + @Override + public Object get(WrappedKey key) { + return container.get(BukkitKey1_16_R3.asBukkit(key), OBJECT_TYPE); + } + + @Override + public C get(String key, WrapType type) { + return get(wrappedKey(key), type); + } + + @Override + public C get(WrappedKey key, WrapType type) { + return container.get(BukkitKey1_16_R3.asBukkit(key), new SimpleBukkitType1_16_R3<>(type)); + } + + @Override + public void set(String key, B value, WrapType type) { + set(wrappedKey(key), value, type); + } + + @Override + public void set(WrappedKey key, B value, WrapType type) { + container.set(BukkitKey1_16_R3.asBukkit(key), new SimpleBukkitType1_16_R3<>(type), value); + } + + @Override + public boolean remove(WrappedKey key) { + Object value = get(key); + container.remove(BukkitKey1_16_R3.asBukkit(key)); + return value != null && get(key) == null; + } + + @Override + public Set keySet() { + return getKeyspaces(); + } + + @Override + public boolean isEmpty() { + return container.isEmpty(); + } + + @Override + public int size() { + return container.getKeys().size(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxContext1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxContext1_16_R3.java index 2b09a28..27cf296 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxContext1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxContext1_16_R3.java @@ -9,30 +9,30 @@ public final class SyntaxContext1_16_R3 extends WrappedContext implements PersistentDataAdapterContext { - private final PersistentDataAdapterContext context; - - public SyntaxContext1_16_R3(PersistentDataAdapterContext context) { - this.context = context; - } - - @Override - public PersistentDataAdapterContext getHandle() { - return context; - } - - @Override - public PersistentDataContainer newPersistentDataContainer() { - return context.newPersistentDataContainer(); - } - - @Override - public IDataContainer newDataContainer() { - return newContainer(); - } - - @Override - public SyntaxContainer1_16_R3 newContainer() { - return new SyntaxContainer1_16_R3(context.newPersistentDataContainer()); - } + private final PersistentDataAdapterContext context; + + public SyntaxContext1_16_R3(PersistentDataAdapterContext context) { + this.context = context; + } + + @Override + public PersistentDataAdapterContext getHandle() { + return context; + } + + @Override + public PersistentDataContainer newPersistentDataContainer() { + return context.newPersistentDataContainer(); + } + + @Override + public IDataContainer newDataContainer() { + return newContainer(); + } + + @Override + public SyntaxContainer1_16_R3 newContainer() { + return new SyntaxContainer1_16_R3(context.newPersistentDataContainer()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxType1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxType1_16_R3.java index 6822da8..e8a7c31 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxType1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/SyntaxType1_16_R3.java @@ -8,68 +8,69 @@ import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContext; -public class SyntaxType1_16_R3 extends WrappedType1_16_R3, P0, P1, C0, C1> implements DataType { - - private final PersistentDataType type; - - public SyntaxType1_16_R3(PersistentDataType type) { - super(type.getPrimitiveType(), type.getComplexType()); - this.type = type; - } - - @Override - public PersistentDataType getHandle() { - return type; - } - - @Override - public Class getPrimitiveOriginal() { - return type.getPrimitiveType(); - } - - @Override - public Class getComplexOriginal() { - return type.getComplexType(); - } - - /* - * - */ - - @Override - public Class getComplex() { - return complexType; - } - - @Override - public Class getPrimitive() { - return primitiveType; - } - - @Override - public P0 toPrimitive(DataAdapterContext context, C0 complex) { - return wrapToPrimitive(complex, new BukkitContext1_16_R3(context)); - } - - @Override - public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { - return wrapToComplex(primitive, new BukkitContext1_16_R3(context)); - } - - @Override - public P0 wrapToPrimitive(C0 complex, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); - } - - @Override - public C0 wrapToComplex(P0 primitive, WrappedContext context) { - if (!(context instanceof PersistentDataAdapterContext)) { - return null; - } - return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); - } +public class SyntaxType1_16_R3 extends WrappedType1_16_R3, P0, P1, C0, C1> + implements DataType { + + private final PersistentDataType type; + + public SyntaxType1_16_R3(PersistentDataType type) { + super(type.getPrimitiveType(), type.getComplexType()); + this.type = type; + } + + @Override + public PersistentDataType getHandle() { + return type; + } + + @Override + public Class getPrimitiveOriginal() { + return type.getPrimitiveType(); + } + + @Override + public Class getComplexOriginal() { + return type.getComplexType(); + } + + /* + * + */ + + @Override + public Class getComplex() { + return complexType; + } + + @Override + public Class getPrimitive() { + return primitiveType; + } + + @Override + public P0 toPrimitive(DataAdapterContext context, C0 complex) { + return wrapToPrimitive(complex, new BukkitContext1_16_R3(context)); + } + + @Override + public C0 fromPrimitive(DataAdapterContext context, P0 primitive) { + return wrapToComplex(primitive, new BukkitContext1_16_R3(context)); + } + + @Override + public P0 wrapToPrimitive(C0 complex, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toPrimitiveWrapped(type.toPrimitive(toComplexOriginal(complex), (PersistentDataAdapterContext) context)); + } + + @Override + public C0 wrapToComplex(P0 primitive, WrappedContext context) { + if (!(context instanceof PersistentDataAdapterContext)) { + return null; + } + return toComplexWrapped(type.fromPrimitive(toPrimitiveOriginal(primitive), (PersistentDataAdapterContext) context)); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/WrappedType1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/WrappedType1_16_R3.java index 28df672..3b29f9c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/WrappedType1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/data/WrappedType1_16_R3.java @@ -12,135 +12,139 @@ public abstract class WrappedType1_16_R3 implements WrapType { - protected final Class primitiveType; - protected final Class complexType; - - private final int primitiveWrap; - private final int complexWrap; - - @SuppressWarnings("unchecked") - protected WrappedType1_16_R3(Class primitive, Class complex) { - this.primitiveWrap = WrappedType1_16_R3.internalState(primitive); - this.complexWrap = WrappedType1_16_R3.internalState(complex); - this.primitiveType = (Class) WrappedType1_16_R3.internalWrap(primitive, primitiveWrap); - this.complexType = (Class) WrappedType1_16_R3.internalWrap(complex, complexWrap); - } - - public abstract H getHandle(); - - public Class getPrimitiveWrapped() { - return primitiveType; - } - - public Class getComplexWrapped() { - return complexType; - } - - public abstract Class getPrimitiveOriginal(); - - public abstract Class getComplexOriginal(); - - @SuppressWarnings("unchecked") - public P0 toPrimitiveWrapped(P1 primitive) { - switch (primitiveWrap) { - case 1: - return (P0) new SyntaxContainer1_16_R3((PersistentDataContainer) primitive); - case 2: - return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R3::new).toArray(IDataContainer[]::new); - case 3: - return (P0) new BukkitContainer1_16_R3((IDataContainer) primitive); - case 4: - return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R3::new).toArray(PersistentDataContainer[]::new); - default: - return (P0) primitive; - } - } - - @SuppressWarnings("unchecked") - public C0 toComplexWrapped(C1 complex) { - switch (complexWrap) { - case 1: - return (C0) new SyntaxContainer1_16_R3((PersistentDataContainer) complex); - case 2: - return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R3::new).toArray(IDataContainer[]::new); - case 3: - return (C0) new BukkitContainer1_16_R3((IDataContainer) complex); - case 4: - return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R3::new).toArray(PersistentDataContainer[]::new); - default: - return (C0) complex; - } - } - - @SuppressWarnings("unchecked") - public P1 toPrimitiveOriginal(P0 primitive) { - switch (primitiveWrap) { - case 1: - return (P1) new BukkitContainer1_16_R3((IDataContainer) primitive); - case 2: - return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R3::new).toArray(PersistentDataContainer[]::new); - case 3: - return (P1) new SyntaxContainer1_16_R3((PersistentDataContainer) primitive); - case 4: - return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R3::new).toArray(IDataContainer[]::new); - default: - return (P1) primitive; - } - } - - @SuppressWarnings("unchecked") - public C1 toComplexOriginal(C0 complex) { - switch (complexWrap) { - case 1: - return (C1) new BukkitContainer1_16_R3((IDataContainer) complex); - case 2: - return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R3::new).toArray(PersistentDataContainer[]::new); - case 3: - return (C1) new SyntaxContainer1_16_R3((PersistentDataContainer) complex); - case 4: - return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R3::new).toArray(IDataContainer[]::new); - default: - return (C1) complex; - } - } - - protected static Class internalWrap(Class clazz, int state) { - switch (state) { - case 1: - return IDataContainer.class; - case 2: - return IDataContainer[].class; - case 3: - return PersistentDataContainer.class; - case 4: - return PersistentDataContainer[].class; - default: - return clazz; - } - } - - protected static int internalState(Class clazz) { - if (clazz.equals(PersistentDataContainer.class)) { - return 1; - } - if (clazz.equals(PersistentDataContainer[].class)) { - return 2; - } - if (clazz.equals(IDataContainer.class)) { - return 3; - } - if (clazz.equals(IDataContainer[].class)) { - return 4; - } - return 0; - } - - public static BukkitType1_16_R3 wrap(DataType type) { - return new BukkitType1_16_R3<>(type); - } - - public static SyntaxType1_16_R3 wrap(PersistentDataType type) { - return new SyntaxType1_16_R3<>(type); - } + protected final Class primitiveType; + protected final Class complexType; + + private final int primitiveWrap; + private final int complexWrap; + + @SuppressWarnings("unchecked") + protected WrappedType1_16_R3(Class primitive, Class complex) { + this.primitiveWrap = WrappedType1_16_R3.internalState(primitive); + this.complexWrap = WrappedType1_16_R3.internalState(complex); + this.primitiveType = (Class) WrappedType1_16_R3.internalWrap(primitive, primitiveWrap); + this.complexType = (Class) WrappedType1_16_R3.internalWrap(complex, complexWrap); + } + + public abstract H getHandle(); + + public Class getPrimitiveWrapped() { + return primitiveType; + } + + public Class getComplexWrapped() { + return complexType; + } + + public abstract Class getPrimitiveOriginal(); + + public abstract Class getComplexOriginal(); + + @SuppressWarnings("unchecked") + public P0 toPrimitiveWrapped(P1 primitive) { + switch (primitiveWrap) { + case 1: + return (P0) new SyntaxContainer1_16_R3((PersistentDataContainer) primitive); + case 2: + return (P0) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R3::new) + .toArray(IDataContainer[]::new); + case 3: + return (P0) new BukkitContainer1_16_R3((IDataContainer) primitive); + case 4: + return (P0) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R3::new) + .toArray(PersistentDataContainer[]::new); + default: + return (P0) primitive; + } + } + + @SuppressWarnings("unchecked") + public C0 toComplexWrapped(C1 complex) { + switch (complexWrap) { + case 1: + return (C0) new SyntaxContainer1_16_R3((PersistentDataContainer) complex); + case 2: + return (C0) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R3::new).toArray(IDataContainer[]::new); + case 3: + return (C0) new BukkitContainer1_16_R3((IDataContainer) complex); + case 4: + return (C0) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R3::new).toArray(PersistentDataContainer[]::new); + default: + return (C0) complex; + } + } + + @SuppressWarnings("unchecked") + public P1 toPrimitiveOriginal(P0 primitive) { + switch (primitiveWrap) { + case 1: + return (P1) new BukkitContainer1_16_R3((IDataContainer) primitive); + case 2: + return (P1) Arrays.stream((IDataContainer[]) primitive).map(BukkitContainer1_16_R3::new) + .toArray(PersistentDataContainer[]::new); + case 3: + return (P1) new SyntaxContainer1_16_R3((PersistentDataContainer) primitive); + case 4: + return (P1) Arrays.stream((PersistentDataContainer[]) primitive).map(SyntaxContainer1_16_R3::new) + .toArray(IDataContainer[]::new); + default: + return (P1) primitive; + } + } + + @SuppressWarnings("unchecked") + public C1 toComplexOriginal(C0 complex) { + switch (complexWrap) { + case 1: + return (C1) new BukkitContainer1_16_R3((IDataContainer) complex); + case 2: + return (C1) Arrays.stream((IDataContainer[]) complex).map(BukkitContainer1_16_R3::new).toArray(PersistentDataContainer[]::new); + case 3: + return (C1) new SyntaxContainer1_16_R3((PersistentDataContainer) complex); + case 4: + return (C1) Arrays.stream((PersistentDataContainer[]) complex).map(SyntaxContainer1_16_R3::new).toArray(IDataContainer[]::new); + default: + return (C1) complex; + } + } + + protected static Class internalWrap(Class clazz, int state) { + switch (state) { + case 1: + return IDataContainer.class; + case 2: + return IDataContainer[].class; + case 3: + return PersistentDataContainer.class; + case 4: + return PersistentDataContainer[].class; + default: + return clazz; + } + } + + protected static int internalState(Class clazz) { + if (clazz.equals(PersistentDataContainer.class)) { + return 1; + } + if (clazz.equals(PersistentDataContainer[].class)) { + return 2; + } + if (clazz.equals(IDataContainer.class)) { + return 3; + } + if (clazz.equals(IDataContainer[].class)) { + return 4; + } + return 0; + } + + public static BukkitType1_16_R3 wrap(DataType type) { + return new BukkitType1_16_R3<>(type); + } + + public static SyntaxType1_16_R3 wrap(PersistentDataType type) { + return new SyntaxType1_16_R3<>(type); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/ArmorStand1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/ArmorStand1_16_R3.java index d59a763..16aaa21 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/ArmorStand1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/ArmorStand1_16_R3.java @@ -7,18 +7,18 @@ public class ArmorStand1_16_R3 extends EntityLiving1_16_R3 implements NmsArmorStand { - public ArmorStand1_16_R3(World world) { - super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); - } + public ArmorStand1_16_R3(World world) { + super(new EntityArmorStand(EntityTypes.ARMOR_STAND, world)); + } - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } - @Override - public boolean isSmall() { - return handle.isSmall(); - } + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/Entity1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/Entity1_16_R3.java index 95f0334..0aaa6ab 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/Entity1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/Entity1_16_R3.java @@ -13,198 +13,200 @@ import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage; import org.bukkit.entity.Player; +import net.minecraft.server.v1_16_R3.AxisAlignedBB; import net.minecraft.server.v1_16_R3.Entity; import net.minecraft.server.v1_16_R3.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata; import net.minecraft.server.v1_16_R3.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_16_R3.PlayerConnection; import net.minecraft.server.v1_16_R3.Vec3D; -import net.minecraft.server.v1_16_R3.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_16_R3 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_16_R3(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); - } - - @Override - public String getCustomName() { - return CraftChatMessage.fromComponent(handle.getCustomName()); - } - - @Override - public void setGravity(boolean gravity) { - handle.setNoGravity(!gravity); - } - - @Override - public boolean hasGravity() { - return !handle.isNoGravity(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(); - } - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.getPositionVector(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_16_R3(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(CraftChatMessage.fromStringOrNull(name)); + } + + @Override + public String getCustomName() { + return CraftChatMessage.fromComponent(handle.getCustomName()); + } + + @Override + public void setGravity(boolean gravity) { + handle.setNoGravity(!gravity); + } + + @Override + public boolean hasGravity() { + return !handle.isNoGravity(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(); + } + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.getPositionVector(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/EntityLiving1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/EntityLiving1_16_R3.java index b70cb35..537ea88 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/EntityLiving1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/EntityLiving1_16_R3.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_16_R3 extends Entity1_16_R3 implements NmsEntityLiving { - public EntityLiving1_16_R3(E handle) { - super(handle); - } + public EntityLiving1_16_R3(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/Player1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/Player1_16_R3.java index 1c28dac..857c319 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/Player1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/entity/Player1_16_R3.java @@ -36,8 +36,8 @@ import net.minecraft.server.v1_16_R3.PacketPlayOutTitle.EnumTitleAction; import net.minecraft.server.v1_16_R3.PlayerConnection; import net.minecraft.server.v1_16_R3.WorldServer; -import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContainer; import net.sourcewriters.minecraft.versiontools.reflection.data.WrapType; +import net.sourcewriters.minecraft.versiontools.reflection.data.WrappedContainer; import net.sourcewriters.minecraft.versiontools.reflection.data.type.SkinDataType; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsPlayer; import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_16_R3.data.SyntaxContainer1_16_R3; @@ -49,229 +49,230 @@ public class Player1_16_R3 extends EntityLiving1_16_R3 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_16_R3(Player player) { - super(((CraftPlayer) player).getHandle()); - dataAdapter = new SyntaxContainer1_16_R3(getBukkitPlayer().getPersistentDataContainer()); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - dataAdapter.set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - dataAdapter.remove("name"); - return; - } - dataAdapter.set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return dataAdapter.getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return dataAdapter.getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - dataAdapter.set("header", header, WrapType.STRING); - dataAdapter.set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - packet.header = headerComponent; - packet.footer = footerComponent; - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList> list = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - list.add(Pair.of(slot, handle.getEquipment(slot))); - } - PacketPlayOutEntityEquipment equipmentPacket = new PacketPlayOutEntityEquipment(handle.getId(), list); - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - connection.sendPacket(equipmentPacket); - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(world.getDimensionManager(), world.getDimensionKey(), BiomeManager.a(world.getSeed()), - handle.playerInteractManager.getGameMode(), handle.playerInteractManager.c(), world.isDebugWorld(), world.isFlatWorld(), true); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX(), handle.locY(), handle.locZ(), handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_16_R3(Player player) { + super(((CraftPlayer) player).getHandle()); + dataAdapter = new SyntaxContainer1_16_R3(getBukkitPlayer().getPersistentDataContainer()); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + dataAdapter.set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return dataAdapter.getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + dataAdapter.remove("name"); + return; + } + dataAdapter.set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return dataAdapter.getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return dataAdapter.getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return dataAdapter.getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + dataAdapter.set("header", header, WrapType.STRING); + dataAdapter.set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromStringOrNull(header, true); + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromStringOrNull(footer, true); + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + packet.header = headerComponent; + packet.footer = footerComponent; + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.ACTIONBAR, CraftChatMessage.fromStringOrNull(text))); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList> list = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + list.add(Pair.of(slot, handle.getEquipment(slot))); + } + PacketPlayOutEntityEquipment equipmentPacket = new PacketPlayOutEntityEquipment(handle.getId(), list); + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + connection.sendPacket(equipmentPacket); + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(world.getDimensionManager(), world.getDimensionKey(), + BiomeManager.a(world.getSeed()), handle.playerInteractManager.getGameMode(), handle.playerInteractManager.c(), + world.isDebugWorld(), world.isFlatWorld(), true); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX(), handle.locY(), handle.locZ(), handle.yaw, + handle.pitch, Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/BlockTools1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/BlockTools1_16_R3.java index 298ee34..33f9223 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/BlockTools1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/BlockTools1_16_R3.java @@ -14,26 +14,26 @@ public class BlockTools1_16_R3 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.gameProfile.getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.gameProfile.getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.gameProfile.getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/ServerTools1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/ServerTools1_16_R3.java index 277c5e4..50a4c79 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/ServerTools1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/ServerTools1_16_R3.java @@ -7,14 +7,14 @@ public class ServerTools1_16_R3 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/SkinTools1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/SkinTools1_16_R3.java index 390477d..2c80342 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/SkinTools1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/tools/SkinTools1_16_R3.java @@ -8,9 +8,9 @@ public class SkinTools1_16_R3 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/utils/EntityConstructors1_16_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/utils/EntityConstructors1_16_R3.java index 27be10c..8ea7a4e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/utils/EntityConstructors1_16_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_16_R3/utils/EntityConstructors1_16_R3.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_16_R3 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_16_R3(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_16_R3(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/BukkitConversion1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/BukkitConversion1_8_R1.java index 93ebc1b..98a1bc0 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/BukkitConversion1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/BukkitConversion1_8_R1.java @@ -7,7 +7,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_8_R1.ItemStack; import net.minecraft.server.v1_8_R1.NBTBase; @@ -31,180 +45,180 @@ public class BukkitConversion1_8_R1 extends BukkitConversion { - protected BukkitConversion1_8_R1(VersionControl1_8_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - NBTTagList list = new NBTTagList(); - for (long value : (long[]) tag.getValue()) { - list.add(new NBTTagLong(value)); - } - return list; - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTTagByte) tag).f()); - case SHORT: - return new NbtShort(((NBTTagShort) tag).e()); - case INT: - return new NbtInt(((NBTTagInt) tag).d()); - case LONG: - return new NbtLong(((NBTTagLong) tag).c()); - case FLOAT: - return new NbtFloat(((NBTTagFloat) tag).h()); - case DOUBLE: - return new NbtDouble(((NBTTagDouble) tag).g()); - case STRING: - return new NbtString(((NBTTagString) tag).a_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).c()); - case LONG_ARRAY: - return new NbtLongArray(new long[0]); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : content) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.c(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound stackTag; - if (!nmsStack.hasTag()) { - stackTag = nmsStack.save(new NBTTagCompound()); - } else { - stackTag = nmsStack.getTag(); - } - return fromMinecraftCompound(stackTag); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_8_R1(VersionControl1_8_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + NBTTagList list = new NBTTagList(); + for (long value : (long[]) tag.getValue()) { + list.add(new NBTTagLong(value)); + } + return list; + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTTagByte) tag).f()); + case SHORT: + return new NbtShort(((NBTTagShort) tag).e()); + case INT: + return new NbtInt(((NBTTagInt) tag).d()); + case LONG: + return new NbtLong(((NBTTagLong) tag).c()); + case FLOAT: + return new NbtFloat(((NBTTagFloat) tag).h()); + case DOUBLE: + return new NbtDouble(((NBTTagDouble) tag).g()); + case STRING: + return new NbtString(((NBTTagString) tag).a_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).c()); + case LONG_ARRAY: + return new NbtLongArray(new long[0]); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : content) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.c(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound stackTag; + if (!nmsStack.hasTag()) { + stackTag = nmsStack.save(new NBTTagCompound()); + } else { + stackTag = nmsStack.getTag(); + } + return fromMinecraftCompound(stackTag); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/EntityProvider1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/EntityProvider1_8_R1.java index 7b90c22..cfabc82 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/EntityProvider1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/EntityProvider1_8_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_8_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_8_R1(VersionControl1_8_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_8_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_8_R1(VersionControl1_8_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_8_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/PacketHandler1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/PacketHandler1_8_R1.java index a9b1159..565bb80 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/PacketHandler1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/PacketHandler1_8_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_8_R1 extends PacketHandler { - protected PacketHandler1_8_R1(VersionControl1_8_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_8_R1(VersionControl1_8_R1 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/PlayerProvider1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/PlayerProvider1_8_R1.java index 1c60566..a8083df 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/PlayerProvider1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/PlayerProvider1_8_R1.java @@ -14,17 +14,17 @@ public class PlayerProvider1_8_R1 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_8_R1(VersionControl1_8_R1 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_8_R1(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_8_R1(VersionControl1_8_R1 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_8_R1(player, distributor.get(player.getUniqueId())); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/TextureProvider1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/TextureProvider1_8_R1.java index 33d0dbf..979c7a6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/TextureProvider1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/TextureProvider1_8_R1.java @@ -21,87 +21,87 @@ @SuppressWarnings("deprecation") public class TextureProvider1_8_R1 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final AbstractReflect craftSkullRef = new Reflect(CraftSkull.class).searchField("tileEntity", "skull"); - private final Material skullMaterial = Material.valueOf("SKULL"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final AbstractReflect craftSkullRef = new Reflect(CraftSkull.class).searchField("tileEntity", "skull"); + private final Material skullMaterial = Material.valueOf("SKULL"); - protected TextureProvider1_8_R1(VersionControl1_8_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_8_R1(VersionControl1_8_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - return ((TileEntitySkull) craftSkullRef.getFieldValue("tileEntity", block)).getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + return ((TileEntitySkull) craftSkullRef.getFieldValue("tileEntity", block)).getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag; - if (!stack.hasTag()) { - stackTag = stack.save(new NBTTagCompound()); - } else { - stackTag = stack.getTag(); - } - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag; + if (!stack.hasTag()) { + stackTag = stack.save(new NBTTagCompound()); + } else { + stackTag = stack.getTag(); + } + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - ((TileEntitySkull) craftSkullRef.getFieldValue("tileEntity", block)).setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + ((TileEntitySkull) craftSkullRef.getFieldValue("tileEntity", block)).setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/ToolProvider1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/ToolProvider1_8_R1.java index bb375d8..a488173 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/ToolProvider1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/ToolProvider1_8_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R1.tools.BlockTools1_8_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R1.tools.ServerTools1_8_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R1.tools.SkinTools1_8_R1; public class ToolProvider1_8_R1 extends ToolProvider { - - private final BlockTools1_8_R1 blockTools = new BlockTools1_8_R1(); - private final SkinTools1_8_R1 skinTools = new SkinTools1_8_R1(); - private final ServerTools1_8_R1 serverTools = new ServerTools1_8_R1(); - - protected ToolProvider1_8_R1(VersionControl1_8_R1 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_8_R1 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_8_R1 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_8_R1 getBlockTools() { - return blockTools; - } + + private final BlockTools1_8_R1 blockTools = new BlockTools1_8_R1(); + private final SkinTools1_8_R1 skinTools = new SkinTools1_8_R1(); + private final ServerTools1_8_R1 serverTools = new ServerTools1_8_R1(); + + protected ToolProvider1_8_R1(VersionControl1_8_R1 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_8_R1 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_8_R1 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_8_R1 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/VersionControl1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/VersionControl1_8_R1.java index 2ce2db7..ce4dd50 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/VersionControl1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/VersionControl1_8_R1.java @@ -6,51 +6,51 @@ public class VersionControl1_8_R1 extends VersionControl { - public static VersionControl1_8_R1 INSTANCE; - - public static VersionControl1_8_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_8_R1()); - } - - private final ToolProvider1_8_R1 toolProvider = new ToolProvider1_8_R1(this); - private final TextureProvider1_8_R1 textureProvider = new TextureProvider1_8_R1(this); - private final PacketHandler1_8_R1 packetHandler = new PacketHandler1_8_R1(this); - private final EntityProvider1_8_R1 entityProvider = new EntityProvider1_8_R1(this); - private final PlayerProvider1_8_R1 playerProvider = new PlayerProvider1_8_R1(this); - private final BukkitConversion1_8_R1 bukkitConversion = new BukkitConversion1_8_R1(this); - - private VersionControl1_8_R1() { - NmsReflection1_8_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); - } - - @Override - public ToolProvider1_8_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_8_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_8_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_8_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_8_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_8_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_8_R1 INSTANCE; + + public static VersionControl1_8_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_8_R1()); + } + + private final ToolProvider1_8_R1 toolProvider = new ToolProvider1_8_R1(this); + private final TextureProvider1_8_R1 textureProvider = new TextureProvider1_8_R1(this); + private final PacketHandler1_8_R1 packetHandler = new PacketHandler1_8_R1(this); + private final EntityProvider1_8_R1 entityProvider = new EntityProvider1_8_R1(this); + private final PlayerProvider1_8_R1 playerProvider = new PlayerProvider1_8_R1(this); + private final BukkitConversion1_8_R1 bukkitConversion = new BukkitConversion1_8_R1(this); + + private VersionControl1_8_R1() { + NmsReflection1_8_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + } + + @Override + public ToolProvider1_8_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_8_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_8_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_8_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_8_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_8_R1 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/ArmorStand1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/ArmorStand1_8_R1.java index 5e3c21b..6816223 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/ArmorStand1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/ArmorStand1_8_R1.java @@ -6,28 +6,28 @@ public class ArmorStand1_8_R1 extends EntityLiving1_8_R1 implements NmsArmorStand { - public ArmorStand1_8_R1(World world) { - super(new EntityArmorStand(world)); - } - - @Override - public boolean hasGravity() { - return handle.hasGravity(); - } - - @Override - public void setGravity(boolean gravity) { - handle.setGravity(gravity); - } - - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } - - @Override - public boolean isSmall() { - return handle.isSmall(); - } + public ArmorStand1_8_R1(World world) { + super(new EntityArmorStand(world)); + } + + @Override + public boolean hasGravity() { + return handle.hasGravity(); + } + + @Override + public void setGravity(boolean gravity) { + handle.setGravity(gravity); + } + + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } + + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/Entity1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/Entity1_8_R1.java index 647768c..51f35a4 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/Entity1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/Entity1_8_R1.java @@ -12,6 +12,7 @@ import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_8_R1.AxisAlignedBB; import net.minecraft.server.v1_8_R1.Entity; import net.minecraft.server.v1_8_R1.EntityTypes; import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy; @@ -19,190 +20,191 @@ import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_8_R1.PlayerConnection; import net.minecraft.server.v1_8_R1.Vec3D; -import net.minecraft.server.v1_8_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_8_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_8_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(name); - } - - @Override - public String getCustomName() { - return handle.getCustomName(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.ad(); - } - - @Override - public boolean isCollidable() { - return handle.ae(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.h(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(null); - } - - @Override - public boolean hasGravity() { - return true; - } - - @Override - public void setGravity(boolean gravity) {} - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.d(); - return new Location(handle.getWorld().getWorld(), vector.a, vector.b, vector.c); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_8_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(name); + } + + @Override + public String getCustomName() { + return handle.getCustomName(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.ad(); + } + + @Override + public boolean isCollidable() { + return handle.ae(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.h(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(null); + } + + @Override + public boolean hasGravity() { + return true; + } + + @Override + public void setGravity(boolean gravity) {} + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.d(); + return new Location(handle.getWorld().getWorld(), vector.a, vector.b, vector.c); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/EntityLiving1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/EntityLiving1_8_R1.java index ee1e652..180afad 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/EntityLiving1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/EntityLiving1_8_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_8_R1 extends Entity1_8_R1 implements NmsEntityLiving { - public EntityLiving1_8_R1(E handle) { - super(handle); - } + public EntityLiving1_8_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - - } + @Override + public void setCollidable(boolean collidable) { + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/Player1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/Player1_8_R1.java index df08ccc..d019941 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/Player1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/entity/Player1_8_R1.java @@ -48,231 +48,231 @@ public class Player1_8_R1 extends EntityLiving1_8_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_8_R1(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); - reflect.setFieldValue(packet, "header", headerComponent); - reflect.setFieldValue(packet, "footer", footerComponent); - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (int slot = 0; slot < 5; slot++) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet()); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_8_R1(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + reflect.setFieldValue(packet, "header", headerComponent); + reflect.setFieldValue(packet, "footer", footerComponent); + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (int slot = 0; slot < 5; slot++) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet()); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/reflection/NmsReflection1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/reflection/NmsReflection1_8_R1.java index 1ba0c1c..f2fcf49 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/reflection/NmsReflection1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/reflection/NmsReflection1_8_R1.java @@ -8,27 +8,27 @@ public class NmsReflection1_8_R1 extends Reflections { - public static NmsReflection1_8_R1 INSTANCE = new NmsReflection1_8_R1(); + public static NmsReflection1_8_R1 INSTANCE = new NmsReflection1_8_R1(); - private NmsReflection1_8_R1() {} + private NmsReflection1_8_R1() {} - @Override - public void setup(ReflectionProvider provider) { + @Override + public void setup(ReflectionProvider provider) { - // - // - // Create Reflects - // + // + // + // Create Reflects + // - // - // Minecraft + // + // Minecraft - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class).searchField("header", "a") - .searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); - } + provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); + provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/BlockTools1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/BlockTools1_8_R1.java index 645de93..98e437b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/BlockTools1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/BlockTools1_8_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_8_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/ServerTools1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/ServerTools1_8_R1.java index 8fbb9ae..288d412 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/ServerTools1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/ServerTools1_8_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_8_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/SkinTools1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/SkinTools1_8_R1.java index 0c10ae6..867d52d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/SkinTools1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/tools/SkinTools1_8_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_8_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/utils/EntityConstructors1_8_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/utils/EntityConstructors1_8_R1.java index 96dcfb5..d407a24 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/utils/EntityConstructors1_8_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R1/utils/EntityConstructors1_8_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_8_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_8_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_8_R1(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/BukkitConversion1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/BukkitConversion1_8_R2.java index 7ece1fd..fb500ab 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/BukkitConversion1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/BukkitConversion1_8_R2.java @@ -7,7 +7,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_8_R2.ItemStack; import net.minecraft.server.v1_8_R2.NBTBase; @@ -31,179 +45,179 @@ public class BukkitConversion1_8_R2 extends BukkitConversion { - protected BukkitConversion1_8_R2(VersionControl1_8_R2 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - NBTTagList list = new NBTTagList(); - for(long value : (long[]) tag.getValue()) { - list.add(new NBTTagLong(value)); - } - return list; - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTTagByte) tag).f()); - case SHORT: - return new NbtShort(((NBTTagShort) tag).e()); - case INT: - return new NbtInt(((NBTTagInt) tag).d()); - case LONG: - return new NbtLong(((NBTTagLong) tag).c()); - case FLOAT: - return new NbtFloat(((NBTTagFloat) tag).h()); - case DOUBLE: - return new NbtDouble(((NBTTagDouble) tag).g()); - case STRING: - return new NbtString(((NBTTagString) tag).a_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).c()); - case LONG_ARRAY: - return new NbtLongArray(new long[0]); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : content) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.c(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound stackTag; - if (!nmsStack.hasTag()) { - stackTag = nmsStack.save(new NBTTagCompound()); - } else { - stackTag = nmsStack.getTag(); - } - return fromMinecraftCompound(stackTag); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_8_R2(VersionControl1_8_R2 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + NBTTagList list = new NBTTagList(); + for (long value : (long[]) tag.getValue()) { + list.add(new NBTTagLong(value)); + } + return list; + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTTagByte) tag).f()); + case SHORT: + return new NbtShort(((NBTTagShort) tag).e()); + case INT: + return new NbtInt(((NBTTagInt) tag).d()); + case LONG: + return new NbtLong(((NBTTagLong) tag).c()); + case FLOAT: + return new NbtFloat(((NBTTagFloat) tag).h()); + case DOUBLE: + return new NbtDouble(((NBTTagDouble) tag).g()); + case STRING: + return new NbtString(((NBTTagString) tag).a_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).c()); + case LONG_ARRAY: + return new NbtLongArray(new long[0]); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : content) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.c(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound stackTag; + if (!nmsStack.hasTag()) { + stackTag = nmsStack.save(new NBTTagCompound()); + } else { + stackTag = nmsStack.getTag(); + } + return fromMinecraftCompound(stackTag); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/EntityProvider1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/EntityProvider1_8_R2.java index e15cc7d..25b384e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/EntityProvider1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/EntityProvider1_8_R2.java @@ -13,35 +13,35 @@ public class EntityProvider1_8_R2 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_8_R2(VersionControl1_8_R2 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_8_R2.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_8_R2(VersionControl1_8_R2 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_8_R2.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/PacketHandler1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/PacketHandler1_8_R2.java index f39a253..d037f62 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/PacketHandler1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/PacketHandler1_8_R2.java @@ -4,8 +4,8 @@ public class PacketHandler1_8_R2 extends PacketHandler { - protected PacketHandler1_8_R2(VersionControl1_8_R2 versionControl) { - super(versionControl); - } + protected PacketHandler1_8_R2(VersionControl1_8_R2 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/PlayerProvider1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/PlayerProvider1_8_R2.java index e8091f4..788189f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/PlayerProvider1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/PlayerProvider1_8_R2.java @@ -14,17 +14,17 @@ public class PlayerProvider1_8_R2 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_8_R2(VersionControl1_8_R2 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_8_R2(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_8_R2(VersionControl1_8_R2 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_8_R2(player, distributor.get(player.getUniqueId())); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/TextureProvider1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/TextureProvider1_8_R2.java index c74b0b4..6de5f08 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/TextureProvider1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/TextureProvider1_8_R2.java @@ -20,86 +20,86 @@ @SuppressWarnings("deprecation") public class TextureProvider1_8_R2 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R2.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final Material skullMaterial = Material.valueOf("SKULL"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R2.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final Material skullMaterial = Material.valueOf("SKULL"); - protected TextureProvider1_8_R2(VersionControl1_8_R2 versionControl) { - super(versionControl); - } + protected TextureProvider1_8_R2(VersionControl1_8_R2 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - return ((CraftSkull) block).getTileEntity().getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + return ((CraftSkull) block).getTileEntity().getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag; - if (!stack.hasTag()) { - stackTag = stack.save(new NBTTagCompound()); - } else { - stackTag = stack.getTag(); - } - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag; + if (!stack.hasTag()) { + stackTag = stack.save(new NBTTagCompound()); + } else { + stackTag = stack.getTag(); + } + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - ((CraftSkull) block).getTileEntity().setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + ((CraftSkull) block).getTileEntity().setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/ToolProvider1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/ToolProvider1_8_R2.java index 6817cc6..0d21746 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/ToolProvider1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/ToolProvider1_8_R2.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R2; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R2.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R2.tools.BlockTools1_8_R2; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R2.tools.ServerTools1_8_R2; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R2.tools.SkinTools1_8_R2; public class ToolProvider1_8_R2 extends ToolProvider { - private final BlockTools1_8_R2 blockTools = new BlockTools1_8_R2(); - private final SkinTools1_8_R2 skinTools = new SkinTools1_8_R2(); - private final ServerTools1_8_R2 serverTools = new ServerTools1_8_R2(); + private final BlockTools1_8_R2 blockTools = new BlockTools1_8_R2(); + private final SkinTools1_8_R2 skinTools = new SkinTools1_8_R2(); + private final ServerTools1_8_R2 serverTools = new ServerTools1_8_R2(); - protected ToolProvider1_8_R2(VersionControl1_8_R2 versionControl) { - super(versionControl); - } + protected ToolProvider1_8_R2(VersionControl1_8_R2 versionControl) { + super(versionControl); + } - @Override - public SkinTools1_8_R2 getSkinTools() { - return skinTools; - } + @Override + public SkinTools1_8_R2 getSkinTools() { + return skinTools; + } - @Override - public ServerTools1_8_R2 getServerTools() { - return serverTools; - } + @Override + public ServerTools1_8_R2 getServerTools() { + return serverTools; + } - @Override - public BlockTools1_8_R2 getBlockTools() { - return blockTools; - } + @Override + public BlockTools1_8_R2 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/VersionControl1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/VersionControl1_8_R2.java index da83966..66ae40a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/VersionControl1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/VersionControl1_8_R2.java @@ -6,51 +6,51 @@ public class VersionControl1_8_R2 extends VersionControl { - public static VersionControl1_8_R2 INSTANCE; - - public static VersionControl1_8_R2 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_8_R2()); - } - - private final ToolProvider1_8_R2 toolProvider = new ToolProvider1_8_R2(this); - private final TextureProvider1_8_R2 textureProvider = new TextureProvider1_8_R2(this); - private final PacketHandler1_8_R2 packetHandler = new PacketHandler1_8_R2(this); - private final EntityProvider1_8_R2 entityProvider = new EntityProvider1_8_R2(this); - private final PlayerProvider1_8_R2 playerProvider = new PlayerProvider1_8_R2(this); - private final BukkitConversion1_8_R2 bukkitConversion = new BukkitConversion1_8_R2(this); - - private VersionControl1_8_R2() { - NmsReflection1_8_R2.INSTANCE.setup(ReflectionProvider.DEFAULT); - } - - @Override - public ToolProvider1_8_R2 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_8_R2 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_8_R2 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_8_R2 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_8_R2 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_8_R2 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_8_R2 INSTANCE; + + public static VersionControl1_8_R2 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_8_R2()); + } + + private final ToolProvider1_8_R2 toolProvider = new ToolProvider1_8_R2(this); + private final TextureProvider1_8_R2 textureProvider = new TextureProvider1_8_R2(this); + private final PacketHandler1_8_R2 packetHandler = new PacketHandler1_8_R2(this); + private final EntityProvider1_8_R2 entityProvider = new EntityProvider1_8_R2(this); + private final PlayerProvider1_8_R2 playerProvider = new PlayerProvider1_8_R2(this); + private final BukkitConversion1_8_R2 bukkitConversion = new BukkitConversion1_8_R2(this); + + private VersionControl1_8_R2() { + NmsReflection1_8_R2.INSTANCE.setup(ReflectionProvider.DEFAULT); + } + + @Override + public ToolProvider1_8_R2 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_8_R2 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_8_R2 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_8_R2 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_8_R2 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_8_R2 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/ArmorStand1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/ArmorStand1_8_R2.java index d990fad..544cd91 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/ArmorStand1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/ArmorStand1_8_R2.java @@ -6,28 +6,28 @@ public class ArmorStand1_8_R2 extends EntityLiving1_8_R2 implements NmsArmorStand { - public ArmorStand1_8_R2(World world) { - super(new EntityArmorStand(world)); - } - - @Override - public boolean hasGravity() { - return handle.hasGravity(); - } - - @Override - public void setGravity(boolean gravity) { - handle.setGravity(gravity); - } - - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } - - @Override - public boolean isSmall() { - return handle.isSmall(); - } + public ArmorStand1_8_R2(World world) { + super(new EntityArmorStand(world)); + } + + @Override + public boolean hasGravity() { + return handle.hasGravity(); + } + + @Override + public void setGravity(boolean gravity) { + handle.setGravity(gravity); + } + + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } + + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/Entity1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/Entity1_8_R2.java index 7445b36..c8bfe19 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/Entity1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/Entity1_8_R2.java @@ -25,184 +25,186 @@ public abstract class Entity1_8_R2 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_8_R2(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(name); - } - - @Override - public String getCustomName() { - return handle.getCustomName(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.ad(); - } - - @Override - public boolean isCollidable() { - return handle.ae(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.h(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(null); - } - - @Override - public boolean hasGravity() { - return true; - } - - @Override - public void setGravity(boolean gravity) {} - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.d(); - return new Location(handle.getWorld().getWorld(), vector.a, vector.b, vector.c); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_8_R2(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(name); + } + + @Override + public String getCustomName() { + return handle.getCustomName(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.ad(); + } + + @Override + public boolean isCollidable() { + return handle.ae(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.h(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(null); + } + + @Override + public boolean hasGravity() { + return true; + } + + @Override + public void setGravity(boolean gravity) {} + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.d(); + return new Location(handle.getWorld().getWorld(), vector.a, vector.b, vector.c); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/EntityLiving1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/EntityLiving1_8_R2.java index ae2c777..678b977 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/EntityLiving1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/EntityLiving1_8_R2.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_8_R2 extends Entity1_8_R2 implements NmsEntityLiving { - public EntityLiving1_8_R2(E handle) { - super(handle); - } + public EntityLiving1_8_R2(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - - } + @Override + public void setCollidable(boolean collidable) { + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/Player1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/Player1_8_R2.java index 181f3d4..3fb130f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/Player1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/entity/Player1_8_R2.java @@ -48,231 +48,231 @@ public class Player1_8_R2 extends EntityLiving1_8_R2 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_8_R2(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); - reflect.setFieldValue(packet, "header", headerComponent); - reflect.setFieldValue(packet, "footer", footerComponent); - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (int slot = 0; slot < 5; slot++) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet()); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_8_R2(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + reflect.setFieldValue(packet, "header", headerComponent); + reflect.setFieldValue(packet, "footer", footerComponent); + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (int slot = 0; slot < 5; slot++) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet()); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/reflection/NmsReflection1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/reflection/NmsReflection1_8_R2.java index 8bf0571..1314487 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/reflection/NmsReflection1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/reflection/NmsReflection1_8_R2.java @@ -8,27 +8,27 @@ public class NmsReflection1_8_R2 extends Reflections { - public static NmsReflection1_8_R2 INSTANCE = new NmsReflection1_8_R2(); + public static NmsReflection1_8_R2 INSTANCE = new NmsReflection1_8_R2(); - private NmsReflection1_8_R2() {} + private NmsReflection1_8_R2() {} - @Override - public void setup(ReflectionProvider provider) { + @Override + public void setup(ReflectionProvider provider) { - // - // - // Create Reflects - // + // + // + // Create Reflects + // - // - // Minecraft + // + // Minecraft - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class).searchField("header", "a") - .searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); - } + provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); + provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/BlockTools1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/BlockTools1_8_R2.java index 484bdc2..cd30994 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/BlockTools1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/BlockTools1_8_R2.java @@ -14,26 +14,26 @@ public class BlockTools1_8_R2 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/ServerTools1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/ServerTools1_8_R2.java index c91c476..2e4e928 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/ServerTools1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/ServerTools1_8_R2.java @@ -7,14 +7,14 @@ public class ServerTools1_8_R2 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/SkinTools1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/SkinTools1_8_R2.java index b0a0f6d..a28cbfe 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/SkinTools1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/tools/SkinTools1_8_R2.java @@ -8,9 +8,9 @@ public class SkinTools1_8_R2 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/utils/EntityConstructors1_8_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/utils/EntityConstructors1_8_R2.java index 8418cf4..ee50461 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/utils/EntityConstructors1_8_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R2/utils/EntityConstructors1_8_R2.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_8_R2 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_8_R2(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_8_R2(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/BukkitConversion1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/BukkitConversion1_8_R3.java index 4825700..e21db6c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/BukkitConversion1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/BukkitConversion1_8_R3.java @@ -7,7 +7,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_8_R3.ItemStack; import net.minecraft.server.v1_8_R3.NBTBase; @@ -31,179 +45,179 @@ public class BukkitConversion1_8_R3 extends BukkitConversion { - protected BukkitConversion1_8_R3(VersionControl1_8_R3 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - NBTTagList list = new NBTTagList(); - for(long value : (long[]) tag.getValue()) { - list.add(new NBTTagLong(value)); - } - return list; - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTTagByte) tag).f()); - case SHORT: - return new NbtShort(((NBTTagShort) tag).e()); - case INT: - return new NbtInt(((NBTTagInt) tag).d()); - case LONG: - return new NbtLong(((NBTTagLong) tag).c()); - case FLOAT: - return new NbtFloat(((NBTTagFloat) tag).h()); - case DOUBLE: - return new NbtDouble(((NBTTagDouble) tag).g()); - case STRING: - return new NbtString(((NBTTagString) tag).a_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).c()); - case LONG_ARRAY: - return new NbtLongArray(new long[0]); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : content) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.c(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound stackTag; - if (!nmsStack.hasTag()) { - stackTag = nmsStack.save(new NBTTagCompound()); - } else { - stackTag = nmsStack.getTag(); - } - return fromMinecraftCompound(stackTag); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_8_R3(VersionControl1_8_R3 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + NBTTagList list = new NBTTagList(); + for (long value : (long[]) tag.getValue()) { + list.add(new NBTTagLong(value)); + } + return list; + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTTagByte) tag).f()); + case SHORT: + return new NbtShort(((NBTTagShort) tag).e()); + case INT: + return new NbtInt(((NBTTagInt) tag).d()); + case LONG: + return new NbtLong(((NBTTagLong) tag).c()); + case FLOAT: + return new NbtFloat(((NBTTagFloat) tag).h()); + case DOUBLE: + return new NbtDouble(((NBTTagDouble) tag).g()); + case STRING: + return new NbtString(((NBTTagString) tag).a_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).c()); + case LONG_ARRAY: + return new NbtLongArray(new long[0]); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : content) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.c(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound stackTag; + if (!nmsStack.hasTag()) { + stackTag = nmsStack.save(new NBTTagCompound()); + } else { + stackTag = nmsStack.getTag(); + } + return fromMinecraftCompound(stackTag); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/EntityProvider1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/EntityProvider1_8_R3.java index 81a73df..1380b9e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/EntityProvider1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/EntityProvider1_8_R3.java @@ -13,35 +13,35 @@ public class EntityProvider1_8_R3 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_8_R3(VersionControl1_8_R3 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_8_R3.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_8_R3(VersionControl1_8_R3 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_8_R3.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/PacketHandler1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/PacketHandler1_8_R3.java index 26fa6b1..8ac820b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/PacketHandler1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/PacketHandler1_8_R3.java @@ -4,8 +4,8 @@ public class PacketHandler1_8_R3 extends PacketHandler { - protected PacketHandler1_8_R3(VersionControl1_8_R3 versionControl) { - super(versionControl); - } + protected PacketHandler1_8_R3(VersionControl1_8_R3 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/PlayerProvider1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/PlayerProvider1_8_R3.java index f2fff6b..8f02432 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/PlayerProvider1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/PlayerProvider1_8_R3.java @@ -14,17 +14,17 @@ public class PlayerProvider1_8_R3 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_8_R3(VersionControl1_8_R3 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_8_R3(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_8_R3(VersionControl1_8_R3 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_8_R3(player, distributor.get(player.getUniqueId())); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/TextureProvider1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/TextureProvider1_8_R3.java index 3c2ce1c..85a47be 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/TextureProvider1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/TextureProvider1_8_R3.java @@ -20,86 +20,86 @@ @SuppressWarnings("deprecation") public class TextureProvider1_8_R3 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final Material skullMaterial = Material.valueOf("SKULL"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final Material skullMaterial = Material.valueOf("SKULL"); - protected TextureProvider1_8_R3(VersionControl1_8_R3 versionControl) { - super(versionControl); - } + protected TextureProvider1_8_R3(VersionControl1_8_R3 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - return ((CraftSkull) block).getTileEntity().getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + return ((CraftSkull) block).getTileEntity().getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag; - if (!stack.hasTag()) { - stackTag = stack.save(new NBTTagCompound()); - } else { - stackTag = stack.getTag(); - } - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag; + if (!stack.hasTag()) { + stackTag = stack.save(new NBTTagCompound()); + } else { + stackTag = stack.getTag(); + } + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - ((CraftSkull) block).getTileEntity().setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + ((CraftSkull) block).getTileEntity().setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/ToolProvider1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/ToolProvider1_8_R3.java index 69e8212..653a7e3 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/ToolProvider1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/ToolProvider1_8_R3.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R3; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R3.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R3.tools.BlockTools1_8_R3; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R3.tools.ServerTools1_8_R3; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_8_R3.tools.SkinTools1_8_R3; public class ToolProvider1_8_R3 extends ToolProvider { - private final BlockTools1_8_R3 blockTools = new BlockTools1_8_R3(); - private final SkinTools1_8_R3 skinTools = new SkinTools1_8_R3(); - private final ServerTools1_8_R3 serverTools = new ServerTools1_8_R3(); + private final BlockTools1_8_R3 blockTools = new BlockTools1_8_R3(); + private final SkinTools1_8_R3 skinTools = new SkinTools1_8_R3(); + private final ServerTools1_8_R3 serverTools = new ServerTools1_8_R3(); - protected ToolProvider1_8_R3(VersionControl1_8_R3 versionControl) { - super(versionControl); - } + protected ToolProvider1_8_R3(VersionControl1_8_R3 versionControl) { + super(versionControl); + } - @Override - public SkinTools1_8_R3 getSkinTools() { - return skinTools; - } + @Override + public SkinTools1_8_R3 getSkinTools() { + return skinTools; + } - @Override - public ServerTools1_8_R3 getServerTools() { - return serverTools; - } + @Override + public ServerTools1_8_R3 getServerTools() { + return serverTools; + } - @Override - public BlockTools1_8_R3 getBlockTools() { - return blockTools; - } + @Override + public BlockTools1_8_R3 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/VersionControl1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/VersionControl1_8_R3.java index 7cdac8a..1789023 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/VersionControl1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/VersionControl1_8_R3.java @@ -6,51 +6,51 @@ public class VersionControl1_8_R3 extends VersionControl { - public static VersionControl1_8_R3 INSTANCE; - - public static VersionControl1_8_R3 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_8_R3()); - } - - private final ToolProvider1_8_R3 toolProvider = new ToolProvider1_8_R3(this); - private final TextureProvider1_8_R3 textureProvider = new TextureProvider1_8_R3(this); - private final PacketHandler1_8_R3 packetHandler = new PacketHandler1_8_R3(this); - private final EntityProvider1_8_R3 entityProvider = new EntityProvider1_8_R3(this); - private final PlayerProvider1_8_R3 playerProvider = new PlayerProvider1_8_R3(this); - private final BukkitConversion1_8_R3 bukkitConversion = new BukkitConversion1_8_R3(this); - - private VersionControl1_8_R3() { - NmsReflection1_8_R3.INSTANCE.setup(ReflectionProvider.DEFAULT); - } - - @Override - public ToolProvider1_8_R3 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_8_R3 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_8_R3 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_8_R3 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_8_R3 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_8_R3 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_8_R3 INSTANCE; + + public static VersionControl1_8_R3 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_8_R3()); + } + + private final ToolProvider1_8_R3 toolProvider = new ToolProvider1_8_R3(this); + private final TextureProvider1_8_R3 textureProvider = new TextureProvider1_8_R3(this); + private final PacketHandler1_8_R3 packetHandler = new PacketHandler1_8_R3(this); + private final EntityProvider1_8_R3 entityProvider = new EntityProvider1_8_R3(this); + private final PlayerProvider1_8_R3 playerProvider = new PlayerProvider1_8_R3(this); + private final BukkitConversion1_8_R3 bukkitConversion = new BukkitConversion1_8_R3(this); + + private VersionControl1_8_R3() { + NmsReflection1_8_R3.INSTANCE.setup(ReflectionProvider.DEFAULT); + } + + @Override + public ToolProvider1_8_R3 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_8_R3 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_8_R3 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_8_R3 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_8_R3 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_8_R3 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/ArmorStand1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/ArmorStand1_8_R3.java index 841f162..20681fd 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/ArmorStand1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/ArmorStand1_8_R3.java @@ -6,28 +6,28 @@ public class ArmorStand1_8_R3 extends EntityLiving1_8_R3 implements NmsArmorStand { - public ArmorStand1_8_R3(World world) { - super(new EntityArmorStand(world)); - } - - @Override - public boolean hasGravity() { - return handle.hasGravity(); - } - - @Override - public void setGravity(boolean gravity) { - handle.setGravity(gravity); - } - - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } - - @Override - public boolean isSmall() { - return handle.isSmall(); - } + public ArmorStand1_8_R3(World world) { + super(new EntityArmorStand(world)); + } + + @Override + public boolean hasGravity() { + return handle.hasGravity(); + } + + @Override + public void setGravity(boolean gravity) { + handle.setGravity(gravity); + } + + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } + + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/Entity1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/Entity1_8_R3.java index b9b7a41..79ff828 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/Entity1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/Entity1_8_R3.java @@ -25,184 +25,186 @@ public abstract class Entity1_8_R3 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_8_R3(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(name); - } - - @Override - public String getCustomName() { - return handle.getCustomName(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.ad(); - } - - @Override - public boolean isCollidable() { - return handle.ae(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.h(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(null); - } - - @Override - public boolean hasGravity() { - return true; - } - - @Override - public void setGravity(boolean gravity) {} - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.d(); - return new Location(handle.getWorld().getWorld(), vector.a, vector.b, vector.c); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_8_R3(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(name); + } + + @Override + public String getCustomName() { + return handle.getCustomName(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.ad(); + } + + @Override + public boolean isCollidable() { + return handle.ae(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.h(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(null); + } + + @Override + public boolean hasGravity() { + return true; + } + + @Override + public void setGravity(boolean gravity) {} + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.d(); + return new Location(handle.getWorld().getWorld(), vector.a, vector.b, vector.c); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/EntityLiving1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/EntityLiving1_8_R3.java index 62fc221..088352c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/EntityLiving1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/EntityLiving1_8_R3.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_8_R3 extends Entity1_8_R3 implements NmsEntityLiving { - public EntityLiving1_8_R3(E handle) { - super(handle); - } + public EntityLiving1_8_R3(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - - } + @Override + public void setCollidable(boolean collidable) { + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/Player1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/Player1_8_R3.java index 338bec0..33f33f5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/Player1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/entity/Player1_8_R3.java @@ -48,231 +48,231 @@ public class Player1_8_R3 extends EntityLiving1_8_R3 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_8_R3(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); - reflect.setFieldValue(packet, "header", headerComponent); - reflect.setFieldValue(packet, "footer", footerComponent); - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (int slot = 0; slot < 5; slot++) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet()); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_8_R3(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + reflect.setFieldValue(packet, "header", headerComponent); + reflect.setFieldValue(packet, "footer", footerComponent); + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (int slot = 0; slot < 5; slot++) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet()); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/reflection/NmsReflection1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/reflection/NmsReflection1_8_R3.java index 5053779..fb908b5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/reflection/NmsReflection1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/reflection/NmsReflection1_8_R3.java @@ -8,27 +8,27 @@ public class NmsReflection1_8_R3 extends Reflections { - public static NmsReflection1_8_R3 INSTANCE = new NmsReflection1_8_R3(); + public static NmsReflection1_8_R3 INSTANCE = new NmsReflection1_8_R3(); - private NmsReflection1_8_R3() {} + private NmsReflection1_8_R3() {} - @Override - public void setup(ReflectionProvider provider) { + @Override + public void setup(ReflectionProvider provider) { - // - // - // Create Reflects - // + // + // + // Create Reflects + // - // - // Minecraft + // + // Minecraft - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class).searchField("header", "a") - .searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); - } + provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); + provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/BlockTools1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/BlockTools1_8_R3.java index 0591e71..6f3f53b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/BlockTools1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/BlockTools1_8_R3.java @@ -14,26 +14,26 @@ public class BlockTools1_8_R3 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/ServerTools1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/ServerTools1_8_R3.java index 24e7f9b..afded65 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/ServerTools1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/ServerTools1_8_R3.java @@ -7,14 +7,14 @@ public class ServerTools1_8_R3 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/SkinTools1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/SkinTools1_8_R3.java index 573d9c3..835b650 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/SkinTools1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/tools/SkinTools1_8_R3.java @@ -8,9 +8,9 @@ public class SkinTools1_8_R3 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/utils/EntityConstructors1_8_R3.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/utils/EntityConstructors1_8_R3.java index 9c49748..e0698ab 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/utils/EntityConstructors1_8_R3.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_8_R3/utils/EntityConstructors1_8_R3.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_8_R3 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_8_R3(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_8_R3(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/BukkitConversion1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/BukkitConversion1_9_R1.java index c23074a..e153525 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/BukkitConversion1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/BukkitConversion1_9_R1.java @@ -7,7 +7,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_9_R1.ItemStack; import net.minecraft.server.v1_9_R1.NBTBase; @@ -31,179 +45,179 @@ public class BukkitConversion1_9_R1 extends BukkitConversion { - protected BukkitConversion1_9_R1(VersionControl1_9_R1 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - NBTTagList list = new NBTTagList(); - for(long value : (long[]) tag.getValue()) { - list.add(new NBTTagLong(value)); - } - return list; - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTTagByte) tag).f()); - case SHORT: - return new NbtShort(((NBTTagShort) tag).e()); - case INT: - return new NbtInt(((NBTTagInt) tag).d()); - case LONG: - return new NbtLong(((NBTTagLong) tag).c()); - case FLOAT: - return new NbtFloat(((NBTTagFloat) tag).h()); - case DOUBLE: - return new NbtDouble(((NBTTagDouble) tag).g()); - case STRING: - return new NbtString(((NBTTagString) tag).a_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).c()); - case LONG_ARRAY: - return new NbtLongArray(new long[0]); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : content) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.c(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound stackTag; - if (!nmsStack.hasTag()) { - stackTag = nmsStack.save(new NBTTagCompound()); - } else { - stackTag = nmsStack.getTag(); - } - return fromMinecraftCompound(stackTag); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_9_R1(VersionControl1_9_R1 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + NBTTagList list = new NBTTagList(); + for (long value : (long[]) tag.getValue()) { + list.add(new NBTTagLong(value)); + } + return list; + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTTagByte) tag).f()); + case SHORT: + return new NbtShort(((NBTTagShort) tag).e()); + case INT: + return new NbtInt(((NBTTagInt) tag).d()); + case LONG: + return new NbtLong(((NBTTagLong) tag).c()); + case FLOAT: + return new NbtFloat(((NBTTagFloat) tag).h()); + case DOUBLE: + return new NbtDouble(((NBTTagDouble) tag).g()); + case STRING: + return new NbtString(((NBTTagString) tag).a_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).c()); + case LONG_ARRAY: + return new NbtLongArray(new long[0]); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : content) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.c(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound stackTag; + if (!nmsStack.hasTag()) { + stackTag = nmsStack.save(new NBTTagCompound()); + } else { + stackTag = nmsStack.getTag(); + } + return fromMinecraftCompound(stackTag); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/EntityProvider1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/EntityProvider1_9_R1.java index 39f0b25..22ef623 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/EntityProvider1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/EntityProvider1_9_R1.java @@ -13,35 +13,35 @@ public class EntityProvider1_9_R1 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_9_R1(VersionControl1_9_R1 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_9_R1.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_9_R1(VersionControl1_9_R1 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_9_R1.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/PacketHandler1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/PacketHandler1_9_R1.java index 64ab0ee..e0af845 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/PacketHandler1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/PacketHandler1_9_R1.java @@ -4,8 +4,8 @@ public class PacketHandler1_9_R1 extends PacketHandler { - protected PacketHandler1_9_R1(VersionControl1_9_R1 versionControl) { - super(versionControl); - } + protected PacketHandler1_9_R1(VersionControl1_9_R1 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/PlayerProvider1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/PlayerProvider1_9_R1.java index 88d96f7..dcb4f03 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/PlayerProvider1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/PlayerProvider1_9_R1.java @@ -14,17 +14,17 @@ public class PlayerProvider1_9_R1 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_9_R1(VersionControl1_9_R1 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_9_R1(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_9_R1(VersionControl1_9_R1 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_9_R1(player, distributor.get(player.getUniqueId())); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/TextureProvider1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/TextureProvider1_9_R1.java index 84a6801..f76c8b5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/TextureProvider1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/TextureProvider1_9_R1.java @@ -20,86 +20,86 @@ @SuppressWarnings("deprecation") public class TextureProvider1_9_R1 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_9_R1.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final Material skullMaterial = Material.valueOf("SKULL"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_9_R1.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final Material skullMaterial = Material.valueOf("SKULL"); - protected TextureProvider1_9_R1(VersionControl1_9_R1 versionControl) { - super(versionControl); - } + protected TextureProvider1_9_R1(VersionControl1_9_R1 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - return ((CraftSkull) block).getTileEntity().getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + return ((CraftSkull) block).getTileEntity().getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag; - if (!stack.hasTag()) { - stackTag = stack.save(new NBTTagCompound()); - } else { - stackTag = stack.getTag(); - } - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag; + if (!stack.hasTag()) { + stackTag = stack.save(new NBTTagCompound()); + } else { + stackTag = stack.getTag(); + } + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - ((CraftSkull) block).getTileEntity().setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + ((CraftSkull) block).getTileEntity().setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/ToolProvider1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/ToolProvider1_9_R1.java index 051d846..8bb2d40 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/ToolProvider1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/ToolProvider1_9_R1.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R1; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R1.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R1.tools.BlockTools1_9_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R1.tools.ServerTools1_9_R1; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R1.tools.SkinTools1_9_R1; public class ToolProvider1_9_R1 extends ToolProvider { - private final BlockTools1_9_R1 blockTools = new BlockTools1_9_R1(); - private final SkinTools1_9_R1 skinTools = new SkinTools1_9_R1(); - private final ServerTools1_9_R1 serverTools = new ServerTools1_9_R1(); + private final BlockTools1_9_R1 blockTools = new BlockTools1_9_R1(); + private final SkinTools1_9_R1 skinTools = new SkinTools1_9_R1(); + private final ServerTools1_9_R1 serverTools = new ServerTools1_9_R1(); - protected ToolProvider1_9_R1(VersionControl1_9_R1 versionControl) { - super(versionControl); - } + protected ToolProvider1_9_R1(VersionControl1_9_R1 versionControl) { + super(versionControl); + } - @Override - public SkinTools1_9_R1 getSkinTools() { - return skinTools; - } + @Override + public SkinTools1_9_R1 getSkinTools() { + return skinTools; + } - @Override - public ServerTools1_9_R1 getServerTools() { - return serverTools; - } + @Override + public ServerTools1_9_R1 getServerTools() { + return serverTools; + } - @Override - public BlockTools1_9_R1 getBlockTools() { - return blockTools; - } + @Override + public BlockTools1_9_R1 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/VersionControl1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/VersionControl1_9_R1.java index 4e652a2..3edcaf7 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/VersionControl1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/VersionControl1_9_R1.java @@ -6,51 +6,51 @@ public class VersionControl1_9_R1 extends VersionControl { - public static VersionControl1_9_R1 INSTANCE; - - public static VersionControl1_9_R1 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_9_R1()); - } - - private final ToolProvider1_9_R1 toolProvider = new ToolProvider1_9_R1(this); - private final TextureProvider1_9_R1 textureProvider = new TextureProvider1_9_R1(this); - private final PacketHandler1_9_R1 packetHandler = new PacketHandler1_9_R1(this); - private final EntityProvider1_9_R1 entityProvider = new EntityProvider1_9_R1(this); - private final PlayerProvider1_9_R1 playerProvider = new PlayerProvider1_9_R1(this); - private final BukkitConversion1_9_R1 bukkitConversion = new BukkitConversion1_9_R1(this); - - private VersionControl1_9_R1() { - NmsReflection1_9_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); - } - - @Override - public ToolProvider1_9_R1 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_9_R1 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_9_R1 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_9_R1 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_9_R1 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_9_R1 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_9_R1 INSTANCE; + + public static VersionControl1_9_R1 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_9_R1()); + } + + private final ToolProvider1_9_R1 toolProvider = new ToolProvider1_9_R1(this); + private final TextureProvider1_9_R1 textureProvider = new TextureProvider1_9_R1(this); + private final PacketHandler1_9_R1 packetHandler = new PacketHandler1_9_R1(this); + private final EntityProvider1_9_R1 entityProvider = new EntityProvider1_9_R1(this); + private final PlayerProvider1_9_R1 playerProvider = new PlayerProvider1_9_R1(this); + private final BukkitConversion1_9_R1 bukkitConversion = new BukkitConversion1_9_R1(this); + + private VersionControl1_9_R1() { + NmsReflection1_9_R1.INSTANCE.setup(ReflectionProvider.DEFAULT); + } + + @Override + public ToolProvider1_9_R1 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_9_R1 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_9_R1 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_9_R1 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_9_R1 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_9_R1 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/ArmorStand1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/ArmorStand1_9_R1.java index e13ecf4..77102a7 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/ArmorStand1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/ArmorStand1_9_R1.java @@ -6,28 +6,28 @@ public class ArmorStand1_9_R1 extends EntityLiving1_9_R1 implements NmsArmorStand { - public ArmorStand1_9_R1(World world) { - super(new EntityArmorStand(world)); - } - - @Override - public boolean hasGravity() { - return handle.hasGravity(); - } - - @Override - public void setGravity(boolean gravity) { - handle.setGravity(gravity); - } - - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } - - @Override - public boolean isSmall() { - return handle.isSmall(); - } + public ArmorStand1_9_R1(World world) { + super(new EntityArmorStand(world)); + } + + @Override + public boolean hasGravity() { + return handle.hasGravity(); + } + + @Override + public void setGravity(boolean gravity) { + handle.setGravity(gravity); + } + + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } + + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/Entity1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/Entity1_9_R1.java index 28b1b8f..c976e9b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/Entity1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/Entity1_9_R1.java @@ -12,6 +12,7 @@ import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import net.minecraft.server.v1_9_R1.AxisAlignedBB; import net.minecraft.server.v1_9_R1.Entity; import net.minecraft.server.v1_9_R1.EntityTypes; import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy; @@ -19,190 +20,191 @@ import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntity; import net.minecraft.server.v1_9_R1.PlayerConnection; import net.minecraft.server.v1_9_R1.Vec3D; -import net.minecraft.server.v1_9_R1.AxisAlignedBB; import net.sourcewriters.minecraft.versiontools.reflection.entity.NmsEntity; import net.sourcewriters.minecraft.versiontools.reflection.utils.NmsBoundingBox; public abstract class Entity1_9_R1 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_9_R1(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(name); - } - - @Override - public String getCustomName() { - return handle.getCustomName(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.h(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(null); - } - - @Override - public boolean hasGravity() { - return true; - } - - @Override - public void setGravity(boolean gravity) {} - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.d(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_9_R1(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(name); + } + + @Override + public String getCustomName() { + return handle.getCustomName(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.h(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(null); + } + + @Override + public boolean hasGravity() { + return true; + } + + @Override + public void setGravity(boolean gravity) {} + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.d(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/EntityLiving1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/EntityLiving1_9_R1.java index 9314ab3..aa85a6d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/EntityLiving1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/EntityLiving1_9_R1.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_9_R1 extends Entity1_9_R1 implements NmsEntityLiving { - public EntityLiving1_9_R1(E handle) { - super(handle); - } + public EntityLiving1_9_R1(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/Player1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/Player1_9_R1.java index 0107592..236b1f8 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/Player1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/entity/Player1_9_R1.java @@ -49,231 +49,231 @@ public class Player1_9_R1 extends EntityLiving1_9_R1 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_9_R1(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); - reflect.setFieldValue(packet, "header", headerComponent); - reflect.setFieldValue(packet, "footer", footerComponent); - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_9_R1(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + reflect.setFieldValue(packet, "header", headerComponent); + reflect.setFieldValue(packet, "footer", footerComponent); + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/reflection/NmsReflection1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/reflection/NmsReflection1_9_R1.java index 0fe3586..adff592 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/reflection/NmsReflection1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/reflection/NmsReflection1_9_R1.java @@ -8,27 +8,27 @@ public class NmsReflection1_9_R1 extends Reflections { - public static NmsReflection1_9_R1 INSTANCE = new NmsReflection1_9_R1(); + public static NmsReflection1_9_R1 INSTANCE = new NmsReflection1_9_R1(); - private NmsReflection1_9_R1() {} + private NmsReflection1_9_R1() {} - @Override - public void setup(ReflectionProvider provider) { + @Override + public void setup(ReflectionProvider provider) { - // - // - // Create Reflects - // + // + // + // Create Reflects + // - // - // Minecraft + // + // Minecraft - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class).searchField("header", "a") - .searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); - } + provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); + provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/BlockTools1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/BlockTools1_9_R1.java index 15bffa4..c06bb32 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/BlockTools1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/BlockTools1_9_R1.java @@ -14,26 +14,26 @@ public class BlockTools1_9_R1 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/ServerTools1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/ServerTools1_9_R1.java index d236675..023c62c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/ServerTools1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/ServerTools1_9_R1.java @@ -7,14 +7,14 @@ public class ServerTools1_9_R1 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/SkinTools1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/SkinTools1_9_R1.java index 83c8373..d4d3c15 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/SkinTools1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/tools/SkinTools1_9_R1.java @@ -8,9 +8,9 @@ public class SkinTools1_9_R1 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/utils/EntityConstructors1_9_R1.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/utils/EntityConstructors1_9_R1.java index 9b192a0..103af78 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/utils/EntityConstructors1_9_R1.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R1/utils/EntityConstructors1_9_R1.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_9_R1 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_9_R1(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_9_R1(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/BukkitConversion1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/BukkitConversion1_9_R2.java index 19c28a6..8787288 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/BukkitConversion1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/BukkitConversion1_9_R2.java @@ -7,7 +7,21 @@ import org.bukkit.entity.EntityType; import com.syntaxphoenix.syntaxapi.data.DataAdapterContext; -import com.syntaxphoenix.syntaxapi.nbt.*; +import com.syntaxphoenix.syntaxapi.nbt.NbtByte; +import com.syntaxphoenix.syntaxapi.nbt.NbtByteArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; +import com.syntaxphoenix.syntaxapi.nbt.NbtDouble; +import com.syntaxphoenix.syntaxapi.nbt.NbtEnd; +import com.syntaxphoenix.syntaxapi.nbt.NbtFloat; +import com.syntaxphoenix.syntaxapi.nbt.NbtInt; +import com.syntaxphoenix.syntaxapi.nbt.NbtIntArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtList; +import com.syntaxphoenix.syntaxapi.nbt.NbtLong; +import com.syntaxphoenix.syntaxapi.nbt.NbtLongArray; +import com.syntaxphoenix.syntaxapi.nbt.NbtShort; +import com.syntaxphoenix.syntaxapi.nbt.NbtString; +import com.syntaxphoenix.syntaxapi.nbt.NbtTag; +import com.syntaxphoenix.syntaxapi.nbt.NbtType; import net.minecraft.server.v1_9_R2.ItemStack; import net.minecraft.server.v1_9_R2.NBTBase; @@ -31,179 +45,179 @@ public class BukkitConversion1_9_R2 extends BukkitConversion { - protected BukkitConversion1_9_R2(VersionControl1_9_R2 versionControl) { - super(versionControl); - } - - @Override - public EntityType toEntityType(NmsEntityType type) { - try { - return EntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NmsEntityType fromEntityType(EntityType type) { - try { - return NmsEntityType.valueOf(type.name()); - } catch (IllegalArgumentException ignore) { - return null; - } - } - - @Override - public NBTBase toMinecraftTag(NbtTag tag) { - switch (tag.getType()) { - case BYTE: - return new NBTTagByte((byte) tag.getValue()); - case SHORT: - return new NBTTagShort((short) tag.getValue()); - case INT: - return new NBTTagInt((int) tag.getValue()); - case LONG: - return new NBTTagLong((long) tag.getValue()); - case FLOAT: - return new NBTTagFloat((float) tag.getValue()); - case DOUBLE: - return new NBTTagDouble((double) tag.getValue()); - case STRING: - return new NBTTagString((String) tag.getValue()); - case BYTE_ARRAY: - return new NBTTagByteArray((byte[]) tag.getValue()); - case INT_ARRAY: - return new NBTTagIntArray((int[]) tag.getValue()); - case LONG_ARRAY: - NBTTagList list = new NBTTagList(); - for(long value : (long[]) tag.getValue()) { - list.add(new NBTTagLong(value)); - } - return list; - case LIST: - return toMinecraftList((NbtList) tag); - case COMPOUND: - return toMinecraftCompound((NbtCompound) tag); - case END: - return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); - default: - return null; - } - } - - @Override - public NbtTag fromMinecraftTag(Object raw) { - if (!(raw instanceof NBTBase)) { - return null; - } - NBTBase tag = (NBTBase) raw; - NbtType type = NbtType.getById(tag.getTypeId()); - switch (type) { - case BYTE: - return new NbtByte(((NBTTagByte) tag).f()); - case SHORT: - return new NbtShort(((NBTTagShort) tag).e()); - case INT: - return new NbtInt(((NBTTagInt) tag).d()); - case LONG: - return new NbtLong(((NBTTagLong) tag).c()); - case FLOAT: - return new NbtFloat(((NBTTagFloat) tag).h()); - case DOUBLE: - return new NbtDouble(((NBTTagDouble) tag).g()); - case STRING: - return new NbtString(((NBTTagString) tag).a_()); - case BYTE_ARRAY: - return new NbtByteArray(((NBTTagByteArray) tag).c()); - case INT_ARRAY: - return new NbtIntArray(((NBTTagIntArray) tag).c()); - case LONG_ARRAY: - return new NbtLongArray(new long[0]); - case LIST: - return fromMinecraftList(tag); - case COMPOUND: - return fromMinecraftCompound(tag); - case END: - return NbtEnd.INSTANCE; - default: - return null; - } - } - - @Override - public NBTTagList toMinecraftList(NbtList list) { - NBTTagList output = new NBTTagList(); - for (NbtTag tag : list) { - output.add(toMinecraftTag(tag)); - } - return output; - } - - @SuppressWarnings("unchecked") - @Override - public NbtList fromMinecraftList(Object raw) { - if (!(raw instanceof NBTTagList)) { - return null; - } - NBTTagList list = (NBTTagList) raw; - List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); - NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); - for (NBTBase base : content) { - output.add(fromMinecraftTag(base)); - } - return output; - } - - @Override - public NBTTagCompound toMinecraftCompound(NbtCompound compound) { - NBTTagCompound output = new NBTTagCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.getKeys(); - for (String key : keys) { - output.set(key, toMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public NbtCompound fromMinecraftCompound(Object raw) { - if (!(raw instanceof NBTTagCompound)) { - return null; - } - NBTTagCompound compound = (NBTTagCompound) raw; - NbtCompound output = new NbtCompound(); - if (compound.isEmpty()) { - return output; - } - Set keys = compound.c(); - for (String key : keys) { - output.set(key, fromMinecraftTag(compound.get(key))); - } - return output; - } - - @Override - public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { - return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); - } - - @Override - public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { - ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagCompound stackTag; - if (!nmsStack.hasTag()) { - stackTag = nmsStack.save(new NBTTagCompound()); - } else { - stackTag = nmsStack.getTag(); - } - return fromMinecraftCompound(stackTag); - } - - @Override - public WrappedContext createContext(DataAdapterContext context) { - return new SimpleSyntaxContext(context); - } + protected BukkitConversion1_9_R2(VersionControl1_9_R2 versionControl) { + super(versionControl); + } + + @Override + public EntityType toEntityType(NmsEntityType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NmsEntityType fromEntityType(EntityType type) { + try { + return NmsEntityType.valueOf(type.name()); + } catch (IllegalArgumentException ignore) { + return null; + } + } + + @Override + public NBTBase toMinecraftTag(NbtTag tag) { + switch (tag.getType()) { + case BYTE: + return new NBTTagByte((byte) tag.getValue()); + case SHORT: + return new NBTTagShort((short) tag.getValue()); + case INT: + return new NBTTagInt((int) tag.getValue()); + case LONG: + return new NBTTagLong((long) tag.getValue()); + case FLOAT: + return new NBTTagFloat((float) tag.getValue()); + case DOUBLE: + return new NBTTagDouble((double) tag.getValue()); + case STRING: + return new NBTTagString((String) tag.getValue()); + case BYTE_ARRAY: + return new NBTTagByteArray((byte[]) tag.getValue()); + case INT_ARRAY: + return new NBTTagIntArray((int[]) tag.getValue()); + case LONG_ARRAY: + NBTTagList list = new NBTTagList(); + for (long value : (long[]) tag.getValue()) { + list.add(new NBTTagLong(value)); + } + return list; + case LIST: + return toMinecraftList((NbtList) tag); + case COMPOUND: + return toMinecraftCompound((NbtCompound) tag); + case END: + return (NBTTagEnd) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagEnd").init(); + default: + return null; + } + } + + @Override + public NbtTag fromMinecraftTag(Object raw) { + if (!(raw instanceof NBTBase)) { + return null; + } + NBTBase tag = (NBTBase) raw; + NbtType type = NbtType.getById(tag.getTypeId()); + switch (type) { + case BYTE: + return new NbtByte(((NBTTagByte) tag).f()); + case SHORT: + return new NbtShort(((NBTTagShort) tag).e()); + case INT: + return new NbtInt(((NBTTagInt) tag).d()); + case LONG: + return new NbtLong(((NBTTagLong) tag).c()); + case FLOAT: + return new NbtFloat(((NBTTagFloat) tag).h()); + case DOUBLE: + return new NbtDouble(((NBTTagDouble) tag).g()); + case STRING: + return new NbtString(((NBTTagString) tag).a_()); + case BYTE_ARRAY: + return new NbtByteArray(((NBTTagByteArray) tag).c()); + case INT_ARRAY: + return new NbtIntArray(((NBTTagIntArray) tag).c()); + case LONG_ARRAY: + return new NbtLongArray(new long[0]); + case LIST: + return fromMinecraftList(tag); + case COMPOUND: + return fromMinecraftCompound(tag); + case END: + return NbtEnd.INSTANCE; + default: + return null; + } + } + + @Override + public NBTTagList toMinecraftList(NbtList list) { + NBTTagList output = new NBTTagList(); + for (NbtTag tag : list) { + output.add(toMinecraftTag(tag)); + } + return output; + } + + @SuppressWarnings("unchecked") + @Override + public NbtList fromMinecraftList(Object raw) { + if (!(raw instanceof NBTTagList)) { + return null; + } + NBTTagList list = (NBTTagList) raw; + List content = (List) ReflectionProvider.DEFAULT.getReflect("nmsNBTTagList").getFieldValue("value", list); + NbtList output = new NbtList<>(NbtType.getById(list.getTypeId())); + for (NBTBase base : content) { + output.add(fromMinecraftTag(base)); + } + return output; + } + + @Override + public NBTTagCompound toMinecraftCompound(NbtCompound compound) { + NBTTagCompound output = new NBTTagCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.getKeys(); + for (String key : keys) { + output.set(key, toMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public NbtCompound fromMinecraftCompound(Object raw) { + if (!(raw instanceof NBTTagCompound)) { + return null; + } + NBTTagCompound compound = (NBTTagCompound) raw; + NbtCompound output = new NbtCompound(); + if (compound.isEmpty()) { + return output; + } + Set keys = compound.c(); + for (String key : keys) { + output.set(key, fromMinecraftTag(compound.get(key))); + } + return output; + } + + @Override + public org.bukkit.inventory.ItemStack itemFromCompound(NbtCompound compound) { + return CraftItemStack.asBukkitCopy(ItemStack.createStack(toMinecraftCompound(compound))); + } + + @Override + public NbtCompound itemToCompound(org.bukkit.inventory.ItemStack itemStack) { + ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound stackTag; + if (!nmsStack.hasTag()) { + stackTag = nmsStack.save(new NBTTagCompound()); + } else { + stackTag = nmsStack.getTag(); + } + return fromMinecraftCompound(stackTag); + } + + @Override + public WrappedContext createContext(DataAdapterContext context) { + return new SimpleSyntaxContext(context); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/EntityProvider1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/EntityProvider1_9_R2.java index 9d53c7b..0924987 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/EntityProvider1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/EntityProvider1_9_R2.java @@ -13,35 +13,35 @@ public class EntityProvider1_9_R2 extends EntityProvider { - private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); - - protected EntityProvider1_9_R2(VersionControl1_9_R2 versionControl) { - super(versionControl); - } - - @SuppressWarnings("unchecked") - private final Function searchConstructor(NmsEntityType type) { - try { - return (Function) EntityConstructors1_9_R2.class.getField(type.name()).get(null); - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { - return null; - } - } - - private final Function getConstructor(NmsEntityType type) { - return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); - } - - @Override - public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { - if (!(world instanceof CraftWorld)) { - return null; - } - Function function; - if ((function = getConstructor(type)) == null) { - return null; - } - return function.apply(((CraftWorld) world).getHandle()); - } + private final EnumMap> entityMap = new EnumMap<>(NmsEntityType.class); + + protected EntityProvider1_9_R2(VersionControl1_9_R2 versionControl) { + super(versionControl); + } + + @SuppressWarnings("unchecked") + private final Function searchConstructor(NmsEntityType type) { + try { + return (Function) EntityConstructors1_9_R2.class.getField(type.name()).get(null); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignore) { + return null; + } + } + + private final Function getConstructor(NmsEntityType type) { + return entityMap.computeIfAbsent(type, (key -> searchConstructor(key))); + } + + @Override + public NmsEntity createEntity(org.bukkit.World world, NmsEntityType type) { + if (!(world instanceof CraftWorld)) { + return null; + } + Function function; + if ((function = getConstructor(type)) == null) { + return null; + } + return function.apply(((CraftWorld) world).getHandle()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/PacketHandler1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/PacketHandler1_9_R2.java index 65e797f..489d011 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/PacketHandler1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/PacketHandler1_9_R2.java @@ -4,8 +4,8 @@ public class PacketHandler1_9_R2 extends PacketHandler { - protected PacketHandler1_9_R2(VersionControl1_9_R2 versionControl) { - super(versionControl); - } + protected PacketHandler1_9_R2(VersionControl1_9_R2 versionControl) { + super(versionControl); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/PlayerProvider1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/PlayerProvider1_9_R2.java index 98bdf85..5ecdfac 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/PlayerProvider1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/PlayerProvider1_9_R2.java @@ -14,17 +14,17 @@ public class PlayerProvider1_9_R2 extends PlayerProvider { - private final DataDistributor distributor; - - protected PlayerProvider1_9_R2(VersionControl1_9_R2 versionControl) { - super(versionControl); - distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), - uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); - } - - @Override - protected NmsPlayer createPlayer(Player player) { - return new Player1_9_R2(player, distributor.get(player.getUniqueId())); - } + private final DataDistributor distributor; + + protected PlayerProvider1_9_R2(VersionControl1_9_R2 versionControl) { + super(versionControl); + distributor = versionControl.getDataProvider().createDistributor(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"), + uuid -> "custom_" + uuid.toString(), DataProvider.DEFAULT_RANDOM); + } + + @Override + protected NmsPlayer createPlayer(Player player) { + return new Player1_9_R2(player, distributor.get(player.getUniqueId())); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/TextureProvider1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/TextureProvider1_9_R2.java index b9b058c..09860c0 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/TextureProvider1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/TextureProvider1_9_R2.java @@ -20,86 +20,86 @@ @SuppressWarnings("deprecation") public class TextureProvider1_9_R2 extends TextureProvider { - private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); - private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_9_R2.inventory.CraftMetaSkull") - .searchField("serialized", "serializedProfile").searchField("profile", "profile"); - private final Material skullMaterial = Material.valueOf("SKULL"); + private final AbstractReflect craftItemStackRef = new Reflect(CraftItemStack.class).searchField("handle", "handle"); + private final AbstractReflect craftMetaSkullRef = new Reflect("org.bukkit.craftbukkit.v1_9_R2.inventory.CraftMetaSkull") + .searchField("serialized", "serializedProfile").searchField("profile", "profile"); + private final Material skullMaterial = Material.valueOf("SKULL"); - protected TextureProvider1_9_R2(VersionControl1_9_R2 versionControl) { - super(versionControl); - } + protected TextureProvider1_9_R2(VersionControl1_9_R2 versionControl) { + super(versionControl); + } - @Override - public GameProfile profileFromBlock(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - return ((CraftSkull) block).getTileEntity().getGameProfile(); - } + @Override + public GameProfile profileFromBlock(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + return ((CraftSkull) block).getTileEntity().getGameProfile(); + } - @Override - public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { - if (!(itemStack.getItemMeta() instanceof SkullMeta)) { - return null; - } - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); - if (profile == null) { - NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); - if (compound == null) { - ItemStack stack = null; - if (itemStack instanceof CraftItemStack) { - stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); - } - if (stack == null) { - stack = CraftItemStack.asNMSCopy(itemStack); - } - NBTTagCompound stackTag; - if (!stack.hasTag()) { - stackTag = stack.save(new NBTTagCompound()); - } else { - stackTag = stack.getTag(); - } - if (stackTag.hasKeyOfType("SkullOwner", 10)) { - compound = stackTag.getCompound("SkullOwner"); - } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { - compound = stackTag.getCompound("SkullProfile"); - } - } - if (compound == null) { - return null; - } - profile = GameProfileSerializer.deserialize(compound); - } - return profile; - } + @Override + public GameProfile profileFromItem(org.bukkit.inventory.ItemStack itemStack) { + if (!(itemStack.getItemMeta() instanceof SkullMeta)) { + return null; + } + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + GameProfile profile = (GameProfile) craftMetaSkullRef.getFieldValue("profile", meta); + if (profile == null) { + NBTTagCompound compound = (NBTTagCompound) craftMetaSkullRef.getFieldValue("serialized", meta); + if (compound == null) { + ItemStack stack = null; + if (itemStack instanceof CraftItemStack) { + stack = (ItemStack) craftItemStackRef.getFieldValue("handle", itemStack); + } + if (stack == null) { + stack = CraftItemStack.asNMSCopy(itemStack); + } + NBTTagCompound stackTag; + if (!stack.hasTag()) { + stackTag = stack.save(new NBTTagCompound()); + } else { + stackTag = stack.getTag(); + } + if (stackTag.hasKeyOfType("SkullOwner", 10)) { + compound = stackTag.getCompound("SkullOwner"); + } else if (stackTag.hasKeyOfType("SkullProfile", 10)) { + compound = stackTag.getCompound("SkullProfile"); + } + } + if (compound == null) { + return null; + } + profile = GameProfileSerializer.deserialize(compound); + } + return profile; + } - @Override - public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { - org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); - applyItem(craftStack, profile); - return craftStack; - } + @Override + public org.bukkit.inventory.ItemStack getItem(GameProfile profile) { + org.bukkit.inventory.ItemStack craftStack = CraftItemStack.asCraftCopy(new MaterialData(skullMaterial, (byte) 3).toItemStack(1)); + applyItem(craftStack, profile); + return craftStack; + } - @Override - public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { - ItemMeta meta = itemStack.getItemMeta(); - if (!(meta instanceof SkullMeta)) { - return false; - } - SkullMeta skullMeta = (SkullMeta) meta; - craftMetaSkullRef.setFieldValue(meta, "profile", profile); - itemStack.setItemMeta(skullMeta); - return true; - } + @Override + public boolean applyItem(org.bukkit.inventory.ItemStack itemStack, GameProfile profile) { + ItemMeta meta = itemStack.getItemMeta(); + if (!(meta instanceof SkullMeta)) { + return false; + } + SkullMeta skullMeta = (SkullMeta) meta; + craftMetaSkullRef.setFieldValue(meta, "profile", profile); + itemStack.setItemMeta(skullMeta); + return true; + } - @Override - public boolean applyBlock(Block block, GameProfile profile) { - if (!(block instanceof CraftSkull)) { - return false; - } - ((CraftSkull) block).getTileEntity().setGameProfile(profile); - return true; - } + @Override + public boolean applyBlock(Block block, GameProfile profile) { + if (!(block instanceof CraftSkull)) { + return false; + } + ((CraftSkull) block).getTileEntity().setGameProfile(profile); + return true; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/ToolProvider1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/ToolProvider1_9_R2.java index 4984675..27fcd7f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/ToolProvider1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/ToolProvider1_9_R2.java @@ -1,31 +1,33 @@ package net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R2; import net.sourcewriters.minecraft.versiontools.reflection.ToolProvider; -import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R2.tools.*; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R2.tools.BlockTools1_9_R2; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R2.tools.ServerTools1_9_R2; +import net.sourcewriters.minecraft.versiontools.reflection.provider.v1_9_R2.tools.SkinTools1_9_R2; public class ToolProvider1_9_R2 extends ToolProvider { - private final BlockTools1_9_R2 blockTools = new BlockTools1_9_R2(); - private final SkinTools1_9_R2 skinTools = new SkinTools1_9_R2(); - private final ServerTools1_9_R2 serverTools = new ServerTools1_9_R2(); - - protected ToolProvider1_9_R2(VersionControl1_9_R2 versionControl) { - super(versionControl); - } - - @Override - public SkinTools1_9_R2 getSkinTools() { - return skinTools; - } - - @Override - public ServerTools1_9_R2 getServerTools() { - return serverTools; - } - - @Override - public BlockTools1_9_R2 getBlockTools() { - return blockTools; - } + private final BlockTools1_9_R2 blockTools = new BlockTools1_9_R2(); + private final SkinTools1_9_R2 skinTools = new SkinTools1_9_R2(); + private final ServerTools1_9_R2 serverTools = new ServerTools1_9_R2(); + + protected ToolProvider1_9_R2(VersionControl1_9_R2 versionControl) { + super(versionControl); + } + + @Override + public SkinTools1_9_R2 getSkinTools() { + return skinTools; + } + + @Override + public ServerTools1_9_R2 getServerTools() { + return serverTools; + } + + @Override + public BlockTools1_9_R2 getBlockTools() { + return blockTools; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/VersionControl1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/VersionControl1_9_R2.java index b086ad9..9549f16 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/VersionControl1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/VersionControl1_9_R2.java @@ -6,51 +6,51 @@ public class VersionControl1_9_R2 extends VersionControl { - public static VersionControl1_9_R2 INSTANCE; - - public static VersionControl1_9_R2 init() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_9_R2()); - } - - private final ToolProvider1_9_R2 toolProvider = new ToolProvider1_9_R2(this); - private final TextureProvider1_9_R2 textureProvider = new TextureProvider1_9_R2(this); - private final PacketHandler1_9_R2 packetHandler = new PacketHandler1_9_R2(this); - private final EntityProvider1_9_R2 entityProvider = new EntityProvider1_9_R2(this); - private final PlayerProvider1_9_R2 playerProvider = new PlayerProvider1_9_R2(this); - private final BukkitConversion1_9_R2 bukkitConversion = new BukkitConversion1_9_R2(this); - - private VersionControl1_9_R2() { - NmsReflection1_9_R2.INSTANCE.setup(ReflectionProvider.DEFAULT); - } - - @Override - public ToolProvider1_9_R2 getToolProvider() { - return toolProvider; - } - - @Override - public EntityProvider1_9_R2 getEntityProvider() { - return entityProvider; - } - - @Override - public PlayerProvider1_9_R2 getPlayerProvider() { - return playerProvider; - } - - @Override - public TextureProvider1_9_R2 getTextureProvider() { - return textureProvider; - } - - @Override - public PacketHandler1_9_R2 getPacketHandler() { - return packetHandler; - } - - @Override - public BukkitConversion1_9_R2 getBukkitConversion() { - return bukkitConversion; - } + public static VersionControl1_9_R2 INSTANCE; + + public static VersionControl1_9_R2 init() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new VersionControl1_9_R2()); + } + + private final ToolProvider1_9_R2 toolProvider = new ToolProvider1_9_R2(this); + private final TextureProvider1_9_R2 textureProvider = new TextureProvider1_9_R2(this); + private final PacketHandler1_9_R2 packetHandler = new PacketHandler1_9_R2(this); + private final EntityProvider1_9_R2 entityProvider = new EntityProvider1_9_R2(this); + private final PlayerProvider1_9_R2 playerProvider = new PlayerProvider1_9_R2(this); + private final BukkitConversion1_9_R2 bukkitConversion = new BukkitConversion1_9_R2(this); + + private VersionControl1_9_R2() { + NmsReflection1_9_R2.INSTANCE.setup(ReflectionProvider.DEFAULT); + } + + @Override + public ToolProvider1_9_R2 getToolProvider() { + return toolProvider; + } + + @Override + public EntityProvider1_9_R2 getEntityProvider() { + return entityProvider; + } + + @Override + public PlayerProvider1_9_R2 getPlayerProvider() { + return playerProvider; + } + + @Override + public TextureProvider1_9_R2 getTextureProvider() { + return textureProvider; + } + + @Override + public PacketHandler1_9_R2 getPacketHandler() { + return packetHandler; + } + + @Override + public BukkitConversion1_9_R2 getBukkitConversion() { + return bukkitConversion; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/ArmorStand1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/ArmorStand1_9_R2.java index ccdd26c..f56f107 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/ArmorStand1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/ArmorStand1_9_R2.java @@ -6,28 +6,28 @@ public class ArmorStand1_9_R2 extends EntityLiving1_9_R2 implements NmsArmorStand { - public ArmorStand1_9_R2(World world) { - super(new EntityArmorStand(world)); - } - - @Override - public boolean hasGravity() { - return handle.hasGravity(); - } - - @Override - public void setGravity(boolean gravity) { - handle.setGravity(gravity); - } - - @Override - public void setSmall(boolean small) { - handle.setSmall(small); - } - - @Override - public boolean isSmall() { - return handle.isSmall(); - } + public ArmorStand1_9_R2(World world) { + super(new EntityArmorStand(world)); + } + + @Override + public boolean hasGravity() { + return handle.hasGravity(); + } + + @Override + public void setGravity(boolean gravity) { + handle.setGravity(gravity); + } + + @Override + public void setSmall(boolean small) { + handle.setSmall(small); + } + + @Override + public boolean isSmall() { + return handle.isSmall(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/Entity1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/Entity1_9_R2.java index eb24574..f16b0fc 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/Entity1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/Entity1_9_R2.java @@ -25,184 +25,186 @@ public abstract class Entity1_9_R2 implements NmsEntity { - protected final E handle; - - protected final List visible = Collections.synchronizedList(new ArrayList<>()); - - public Entity1_9_R2(E handle) { - this.handle = handle; - } - - @Override - public final E getHandle() { - return handle; - } - - @Override - public int getId() { - return handle.getId(); - } - - @Override - public UUID getUniqueId() { - return handle.getUniqueID(); - } - - @Override - public NmsBoundingBox getBoundingBox() { - AxisAlignedBB box = handle.getBoundingBox(); - return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); - } - - @Override - public void setCustomName(String name) { - handle.setCustomName(name); - } - - @Override - public String getCustomName() { - return handle.getCustomName(); - } - - @Override - public void setCustomNameVisible(boolean visible) { - handle.setCustomNameVisible(visible); - } - - @Override - public boolean isCustomNameVisible() { - return handle.getCustomNameVisible(); - } - - @Override - public void setInvisible(boolean invisible) { - handle.setInvisible(invisible); - } - - @Override - public boolean isInvisible() { - return handle.isInvisible(); - } - - @Override - public boolean isInteractable() { - return handle.isInteractable(); - } - - @Override - public boolean isCollidable() { - return handle.isCollidable(); - } - - @Override - public void setInvulnerable(boolean invulnerable) { - handle.setInvulnerable(invulnerable); - } - - @Override - public boolean isInvulnerable() { - return handle.isInvulnerable(null); - } - - @Override - public boolean hasGravity() { - return true; - } - - @Override - public void setGravity(boolean gravity) {} - - @Override - public void setLocation(Location location) { - handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { - updateVisibility(); - return; - } - handle.world = ((CraftWorld) location.getWorld()).getHandle(); - updateVisibility(); - } - - @Override - public Location getLocation() { - Vec3D vector = handle.d(); - return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); - } - - private void updateVisibility() { - if (visible.isEmpty()) { - return; - } - Player[] players; - synchronized (visible) { - players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - hide(players); - show(players); - } - - @Override - public boolean isShown(Player player) { - synchronized (visible) { - return visible.contains(player.getUniqueId()); - } - } - - @Override - public void hide(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); - for (Player player : players) { - if (!isShown(player)) { - continue; - } - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - synchronized (visible) { - visible.remove(player.getUniqueId()); - } - } - } - - @Override - public void show(Player... players) { - if (players.length == 0) { - return; - } - PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - PlayerConnection connection; - for (Player player : players) { - if (isShown(player)) { - continue; - } - connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(packet); - connection.sendPacket(metadataPacket); - synchronized (visible) { - visible.add(player.getUniqueId()); - } - } - } - - @Override - public UUID[] getVisible() { - synchronized (visible) { - return visible.toArray(new UUID[0]); - } - } - - @Override - public Player[] getVisibleAsPlayer() { - synchronized (visible) { - return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).toArray(Player[]::new); - } - } - - @Override - public void kill() { - handle.die(); - } + protected final E handle; + + protected final List visible = Collections.synchronizedList(new ArrayList<>()); + + public Entity1_9_R2(E handle) { + this.handle = handle; + } + + @Override + public final E getHandle() { + return handle; + } + + @Override + public int getId() { + return handle.getId(); + } + + @Override + public UUID getUniqueId() { + return handle.getUniqueID(); + } + + @Override + public NmsBoundingBox getBoundingBox() { + AxisAlignedBB box = handle.getBoundingBox(); + return new NmsBoundingBox(box.a, box.b, box.c, box.d, box.e, box.f); + } + + @Override + public void setCustomName(String name) { + handle.setCustomName(name); + } + + @Override + public String getCustomName() { + return handle.getCustomName(); + } + + @Override + public void setCustomNameVisible(boolean visible) { + handle.setCustomNameVisible(visible); + } + + @Override + public boolean isCustomNameVisible() { + return handle.getCustomNameVisible(); + } + + @Override + public void setInvisible(boolean invisible) { + handle.setInvisible(invisible); + } + + @Override + public boolean isInvisible() { + return handle.isInvisible(); + } + + @Override + public boolean isInteractable() { + return handle.isInteractable(); + } + + @Override + public boolean isCollidable() { + return handle.isCollidable(); + } + + @Override + public void setInvulnerable(boolean invulnerable) { + handle.setInvulnerable(invulnerable); + } + + @Override + public boolean isInvulnerable() { + return handle.isInvulnerable(null); + } + + @Override + public boolean hasGravity() { + return true; + } + + @Override + public void setGravity(boolean gravity) {} + + @Override + public void setLocation(Location location) { + handle.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + if (location.getWorld() == null || handle.getWorld().getWorld() == location.getWorld()) { + updateVisibility(); + return; + } + handle.world = ((CraftWorld) location.getWorld()).getHandle(); + updateVisibility(); + } + + @Override + public Location getLocation() { + Vec3D vector = handle.d(); + return new Location(handle.getWorld().getWorld(), vector.x, vector.y, vector.z); + } + + private void updateVisibility() { + if (visible.isEmpty()) { + return; + } + Player[] players; + synchronized (visible) { + players = visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + hide(players); + show(players); + } + + @Override + public boolean isShown(Player player) { + synchronized (visible) { + return visible.contains(player.getUniqueId()); + } + } + + @Override + public void hide(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(handle.getId()); + for (Player player : players) { + if (!isShown(player)) { + continue; + } + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + synchronized (visible) { + visible.remove(player.getUniqueId()); + } + } + } + + @Override + public void show(Player... players) { + if (players.length == 0) { + return; + } + PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(handle, EntityTypes.a(handle)); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + PlayerConnection connection; + for (Player player : players) { + if (isShown(player)) { + continue; + } + connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(packet); + connection.sendPacket(metadataPacket); + synchronized (visible) { + visible.add(player.getUniqueId()); + } + } + } + + @Override + public UUID[] getVisible() { + synchronized (visible) { + return visible.toArray(new UUID[0]); + } + } + + @Override + public Player[] getVisibleAsPlayer() { + synchronized (visible) { + return visible.stream().map(Bukkit::getOfflinePlayer).filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer) + .toArray(Player[]::new); + } + } + + @Override + public void kill() { + handle.die(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/EntityLiving1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/EntityLiving1_9_R2.java index a607ef3..713d3b1 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/EntityLiving1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/EntityLiving1_9_R2.java @@ -5,13 +5,13 @@ public abstract class EntityLiving1_9_R2 extends Entity1_9_R2 implements NmsEntityLiving { - public EntityLiving1_9_R2(E handle) { - super(handle); - } + public EntityLiving1_9_R2(E handle) { + super(handle); + } - @Override - public void setCollidable(boolean collidable) { - handle.collides = collidable; - } + @Override + public void setCollidable(boolean collidable) { + handle.collides = collidable; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/Player1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/Player1_9_R2.java index 09ad79f..1fc7f47 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/Player1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/entity/Player1_9_R2.java @@ -49,231 +49,231 @@ public class Player1_9_R2 extends EntityLiving1_9_R2 implements NmsPlayer { - private String realName; - private final WrappedContainer dataAdapter; - - public Player1_9_R2(Player player, PersistentContainer container) { - super(((CraftPlayer) player).getHandle()); - this.dataAdapter = new SimpleSyntaxContainer<>(container); - update(false); - } - - @Override - public CraftPlayer getBukkitPlayer() { - return handle.getBukkitEntity(); - } - - @Override - public WrappedContainer getDataAdapter() { - return dataAdapter; - } - - @Override - public void setSkin(Skin skin) { - if (skin == null || getSkin().equals(skin)) { - return; - } - getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); - } - - @Override - public Skin getSkin() { - return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); - } - - @Override - public void setName(String name) { - if (getName().equals(name)) { - return; - } - if (name == null) { - getDataAdapter().remove("name"); - return; - } - getDataAdapter().set("name", name, WrapType.STRING); - } - - @Override - public String getName() { - return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); - } - - @Override - public String getRealName() { - return realName; - } - - @Override - public void setPlayerListHeader(String text) { - setPlayerListHeaderAndFooter(text, getPlayerListFooter()); - } - - @Override - public String getPlayerListHeader() { - return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); - } - - @Override - public void setPlayerListFooter(String text) { - setPlayerListHeaderAndFooter(getPlayerListHeader(), text); - } - - @Override - public String getPlayerListFooter() { - return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); - } - - @Override - public int getPing() { - return handle.ping; - } - - @Override - public void setPlayerListHeaderAndFooter(String header, String footer) { - getDataAdapter().set("header", header, WrapType.STRING); - getDataAdapter().set("footer", footer, WrapType.STRING); - sendPlayerListInfo(header, footer); - } - - private final void sendPlayerListInfo(String header, String footer) { - if (handle.playerConnection.isDisconnected()) { - return; - } - - IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; - IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; - - PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); - - Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); - reflect.setFieldValue(packet, "header", headerComponent); - reflect.setFieldValue(packet, "footer", footerComponent); - - handle.playerConnection.sendPacket(packet); - } - - @Override - public void setTitleTimes(int fadeIn, int stay, int fadeOut) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); - } - - @Override - public void sendSubtitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendTitle(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); - } - - @Override - public void sendActionBar(String text) { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); - } - - @Override - public void fakeRespawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); - PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); - - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); - PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, - (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); - - ArrayList equipmentPackets = new ArrayList<>(); - for (EnumItemSlot slot : EnumItemSlot.values()) { - equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); - } - - Player self = getBukkitPlayer(); - Player[] players = Players.getOnlineWithout(getUniqueId()); - for (Player player : players) { - if (!player.canSee(self)) { - continue; - } - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(destroyPacket); - connection.sendPacket(spawnPacket); - connection.sendPacket(rotationPacket); - for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { - connection.sendPacket(equipmentPacket); - } - } - - WorldServer world = (WorldServer) handle.world; - - PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), handle.world.worldData.getType(), - handle.playerInteractManager.getGameMode()); - PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, - Collections.emptySet(), 0); - PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); - PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); - PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); - - PlayerConnection connection = handle.playerConnection; - connection.sendPacket(remInfoPacket); - connection.sendPacket(addInfoPacket); - connection.sendPacket(respawnPacket); - connection.sendPacket(positionPacket); - connection.sendPacket(itemPacket); - connection.sendPacket(statusPacket); - connection.sendPacket(metadataPacket); - - handle.updateAbilities(); - handle.triggerHealthUpdate(); - handle.updateInventory(handle.defaultContainer); - if (handle.activeContainer != handle.defaultContainer) { - handle.updateInventory(handle.activeContainer); - } - self.recalculatePermissions(); - } - - @Override - public void respawn() { - if (handle.playerConnection.isDisconnected()) { - return; - } - handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); - } - - @Override - public void update() { - update(true); - } - - private final void update(boolean flag) { - PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); - if (flag) { - GameProfile profile = handle.getProfile(); - - Skin skin = getSkin(); - PropertyMap properties = profile.getProperties(); - properties.removeAll("textures"); - properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); - - ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); - - fakeRespawn(); - } - } + private String realName; + private final WrappedContainer dataAdapter; + + public Player1_9_R2(Player player, PersistentContainer container) { + super(((CraftPlayer) player).getHandle()); + this.dataAdapter = new SimpleSyntaxContainer<>(container); + update(false); + } + + @Override + public CraftPlayer getBukkitPlayer() { + return handle.getBukkitEntity(); + } + + @Override + public WrappedContainer getDataAdapter() { + return dataAdapter; + } + + @Override + public void setSkin(Skin skin) { + if (skin == null || getSkin().equals(skin)) { + return; + } + getDataAdapter().set("skin", skin, SkinDataType.INSTANCE); + } + + @Override + public Skin getSkin() { + return getDataAdapter().getOrDefault("skin", SkinDataType.INSTANCE, Skin.NONE); + } + + @Override + public void setName(String name) { + if (getName().equals(name)) { + return; + } + if (name == null) { + getDataAdapter().remove("name"); + return; + } + getDataAdapter().set("name", name, WrapType.STRING); + } + + @Override + public String getName() { + return getDataAdapter().getOrDefault("name", WrapType.STRING, realName); + } + + @Override + public String getRealName() { + return realName; + } + + @Override + public void setPlayerListHeader(String text) { + setPlayerListHeaderAndFooter(text, getPlayerListFooter()); + } + + @Override + public String getPlayerListHeader() { + return getDataAdapter().getOrDefault("header", WrapType.STRING, ""); + } + + @Override + public void setPlayerListFooter(String text) { + setPlayerListHeaderAndFooter(getPlayerListHeader(), text); + } + + @Override + public String getPlayerListFooter() { + return getDataAdapter().getOrDefault("footer", WrapType.STRING, ""); + } + + @Override + public int getPing() { + return handle.ping; + } + + @Override + public void setPlayerListHeaderAndFooter(String header, String footer) { + getDataAdapter().set("header", header, WrapType.STRING); + getDataAdapter().set("footer", footer, WrapType.STRING); + sendPlayerListInfo(header, footer); + } + + private final void sendPlayerListInfo(String header, String footer) { + if (handle.playerConnection.isDisconnected()) { + return; + } + + IChatBaseComponent headerComponent = header.isEmpty() ? null : CraftChatMessage.fromString(header, true)[0]; + IChatBaseComponent footerComponent = footer.isEmpty() ? null : CraftChatMessage.fromString(footer, true)[0]; + + PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(); + + Reflect reflect = ReflectionProvider.DEFAULT.getReflect("nmsPacketPlayOutPlayerListHeaderFooter"); + reflect.setFieldValue(packet, "header", headerComponent); + reflect.setFieldValue(packet, "footer", footerComponent); + + handle.playerConnection.sendPacket(packet); + } + + @Override + public void setTitleTimes(int fadeIn, int stay, int fadeOut) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn, stay, fadeOut)); + } + + @Override + public void sendSubtitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendTitle(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutTitle(EnumTitleAction.TITLE, CraftChatMessage.fromString(text)[0])); + } + + @Override + public void sendActionBar(String text) { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayOutChat(CraftChatMessage.fromString(text)[0], (byte) 2)); + } + + @Override + public void fakeRespawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + PacketPlayOutPlayerInfo remInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, handle); + PacketPlayOutPlayerInfo addInfoPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, handle); + + PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(handle.getId()); + PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(handle); + PacketPlayOutEntityHeadRotation rotationPacket = new PacketPlayOutEntityHeadRotation(handle, + (byte) MathHelper.d(handle.getHeadRotation() * 256F / 360F)); + + ArrayList equipmentPackets = new ArrayList<>(); + for (EnumItemSlot slot : EnumItemSlot.values()) { + equipmentPackets.add(new PacketPlayOutEntityEquipment(handle.getId(), slot, handle.getEquipment(slot))); + } + + Player self = getBukkitPlayer(); + Player[] players = Players.getOnlineWithout(getUniqueId()); + for (Player player : players) { + if (!player.canSee(self)) { + continue; + } + PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(destroyPacket); + connection.sendPacket(spawnPacket); + connection.sendPacket(rotationPacket); + for (PacketPlayOutEntityEquipment equipmentPacket : equipmentPackets) { + connection.sendPacket(equipmentPacket); + } + } + + WorldServer world = (WorldServer) handle.world; + + PacketPlayOutRespawn respawnPacket = new PacketPlayOutRespawn(handle.dimension, world.getDifficulty(), + handle.world.worldData.getType(), handle.playerInteractManager.getGameMode()); + PacketPlayOutPosition positionPacket = new PacketPlayOutPosition(handle.locX, handle.locY, handle.locZ, handle.yaw, handle.pitch, + Collections.emptySet(), 0); + PacketPlayOutHeldItemSlot itemPacket = new PacketPlayOutHeldItemSlot(handle.inventory.itemInHandIndex); + PacketPlayOutEntityStatus statusPacket = new PacketPlayOutEntityStatus(handle, (byte) 28); + PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true); + + PlayerConnection connection = handle.playerConnection; + connection.sendPacket(remInfoPacket); + connection.sendPacket(addInfoPacket); + connection.sendPacket(respawnPacket); + connection.sendPacket(positionPacket); + connection.sendPacket(itemPacket); + connection.sendPacket(statusPacket); + connection.sendPacket(metadataPacket); + + handle.updateAbilities(); + handle.triggerHealthUpdate(); + handle.updateInventory(handle.defaultContainer); + if (handle.activeContainer != handle.defaultContainer) { + handle.updateInventory(handle.activeContainer); + } + self.recalculatePermissions(); + } + + @Override + public void respawn() { + if (handle.playerConnection.isDisconnected()) { + return; + } + handle.playerConnection.sendPacket(new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN)); + } + + @Override + public void update() { + update(true); + } + + private final void update(boolean flag) { + PostAsync.forcePost(() -> realName = MojangProfileServer.getName(getUniqueId())); + if (flag) { + GameProfile profile = handle.getProfile(); + + Skin skin = getSkin(); + PropertyMap properties = profile.getProperties(); + properties.removeAll("textures"); + properties.put("textures", new Property("textures", skin.getValue(), skin.getSignature())); + + ReflectionProvider.DEFAULT.getReflect("mjGameProfile").setFieldValue(profile, "name", getName()); + + fakeRespawn(); + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/reflection/NmsReflection1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/reflection/NmsReflection1_9_R2.java index d562ccf..f0494dd 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/reflection/NmsReflection1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/reflection/NmsReflection1_9_R2.java @@ -8,27 +8,27 @@ public class NmsReflection1_9_R2 extends Reflections { - public static NmsReflection1_9_R2 INSTANCE = new NmsReflection1_9_R2(); + public static NmsReflection1_9_R2 INSTANCE = new NmsReflection1_9_R2(); - private NmsReflection1_9_R2() {} + private NmsReflection1_9_R2() {} - @Override - public void setup(ReflectionProvider provider) { + @Override + public void setup(ReflectionProvider provider) { - // - // - // Create Reflects - // + // + // + // Create Reflects + // - // - // Minecraft + // + // Minecraft - provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class).searchField("header", "a") - .searchField("header", "b"); - - provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); - provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + provider.createReflect("nmsPacketPlayOutPlayerListHeaderFooter", PacketPlayOutPlayerListHeaderFooter.class) + .searchField("header", "a").searchField("header", "b"); - } + provider.createReflect("nmsNBTTagEnd", NBTTagEnd.class); + provider.createReflect("nmsNBTTagList", NBTTagList.class).searchField("value", "list"); + + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/BlockTools1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/BlockTools1_9_R2.java index 5279b1c..45173b5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/BlockTools1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/BlockTools1_9_R2.java @@ -14,26 +14,26 @@ public class BlockTools1_9_R2 extends BlockTools { - private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); - - @Override - public void setHeadTexture(Block block, String texture) { - if (!(block instanceof CraftSkull)) { - return; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - PropertyMap map = entitySkull.getGameProfile().getProperties(); - map.removeAll("textures"); - map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); - } - - @Override - public String getHeadTexture(Block block) { - if (!(block instanceof CraftSkull)) { - return null; - } - TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); - return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - } + private final AbstractReflect craftEntityStateRef = new Reflect(CraftSkull.class).searchField("tileEntity", "tileEntity"); + + @Override + public void setHeadTexture(Block block, String texture) { + if (!(block instanceof CraftSkull)) { + return; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + PropertyMap map = entitySkull.getGameProfile().getProperties(); + map.removeAll("textures"); + map.put("textures", new Property("textures", MinecraftConstants.TEXTURE_SIGNATURE, texture)); + } + + @Override + public String getHeadTexture(Block block) { + if (!(block instanceof CraftSkull)) { + return null; + } + TileEntitySkull entitySkull = (TileEntitySkull) craftEntityStateRef.getFieldValue("tileEntity", block); + return entitySkull.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/ServerTools1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/ServerTools1_9_R2.java index 64eacfe..67d15e6 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/ServerTools1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/ServerTools1_9_R2.java @@ -7,14 +7,14 @@ public class ServerTools1_9_R2 extends ServerTools { - @Override - public void setMotd(String text) { - ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); - } + @Override + public void setMotd(String text) { + ((CraftServer) Bukkit.getServer()).getServer().setMotd(text); + } - @Override - public String getMotd() { - return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); - } + @Override + public String getMotd() { + return ((CraftServer) Bukkit.getServer()).getServer().getMotd(); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/SkinTools1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/SkinTools1_9_R2.java index 5154013..3895604 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/SkinTools1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/tools/SkinTools1_9_R2.java @@ -8,9 +8,9 @@ public class SkinTools1_9_R2 extends SkinTools { - @Override - public Skin skinFromPlayer(Player player) { - return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); - } + @Override + public Skin skinFromPlayer(Player player) { + return skinFromGameProfile(((CraftPlayer) player).getHandle().getProfile()); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/utils/EntityConstructors1_9_R2.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/utils/EntityConstructors1_9_R2.java index ef58eb9..76e2f03 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/utils/EntityConstructors1_9_R2.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/provider/v1_9_R2/utils/EntityConstructors1_9_R2.java @@ -7,6 +7,6 @@ public abstract class EntityConstructors1_9_R2 { - public static final Function ARMOR_STAND = (world -> new ArmorStand1_9_R2(world)); + public static final Function ARMOR_STAND = (world -> new ArmorStand1_9_R2(world)); } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/FakeReflect.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/FakeReflect.java index b2e7896..e621cdb 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/FakeReflect.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/FakeReflect.java @@ -13,228 +13,228 @@ public class FakeReflect extends Reflect { - public static final FakeReflect FAKE = new FakeReflect(); - - @SuppressWarnings("rawtypes") - private final Collection collection = Collections.unmodifiableCollection(Arrays.asList()); - - private FakeReflect() { - super((Class) null); - } - - /* - * - */ - - @Override - public Class getOwner() { - return null; - } - - /* - * - */ - - @Override - public void delete() {} - - /* - * - */ - - @SuppressWarnings("unchecked") - @Override - public Collection> getConstructors() { - return collection; - } - - @SuppressWarnings("unchecked") - @Override - public Collection getMethods() { - return collection; - } - - @SuppressWarnings("unchecked") - @Override - public Collection getFields() { - return collection; - } - - /* - * - */ - - @Override - public boolean putConstructor(String name, Constructor constructor) { - return true; - } - - @Override - public boolean putMethod(String name, Method method) { - return true; - } - - @Override - public boolean putField(String name, Field field) { - return true; - } - - /* - * - */ - - @Override - public boolean containsMethod(String name) { - return false; - } - - @Override - public boolean containsField(String name) { - return false; - } - - /* - * - */ - - @Override - public Object init() { - return null; - } - - @Override - public Object init(String name, Object... args) { - return null; - } - - /* - * - */ - - @Override - public FakeReflect execute(String name, Object... args) { - return this; - } - - @Override - public FakeReflect execute(Object source, String name, Object... args) { - return this; - } - - @Override - public Object run(String name, Object... args) { - return null; - } - - @Override - public Object run(Object source, String name, Object... args) { - return null; - } - - /* - * - */ - - @Override - public Object getFieldValue(String name) { - return null; - } - - @Override - public Object getFieldValue(String name, Object source) { - return null; - } - - @Override - public void setFieldValue(String name, Object value) {} - - @Override - public void setFieldValue(Object source, String name, Object value) {} - - /* - * - */ - - @Override - public Constructor getConstructor(String name) { - return null; - } - - @Override - public Method getMethod(String name) { - return null; - } - - @Override - public Field getField(String name) { - return null; - } - - /* - * - */ - - @Override - public FakeReflect searchConstructor(Predicate predicate, String name, Class... args) { - return this; - } - - @Override - public FakeReflect searchConstructor(String name, Class... args) { - return this; - } - - @Override - public FakeReflect searchConstructorsByArguments(String base, Class... arguments) { - return this; - } - - /* - * - */ - - @Override - public FakeReflect searchMethod(Predicate predicate, String name, String methodName, Class... arguments) { - return this; - } - - @Override - public FakeReflect searchMethod(String name, String methodName, Class... arguments) { - return this; - } - - @Override - public FakeReflect searchMethodsByArguments(String base, Class... arguments) { - return this; - } - - /* - * - */ - - @Override - public FakeReflect searchField(Predicate predicate, String name, String fieldName) { - return this; - } - - @Override - public FakeReflect searchField(String name, String fieldName) { - return this; - } - - @Override - public FakeReflect searchFields(String name, String fieldName) { - return this; - } - - @Override - public FakeReflect searchField(String name, Class type) { - return this; - } - - @Override - public FakeReflect searchFields(String name, Class type) { - return this; - } + public static final FakeReflect FAKE = new FakeReflect(); + + @SuppressWarnings("rawtypes") + private final Collection collection = Collections.unmodifiableCollection(Arrays.asList()); + + private FakeReflect() { + super((Class) null); + } + + /* + * + */ + + @Override + public Class getOwner() { + return null; + } + + /* + * + */ + + @Override + public void delete() {} + + /* + * + */ + + @SuppressWarnings("unchecked") + @Override + public Collection> getConstructors() { + return collection; + } + + @SuppressWarnings("unchecked") + @Override + public Collection getMethods() { + return collection; + } + + @SuppressWarnings("unchecked") + @Override + public Collection getFields() { + return collection; + } + + /* + * + */ + + @Override + public boolean putConstructor(String name, Constructor constructor) { + return true; + } + + @Override + public boolean putMethod(String name, Method method) { + return true; + } + + @Override + public boolean putField(String name, Field field) { + return true; + } + + /* + * + */ + + @Override + public boolean containsMethod(String name) { + return false; + } + + @Override + public boolean containsField(String name) { + return false; + } + + /* + * + */ + + @Override + public Object init() { + return null; + } + + @Override + public Object init(String name, Object... args) { + return null; + } + + /* + * + */ + + @Override + public FakeReflect execute(String name, Object... args) { + return this; + } + + @Override + public FakeReflect execute(Object source, String name, Object... args) { + return this; + } + + @Override + public Object run(String name, Object... args) { + return null; + } + + @Override + public Object run(Object source, String name, Object... args) { + return null; + } + + /* + * + */ + + @Override + public Object getFieldValue(String name) { + return null; + } + + @Override + public Object getFieldValue(String name, Object source) { + return null; + } + + @Override + public void setFieldValue(String name, Object value) {} + + @Override + public void setFieldValue(Object source, String name, Object value) {} + + /* + * + */ + + @Override + public Constructor getConstructor(String name) { + return null; + } + + @Override + public Method getMethod(String name) { + return null; + } + + @Override + public Field getField(String name) { + return null; + } + + /* + * + */ + + @Override + public FakeReflect searchConstructor(Predicate predicate, String name, Class... args) { + return this; + } + + @Override + public FakeReflect searchConstructor(String name, Class... args) { + return this; + } + + @Override + public FakeReflect searchConstructorsByArguments(String base, Class... arguments) { + return this; + } + + /* + * + */ + + @Override + public FakeReflect searchMethod(Predicate predicate, String name, String methodName, Class... arguments) { + return this; + } + + @Override + public FakeReflect searchMethod(String name, String methodName, Class... arguments) { + return this; + } + + @Override + public FakeReflect searchMethodsByArguments(String base, Class... arguments) { + return this; + } + + /* + * + */ + + @Override + public FakeReflect searchField(Predicate predicate, String name, String fieldName) { + return this; + } + + @Override + public FakeReflect searchField(String name, String fieldName) { + return this; + } + + @Override + public FakeReflect searchFields(String name, String fieldName) { + return this; + } + + @Override + public FakeReflect searchField(String name, Class type) { + return this; + } + + @Override + public FakeReflect searchFields(String name, Class type) { + return this; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/ReflectionProvider.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/ReflectionProvider.java index 5269615..affbebf 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/ReflectionProvider.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/ReflectionProvider.java @@ -14,112 +14,112 @@ public class ReflectionProvider { - public static final String CB_PATH_FORMAT = "org.bukkit.craftbukkit.%s.%s"; - public static final String NMS_PATH_FORMAT = "net.minecraft.server.%s.%s"; + public static final String CB_PATH_FORMAT = "org.bukkit.craftbukkit.%s.%s"; + public static final String NMS_PATH_FORMAT = "net.minecraft.server.%s.%s"; - public static final ReflectionProvider DEFAULT = new ReflectionProvider(provider -> Reflections.globalSetup(provider)); + public static final ReflectionProvider DEFAULT = new ReflectionProvider(provider -> Reflections.globalSetup(provider)); - protected final ReflectCache cache; + protected final ReflectCache cache; - protected final String cbPath; - protected final String nmsPath; + protected final String cbPath; + protected final String nmsPath; - protected final ServerVersion version; + protected final ServerVersion version; - private boolean skip = false; + private boolean skip = false; - public ReflectionProvider() { - this((Consumer) null); - } + public ReflectionProvider() { + this((Consumer) null); + } - public ReflectionProvider(Consumer setup) { - this(new ReflectCache(), setup); - } + public ReflectionProvider(Consumer setup) { + this(new ReflectCache(), setup); + } - public ReflectionProvider(ReflectCache cache) { - this(cache, null); - } + public ReflectionProvider(ReflectCache cache) { + this(cache, null); + } - public ReflectionProvider(ReflectCache cache, Consumer setup) { - this.cache = cache; - this.version = Versions.getServer(); - this.cbPath = String.format(CB_PATH_FORMAT, Versions.getServerAsString(), "%s"); - this.nmsPath = String.format(NMS_PATH_FORMAT, Versions.getServerAsString(), "%s"); - setup.accept(this); - } + public ReflectionProvider(ReflectCache cache, Consumer setup) { + this.cache = cache; + this.version = Versions.getServer(); + this.cbPath = String.format(CB_PATH_FORMAT, Versions.getServerAsString(), "%s"); + this.nmsPath = String.format(NMS_PATH_FORMAT, Versions.getServerAsString(), "%s"); + setup.accept(this); + } - public ServerVersion getVersion() { - return version; - } + public ServerVersion getVersion() { + return version; + } - /* - * Skip - */ + /* + * Skip + */ - public ReflectionProvider require(boolean skip) { - this.skip = !skip; - return this; - } + public ReflectionProvider require(boolean skip) { + this.skip = !skip; + return this; + } - public ReflectionProvider skip(boolean skip) { - this.skip = skip; - return this; - } + public ReflectionProvider skip(boolean skip) { + this.skip = skip; + return this; + } - public boolean skip() { - return skip; - } + public boolean skip() { + return skip; + } - /* - * Reflection - */ + /* + * Reflection + */ - public ReflectCache getReflection() { - return cache; - } + public ReflectCache getReflection() { + return cache; + } - public String getNmsPath() { - return nmsPath; - } + public String getNmsPath() { + return nmsPath; + } - public String getCbPath() { - return cbPath; - } + public String getCbPath() { + return cbPath; + } - public Reflect createNMSReflect(String name, String path) { - return skip ? FAKE : cache.create(name, getNMSClass(path)); - } + public Reflect createNMSReflect(String name, String path) { + return skip ? FAKE : cache.create(name, getNMSClass(path)); + } - public Reflect createCBReflect(String name, String path) { - return skip ? FAKE : cache.create(name, getCBClass(path)); - } + public Reflect createCBReflect(String name, String path) { + return skip ? FAKE : cache.create(name, getCBClass(path)); + } - public Reflect createReflect(String name, String path) { - return skip ? FAKE : cache.create(name, getClass(path)); - } + public Reflect createReflect(String name, String path) { + return skip ? FAKE : cache.create(name, getClass(path)); + } - public Reflect createReflect(String name, Class clazz) { - return skip ? FAKE : cache.create(name, clazz); - } + public Reflect createReflect(String name, Class clazz) { + return skip ? FAKE : cache.create(name, clazz); + } - public Optional getOptionalReflect(String name) { - return cache.get(name); - } + public Optional getOptionalReflect(String name) { + return cache.get(name); + } - public Reflect getReflect(String name) { - return cache.get(name).orElse(null); - } + public Reflect getReflect(String name) { + return cache.get(name).orElse(null); + } - public Class getNMSClass(String path) { - return getClass(String.format(nmsPath, path)); - } + public Class getNMSClass(String path) { + return getClass(String.format(nmsPath, path)); + } - public Class getCBClass(String path) { - return getClass(String.format(cbPath, path)); - } + public Class getCBClass(String path) { + return getClass(String.format(cbPath, path)); + } - public Class getClass(String path) { - return ClassCache.getClass(path); - } + public Class getClass(String path) { + return ClassCache.getClass(path); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/Reflections.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/Reflections.java index f82f034..80e941e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/Reflections.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/Reflections.java @@ -2,25 +2,25 @@ import java.util.function.Consumer; -import net.sourcewriters.minecraft.versiontools.reflection.reflect.provider.*; +import net.sourcewriters.minecraft.versiontools.reflection.reflect.provider.GeneralReflections; public abstract class Reflections { - public static void globalSetup(ReflectionProvider provider) { - GeneralReflections.INSTANCE.setup(provider); - } + public static void globalSetup(ReflectionProvider provider) { + GeneralReflections.INSTANCE.setup(provider); + } - public abstract void setup(ReflectionProvider provider); + public abstract void setup(ReflectionProvider provider); - public static T predicate(boolean condition, T value, Consumer action) { - if (condition) { - action.accept(value); - } - return value; - } + public static T predicate(boolean condition, T value, Consumer action) { + if (condition) { + action.accept(value); + } + return value; + } - public int priority() { - return 0; - } + public int priority() { + return 0; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/provider/GeneralReflections.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/provider/GeneralReflections.java index de5ff3e..25e2b5f 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/provider/GeneralReflections.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/reflect/provider/GeneralReflections.java @@ -6,29 +6,29 @@ import net.sourcewriters.minecraft.versiontools.reflection.reflect.Reflections; public class GeneralReflections extends Reflections { - - public static GeneralReflections INSTANCE = new GeneralReflections(); - - private GeneralReflections() {} - @Override - public void setup(ReflectionProvider provider) { + public static GeneralReflections INSTANCE = new GeneralReflections(); - // - // - // Needed classes to create Reflects - // + private GeneralReflections() {} - // - // - // Create Reflects - // + @Override + public void setup(ReflectionProvider provider) { - // - // Mojang + // + // + // Needed classes to create Reflects + // - provider.createReflect("mjGameProfile", GameProfile.class).searchField("name", "name"); + // + // + // Create Reflects + // - } + // + // Mojang + + provider.createReflect("mjGameProfile", GameProfile.class).searchField("name", "name"); + + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/BlockTools.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/BlockTools.java index 380091e..f00bd75 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/BlockTools.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/BlockTools.java @@ -4,8 +4,8 @@ public abstract class BlockTools { - public abstract void setHeadTexture(Block block, String texture); + public abstract void setHeadTexture(Block block, String texture); - public abstract String getHeadTexture(Block block); + public abstract String getHeadTexture(Block block); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/ServerTools.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/ServerTools.java index 85ed8ac..b02a6e1 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/ServerTools.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/ServerTools.java @@ -2,8 +2,8 @@ public abstract class ServerTools { - public abstract void setMotd(String text); + public abstract void setMotd(String text); - public abstract String getMotd(); + public abstract String getMotd(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/SkinTools.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/SkinTools.java index c692483..6f9ba53 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/SkinTools.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/tools/SkinTools.java @@ -10,16 +10,16 @@ public abstract class SkinTools { - public abstract Skin skinFromPlayer(Player player); + public abstract Skin skinFromPlayer(Player player); - public Skin skinFromGameProfile(GameProfile profile) { - PropertyMap properties = profile.getProperties(); - if (!properties.containsKey("textures")) { - return null; - } + public Skin skinFromGameProfile(GameProfile profile) { + PropertyMap properties = profile.getProperties(); + if (!properties.containsKey("textures")) { + return null; + } - Property property = properties.get("textures").iterator().next(); - return new Skin(profile.getName(), property.getValue(), property.getSignature()); - } + Property property = properties.get("textures").iterator().next(); + return new Skin(profile.getName(), property.getValue(), property.getSignature()); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/utils/NmsBoundingBox.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/utils/NmsBoundingBox.java index 37e5ba7..00ba282 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/utils/NmsBoundingBox.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/utils/NmsBoundingBox.java @@ -14,543 +14,545 @@ public class NmsBoundingBox { - public static NmsBoundingBox of(Vector min, Vector max) { - Objects.requireNonNull(min, "min is null!"); - Objects.requireNonNull(max, "max is null!"); - return new NmsBoundingBox(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ()); - } - - public static NmsBoundingBox of(Location min, Location max) { - Objects.requireNonNull(min, "min is null!"); - Objects.requireNonNull(max, "max is null!"); - ValidationHelper.isTrue(Objects.equals(min.getWorld(), max.getWorld()), "Locations from different worlds!"); - return new NmsBoundingBox(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ()); - } - - public static NmsBoundingBox of(Block min, Block max) { - Objects.requireNonNull(min, "min is null!"); - Objects.requireNonNull(max, "max is null!"); - ValidationHelper.isTrue(Objects.equals(min.getWorld(), max.getWorld()), "Blocks from different worlds!"); - int x1 = min.getX(); - int y1 = min.getY(); - int z1 = min.getZ(); - int x2 = max.getX(); - int y2 = max.getY(); - int z2 = max.getZ(); - int minX = Math.min(x1, x2); - int minY = Math.min(y1, y2); - int minZ = Math.min(z1, z2); - int maxX = Math.max(x1, x2) + 1; - int maxY = Math.max(y1, y2) + 1; - int maxZ = Math.max(z1, z2) + 1; - return new NmsBoundingBox((double) minX, (double) minY, (double) minZ, (double) maxX, (double) maxY, (double) maxZ); - } - - public static NmsBoundingBox of(Block block) { - Objects.requireNonNull(block, "Block is null!"); - return new NmsBoundingBox((double) block.getX(), (double) block.getY(), (double) block.getZ(), (double) (block.getX() + 1), (double) (block.getY() + 1), - (double) (block.getZ() + 1)); - } - - public static NmsBoundingBox of(Vector center, double x, double y, double z) { - Objects.requireNonNull(center, "Center is null!"); - return new NmsBoundingBox(center.getX() - x, center.getY() - y, center.getZ() - z, center.getX() + x, center.getY() + y, center.getZ() + z); - } - - public static NmsBoundingBox of(Location center, double x, double y, double z) { - Objects.requireNonNull(center, "Center is null!"); - return new NmsBoundingBox(center.getX() - x, center.getY() - y, center.getZ() - z, center.getX() + x, center.getY() + y, center.getZ() + z); - } - - private double minX, minY, minZ; - private double maxX, maxY, maxZ; - - public NmsBoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - resize(minX, minY, minZ, maxX, maxY, maxZ); - } - - public double getMinX() { - return minX; - } - - public double getMinY() { - return minY; - } - - public double getMinZ() { - return minZ; - } - - public double getMaxX() { - return maxX; - } - - public double getMaxY() { - return maxY; - } - - public double getMaxZ() { - return maxZ; - } - - public Vector getMin() { - return new Vector(getMinX(), getMinY(), getMinZ()); - } - - public Vector getMax() { - return new Vector(getMaxX(), getMaxY(), getMaxZ()); - } - - public NmsBoundingBox resize(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - checkFinite(minX, "minX not finite"); - checkFinite(minY, "minY not finite"); - checkFinite(minZ, "minZ not finite"); - checkFinite(maxX, "maxX not finite"); - checkFinite(maxY, "maxY not finite"); - checkFinite(maxZ, "maxZ not finite"); - this.minX = Math.min(minX, maxX); - this.minY = Math.min(minY, maxY); - this.minZ = Math.min(minZ, maxZ); - this.maxX = Math.max(minX, maxX); - this.maxY = Math.max(minY, maxY); - this.maxZ = Math.max(minZ, maxZ); - return this; - } - - public double getWidth() { - return getMaxX() - getMinX(); - } - - public double getDepth() { - return getMaxZ() - getMinZ(); - } - - public double getHeight() { - return getMaxY() - getMinY(); - } - - public double getVolume() { - return getHeight() * getWidth() * getDepth(); - } - - public double getCenterX() { - return getMinX() + getWidth() * 0.5D; - } - - public double getCenterY() { - return getMinY() + getHeight() * 0.5D; - } - - public double getCenterZ() { - return getMinZ() + getDepth() * 0.5D; - } - - public Vector getCenter() { - return new Vector(getCenterX(), getCenterY(), getCenterZ()); - } - - public NmsBoundingBox copy(NmsBoundingBox other) { - Objects.requireNonNull(other, "Other bounding box is null!"); - return resize(other.getMinX(), other.getMinY(), other.getMinZ(), other.getMaxX(), other.getMaxY(), other.getMaxZ()); - } - - public NmsBoundingBox expand(double negativeX, double negativeY, double negativeZ, double positiveX, double positiveY, double positiveZ) { - if (negativeX == 0.0D && negativeY == 0.0D && negativeZ == 0.0D && positiveX == 0.0D && positiveY == 0.0D && positiveZ == 0.0D) { - return this; - } else { - double newMinX = getMinX() - negativeX; - double newMinY = getMinY() - negativeY; - double newMinZ = getMinZ() - negativeZ; - double newMaxX = getMaxX() + positiveX; - double newMaxY = getMaxY() + positiveY; - double newMaxZ = getMaxZ() + positiveZ; - double centerZ; - if (newMinX > newMaxX) { - centerZ = getCenterX(); - if (newMaxX >= centerZ) { - newMinX = newMaxX; - } else if (newMinX <= centerZ) { - newMaxX = newMinX; - } else { - newMinX = centerZ; - newMaxX = centerZ; - } - } - - if (newMinY > newMaxY) { - centerZ = getCenterY(); - if (newMaxY >= centerZ) { - newMinY = newMaxY; - } else if (newMinY <= centerZ) { - newMaxY = newMinY; - } else { - newMinY = centerZ; - newMaxY = centerZ; - } - } - - if (newMinZ > newMaxZ) { - centerZ = getCenterZ(); - if (newMaxZ >= centerZ) { - newMinZ = newMaxZ; - } else if (newMinZ <= centerZ) { - newMaxZ = newMinZ; - } else { - newMinZ = centerZ; - newMaxZ = centerZ; - } - } - - return resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); - } - } - - public NmsBoundingBox expand(double x, double y, double z) { - return expand(x, y, z, x, y, z); - } - - public NmsBoundingBox expand(Vector expansion) { - Objects.requireNonNull(expansion, "Expansion is null!"); - return expand(expansion.getX(), expansion.getY(), expansion.getZ()); - } - - public NmsBoundingBox expand(double expansion) { - return expand(expansion, expansion, expansion, expansion, expansion, expansion); - } - - public NmsBoundingBox expand(double dirX, double dirY, double dirZ, double expansion) { - if (expansion == 0.0D) { - return this; - } else if (dirX == 0.0D && dirY == 0.0D && dirZ == 0.0D) { - return this; - } else { - double negativeX = dirX < 0.0D ? -dirX * expansion : 0.0D; - double negativeY = dirY < 0.0D ? -dirY * expansion : 0.0D; - double negativeZ = dirZ < 0.0D ? -dirZ * expansion : 0.0D; - double positiveX = dirX > 0.0D ? dirX * expansion : 0.0D; - double positiveY = dirY > 0.0D ? dirY * expansion : 0.0D; - double positiveZ = dirZ > 0.0D ? dirZ * expansion : 0.0D; - return expand(negativeX, negativeY, negativeZ, positiveX, positiveY, positiveZ); - } - } - - public NmsBoundingBox expand(Vector direction, double expansion) { - Objects.requireNonNull(direction, "Direction is null!"); - return expand(direction.getX(), direction.getY(), direction.getZ(), expansion); - } - - public NmsBoundingBox expand(BlockFace blockFace, double expansion) { - Objects.requireNonNull(blockFace, "Block face is null!"); - return blockFace == BlockFace.SELF ? this : expand(blockFace.getDirection(), expansion); - } - - public NmsBoundingBox expandDirectional(double dirX, double dirY, double dirZ) { - return expand(dirX, dirY, dirZ, 1.0D); - } - - public NmsBoundingBox expandDirectional(Vector direction) { - Objects.requireNonNull(direction, "Expansion is null!"); - return expand(direction.getX(), direction.getY(), direction.getZ(), 1.0D); - } - - public NmsBoundingBox union(double posX, double posY, double posZ) { - double newMinX = Math.min(getMinX(), posX); - double newMinY = Math.min(getMinY(), posY); - double newMinZ = Math.min(getMinZ(), posZ); - double newMaxX = Math.max(getMaxX(), posX); - double newMaxY = Math.max(getMaxY(), posY); - double newMaxZ = Math.max(getMaxZ(), posZ); - return newMinX == getMinX() && newMinY == getMinY() && newMinZ == getMinZ() && newMaxX == getMaxX() && newMaxY == getMaxY() && newMaxZ == getMaxZ() - ? this - : resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); - } - - public NmsBoundingBox union(Vector position) { - Objects.requireNonNull(position, "Position is null!"); - return union(position.getX(), position.getY(), position.getZ()); - } - - public NmsBoundingBox union(Location position) { - Objects.requireNonNull(position, "Position is null!"); - return union(position.getX(), position.getY(), position.getZ()); - } - - public NmsBoundingBox union(NmsBoundingBox other) { - Objects.requireNonNull(other, "Other bounding box is null!"); - if (contains(other)) { - return this; - } else { - double newMinX = Math.min(getMinX(), other.getMinX()); - double newMinY = Math.min(getMinY(), other.getMinY()); - double newMinZ = Math.min(getMinZ(), other.getMinZ()); - double newMaxX = Math.max(getMaxX(), other.getMaxX()); - double newMaxY = Math.max(getMaxY(), other.getMaxY()); - double newMaxZ = Math.max(getMaxZ(), other.getMaxZ()); - return resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); - } - } - - public NmsBoundingBox intersection(NmsBoundingBox other) { - Objects.requireNonNull(other, "Other bounding box is null!"); - ValidationHelper.isTrue(overlaps(other), "The bounding boxes do not overlap!"); - double newMinX = Math.max(getMinX(), other.getMinX()); - double newMinY = Math.max(getMinY(), other.getMinY()); - double newMinZ = Math.max(getMinZ(), other.getMinZ()); - double newMaxX = Math.min(getMaxX(), other.getMaxX()); - double newMaxY = Math.min(getMaxY(), other.getMaxY()); - double newMaxZ = Math.min(getMaxZ(), other.getMaxZ()); - return resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); - } - - public NmsBoundingBox shift(double shiftX, double shiftY, double shiftZ) { - return shiftX == 0.0D && shiftY == 0.0D && shiftZ == 0.0D ? this - : resize(getMinX() + shiftX, getMinY() + shiftY, getMinZ() + shiftZ, getMaxX() + shiftX, getMaxY() + shiftY, getMaxZ() + shiftZ); - } - - public NmsBoundingBox shift(Vector shift) { - Objects.requireNonNull(shift, "Shift is null!"); - return shift(shift.getX(), shift.getY(), shift.getZ()); - } - - public NmsBoundingBox shift(Location shift) { - Objects.requireNonNull(shift, "Shift is null!"); - return shift(shift.getX(), shift.getY(), shift.getZ()); - } - - private boolean overlaps(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - return getMinX() < maxX && getMaxX() > minX && getMinY() < maxY && getMaxY() > minY && getMinZ() < maxZ && getMaxZ() > minZ; - } - - public boolean overlaps(NmsBoundingBox other) { - Objects.requireNonNull(other, "Other bounding box is null!"); - return overlaps(other.getMinX(), other.getMinY(), other.getMinZ(), other.getMaxX(), other.getMaxY(), other.getMaxZ()); - } - - public boolean overlaps(Vector min, Vector max) { - Objects.requireNonNull(min, "Min is null!"); - Objects.requireNonNull(max, "Max is null!"); - double x1 = min.getX(); - double y1 = min.getY(); - double z1 = min.getZ(); - double x2 = max.getX(); - double y2 = max.getY(); - double z2 = max.getZ(); - return overlaps(x1, y1, z1, x2, y2, z2); - } - - public boolean contains(double x, double y, double z) { - return x >= getMinX() && x < getMaxX() && y >= getMinY() && y < getMaxY() && z >= getMinZ() && z < getMaxZ(); - } - - public boolean contains(Vector position) { - Objects.requireNonNull(position, "Position is null!"); - return contains(position.getX(), position.getY(), position.getZ()); - } - - private boolean contains(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - return getMinX() <= minX && getMaxX() >= maxX && getMinY() <= minY && getMaxY() >= maxY && getMinZ() <= minZ && getMaxZ() >= maxZ; - } - - public boolean contains(NmsBoundingBox other) { - Objects.requireNonNull(other, "Other bounding box is null!"); - return contains(other.getMinX(), other.getMinY(), other.getMinZ(), other.getMaxX(), other.getMaxY(), other.getMaxZ()); - } - - public boolean contains(Vector min, Vector max) { - Objects.requireNonNull(min, "Min is null!"); - Objects.requireNonNull(max, "Max is null!"); - double x1 = min.getX(); - double y1 = min.getY(); - double z1 = min.getZ(); - double x2 = max.getX(); - double y2 = max.getY(); - double z2 = max.getZ(); - return contains(x1, y1, z1, x2, y2, z2); - } - - public RayTraceResult rayTrace(Vector start, Vector direction, double maxDistance) { - Objects.requireNonNull(start, "Start is null!"); - start.checkFinite(); - Objects.requireNonNull(direction, "Direction is null!"); - direction.checkFinite(); - ValidationHelper.isTrue(direction.lengthSquared() > 0.0D, "Direction's magnitude is 0!"); - if (maxDistance < 0.0D) { - return null; - } else { - double startX = start.getX(); - double startY = start.getY(); - double startZ = start.getZ(); - Vector dir = direction.clone(); - dir.setX(dir.getX() == -0.0D ? 0.0D : dir.getX()); - dir.setY(dir.getY() == -0.0D ? 0.0D : dir.getY()); - dir.setZ(dir.getZ() == -0.0D ? 0.0D : dir.getZ()); - double dirX = dir.getX(); - double dirY = dir.getY(); - double dirZ = dir.getZ(); - double divX = 1.0D / dirX; - double divY = 1.0D / dirY; - double divZ = 1.0D / dirZ; - double tMin; - double tMax; - BlockFace hitBlockFaceMin; - BlockFace hitBlockFaceMax; - if (dirX >= 0.0D) { - tMin = (getMinX() - startX) * divX; - tMax = (getMaxX() - startX) * divX; - hitBlockFaceMin = BlockFace.WEST; - hitBlockFaceMax = BlockFace.EAST; - } else { - tMin = (getMaxX() - startX) * divX; - tMax = (getMinX() - startX) * divX; - hitBlockFaceMin = BlockFace.EAST; - hitBlockFaceMax = BlockFace.WEST; - } - - double tyMin; - double tyMax; - BlockFace hitBlockFaceYMin; - BlockFace hitBlockFaceYMax; - if (dirY >= 0.0D) { - tyMin = (getMinY() - startY) * divY; - tyMax = (getMaxY() - startY) * divY; - hitBlockFaceYMin = BlockFace.DOWN; - hitBlockFaceYMax = BlockFace.UP; - } else { - tyMin = (getMaxY() - startY) * divY; - tyMax = (getMinY() - startY) * divY; - hitBlockFaceYMin = BlockFace.UP; - hitBlockFaceYMax = BlockFace.DOWN; - } - - if (tMin <= tyMax && tMax >= tyMin) { - if (tyMin > tMin) { - tMin = tyMin; - hitBlockFaceMin = hitBlockFaceYMin; - } - - if (tyMax < tMax) { - tMax = tyMax; - hitBlockFaceMax = hitBlockFaceYMax; - } - - double tzMin; - double tzMax; - BlockFace hitBlockFaceZMin; - BlockFace hitBlockFaceZMax; - if (dirZ >= 0.0D) { - tzMin = (getMinZ() - startZ) * divZ; - tzMax = (getMaxZ() - startZ) * divZ; - hitBlockFaceZMin = BlockFace.NORTH; - hitBlockFaceZMax = BlockFace.SOUTH; - } else { - tzMin = (getMaxZ() - startZ) * divZ; - tzMax = (getMinZ() - startZ) * divZ; - hitBlockFaceZMin = BlockFace.SOUTH; - hitBlockFaceZMax = BlockFace.NORTH; - } - - if (tMin <= tzMax && tMax >= tzMin) { - if (tzMin > tMin) { - tMin = tzMin; - hitBlockFaceMin = hitBlockFaceZMin; - } - - if (tzMax < tMax) { - tMax = tzMax; - hitBlockFaceMax = hitBlockFaceZMax; - } - - if (tMax < 0.0D) { - return null; - } else if (tMin > maxDistance) { - return null; - } else { - double t; - BlockFace hitBlockFace; - if (tMin < 0.0D) { - t = tMax; - hitBlockFace = hitBlockFaceMax; - } else { - t = tMin; - hitBlockFace = hitBlockFaceMin; - } - - Vector hitPosition = dir.multiply(t).add(start); - return new RayTraceResult(hitPosition, hitBlockFace); - } - } else { - return null; - } - } else { - return null; - } - } - } - - public int hashCode() { - int result = 1; - long temp = Double.doubleToLongBits(getMaxX()); - result = 31 * result + (int) (temp ^ temp >>> 32); - temp = Double.doubleToLongBits(getMaxY()); - result = 31 * result + (int) (temp ^ temp >>> 32); - temp = Double.doubleToLongBits(getMaxZ()); - result = 31 * result + (int) (temp ^ temp >>> 32); - temp = Double.doubleToLongBits(getMinX()); - result = 31 * result + (int) (temp ^ temp >>> 32); - temp = Double.doubleToLongBits(getMinY()); - result = 31 * result + (int) (temp ^ temp >>> 32); - temp = Double.doubleToLongBits(getMinZ()); - result = 31 * result + (int) (temp ^ temp >>> 32); - return result; - } - - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if (!(obj instanceof NmsBoundingBox)) { - return false; - } else { - NmsBoundingBox other = (NmsBoundingBox) obj; - if (Double.doubleToLongBits(getMaxX()) != Double.doubleToLongBits(other.getMaxX())) { - return false; - } else if (Double.doubleToLongBits(getMaxY()) != Double.doubleToLongBits(other.getMaxY())) { - return false; - } else if (Double.doubleToLongBits(getMaxZ()) != Double.doubleToLongBits(other.getMaxZ())) { - return false; - } else if (Double.doubleToLongBits(getMinX()) != Double.doubleToLongBits(other.getMinX())) { - return false; - } else if (Double.doubleToLongBits(getMinY()) != Double.doubleToLongBits(other.getMinY())) { - return false; - } else { - return Double.doubleToLongBits(getMinZ()) == Double.doubleToLongBits(other.getMinZ()); - } - } - } - - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("NmsBoundingBox [minX="); - builder.append(getMinX()); - builder.append(", minY="); - builder.append(getMinY()); - builder.append(", minZ="); - builder.append(getMinZ()); - builder.append(", maxX="); - builder.append(getMaxX()); - builder.append(", maxY="); - builder.append(getMaxY()); - builder.append(", maxZ="); - builder.append(getMaxZ()); - builder.append("]"); - return builder.toString(); - } - - public NmsBoundingBox clone() { - try { - return (NmsBoundingBox) super.clone(); - } catch (CloneNotSupportedException var2) { - throw new Error(var2); - } - } + public static NmsBoundingBox of(Vector min, Vector max) { + Objects.requireNonNull(min, "min is null!"); + Objects.requireNonNull(max, "max is null!"); + return new NmsBoundingBox(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ()); + } + + public static NmsBoundingBox of(Location min, Location max) { + Objects.requireNonNull(min, "min is null!"); + Objects.requireNonNull(max, "max is null!"); + ValidationHelper.isTrue(Objects.equals(min.getWorld(), max.getWorld()), "Locations from different worlds!"); + return new NmsBoundingBox(min.getX(), min.getY(), min.getZ(), max.getX(), max.getY(), max.getZ()); + } + + public static NmsBoundingBox of(Block min, Block max) { + Objects.requireNonNull(min, "min is null!"); + Objects.requireNonNull(max, "max is null!"); + ValidationHelper.isTrue(Objects.equals(min.getWorld(), max.getWorld()), "Blocks from different worlds!"); + int x1 = min.getX(); + int y1 = min.getY(); + int z1 = min.getZ(); + int x2 = max.getX(); + int y2 = max.getY(); + int z2 = max.getZ(); + int minX = Math.min(x1, x2); + int minY = Math.min(y1, y2); + int minZ = Math.min(z1, z2); + int maxX = Math.max(x1, x2) + 1; + int maxY = Math.max(y1, y2) + 1; + int maxZ = Math.max(z1, z2) + 1; + return new NmsBoundingBox(minX, minY, minZ, maxX, maxY, maxZ); + } + + public static NmsBoundingBox of(Block block) { + Objects.requireNonNull(block, "Block is null!"); + return new NmsBoundingBox(block.getX(), block.getY(), block.getZ(), block.getX() + 1, block.getY() + 1, block.getZ() + 1); + } + + public static NmsBoundingBox of(Vector center, double x, double y, double z) { + Objects.requireNonNull(center, "Center is null!"); + return new NmsBoundingBox(center.getX() - x, center.getY() - y, center.getZ() - z, center.getX() + x, center.getY() + y, + center.getZ() + z); + } + + public static NmsBoundingBox of(Location center, double x, double y, double z) { + Objects.requireNonNull(center, "Center is null!"); + return new NmsBoundingBox(center.getX() - x, center.getY() - y, center.getZ() - z, center.getX() + x, center.getY() + y, + center.getZ() + z); + } + + private double minX, minY, minZ; + private double maxX, maxY, maxZ; + + public NmsBoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + resize(minX, minY, minZ, maxX, maxY, maxZ); + } + + public double getMinX() { + return minX; + } + + public double getMinY() { + return minY; + } + + public double getMinZ() { + return minZ; + } + + public double getMaxX() { + return maxX; + } + + public double getMaxY() { + return maxY; + } + + public double getMaxZ() { + return maxZ; + } + + public Vector getMin() { + return new Vector(getMinX(), getMinY(), getMinZ()); + } + + public Vector getMax() { + return new Vector(getMaxX(), getMaxY(), getMaxZ()); + } + + public NmsBoundingBox resize(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + checkFinite(minX, "minX not finite"); + checkFinite(minY, "minY not finite"); + checkFinite(minZ, "minZ not finite"); + checkFinite(maxX, "maxX not finite"); + checkFinite(maxY, "maxY not finite"); + checkFinite(maxZ, "maxZ not finite"); + this.minX = Math.min(minX, maxX); + this.minY = Math.min(minY, maxY); + this.minZ = Math.min(minZ, maxZ); + this.maxX = Math.max(minX, maxX); + this.maxY = Math.max(minY, maxY); + this.maxZ = Math.max(minZ, maxZ); + return this; + } + + public double getWidth() { + return getMaxX() - getMinX(); + } + + public double getDepth() { + return getMaxZ() - getMinZ(); + } + + public double getHeight() { + return getMaxY() - getMinY(); + } + + public double getVolume() { + return getHeight() * getWidth() * getDepth(); + } + + public double getCenterX() { + return getMinX() + getWidth() * 0.5D; + } + + public double getCenterY() { + return getMinY() + getHeight() * 0.5D; + } + + public double getCenterZ() { + return getMinZ() + getDepth() * 0.5D; + } + + public Vector getCenter() { + return new Vector(getCenterX(), getCenterY(), getCenterZ()); + } + + public NmsBoundingBox copy(NmsBoundingBox other) { + Objects.requireNonNull(other, "Other bounding box is null!"); + return resize(other.getMinX(), other.getMinY(), other.getMinZ(), other.getMaxX(), other.getMaxY(), other.getMaxZ()); + } + + public NmsBoundingBox expand(double negativeX, double negativeY, double negativeZ, double positiveX, double positiveY, + double positiveZ) { + if (negativeX == 0.0D && negativeY == 0.0D && negativeZ == 0.0D && positiveX == 0.0D && positiveY == 0.0D && positiveZ == 0.0D) { + return this; + } else { + double newMinX = getMinX() - negativeX; + double newMinY = getMinY() - negativeY; + double newMinZ = getMinZ() - negativeZ; + double newMaxX = getMaxX() + positiveX; + double newMaxY = getMaxY() + positiveY; + double newMaxZ = getMaxZ() + positiveZ; + double centerZ; + if (newMinX > newMaxX) { + centerZ = getCenterX(); + if (newMaxX >= centerZ) { + newMinX = newMaxX; + } else if (newMinX <= centerZ) { + newMaxX = newMinX; + } else { + newMinX = centerZ; + newMaxX = centerZ; + } + } + + if (newMinY > newMaxY) { + centerZ = getCenterY(); + if (newMaxY >= centerZ) { + newMinY = newMaxY; + } else if (newMinY <= centerZ) { + newMaxY = newMinY; + } else { + newMinY = centerZ; + newMaxY = centerZ; + } + } + + if (newMinZ > newMaxZ) { + centerZ = getCenterZ(); + if (newMaxZ >= centerZ) { + newMinZ = newMaxZ; + } else if (newMinZ <= centerZ) { + newMaxZ = newMinZ; + } else { + newMinZ = centerZ; + newMaxZ = centerZ; + } + } + + return resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); + } + } + + public NmsBoundingBox expand(double x, double y, double z) { + return expand(x, y, z, x, y, z); + } + + public NmsBoundingBox expand(Vector expansion) { + Objects.requireNonNull(expansion, "Expansion is null!"); + return expand(expansion.getX(), expansion.getY(), expansion.getZ()); + } + + public NmsBoundingBox expand(double expansion) { + return expand(expansion, expansion, expansion, expansion, expansion, expansion); + } + + public NmsBoundingBox expand(double dirX, double dirY, double dirZ, double expansion) { + if (expansion == 0.0D) { + return this; + } else if (dirX == 0.0D && dirY == 0.0D && dirZ == 0.0D) { + return this; + } else { + double negativeX = dirX < 0.0D ? -dirX * expansion : 0.0D; + double negativeY = dirY < 0.0D ? -dirY * expansion : 0.0D; + double negativeZ = dirZ < 0.0D ? -dirZ * expansion : 0.0D; + double positiveX = dirX > 0.0D ? dirX * expansion : 0.0D; + double positiveY = dirY > 0.0D ? dirY * expansion : 0.0D; + double positiveZ = dirZ > 0.0D ? dirZ * expansion : 0.0D; + return expand(negativeX, negativeY, negativeZ, positiveX, positiveY, positiveZ); + } + } + + public NmsBoundingBox expand(Vector direction, double expansion) { + Objects.requireNonNull(direction, "Direction is null!"); + return expand(direction.getX(), direction.getY(), direction.getZ(), expansion); + } + + public NmsBoundingBox expand(BlockFace blockFace, double expansion) { + Objects.requireNonNull(blockFace, "Block face is null!"); + return blockFace == BlockFace.SELF ? this : expand(blockFace.getDirection(), expansion); + } + + public NmsBoundingBox expandDirectional(double dirX, double dirY, double dirZ) { + return expand(dirX, dirY, dirZ, 1.0D); + } + + public NmsBoundingBox expandDirectional(Vector direction) { + Objects.requireNonNull(direction, "Expansion is null!"); + return expand(direction.getX(), direction.getY(), direction.getZ(), 1.0D); + } + + public NmsBoundingBox union(double posX, double posY, double posZ) { + double newMinX = Math.min(getMinX(), posX); + double newMinY = Math.min(getMinY(), posY); + double newMinZ = Math.min(getMinZ(), posZ); + double newMaxX = Math.max(getMaxX(), posX); + double newMaxY = Math.max(getMaxY(), posY); + double newMaxZ = Math.max(getMaxZ(), posZ); + return newMinX == getMinX() && newMinY == getMinY() && newMinZ == getMinZ() && newMaxX == getMaxX() && newMaxY == getMaxY() + && newMaxZ == getMaxZ() ? this : resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); + } + + public NmsBoundingBox union(Vector position) { + Objects.requireNonNull(position, "Position is null!"); + return union(position.getX(), position.getY(), position.getZ()); + } + + public NmsBoundingBox union(Location position) { + Objects.requireNonNull(position, "Position is null!"); + return union(position.getX(), position.getY(), position.getZ()); + } + + public NmsBoundingBox union(NmsBoundingBox other) { + Objects.requireNonNull(other, "Other bounding box is null!"); + if (contains(other)) { + return this; + } else { + double newMinX = Math.min(getMinX(), other.getMinX()); + double newMinY = Math.min(getMinY(), other.getMinY()); + double newMinZ = Math.min(getMinZ(), other.getMinZ()); + double newMaxX = Math.max(getMaxX(), other.getMaxX()); + double newMaxY = Math.max(getMaxY(), other.getMaxY()); + double newMaxZ = Math.max(getMaxZ(), other.getMaxZ()); + return resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); + } + } + + public NmsBoundingBox intersection(NmsBoundingBox other) { + Objects.requireNonNull(other, "Other bounding box is null!"); + ValidationHelper.isTrue(overlaps(other), "The bounding boxes do not overlap!"); + double newMinX = Math.max(getMinX(), other.getMinX()); + double newMinY = Math.max(getMinY(), other.getMinY()); + double newMinZ = Math.max(getMinZ(), other.getMinZ()); + double newMaxX = Math.min(getMaxX(), other.getMaxX()); + double newMaxY = Math.min(getMaxY(), other.getMaxY()); + double newMaxZ = Math.min(getMaxZ(), other.getMaxZ()); + return resize(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); + } + + public NmsBoundingBox shift(double shiftX, double shiftY, double shiftZ) { + return shiftX == 0.0D && shiftY == 0.0D && shiftZ == 0.0D ? this + : resize(getMinX() + shiftX, getMinY() + shiftY, getMinZ() + shiftZ, getMaxX() + shiftX, getMaxY() + shiftY, + getMaxZ() + shiftZ); + } + + public NmsBoundingBox shift(Vector shift) { + Objects.requireNonNull(shift, "Shift is null!"); + return shift(shift.getX(), shift.getY(), shift.getZ()); + } + + public NmsBoundingBox shift(Location shift) { + Objects.requireNonNull(shift, "Shift is null!"); + return shift(shift.getX(), shift.getY(), shift.getZ()); + } + + private boolean overlaps(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + return getMinX() < maxX && getMaxX() > minX && getMinY() < maxY && getMaxY() > minY && getMinZ() < maxZ && getMaxZ() > minZ; + } + + public boolean overlaps(NmsBoundingBox other) { + Objects.requireNonNull(other, "Other bounding box is null!"); + return overlaps(other.getMinX(), other.getMinY(), other.getMinZ(), other.getMaxX(), other.getMaxY(), other.getMaxZ()); + } + + public boolean overlaps(Vector min, Vector max) { + Objects.requireNonNull(min, "Min is null!"); + Objects.requireNonNull(max, "Max is null!"); + double x1 = min.getX(); + double y1 = min.getY(); + double z1 = min.getZ(); + double x2 = max.getX(); + double y2 = max.getY(); + double z2 = max.getZ(); + return overlaps(x1, y1, z1, x2, y2, z2); + } + + public boolean contains(double x, double y, double z) { + return x >= getMinX() && x < getMaxX() && y >= getMinY() && y < getMaxY() && z >= getMinZ() && z < getMaxZ(); + } + + public boolean contains(Vector position) { + Objects.requireNonNull(position, "Position is null!"); + return contains(position.getX(), position.getY(), position.getZ()); + } + + private boolean contains(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { + return getMinX() <= minX && getMaxX() >= maxX && getMinY() <= minY && getMaxY() >= maxY && getMinZ() <= minZ && getMaxZ() >= maxZ; + } + + public boolean contains(NmsBoundingBox other) { + Objects.requireNonNull(other, "Other bounding box is null!"); + return contains(other.getMinX(), other.getMinY(), other.getMinZ(), other.getMaxX(), other.getMaxY(), other.getMaxZ()); + } + + public boolean contains(Vector min, Vector max) { + Objects.requireNonNull(min, "Min is null!"); + Objects.requireNonNull(max, "Max is null!"); + double x1 = min.getX(); + double y1 = min.getY(); + double z1 = min.getZ(); + double x2 = max.getX(); + double y2 = max.getY(); + double z2 = max.getZ(); + return contains(x1, y1, z1, x2, y2, z2); + } + + public RayTraceResult rayTrace(Vector start, Vector direction, double maxDistance) { + Objects.requireNonNull(start, "Start is null!"); + start.checkFinite(); + Objects.requireNonNull(direction, "Direction is null!"); + direction.checkFinite(); + ValidationHelper.isTrue(direction.lengthSquared() > 0.0D, "Direction's magnitude is 0!"); + if (maxDistance < 0.0D) { + return null; + } else { + double startX = start.getX(); + double startY = start.getY(); + double startZ = start.getZ(); + Vector dir = direction.clone(); + dir.setX(dir.getX() == -0.0D ? 0.0D : dir.getX()); + dir.setY(dir.getY() == -0.0D ? 0.0D : dir.getY()); + dir.setZ(dir.getZ() == -0.0D ? 0.0D : dir.getZ()); + double dirX = dir.getX(); + double dirY = dir.getY(); + double dirZ = dir.getZ(); + double divX = 1.0D / dirX; + double divY = 1.0D / dirY; + double divZ = 1.0D / dirZ; + double tMin; + double tMax; + BlockFace hitBlockFaceMin; + BlockFace hitBlockFaceMax; + if (dirX >= 0.0D) { + tMin = (getMinX() - startX) * divX; + tMax = (getMaxX() - startX) * divX; + hitBlockFaceMin = BlockFace.WEST; + hitBlockFaceMax = BlockFace.EAST; + } else { + tMin = (getMaxX() - startX) * divX; + tMax = (getMinX() - startX) * divX; + hitBlockFaceMin = BlockFace.EAST; + hitBlockFaceMax = BlockFace.WEST; + } + + double tyMin; + double tyMax; + BlockFace hitBlockFaceYMin; + BlockFace hitBlockFaceYMax; + if (dirY >= 0.0D) { + tyMin = (getMinY() - startY) * divY; + tyMax = (getMaxY() - startY) * divY; + hitBlockFaceYMin = BlockFace.DOWN; + hitBlockFaceYMax = BlockFace.UP; + } else { + tyMin = (getMaxY() - startY) * divY; + tyMax = (getMinY() - startY) * divY; + hitBlockFaceYMin = BlockFace.UP; + hitBlockFaceYMax = BlockFace.DOWN; + } + + if (tMin <= tyMax && tMax >= tyMin) { + if (tyMin > tMin) { + tMin = tyMin; + hitBlockFaceMin = hitBlockFaceYMin; + } + + if (tyMax < tMax) { + tMax = tyMax; + hitBlockFaceMax = hitBlockFaceYMax; + } + + double tzMin; + double tzMax; + BlockFace hitBlockFaceZMin; + BlockFace hitBlockFaceZMax; + if (dirZ >= 0.0D) { + tzMin = (getMinZ() - startZ) * divZ; + tzMax = (getMaxZ() - startZ) * divZ; + hitBlockFaceZMin = BlockFace.NORTH; + hitBlockFaceZMax = BlockFace.SOUTH; + } else { + tzMin = (getMaxZ() - startZ) * divZ; + tzMax = (getMinZ() - startZ) * divZ; + hitBlockFaceZMin = BlockFace.SOUTH; + hitBlockFaceZMax = BlockFace.NORTH; + } + + if (tMin <= tzMax && tMax >= tzMin) { + if (tzMin > tMin) { + tMin = tzMin; + hitBlockFaceMin = hitBlockFaceZMin; + } + + if (tzMax < tMax) { + tMax = tzMax; + hitBlockFaceMax = hitBlockFaceZMax; + } + + if (tMax < 0.0D) { + return null; + } else if (tMin > maxDistance) { + return null; + } else { + double t; + BlockFace hitBlockFace; + if (tMin < 0.0D) { + t = tMax; + hitBlockFace = hitBlockFaceMax; + } else { + t = tMin; + hitBlockFace = hitBlockFaceMin; + } + + Vector hitPosition = dir.multiply(t).add(start); + return new RayTraceResult(hitPosition, hitBlockFace); + } + } else { + return null; + } + } else { + return null; + } + } + } + + public int hashCode() { + int result = 1; + long temp = Double.doubleToLongBits(getMaxX()); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(getMaxY()); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(getMaxZ()); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(getMinX()); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(getMinY()); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(getMinZ()); + result = 31 * result + (int) (temp ^ temp >>> 32); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (!(obj instanceof NmsBoundingBox)) { + return false; + } else { + NmsBoundingBox other = (NmsBoundingBox) obj; + if (Double.doubleToLongBits(getMaxX()) != Double.doubleToLongBits(other.getMaxX())) { + return false; + } else if (Double.doubleToLongBits(getMaxY()) != Double.doubleToLongBits(other.getMaxY())) { + return false; + } else if (Double.doubleToLongBits(getMaxZ()) != Double.doubleToLongBits(other.getMaxZ())) { + return false; + } else if (Double.doubleToLongBits(getMinX()) != Double.doubleToLongBits(other.getMinX())) { + return false; + } else if (Double.doubleToLongBits(getMinY()) != Double.doubleToLongBits(other.getMinY())) { + return false; + } else { + return Double.doubleToLongBits(getMinZ()) == Double.doubleToLongBits(other.getMinZ()); + } + } + } + + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("NmsBoundingBox [minX="); + builder.append(getMinX()); + builder.append(", minY="); + builder.append(getMinY()); + builder.append(", minZ="); + builder.append(getMinZ()); + builder.append(", maxX="); + builder.append(getMaxX()); + builder.append(", maxY="); + builder.append(getMaxY()); + builder.append(", maxZ="); + builder.append(getMaxZ()); + builder.append("]"); + return builder.toString(); + } + + public NmsBoundingBox clone() { + try { + return (NmsBoundingBox) super.clone(); + } catch (CloneNotSupportedException var2) { + throw new Error(var2); + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/utils/Tracker.java b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/utils/Tracker.java index 8a6f2f0..8cdf69e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/utils/Tracker.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/reflection/utils/Tracker.java @@ -10,33 +10,33 @@ public abstract class Tracker { - public static Optional> getClassFromStack(int offset) { - StackTraceElement element = Thread.currentThread().getStackTrace()[2 + offset]; - return element == null ? Optional.empty() : ClassCache.getOptionalClass(element.getClassName()); - } - - public static Optional> getCallerClass() { - return getClassFromStack(1); - } - - public static Optional getCallerPlugin() { - StackTraceElement[] elements = Arrays.subArray(StackTraceElement[]::new, Thread.currentThread().getStackTrace(), 2); - for (StackTraceElement element : elements) { - Optional plugin = getPlugin(ClassCache.getOptionalClass(element.getClassName())); - if (plugin.isPresent()) { - return plugin; - } - } - return Optional.empty(); - } - - public static Optional getPlugin(Optional> option) { - if (!option.isPresent()) { - return Optional.empty(); - } - Class clazz = option.get(); - return java.util.Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> plugin.getClass().getClassLoader() == clazz.getClassLoader()) - .findFirst(); - } + public static Optional> getClassFromStack(int offset) { + StackTraceElement element = Thread.currentThread().getStackTrace()[2 + offset]; + return element == null ? Optional.empty() : ClassCache.getOptionalClass(element.getClassName()); + } + + public static Optional> getCallerClass() { + return getClassFromStack(1); + } + + public static Optional getCallerPlugin() { + StackTraceElement[] elements = Arrays.subArray(StackTraceElement[]::new, Thread.currentThread().getStackTrace(), 2); + for (StackTraceElement element : elements) { + Optional plugin = getPlugin(ClassCache.getOptionalClass(element.getClassName())); + if (plugin.isPresent()) { + return plugin; + } + } + return Optional.empty(); + } + + public static Optional getPlugin(Optional> option) { + if (!option.isPresent()) { + return Optional.empty(); + } + Class clazz = option.get(); + return java.util.Arrays.stream(Bukkit.getPluginManager().getPlugins()) + .filter(plugin -> plugin.getClass().getClassLoader() == clazz.getClassLoader()).findFirst(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Mojang.java b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Mojang.java index 0a7b649..4657362 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Mojang.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Mojang.java @@ -18,241 +18,241 @@ public class Mojang { - public static final String URL_SKIN_PROFILE = "https://sessionserver.mojang.com/session/minecraft/profile/%s"; - public static final String URL_SKIN_UPLOAD = "https://api.mojang.com/user/profile/%s/skin"; + public static final String URL_SKIN_PROFILE = "https://sessionserver.mojang.com/session/minecraft/profile/%s"; + public static final String URL_SKIN_UPLOAD = "https://api.mojang.com/user/profile/%s/skin"; - public static final String AUTH_SERVER = "https://authserver.mojang.com/%s"; + public static final String AUTH_SERVER = "https://authserver.mojang.com/%s"; - private final ArrayList skins = new ArrayList<>(); + private final ArrayList skins = new ArrayList<>(); - private final MojangProvider provider; + private final MojangProvider provider; - /* - * - */ + /* + * + */ - public Mojang(MojangProvider provider) { - this.provider = provider; - } + public Mojang(MojangProvider provider) { + this.provider = provider; + } - /* - * - */ + /* + * + */ - public boolean request(Player player, String name) { + public boolean request(Player player, String name) { - Skin skin = getSkin(name.toLowerCase()); + Skin skin = getSkin(name.toLowerCase()); - if (skin == null) { - return false; - } + if (skin == null) { + return false; + } - return request(player, skin); + return request(player, skin); - } + } - public boolean request(Player player, String name, String uniqueId) { + public boolean request(Player player, String name, String uniqueId) { - Skin skin = getSkin((name = name.toLowerCase())); + Skin skin = getSkin((name = name.toLowerCase())); - if (skin == null) { - if ((skin = downloadSkinFromPlayer(name, uniqueId)) == null) { - return false; - } - } + if (skin == null) { + if ((skin = downloadSkinFromPlayer(name, uniqueId)) == null) { + return false; + } + } - return request(player, skin); + return request(player, skin); - } + } - public boolean request(SkinRequest request) { + public boolean request(SkinRequest request) { - Skin skin = getSkin(request.getName()); + Skin skin = getSkin(request.getName()); - if (skin == null) { - if ((skin = downloadSkin(request)) == null) { - return false; - } - } + if (skin == null) { + if ((skin = downloadSkin(request)) == null) { + return false; + } + } - return request(request.getRequester(), skin); + return request(request.getRequester(), skin); - } + } - /* - * - */ + /* + * + */ - public boolean request(Player player, Skin skin) { + public boolean request(Player player, Skin skin) { - if (player == null || skin == null) { - return false; - } + if (player == null || skin == null) { + return false; + } - provider.setSkinProperty(player, skin); + provider.setSkinProperty(player, skin); - if (player.isOnline()) { - VersionControl.get().getPlayerProvider().getPlayer(player).setSkin(skin); - } + if (player.isOnline()) { + VersionControl.get().getPlayerProvider().getPlayer(player).setSkin(skin); + } - return true; + return true; - } + } - /* - * - */ + /* + * + */ - public final MojangProvider getProvider() { - return provider; - } + public final MojangProvider getProvider() { + return provider; + } - public final List getProfiles() { - return provider.getProfiles(); - } + public final List getProfiles() { + return provider.getProfiles(); + } - public final ArrayList getSkins() { - return skins; - } + public final ArrayList getSkins() { + return skins; + } - /* - * - */ + /* + * + */ - public Skin getSkin(String name) { - Optional option = getOptionalSkin(name); - if (option.isPresent()) { - return option.get(); - } - return null; - } + public Skin getSkin(String name) { + Optional option = getOptionalSkin(name); + if (option.isPresent()) { + return option.get(); + } + return null; + } - public Optional getOptionalSkin(String name) { - return skins.stream().filter(skin -> skin.getName().equals(name)).findAny(); - } + public Optional getOptionalSkin(String name) { + return skins.stream().filter(skin -> skin.getName().equals(name)).findAny(); + } - /* - * - */ + /* + * + */ - public Profile getUseableProfile() { + public Profile getUseableProfile() { - Profile[] array = getProfiles().stream().filter(profile -> profile.isAuthenticated()).toArray(size -> new Profile[size]); + Profile[] array = getProfiles().stream().filter(profile -> profile.isAuthenticated()).toArray(size -> new Profile[size]); - if (array.length != 0) { - for (Profile profile : array) { - if (profile.validate()) { - return profile; - } - if (profile.refresh().validate()) { - return profile; - } - } - } + if (array.length != 0) { + for (Profile profile : array) { + if (profile.validate()) { + return profile; + } + if (profile.refresh().validate()) { + return profile; + } + } + } - array = getProfiles().stream().filter(profile -> !profile.isAuthenticated()).toArray(size -> new Profile[size]); + array = getProfiles().stream().filter(profile -> !profile.isAuthenticated()).toArray(size -> new Profile[size]); - if (array.length == 0) { - return null; - } + if (array.length == 0) { + return null; + } - for (Profile profile : array) { - if (profile.authenticate().isAuthenticated()) { - return profile; - } - } + for (Profile profile : array) { + if (profile.authenticate().isAuthenticated()) { + return profile; + } + } - return null; + return null; - } + } - /* - * - */ + /* + * + */ - private Skin downloadSkin(SkinRequest skinRequest) { + private Skin downloadSkin(SkinRequest skinRequest) { - Profile profile = getUseableProfile(); + Profile profile = getUseableProfile(); - if (profile == null) { - return null; - } + if (profile == null) { + return null; + } - try { + try { - Request request = new Request(RequestType.POST); + Request request = new Request(RequestType.POST); - request.header("Authorization", "Bearer " + profile.getAuthToken()); + request.header("Authorization", "Bearer " + profile.getAuthToken()); - request.parameter("url", skinRequest.getUrl()).parameter("model", skinRequest.getModel().toString()); + request.parameter("url", skinRequest.getUrl()).parameter("model", skinRequest.getModel().toString()); - int code = request.execute(String.format(URL_SKIN_UPLOAD, profile.getUniqueId()), StandardContentType.URL_ENCODED).getCode(); + int code = request.execute(String.format(URL_SKIN_UPLOAD, profile.getUniqueId()), StandardContentType.URL_ENCODED).getCode(); - if (code != 204) { - return null; - } + if (code != 204) { + return null; + } - return downloadSkinFromPlayer(skinRequest.getName(), profile.getUniqueId()); + return downloadSkinFromPlayer(skinRequest.getName(), profile.getUniqueId()); - } catch (IOException ignore) { + } catch (IOException ignore) { - } + } - return null; - } + return null; + } - public Skin downloadSkinFromPlayer(String name, String uniqueId) { + public Skin downloadSkinFromPlayer(String name, String uniqueId) { - try { + try { - Request request = new Request(RequestType.GET); + Request request = new Request(RequestType.GET); - JsonObject object = request.execute(URL_SKIN_PROFILE, StandardContentType.URL_ENCODED).getResponseAsJson(); + JsonObject object = request.execute(URL_SKIN_PROFILE, StandardContentType.URL_ENCODED).getResponseAsJson(); - if (!object.has("properties")) { - return null; - } + if (!object.has("properties")) { + return null; + } - JsonObject property = object.get("properties").getAsJsonArray().get(0).getAsJsonObject(); + JsonObject property = object.get("properties").getAsJsonArray().get(0).getAsJsonObject(); - String value = property.get("value").getAsString(); - String signature = property.get("signature").getAsString(); - String url = getSkinUrl(value); + String value = property.get("value").getAsString(); + String signature = property.get("signature").getAsString(); + String url = getSkinUrl(value); - if (url == null) { - return null; - } + if (url == null) { + return null; + } - return new Skin(name, value, signature, false); + return new Skin(name, value, signature, false); - } catch (IOException ignore) { - return null; - } + } catch (IOException ignore) { + return null; + } - } + } - /* - * - */ + /* + * + */ - public String getSkinUrl(String base64) { + public String getSkinUrl(String base64) { - String decoded = Base64Coder.decodeString(base64); + String decoded = Base64Coder.decodeString(base64); - JsonObject json = JsonTools.readJson(decoded); + JsonObject json = JsonTools.readJson(decoded); - if (!json.has("textures")) { - return null; - } + if (!json.has("textures")) { + return null; + } - JsonObject textures = json.get("textures").getAsJsonObject(); + JsonObject textures = json.get("textures").getAsJsonObject(); - if (textures.entrySet().isEmpty()) { - return null; - } + if (textures.entrySet().isEmpty()) { + return null; + } - return textures.get("SKIN").getAsJsonObject().get("url").getAsString(); + return textures.get("SKIN").getAsJsonObject().get("url").getAsString(); - } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/MojangProvider.java b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/MojangProvider.java index 08a1d2d..b4b0e0a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/MojangProvider.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/MojangProvider.java @@ -7,10 +7,10 @@ public interface MojangProvider { - UUID getClientIdentifier(); + UUID getClientIdentifier(); - void setSkinProperty(Player player, Skin skin); + void setSkinProperty(Player player, Skin skin); - List getProfiles(); + List getProfiles(); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Profile.java b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Profile.java index 51beac5..68ef33c 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Profile.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Profile.java @@ -11,147 +11,147 @@ public class Profile { - private final Mojang mojang; + private final Mojang mojang; - private String username; - private String password; + private String username; + private String password; - private String name = ""; - private String uuid; + private String name = ""; + private String uuid; - private String authToken; + private String authToken; - public Profile(Mojang mojang, String user, String pass) { - this.mojang = mojang; - this.username = user; - this.password = pass; - } + public Profile(Mojang mojang, String user, String pass) { + this.mojang = mojang; + this.username = user; + this.password = pass; + } - /* - * - */ + /* + * + */ - public String getUsername() { - return username; - } + public String getUsername() { + return username; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getUniqueId() { - return uuid; - } + public String getUniqueId() { + return uuid; + } - public String getAuthToken() { - return authToken; - } + public String getAuthToken() { + return authToken; + } - /* - * - */ + /* + * + */ - public boolean isAuthenticated() { - return authToken != null; - } + public boolean isAuthenticated() { + return authToken != null; + } - /* - * - */ + /* + * + */ - public boolean validate() { - if (authToken == null) { - return false; - } + public boolean validate() { + if (authToken == null) { + return false; + } - try { + try { - Request request = new Request(RequestType.POST); + Request request = new Request(RequestType.POST); - request.parameter("accessToken", authToken).parameter("clientToken", mojang.getProvider().getClientIdentifier().toString()); + request.parameter("accessToken", authToken).parameter("clientToken", mojang.getProvider().getClientIdentifier().toString()); - int code = request.execute(String.format(AUTH_SERVER, "validate"), StandardContentType.JSON).getCode(); + int code = request.execute(String.format(AUTH_SERVER, "validate"), StandardContentType.JSON).getCode(); - if (code == 204) { - return true; - } else { - return false; - } + if (code == 204) { + return true; + } else { + return false; + } - } catch (IOException ignore) { - return false; - } + } catch (IOException ignore) { + return false; + } - } + } - public Profile refresh() { - if (authToken == null) { - return this; - } + public Profile refresh() { + if (authToken == null) { + return this; + } - try { + try { - Request request = new Request(RequestType.POST); + Request request = new Request(RequestType.POST); - request.parameter("accessToken", authToken).parameter("clientToken", mojang.getProvider().getClientIdentifier().toString()); + request.parameter("accessToken", authToken).parameter("clientToken", mojang.getProvider().getClientIdentifier().toString()); - JsonObject response = request.execute(String.format(AUTH_SERVER, "refresh"), StandardContentType.JSON).getResponseAsJson(); + JsonObject response = request.execute(String.format(AUTH_SERVER, "refresh"), StandardContentType.JSON).getResponseAsJson(); - authToken = null; + authToken = null; - if (!response.has("accessToken")) { - return this; - } + if (!response.has("accessToken")) { + return this; + } - authToken = response.get("accessToken").getAsString(); + authToken = response.get("accessToken").getAsString(); - return this; + return this; - } catch (IOException ignore) { - return this; - } + } catch (IOException ignore) { + return this; + } - } + } - public Profile authenticate() { + public Profile authenticate() { - try { + try { - Request request = new Request(RequestType.POST); + Request request = new Request(RequestType.POST); - JsonObject object = new JsonObject(); - JsonObject agent = new JsonObject(); - agent.addProperty("name", "Minecraft"); - agent.addProperty("version", 1); - object.add("agent", agent); + JsonObject object = new JsonObject(); + JsonObject agent = new JsonObject(); + agent.addProperty("name", "Minecraft"); + agent.addProperty("version", 1); + object.add("agent", agent); - object.addProperty("username", username); - object.addProperty("password", password); - object.addProperty("clientToken", mojang.getProvider().getClientIdentifier().toString()); + object.addProperty("username", username); + object.addProperty("password", password); + object.addProperty("clientToken", mojang.getProvider().getClientIdentifier().toString()); - request.parameter(object); + request.parameter(object); - JsonObject response = request.execute(String.format(AUTH_SERVER, "authenticate"), StandardContentType.JSON).getResponseAsJson(); + JsonObject response = request.execute(String.format(AUTH_SERVER, "authenticate"), StandardContentType.JSON).getResponseAsJson(); - authToken = null; + authToken = null; - if (!object.has("selectedProfile")) { - return this; - } + if (!object.has("selectedProfile")) { + return this; + } - JsonObject profile = response.get("selectedProfile").getAsJsonObject(); + JsonObject profile = response.get("selectedProfile").getAsJsonObject(); - uuid = profile.get("id").getAsString(); - name = profile.get("name").getAsString(); + uuid = profile.get("id").getAsString(); + name = profile.get("name").getAsString(); - authToken = response.get("accessToken").getAsString(); + authToken = response.get("accessToken").getAsString(); - return this; + return this; - } catch (IOException ignore) { - return this; - } + } catch (IOException ignore) { + return this; + } - } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Skin.java b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Skin.java index 62e3677..6ac4b46 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Skin.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/Skin.java @@ -11,166 +11,166 @@ public class Skin implements Serializable, NbtStorage { - public static final Skin NONE = new Skin(); - - /** - * - */ - private static final long serialVersionUID = -6279824025820566499L; - private final boolean editable; - private String name; - private String value; - private String signature; - private SkinModel model; - - private Skin() { - this.editable = false; - } - - public Skin(String name, String value, String signature) { - this.name = name; - this.editable = false; - this.value = value; - this.signature = signature; - setModel(parseModel()); - } - - public Skin(String name, String value, String signature, boolean editable) { - this.name = name; - this.editable = editable; - this.value = value; - this.signature = signature; - setModel(parseModel()); - } - - public boolean isEditable() { - return editable; - } - - public String getName() { - return name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - if (!isEditable()) { - return; - } - this.value = value; - setModel(parseModel()); - } - - public String getSignature() { - return signature; - } - - public void setSignature(String signature) { - if (!isEditable()) { - return; - } - this.signature = signature; - } - - public SkinModel getModel() { - return model; - } - - public void setModel(SkinModel model) { - if (!isEditable()) { - return; - } - this.model = model; - } - - /** - * @return Decoded skin url string, or null if skin value empty - */ - public String getURL() { - JsonObject textures = getTextures(); - - if (textures.entrySet().size() != 0) { - return textures.get("SKIN").getAsJsonObject().get("url").getAsString(); - } - - return null; - } - - /** - * @return UUID string of real skin owner - */ - public String getOwnerUUID() { - String decoded = Base64Coder.decodeString(value); - JsonObject json = new JsonParser().parse(decoded).getAsJsonObject(); - return json.get("profileId").getAsString(); - } - - /** - * @return Name of real skin owner - */ - public String getOwnerName() { - String decoded = Base64Coder.decodeString(value); - JsonObject json = new JsonParser().parse(decoded).getAsJsonObject(); - return json.get("profileName").getAsString(); - } - - private SkinModel parseModel() { - JsonObject textures = getTextures(); - - if (textures.entrySet().size() != 0) { - JsonObject skinObj = textures.get("SKIN").getAsJsonObject(); - if (skinObj.has("metadata")) { - JsonObject metadata = skinObj.get("metadata").getAsJsonObject(); - if (metadata.has("model")) { - return SkinModel.SLIM; - } - } - } - - return SkinModel.NORMAL; - } - - private JsonObject getTextures() { - String decoded = Base64Coder.decodeString(value); - JsonObject json = new JsonParser().parse(decoded).getAsJsonObject(); - return json.get("textures").getAsJsonObject(); - } - - /* - * - */ - - @Override - public boolean equals(Object obj) { - if (obj instanceof Skin) { - Skin skin = (Skin) obj; - return skin.name.equals(name) && skin.value.equals(value) && skin.signature.equals(signature); - } - return false; - } - - /* - * - */ - - @Override - public void fromNbt(NbtCompound nbt) { - name = nbt.getString("name"); - value = nbt.getString("value"); - signature = nbt.getString("signature"); - model = SkinModel.fromString(nbt.getString("model")); - } - - @Override - public NbtCompound asNbt() { - NbtCompound compound = new NbtCompound(); - compound.set("name", name); - compound.set("value", value); - compound.set("signature", signature); - compound.set("model", model.name()); - return compound; - } + public static final Skin NONE = new Skin(); + + /** + * + */ + private static final long serialVersionUID = -6279824025820566499L; + private final boolean editable; + private String name; + private String value; + private String signature; + private SkinModel model; + + private Skin() { + this.editable = false; + } + + public Skin(String name, String value, String signature) { + this.name = name; + this.editable = false; + this.value = value; + this.signature = signature; + setModel(parseModel()); + } + + public Skin(String name, String value, String signature, boolean editable) { + this.name = name; + this.editable = editable; + this.value = value; + this.signature = signature; + setModel(parseModel()); + } + + public boolean isEditable() { + return editable; + } + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + if (!isEditable()) { + return; + } + this.value = value; + setModel(parseModel()); + } + + public String getSignature() { + return signature; + } + + public void setSignature(String signature) { + if (!isEditable()) { + return; + } + this.signature = signature; + } + + public SkinModel getModel() { + return model; + } + + public void setModel(SkinModel model) { + if (!isEditable()) { + return; + } + this.model = model; + } + + /** + * @return Decoded skin url string, or null if skin value empty + */ + public String getURL() { + JsonObject textures = getTextures(); + + if (textures.entrySet().size() != 0) { + return textures.get("SKIN").getAsJsonObject().get("url").getAsString(); + } + + return null; + } + + /** + * @return UUID string of real skin owner + */ + public String getOwnerUUID() { + String decoded = Base64Coder.decodeString(value); + JsonObject json = new JsonParser().parse(decoded).getAsJsonObject(); + return json.get("profileId").getAsString(); + } + + /** + * @return Name of real skin owner + */ + public String getOwnerName() { + String decoded = Base64Coder.decodeString(value); + JsonObject json = new JsonParser().parse(decoded).getAsJsonObject(); + return json.get("profileName").getAsString(); + } + + private SkinModel parseModel() { + JsonObject textures = getTextures(); + + if (textures.entrySet().size() != 0) { + JsonObject skinObj = textures.get("SKIN").getAsJsonObject(); + if (skinObj.has("metadata")) { + JsonObject metadata = skinObj.get("metadata").getAsJsonObject(); + if (metadata.has("model")) { + return SkinModel.SLIM; + } + } + } + + return SkinModel.NORMAL; + } + + private JsonObject getTextures() { + String decoded = Base64Coder.decodeString(value); + JsonObject json = new JsonParser().parse(decoded).getAsJsonObject(); + return json.get("textures").getAsJsonObject(); + } + + /* + * + */ + + @Override + public boolean equals(Object obj) { + if (obj instanceof Skin) { + Skin skin = (Skin) obj; + return skin.name.equals(name) && skin.value.equals(value) && skin.signature.equals(signature); + } + return false; + } + + /* + * + */ + + @Override + public void fromNbt(NbtCompound nbt) { + name = nbt.getString("name"); + value = nbt.getString("value"); + signature = nbt.getString("signature"); + model = SkinModel.fromString(nbt.getString("model")); + } + + @Override + public NbtCompound asNbt() { + NbtCompound compound = new NbtCompound(); + compound.set("name", name); + compound.set("value", value); + compound.set("signature", signature); + compound.set("model", model.name()); + return compound; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/SkinModel.java b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/SkinModel.java index 08f49e2..e70b99d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/SkinModel.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/SkinModel.java @@ -2,31 +2,31 @@ public enum SkinModel { - SLIM, - NORMAL; + SLIM, + NORMAL; - public static SkinModel get(String name) { - if (name.equalsIgnoreCase("SLIM")) { - return SkinModel.SLIM; - } - return SkinModel.NORMAL; - } + public static SkinModel get(String name) { + if (name.equalsIgnoreCase("SLIM")) { + return SkinModel.SLIM; + } + return SkinModel.NORMAL; + } - @Override - public String toString() { - String name = name(); - if (name.equals("NORMAL")) { - return "steve"; - } - return name.toLowerCase(); - } + @Override + public String toString() { + String name = name(); + if (name.equals("NORMAL")) { + return "steve"; + } + return name.toLowerCase(); + } - public static SkinModel fromString(String name) { - name = name.toLowerCase(); - if (name.equals("slim") || name.equals("alex")) { - return SkinModel.SLIM; - } - return SkinModel.NORMAL; - } + public static SkinModel fromString(String name) { + name = name.toLowerCase(); + if (name.equals("slim") || name.equals("alex")) { + return SkinModel.SLIM; + } + return SkinModel.NORMAL; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/SkinRequest.java b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/SkinRequest.java index d02fd20..b003cc2 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/skin/SkinRequest.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/skin/SkinRequest.java @@ -4,32 +4,32 @@ public class SkinRequest { - public SkinRequest(String name, String url, SkinModel model, Player requester) { - this.name = name.toLowerCase(); - this.url = url.toLowerCase(); - this.model = model; - this.requester = requester; - } - - private String name; - private String url; - private SkinModel model; - private Player requester; - - public String getName() { - return name; - } - - public String getUrl() { - return url; - } - - public SkinModel getModel() { - return model; - } - - public Player getRequester() { - return requester; - } + public SkinRequest(String name, String url, SkinModel model, Player requester) { + this.name = name.toLowerCase(); + this.url = url.toLowerCase(); + this.model = model; + this.requester = requester; + } + + private String name; + private String url; + private SkinModel model; + private Player requester; + + public String getName() { + return name; + } + + public String getUrl() { + return url; + } + + public SkinModel getModel() { + return model; + } + + public Player getRequester() { + return requester; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/BukkitColor.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/BukkitColor.java index c3fe81f..c88ff39 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/BukkitColor.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/BukkitColor.java @@ -4,34 +4,34 @@ public abstract class BukkitColor { - public static final char COLOR_CHAR = '\u00A7'; - public static final char REPLACEMENT_CHAR = '\u0026'; - public static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx"; - public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-ORX]"); + public static final char COLOR_CHAR = '\u00A7'; + public static final char REPLACEMENT_CHAR = '\u0026'; + public static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx"; + public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-ORX]"); - public static String strip(String text) { - return text == null ? null : STRIP_COLOR_PATTERN.matcher(text).replaceAll(""); - } + public static String strip(String text) { + return text == null ? null : STRIP_COLOR_PATTERN.matcher(text).replaceAll(""); + } - public static String apply(String text) { - char[] chars = text.toCharArray(); - for (int i = 0; i < chars.length - 1; ++i) { - if (chars[i] == REPLACEMENT_CHAR && ALL_CODES.indexOf(chars[i + 1]) > -1) { - chars[i] = COLOR_CHAR; - chars[i + 1] = Character.toLowerCase(chars[i + 1]); - } - } - return new String(chars); - } + public static String apply(String text) { + char[] chars = text.toCharArray(); + for (int i = 0; i < chars.length - 1; ++i) { + if (chars[i] == REPLACEMENT_CHAR && ALL_CODES.indexOf(chars[i + 1]) > -1) { + chars[i] = COLOR_CHAR; + chars[i + 1] = Character.toLowerCase(chars[i + 1]); + } + } + return new String(chars); + } - public static String unapply(String text) { - char[] chars = text.toCharArray(); - for (int i = 0; i < chars.length - 1; ++i) { - if (chars[i] == COLOR_CHAR && ALL_CODES.indexOf(chars[i + 1]) > -1) { - chars[i] = REPLACEMENT_CHAR; - chars[i + 1] = Character.toLowerCase(chars[i + 1]); - } - } - return new String(chars); - } + public static String unapply(String text) { + char[] chars = text.toCharArray(); + for (int i = 0; i < chars.length - 1; ++i) { + if (chars[i] == COLOR_CHAR && ALL_CODES.indexOf(chars[i + 1]) > -1) { + chars[i] = REPLACEMENT_CHAR; + chars[i + 1] = Character.toLowerCase(chars[i + 1]); + } + } + return new String(chars); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/MojangProfileServer.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/MojangProfileServer.java index 4341ae2..d30dd7a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/MojangProfileServer.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/MojangProfileServer.java @@ -13,62 +13,62 @@ public abstract class MojangProfileServer { - private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s"; - private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/%s"; + private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s"; + private static final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/%s"; - public static UUID getUniqueIdPlayed(String name) { - OfflinePlayer player = Bukkit.getOfflinePlayer(fromShortenId(getUniqueIdString(name))); - if (player.hasPlayedBefore()) { - return player.getUniqueId(); - } - return null; - } + public static UUID getUniqueIdPlayed(String name) { + OfflinePlayer player = Bukkit.getOfflinePlayer(fromShortenId(getUniqueIdString(name))); + if (player.hasPlayedBefore()) { + return player.getUniqueId(); + } + return null; + } - public static UUID getUniqueId(String name) { - return fromShortenId(getUniqueIdString(name)); - } + public static UUID getUniqueId(String name) { + return fromShortenId(getUniqueIdString(name)); + } - public static UUID fromShortenId(String uid) { - return UUID.fromString( - uid.substring(0, 8) + "-" + uid.substring(8, 12) + "-" + uid.substring(12, 16) + "-" + uid.substring(16, 20) + "-" + uid.substring(20, 32)); - } + public static UUID fromShortenId(String uid) { + return UUID.fromString(uid.substring(0, 8) + "-" + uid.substring(8, 12) + "-" + uid.substring(12, 16) + "-" + uid.substring(16, 20) + + "-" + uid.substring(20, 32)); + } - public static String shortUUID(UUID id) { - return id.toString().replace("-", ""); - } + public static String shortUUID(UUID id) { + return id.toString().replace("-", ""); + } - public static String getUniqueIdString(String name) { - try { - URL url = new URL(String.format(UUID_URL, name)); - String jsonString = Streams.toString(url.openStream()); + public static String getUniqueIdString(String name) { + try { + URL url = new URL(String.format(UUID_URL, name)); + String jsonString = Streams.toString(url.openStream()); - if (!jsonString.isEmpty()) { - JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); - String uuid = object.get("id").getAsString(); + if (!jsonString.isEmpty()) { + JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); + String uuid = object.get("id").getAsString(); - return uuid; - } - } catch (IOException e) { - e.printStackTrace(); - } - return ""; - } + return uuid; + } + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } - public static String getName(UUID uniqueId) { - String uuid = shortUUID(uniqueId); - try { - URL url = new URL(String.format(PROFILE_URL, uuid)); - String jsonString = Streams.toString(url.openStream()); + public static String getName(UUID uniqueId) { + String uuid = shortUUID(uniqueId); + try { + URL url = new URL(String.format(PROFILE_URL, uuid)); + String jsonString = Streams.toString(url.openStream()); - if (!jsonString.isEmpty()) { - JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); - String name = object.get("name").getAsString(); + if (!jsonString.isEmpty()) { + JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); + String name = object.get("name").getAsString(); - return name; - } - } catch (IOException e) { - e.printStackTrace(); - } - return ""; - } + return name; + } + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/Players.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/Players.java index c9c7d5a..4feada5 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/Players.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/Players.java @@ -12,54 +12,54 @@ public abstract class Players { - public static final IntFunction OFFLINE_FUNCTION = size -> new OfflinePlayer[size]; - public static final IntFunction ONLINE_FUNCTION = size -> new Player[size]; + public static final IntFunction OFFLINE_FUNCTION = size -> new OfflinePlayer[size]; + public static final IntFunction ONLINE_FUNCTION = size -> new Player[size]; - /* - * - */ + /* + * + */ - public static Player[] getOnline() { - return Bukkit.getOnlinePlayers().stream().toArray(ONLINE_FUNCTION); - } + public static Player[] getOnline() { + return Bukkit.getOnlinePlayers().stream().toArray(ONLINE_FUNCTION); + } - public static Player[] getOnlineWith(UUID... uniqueIds) { - return filter(getOnline(), uniqueIds, false).stream().toArray(ONLINE_FUNCTION); - } + public static Player[] getOnlineWith(UUID... uniqueIds) { + return filter(getOnline(), uniqueIds, false).stream().toArray(ONLINE_FUNCTION); + } - public static Player[] getOnlineWithout(UUID... uniqueIds) { - return filter(getOnline(), uniqueIds, true).stream().toArray(ONLINE_FUNCTION); - } + public static Player[] getOnlineWithout(UUID... uniqueIds) { + return filter(getOnline(), uniqueIds, true).stream().toArray(ONLINE_FUNCTION); + } - /* - * - */ + /* + * + */ - public static OfflinePlayer[] getOffline() { - return Bukkit.getOfflinePlayers(); - } + public static OfflinePlayer[] getOffline() { + return Bukkit.getOfflinePlayers(); + } - public static OfflinePlayer[] getOfflineWith(UUID... uniqueIds) { - return filter(getOffline(), uniqueIds, false).stream().toArray(ONLINE_FUNCTION); - } + public static OfflinePlayer[] getOfflineWith(UUID... uniqueIds) { + return filter(getOffline(), uniqueIds, false).stream().toArray(ONLINE_FUNCTION); + } - public static OfflinePlayer[] getOfflineWithout(UUID... uniqueIds) { - return filter(getOffline(), uniqueIds, true).stream().toArray(OFFLINE_FUNCTION); - } + public static OfflinePlayer[] getOfflineWithout(UUID... uniqueIds) { + return filter(getOffline(), uniqueIds, true).stream().toArray(OFFLINE_FUNCTION); + } - /* - * - */ + /* + * + */ - public static List filter(E[] players, UUID[] uniqueIds, boolean blacklist) { - ArrayList output = new ArrayList<>(); - List filter = Arrays.asList(uniqueIds); - for (E player : players) { - if (blacklist ? !filter.contains(player.getUniqueId()) : filter.contains(player.getUniqueId())) { - output.add(player); - } - } - return output; - } + public static List filter(E[] players, UUID[] uniqueIds, boolean blacklist) { + ArrayList output = new ArrayList<>(); + List filter = Arrays.asList(uniqueIds); + for (E player : players) { + if (blacklist ? !filter.contains(player.getUniqueId()) : filter.contains(player.getUniqueId())) { + output.add(player); + } + } + return output; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/unsafe/KeyCache.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/unsafe/KeyCache.java index 71de0ce..ceed823 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/unsafe/KeyCache.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/bukkit/unsafe/KeyCache.java @@ -8,46 +8,46 @@ public final class KeyCache { - private static final Map KEYS = Collections.synchronizedMap(new HashMap<>()); - - public static final KeyCache versionUtils() { - return cache("versionUtils"); - } - - public static final KeyCache cache(String namespace) { - return KEYS.computeIfAbsent(namespace, name -> new KeyCache(name)); - } - - public static final NamespacedKey key(String key) { - if (!key.contains(":")) { - return versionUtils().get(key); - } - String[] keys = key.split(":", 2); - return cache(keys[0]).get(keys[1]); - } - - private final String namespace; - private final Map keys = Collections.synchronizedMap(new HashMap<>()); - - private KeyCache(String namespace) { - this.namespace = namespace; - } - - public String getNamespace() { - return namespace; - } - - @SuppressWarnings("deprecation") - public NamespacedKey get(String key) { - if (keys.containsKey(key)) { - return keys.get(key); - } - NamespacedKey output = new NamespacedKey(namespace, key); - keys.put(key, output); - return output; - } - - public NamespacedKey remove(String key) { - return keys.remove(key); - } + private static final Map KEYS = Collections.synchronizedMap(new HashMap<>()); + + public static final KeyCache versionUtils() { + return cache("versionUtils"); + } + + public static final KeyCache cache(String namespace) { + return KEYS.computeIfAbsent(namespace, name -> new KeyCache(name)); + } + + public static final NamespacedKey key(String key) { + if (!key.contains(":")) { + return versionUtils().get(key); + } + String[] keys = key.split(":", 2); + return cache(keys[0]).get(keys[1]); + } + + private final String namespace; + private final Map keys = Collections.synchronizedMap(new HashMap<>()); + + private KeyCache(String namespace) { + this.namespace = namespace; + } + + public String getNamespace() { + return namespace; + } + + @SuppressWarnings("deprecation") + public NamespacedKey get(String key) { + if (keys.containsKey(key)) { + return keys.get(key); + } + NamespacedKey output = new NamespacedKey(namespace, key); + keys.put(key, output); + return output; + } + + public NamespacedKey remove(String key) { + return keys.remove(key); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/constants/DefaultConstants.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/constants/DefaultConstants.java index 6c28825..b55e532 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/constants/DefaultConstants.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/constants/DefaultConstants.java @@ -4,7 +4,7 @@ public class DefaultConstants { - public static final String NAMESPACE_STRING = "versionUtils"; - public static final Namespace NAMESPACE = Namespace.of(NAMESPACE_STRING); + public static final String NAMESPACE_STRING = "versionUtils"; + public static final Namespace NAMESPACE = Namespace.of(NAMESPACE_STRING); } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/constants/MinecraftConstants.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/constants/MinecraftConstants.java index 31af4e8..fef9be2 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/constants/MinecraftConstants.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/constants/MinecraftConstants.java @@ -2,6 +2,6 @@ public class MinecraftConstants { - public final static String TEXTURE_SIGNATURE = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUv"; + public final static String TEXTURE_SIGNATURE = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUv"; } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/ArrayTools.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/ArrayTools.java index 4779d8d..dc766d9 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/ArrayTools.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/ArrayTools.java @@ -5,21 +5,21 @@ public abstract class ArrayTools { - public static List toLowercaseList(String... values) { - ArrayList list = new ArrayList<>(); - for (String value : values) { - list.add(value.toLowerCase()); - } - return list; - } + public static List toLowercaseList(String... values) { + ArrayList list = new ArrayList<>(); + for (String value : values) { + list.add(value.toLowerCase()); + } + return list; + } - public static Object filter(Object[] array, String name) { - for (Object object : array) { - if (object.toString().equals(name)) { - return object; - } - } - return null; - } + public static Object filter(Object[] array, String name) { + for (Object object : array) { + if (object.toString().equals(name)) { + return object; + } + } + return null; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/OptionTools.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/OptionTools.java index 1ff9c4f..e814936 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/OptionTools.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/OptionTools.java @@ -4,14 +4,14 @@ public abstract class OptionTools { - @SuppressWarnings("rawtypes") - public static boolean checkPresence(Optional... optionals) { - for (Optional optional : optionals) { - if (!optional.isPresent()) { - return false; - } - } - return true; - } + @SuppressWarnings("rawtypes") + public static boolean checkPresence(Optional... optionals) { + for (Optional optional : optionals) { + if (!optional.isPresent()) { + return false; + } + } + return true; + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/ReflectionTools.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/ReflectionTools.java index 6746b8b..0842fff 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/ReflectionTools.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/ReflectionTools.java @@ -4,17 +4,17 @@ public abstract class ReflectionTools { - public static Class subclass(Class clazz, String name) { - for (Class search : clazz.getClasses()) { - if (search.getSimpleName().split("\\.")[0].equals(name)) { - return search; - } - } - return null; - } + public static Class subclass(Class clazz, String name) { + for (Class search : clazz.getClasses()) { + if (search.getSimpleName().split("\\.")[0].equals(name)) { + return search; + } + } + return null; + } - public static Class arrayclass(Class clazz) { - return Array.newInstance(clazz, 1).getClass(); - } + public static Class arrayclass(Class clazz) { + return Array.newInstance(clazz, 1).getClass(); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/UUIDHelper.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/UUIDHelper.java index 8f166f1..411ba7e 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/UUIDHelper.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/UUIDHelper.java @@ -7,36 +7,36 @@ public final class UUIDHelper { - private UUIDHelper() {} - - public static UUID generateUniqueId(RandomNumberGenerator generator) { - byte[] randomBytes = new byte[16]; - System.arraycopy(longToBytes(generator.nextLong()), 0, randomBytes, 0, 8); - System.arraycopy(longToBytes(generator.nextLong()), 0, randomBytes, 8, 8); - randomBytes[6] &= 0x0f; /* clear version */ - randomBytes[6] |= 0x40; /* set to version 4 */ - randomBytes[8] &= 0x3f; /* clear variant */ - randomBytes[8] |= 0x80; /* set to IETF variant */ - return UUID.nameUUIDFromBytes(randomBytes); - } - - public static UUID generateUniqueId(SecureRandom random) { - byte[] randomBytes = new byte[16]; - random.nextBytes(randomBytes); - randomBytes[6] &= 0x0f; /* clear version */ - randomBytes[6] |= 0x40; /* set to version 4 */ - randomBytes[8] &= 0x3f; /* clear variant */ - randomBytes[8] |= 0x80; /* set to IETF variant */ - return UUID.nameUUIDFromBytes(randomBytes); - } - - private static byte[] longToBytes(long seed) { - byte[] result = new byte[8]; - for (int i = 7; i >= 0; i--) { - result[i] = (byte) (seed & 0xFF); - seed >>= 8; - } - return result; - } + private UUIDHelper() {} + + public static UUID generateUniqueId(RandomNumberGenerator generator) { + byte[] randomBytes = new byte[16]; + System.arraycopy(longToBytes(generator.nextLong()), 0, randomBytes, 0, 8); + System.arraycopy(longToBytes(generator.nextLong()), 0, randomBytes, 8, 8); + randomBytes[6] &= 0x0f; /* clear version */ + randomBytes[6] |= 0x40; /* set to version 4 */ + randomBytes[8] &= 0x3f; /* clear variant */ + randomBytes[8] |= 0x80; /* set to IETF variant */ + return UUID.nameUUIDFromBytes(randomBytes); + } + + public static UUID generateUniqueId(SecureRandom random) { + byte[] randomBytes = new byte[16]; + random.nextBytes(randomBytes); + randomBytes[6] &= 0x0f; /* clear version */ + randomBytes[6] |= 0x40; /* set to version 4 */ + randomBytes[8] &= 0x3f; /* clear variant */ + randomBytes[8] |= 0x80; /* set to IETF variant */ + return UUID.nameUUIDFromBytes(randomBytes); + } + + private static byte[] longToBytes(long seed) { + byte[] result = new byte[8]; + for (int i = 7; i >= 0; i--) { + result[i] = (byte) (seed & 0xFF); + seed >>= 8; + } + return result; + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/function/TriPredicate.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/function/TriPredicate.java index e64e167..5f6568d 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/function/TriPredicate.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/java/function/TriPredicate.java @@ -20,64 +20,64 @@ @FunctionalInterface public interface TriPredicate { - /** - * Evaluates this predicate on the given arguments. - * - * @param t the first input argument - * @param u the second input argument - * @param v the third input argument - * @return {@code true} if the input arguments match the predicate, otherwise - * {@code false} - */ - boolean test(T t, U u, V v); + /** + * Evaluates this predicate on the given arguments. + * + * @param t the first input argument + * @param u the second input argument + * @param v the third input argument + * @return {@code true} if the input arguments match the predicate, otherwise + * {@code false} + */ + boolean test(T t, U u, V v); - /** - * Returns a composed predicate that represents a short-circuiting logical AND - * of this predicate and another. When evaluating the composed predicate, if - * this predicate is {@code false}, then the {@code other} predicate is not - * evaluated. - * - *

- * Any exceptions thrown during evaluation of either predicate are relayed to - * the caller; if evaluation of this predicate throws an exception, the - * {@code other} predicate will not be evaluated. - * - * @param other a predicate that will be logically-ANDed with this predicate - * @return a composed predicate that represents the short-circuiting logical AND - * of this predicate and the {@code other} predicate - * @throws NullPointerException if other is null - */ - default TriPredicate and(TriPredicate other) { - Objects.requireNonNull(other); - return (T t, U u, V v) -> test(t, u, v) && other.test(t, u, v); - } + /** + * Returns a composed predicate that represents a short-circuiting logical AND + * of this predicate and another. When evaluating the composed predicate, if + * this predicate is {@code false}, then the {@code other} predicate is not + * evaluated. + * + *

+ * Any exceptions thrown during evaluation of either predicate are relayed to + * the caller; if evaluation of this predicate throws an exception, the + * {@code other} predicate will not be evaluated. + * + * @param other a predicate that will be logically-ANDed with this predicate + * @return a composed predicate that represents the short-circuiting logical AND + * of this predicate and the {@code other} predicate + * @throws NullPointerException if other is null + */ + default TriPredicate and(TriPredicate other) { + Objects.requireNonNull(other); + return (T t, U u, V v) -> test(t, u, v) && other.test(t, u, v); + } - /** - * Returns a predicate that represents the logical negation of this predicate. - * - * @return a predicate that represents the logical negation of this predicate - */ - default TriPredicate negate() { - return (T t, U u, V v) -> !test(t, u, v); - } + /** + * Returns a predicate that represents the logical negation of this predicate. + * + * @return a predicate that represents the logical negation of this predicate + */ + default TriPredicate negate() { + return (T t, U u, V v) -> !test(t, u, v); + } - /** - * Returns a composed predicate that represents a short-circuiting logical OR of - * this predicate and another. When evaluating the composed predicate, if this - * predicate is {@code true}, then the {@code other} predicate is not evaluated. - * - *

- * Any exceptions thrown during evaluation of either predicate are relayed to - * the caller; if evaluation of this predicate throws an exception, the - * {@code other} predicate will not be evaluated. - * - * @param other a predicate that will be logically-ORed with this predicate - * @return a composed predicate that represents the short-circuiting logical OR - * of this predicate and the {@code other} predicate - * @throws NullPointerException if other is null - */ - default TriPredicate or(TriPredicate other) { - Objects.requireNonNull(other); - return (T t, U u, V v) -> test(t, u, v) || other.test(t, u, v); - } + /** + * Returns a composed predicate that represents a short-circuiting logical OR of + * this predicate and another. When evaluating the composed predicate, if this + * predicate is {@code true}, then the {@code other} predicate is not evaluated. + * + *

+ * Any exceptions thrown during evaluation of either predicate are relayed to + * the caller; if evaluation of this predicate throws an exception, the + * {@code other} predicate will not be evaluated. + * + * @param other a predicate that will be logically-ORed with this predicate + * @return a composed predicate that represents the short-circuiting logical OR + * of this predicate and the {@code other} predicate + * @throws NullPointerException if other is null + */ + default TriPredicate or(TriPredicate other) { + Objects.requireNonNull(other); + return (T t, U u, V v) -> test(t, u, v) || other.test(t, u, v); + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/thread/PostAsync.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/thread/PostAsync.java index 836c289..1ee2d97 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/thread/PostAsync.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/thread/PostAsync.java @@ -5,43 +5,43 @@ public abstract class PostAsync { - private static ExecutorService SERVICE = Executors.newCachedThreadPool(); - - public static void start() { - if (isAlive()) { - return; - } - SERVICE = Executors.newCachedThreadPool(); - } - - public static void shutdown() { - if (isDead()) { - return; - } - SERVICE.shutdown(); - SERVICE = null; - } - - public static boolean isAlive() { - return SERVICE != null; - } - - public static boolean isDead() { - return SERVICE == null; - } - - public static void post(Runnable runnable) { - if (isDead()) { - return; - } - SERVICE.submit(runnable); - } - - public static void forcePost(Runnable runnable) { - if (isDead()) { - start(); - } - post(runnable); - } + private static ExecutorService SERVICE = Executors.newCachedThreadPool(); + + public static void start() { + if (isAlive()) { + return; + } + SERVICE = Executors.newCachedThreadPool(); + } + + public static void shutdown() { + if (isDead()) { + return; + } + SERVICE.shutdown(); + SERVICE = null; + } + + public static boolean isAlive() { + return SERVICE != null; + } + + public static boolean isDead() { + return SERVICE == null; + } + + public static void post(Runnable runnable) { + if (isDead()) { + return; + } + SERVICE.submit(runnable); + } + + public static void forcePost(Runnable runnable) { + if (isDead()) { + start(); + } + post(runnable); + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/validation/ValidationHelper.java b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/validation/ValidationHelper.java index ddf3a50..43ca62b 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/utils/validation/ValidationHelper.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/utils/validation/ValidationHelper.java @@ -2,12 +2,12 @@ public class ValidationHelper { - private ValidationHelper() {} + private ValidationHelper() {} - public static void isTrue(final boolean expression, final String message, final Object... values) { - if (expression == false) { - throw new IllegalArgumentException(String.format(message, values)); - } - } + public static void isTrue(final boolean expression, final String message, final Object... values) { + if (expression == false) { + throw new IllegalArgumentException(String.format(message, values)); + } + } } diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/version/ServerVersion.java b/src/main/java/net/sourcewriters/minecraft/versiontools/version/ServerVersion.java index dd6328c..49a6c27 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/version/ServerVersion.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/version/ServerVersion.java @@ -7,166 +7,166 @@ public class ServerVersion extends Version { - public static final ServerAnalyzer ANALYZER = new ServerAnalyzer(); - - protected int revision; - - public ServerVersion() { - this(0); - } - - public ServerVersion(int major) { - this(major, 0); - } - - public ServerVersion(int major, int minor) { - this(major, minor, 0); - } - - public ServerVersion(int major, int minor, int patch) { - this(major, minor, patch, 0); - } - - public ServerVersion(int major, int minor, int patch, int revision) { - super(major, minor, patch); - this.revision = revision; - } - - public int getRevision() { - return revision; - } - - @Override - protected ServerVersion setMajor(int major) { - super.setMajor(major); - return this; - } - - @Override - protected ServerVersion setMinor(int minor) { - super.setMinor(minor); - return this; - } - - @Override - protected ServerVersion setPatch(int patch) { - super.setPatch(patch); - return this; - } - - protected ServerVersion setRevision(int revision) { - this.revision = revision; - return this; - } - - @Override - public boolean isHigher(Version version) { - if (super.isHigher(version)) { - return true; - } - if (version instanceof ServerVersion) { - ServerVersion other = (ServerVersion) version; - return revision > other.revision; - } else { - return revision > 0; - } - } - - @Override - public boolean isSimilar(Version version) { - return super.isSimilar(version) && ((version instanceof ServerVersion) && revision == ((ServerVersion) version).revision); - } - - @Override - public boolean isLower(Version version) { - if (super.isHigher(version)) { - return true; - } - if (version instanceof ServerVersion) { - ServerVersion other = (ServerVersion) version; - return revision < other.revision; - } - return false; - } - - @Override - public ServerVersion clone() { - return new ServerVersion(getMajor(), getMinor(), getPatch(), revision); - } - - @Override - public ServerVersion update(int major, int minor, int patch) { - return update(major, minor, patch, 0); - } - - public ServerVersion update(int major, int minor, int patch, int revision) { - return ((ServerVersion) super.update(major, minor, patch)).setRevision(this.revision + revision); - } - - @Override - protected ServerVersion init(int major, int minor, int patch) { - return new ServerVersion(major, minor, patch); - } - - @Override - public ServerAnalyzer getAnalyzer() { - return ANALYZER; - } - - @Override - public VersionFormatter getFormatter() { - return version -> { - StringBuilder builder = new StringBuilder(); - builder.append('v'); - builder.append(version.getMajor()); - builder.append('_'); - builder.append(version.getMinor()); - builder.append("_R"); - builder.append(version.getPatch()); - - if (version instanceof ServerVersion) { - ServerVersion server = (ServerVersion) version; - if (server.getRevision() != 0) { - builder.append('.'); - builder.append(server.getRevision()); - } - } - - return builder.toString(); - }; - } - - public static class ServerAnalyzer implements VersionAnalyzer { - @Override - public ServerVersion analyze(String formatted) { - ServerVersion version = new ServerVersion(); - String[] parts = (formatted = formatted.replaceFirst("v", "")).contains("_") ? formatted.split("_") - : (formatted.contains(".") ? formatted.split("\\.") - : new String[] { - formatted - }); - try { - if (parts.length == 1) { - version.setMajor(Strings.isNumeric(parts[0]) ? Integer.parseInt(parts[0]) : 0); - } else if (parts.length == 2) { - version.setMajor(Strings.isNumeric(parts[0]) ? Integer.parseInt(parts[0]) : 0); - version.setMinor(Strings.isNumeric(parts[1]) ? Integer.parseInt(parts[1]) : 0); - } else if (parts.length >= 3) { - version.setMajor(Strings.isNumeric(parts[0]) ? Integer.parseInt(parts[0]) : 0); - version.setMinor(Strings.isNumeric(parts[1]) ? Integer.parseInt(parts[1]) : 0); - if ((parts[2] = parts[2].replaceFirst("R", "")).contains(".")) { - String[] parts0 = parts[2].split("\\."); - version.setPatch(Strings.isNumeric(parts0[0]) ? Integer.parseInt(parts0[0]) : 0); - version.setRevision(Strings.isNumeric(parts0[1]) ? Integer.parseInt(parts0[1]) : 0); - } else { - version.setPatch(Strings.isNumeric(parts[2]) ? Integer.parseInt(parts[2]) : 0); - } - } - } catch (NumberFormatException ex) { - - } - return version; - } - } + public static final ServerAnalyzer ANALYZER = new ServerAnalyzer(); + + protected int revision; + + public ServerVersion() { + this(0); + } + + public ServerVersion(int major) { + this(major, 0); + } + + public ServerVersion(int major, int minor) { + this(major, minor, 0); + } + + public ServerVersion(int major, int minor, int patch) { + this(major, minor, patch, 0); + } + + public ServerVersion(int major, int minor, int patch, int revision) { + super(major, minor, patch); + this.revision = revision; + } + + public int getRevision() { + return revision; + } + + @Override + protected ServerVersion setMajor(int major) { + super.setMajor(major); + return this; + } + + @Override + protected ServerVersion setMinor(int minor) { + super.setMinor(minor); + return this; + } + + @Override + protected ServerVersion setPatch(int patch) { + super.setPatch(patch); + return this; + } + + protected ServerVersion setRevision(int revision) { + this.revision = revision; + return this; + } + + @Override + public boolean isHigher(Version version) { + if (super.isHigher(version)) { + return true; + } + if (version instanceof ServerVersion) { + ServerVersion other = (ServerVersion) version; + return revision > other.revision; + } else { + return revision > 0; + } + } + + @Override + public boolean isSimilar(Version version) { + return super.isSimilar(version) && ((version instanceof ServerVersion) && revision == ((ServerVersion) version).revision); + } + + @Override + public boolean isLower(Version version) { + if (super.isHigher(version)) { + return true; + } + if (version instanceof ServerVersion) { + ServerVersion other = (ServerVersion) version; + return revision < other.revision; + } + return false; + } + + @Override + public ServerVersion clone() { + return new ServerVersion(getMajor(), getMinor(), getPatch(), revision); + } + + @Override + public ServerVersion update(int major, int minor, int patch) { + return update(major, minor, patch, 0); + } + + public ServerVersion update(int major, int minor, int patch, int revision) { + return ((ServerVersion) super.update(major, minor, patch)).setRevision(this.revision + revision); + } + + @Override + protected ServerVersion init(int major, int minor, int patch) { + return new ServerVersion(major, minor, patch); + } + + @Override + public ServerAnalyzer getAnalyzer() { + return ANALYZER; + } + + @Override + public VersionFormatter getFormatter() { + return version -> { + StringBuilder builder = new StringBuilder(); + builder.append('v'); + builder.append(version.getMajor()); + builder.append('_'); + builder.append(version.getMinor()); + builder.append("_R"); + builder.append(version.getPatch()); + + if (version instanceof ServerVersion) { + ServerVersion server = (ServerVersion) version; + if (server.getRevision() != 0) { + builder.append('.'); + builder.append(server.getRevision()); + } + } + + return builder.toString(); + }; + } + + public static class ServerAnalyzer implements VersionAnalyzer { + @Override + public ServerVersion analyze(String formatted) { + ServerVersion version = new ServerVersion(); + String[] parts = (formatted = formatted.replaceFirst("v", "")).contains("_") ? formatted.split("_") + : (formatted.contains(".") ? formatted.split("\\.") + : new String[] { + formatted + }); + try { + if (parts.length == 1) { + version.setMajor(Strings.isNumeric(parts[0]) ? Integer.parseInt(parts[0]) : 0); + } else if (parts.length == 2) { + version.setMajor(Strings.isNumeric(parts[0]) ? Integer.parseInt(parts[0]) : 0); + version.setMinor(Strings.isNumeric(parts[1]) ? Integer.parseInt(parts[1]) : 0); + } else if (parts.length >= 3) { + version.setMajor(Strings.isNumeric(parts[0]) ? Integer.parseInt(parts[0]) : 0); + version.setMinor(Strings.isNumeric(parts[1]) ? Integer.parseInt(parts[1]) : 0); + if ((parts[2] = parts[2].replaceFirst("R", "")).contains(".")) { + String[] parts0 = parts[2].split("\\."); + version.setPatch(Strings.isNumeric(parts0[0]) ? Integer.parseInt(parts0[0]) : 0); + version.setRevision(Strings.isNumeric(parts0[1]) ? Integer.parseInt(parts0[1]) : 0); + } else { + version.setPatch(Strings.isNumeric(parts[2]) ? Integer.parseInt(parts[2]) : 0); + } + } + } catch (NumberFormatException ex) { + + } + return version; + } + } } \ No newline at end of file diff --git a/src/main/java/net/sourcewriters/minecraft/versiontools/version/Versions.java b/src/main/java/net/sourcewriters/minecraft/versiontools/version/Versions.java index b93ca30..ab2852a 100644 --- a/src/main/java/net/sourcewriters/minecraft/versiontools/version/Versions.java +++ b/src/main/java/net/sourcewriters/minecraft/versiontools/version/Versions.java @@ -12,107 +12,107 @@ public abstract class Versions { - private static Version MINECRAFT_VERSION; - private static String MINECRAFT_VERSION_STRING; - - private static ServerVersion SERVER_VERSION; - private static String SERVER_VERSION_STRING; - - /* - * Minecraft - */ - - public static Version getMinecraft() { - return MINECRAFT_VERSION != null ? MINECRAFT_VERSION - : (MINECRAFT_VERSION = new DefaultVersion().getAnalyzer().analyze(Bukkit.getVersion().split(" ")[2].replace(")", ""))); - } - - public static String getMinecraftAsString() { - return MINECRAFT_VERSION_STRING != null ? MINECRAFT_VERSION_STRING : (MINECRAFT_VERSION_STRING = getMinecraft().toString()); - } - - public static String patchMinecraft(String input) { - return input + getServerAsString(); - } - - /* - * Server Version - */ - - public static ServerVersion getServer() { - return SERVER_VERSION != null ? SERVER_VERSION - : (SERVER_VERSION = ServerVersion.ANALYZER.analyze(Bukkit.getServer().getClass().getPackage().getName().split("\\.", 4)[3])); - } - - public static String getServerAsString() { - return SERVER_VERSION_STRING != null ? SERVER_VERSION_STRING : (SERVER_VERSION_STRING = getServer().toString()); - } - - public static String patchServer(String input) { - return input + getServerAsString(); - } - - // - // Predicates - - public static boolean version(int major, int minor) { - return major(major) && minor(minor); - } - - public static boolean version(int major, int minor, int refaction) { - return major(major) && minor(minor) && refaction(refaction); - } - - public static boolean major(int... major) { - int server = getServer().getMajor(); - for (int current : major) { - if (server == current) { - return true; - } - } - return false; - } - - public static boolean minor(int... minor) { - int server = getServer().getMinor(); - for (int current : minor) { - if (server == current) { - return true; - } - } - return false; - } - - public static boolean refaction(int... refaction) { - int server = getServer().getRevision(); - for (int current : refaction) { - if (server == current) { - return true; - } - } - return false; - } - - public static boolean version(TriPredicate predicate) { - ServerVersion version = getServer(); - return predicate.test(version.getMajor(), version.getMinor(), version.getRevision()); - } - - public static boolean version(BiPredicate predicate) { - ServerVersion version = getServer(); - return predicate.test(version.getMajor(), version.getMinor()); - } - - public static boolean major(Predicate predicate) { - return predicate.test(getServer().getMajor()); - } - - public static boolean minor(Predicate predicate) { - return predicate.test(getServer().getMinor()); - } - - public boolean refaction(Predicate predicate) { - return predicate.test(getServer().getRevision()); - } + private static Version MINECRAFT_VERSION; + private static String MINECRAFT_VERSION_STRING; + + private static ServerVersion SERVER_VERSION; + private static String SERVER_VERSION_STRING; + + /* + * Minecraft + */ + + public static Version getMinecraft() { + return MINECRAFT_VERSION != null ? MINECRAFT_VERSION + : (MINECRAFT_VERSION = new DefaultVersion().getAnalyzer().analyze(Bukkit.getVersion().split(" ")[2].replace(")", ""))); + } + + public static String getMinecraftAsString() { + return MINECRAFT_VERSION_STRING != null ? MINECRAFT_VERSION_STRING : (MINECRAFT_VERSION_STRING = getMinecraft().toString()); + } + + public static String patchMinecraft(String input) { + return input + getServerAsString(); + } + + /* + * Server Version + */ + + public static ServerVersion getServer() { + return SERVER_VERSION != null ? SERVER_VERSION + : (SERVER_VERSION = ServerVersion.ANALYZER.analyze(Bukkit.getServer().getClass().getPackage().getName().split("\\.", 4)[3])); + } + + public static String getServerAsString() { + return SERVER_VERSION_STRING != null ? SERVER_VERSION_STRING : (SERVER_VERSION_STRING = getServer().toString()); + } + + public static String patchServer(String input) { + return input + getServerAsString(); + } + + // + // Predicates + + public static boolean version(int major, int minor) { + return major(major) && minor(minor); + } + + public static boolean version(int major, int minor, int refaction) { + return major(major) && minor(minor) && refaction(refaction); + } + + public static boolean major(int... major) { + int server = getServer().getMajor(); + for (int current : major) { + if (server == current) { + return true; + } + } + return false; + } + + public static boolean minor(int... minor) { + int server = getServer().getMinor(); + for (int current : minor) { + if (server == current) { + return true; + } + } + return false; + } + + public static boolean refaction(int... refaction) { + int server = getServer().getRevision(); + for (int current : refaction) { + if (server == current) { + return true; + } + } + return false; + } + + public static boolean version(TriPredicate predicate) { + ServerVersion version = getServer(); + return predicate.test(version.getMajor(), version.getMinor(), version.getRevision()); + } + + public static boolean version(BiPredicate predicate) { + ServerVersion version = getServer(); + return predicate.test(version.getMajor(), version.getMinor()); + } + + public static boolean major(Predicate predicate) { + return predicate.test(getServer().getMajor()); + } + + public static boolean minor(Predicate predicate) { + return predicate.test(getServer().getMinor()); + } + + public boolean refaction(Predicate predicate) { + return predicate.test(getServer().getRevision()); + } }