From 819777b01e14b213c0264a7230fa0f6649a98ba6 Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Fri, 11 Oct 2024 22:01:25 -0400 Subject: [PATCH 01/32] remove old compatibility versions --- .../Core_1_12_R1/build.gradle.kts | 9 - .../compatibility/block/Block_1_12_R1.java | 128 ---- .../compatibility/entity/Entity_1_12_R1.java | 153 ---- .../entity/FakeEntity_1_12_R1.java | 350 --------- .../equipevent/NonNullList_1_12_R1.java | 53 -- .../core/compatibility/nbt/NBT_1_12_R1.java | 331 --------- .../deecaad/core/compatibility/v1_12_R1.java | 74 -- .../Core_1_13_R2/build.gradle.kts | 9 - .../compatibility/block/Block_1_13_R2.java | 118 --- .../command/Command_1_13_R2.java | 596 --------------- .../compatibility/entity/Entity_1_13_R2.java | 131 ---- .../entity/FakeEntity_1_13_R2.java | 341 --------- .../equipevent/NonNullList_1_13_R2.java | 53 -- .../core/compatibility/nbt/NBT_1_13_R2.java | 214 ------ .../deecaad/core/compatibility/v1_13_R2.java | 83 --- .../Core_1_14_R1/build.gradle.kts | 9 - .../compatibility/block/Block_1_14_R1.java | 118 --- .../command/Command_1_14_R1.java | 594 --------------- .../compatibility/entity/Entity_1_14_R1.java | 118 --- .../entity/FakeEntity_1_14_R1.java | 342 --------- .../equipevent/NonNullList_1_14_R1.java | 53 -- .../core/compatibility/nbt/NBT_1_14_R1.java | 88 --- .../deecaad/core/compatibility/v1_14_R1.java | 83 --- .../Core_1_15_R1/build.gradle.kts | 9 - .../compatibility/block/Block_1_15_R1.java | 117 --- .../command/Command_1_15_R1.java | 607 ---------------- .../compatibility/entity/Entity_1_15_R1.java | 99 --- .../entity/FakeEntity_1_15_R1.java | 359 --------- .../equipevent/NonNullList_1_15_R1.java | 53 -- .../core/compatibility/nbt/NBT_1_15_R1.java | 88 --- .../deecaad/core/compatibility/v1_15_R1.java | 83 --- .../Core_1_16_R3/build.gradle.kts | 9 - .../compatibility/block/Block_1_16_R3.java | 71 -- .../command/Command_1_16_R3.java | 610 ---------------- .../compatibility/entity/Entity_1_16_R3.java | 103 --- .../entity/FakeEntity_1_16_R3.java | 336 --------- .../equipevent/NonNullList_1_16_R3.java | 53 -- .../core/compatibility/nbt/NBT_1_16_R3.java | 88 --- .../deecaad/core/compatibility/v1_16_R3.java | 78 -- .../Core_1_17_R1/build.gradle.kts | 21 - .../compatibility/block/Block_1_17_R1.java | 26 - .../command/Command_1_17_R1.java | 621 ---------------- .../compatibility/entity/Entity_1_17_R1.java | 98 --- .../entity/FakeEntity_1_17_R1.java | 337 --------- .../equipevent/NonNullList_1_17_R1.java | 53 -- .../core/compatibility/nbt/NBT_1_17_R1.java | 119 --- .../deecaad/core/compatibility/v1_17_R1.java | 78 -- .../Core_1_18_R2/build.gradle.kts | 20 - .../compatibility/block/Block_1_18_R2.java | 26 - .../command/Command_1_18_R2.java | 633 ---------------- .../compatibility/entity/Entity_1_18_R2.java | 98 --- .../entity/FakeEntity_1_18_R2.java | 342 --------- .../equipevent/NonNullList_1_18_R2.java | 54 -- .../core/compatibility/nbt/NBT_1_18_R2.java | 120 --- .../deecaad/core/compatibility/v1_18_R2.java | 78 -- .../Core_1_19_R3/build.gradle.kts | 18 - .../compatibility/block/Block_1_19_R3.java | 26 - .../command/Command_1_19_R3.java | 635 ---------------- .../compatibility/entity/Entity_1_19_R3.java | 120 --- .../entity/FakeEntity_1_19_R3.java | 343 --------- .../equipevent/NonNullList_1_19_R3.java | 54 -- .../core/compatibility/nbt/NBT_1_19_R3.java | 114 --- .../deecaad/core/compatibility/v1_19_R3.java | 78 -- .../Core_1_20_R1/build.gradle.kts | 18 - .../compatibility/block/Block_1_20_R1.java | 26 - .../command/Command_1_20_R1.java | 637 ---------------- .../compatibility/entity/Entity_1_20_R1.java | 120 --- .../entity/FakeEntity_1_20_R1.java | 350 --------- .../equipevent/NonNullList_1_20_R1.java | 54 -- .../core/compatibility/nbt/NBT_1_20_R1.java | 114 --- .../deecaad/core/compatibility/v1_20_R1.java | 78 -- .../Core_1_20_R2/build.gradle.kts | 18 - .../compatibility/block/Block_1_20_R2.java | 26 - .../command/Command_1_20_R2.java | 638 ---------------- .../compatibility/entity/Entity_1_20_R2.java | 120 --- .../entity/FakeEntity_1_20_R2.java | 350 --------- .../equipevent/NonNullList_1_20_R2.java | 54 -- .../core/compatibility/nbt/NBT_1_20_R2.java | 114 --- .../deecaad/core/compatibility/v1_20_R2.java | 78 -- .../Core_1_20_R3/build.gradle.kts | 18 - .../compatibility/block/Block_1_20_R3.java | 26 - .../command/Command_1_20_R3.java | 645 ---------------- .../compatibility/entity/Entity_1_20_R3.java | 120 --- .../entity/FakeEntity_1_20_R3.java | 350 --------- .../equipevent/NonNullList_1_20_R3.java | 54 -- .../core/compatibility/nbt/NBT_1_20_R3.java | 114 --- .../deecaad/core/compatibility/v1_20_R3.java | 78 -- .../Core_1_20_R4/build.gradle.kts | 18 - .../compatibility/block/Block_1_20_R4.java | 41 -- .../command/Command_1_20_R4.java | 687 ------------------ .../compatibility/entity/Entity_1_20_R4.java | 120 --- .../entity/FakeEntity_1_20_R4.java | 351 --------- .../equipevent/NonNullList_1_20_R4.java | 54 -- .../core/compatibility/nbt/NBT_1_20_R4.java | 115 --- .../deecaad/core/compatibility/v1_20_R4.java | 78 -- .../Weapon_1_12_R1/build.gradle.kts | 11 - .../compatibility/scope/Scope_1_12_R1.java | 67 -- .../compatibility/v1_12_R1.java | 80 -- .../Weapon_1_13_R2/build.gradle.kts | 11 - .../compatibility/scope/Scope_1_13_R2.java | 67 -- .../compatibility/v1_13_R2.java | 80 -- .../Weapon_1_14_R1/build.gradle.kts | 11 - .../compatibility/scope/Scope_1_14_R1.java | 67 -- .../compatibility/v1_14_R1.java | 80 -- .../Weapon_1_15_R1/build.gradle.kts | 11 - .../compatibility/scope/Scope_1_15_R1.java | 67 -- .../compatibility/v1_15_R1.java | 80 -- .../Weapon_1_16_R3/build.gradle.kts | 11 - .../compatibility/scope/Scope_1_16_R3.java | 67 -- .../compatibility/v1_16_R3.java | 82 --- .../Weapon_1_17_R1/build.gradle.kts | 22 - .../compatibility/scope/Scope_1_17_R1.java | 56 -- .../compatibility/v1_17_R1.java | 82 --- .../Weapon_1_18_R2/build.gradle.kts | 22 - .../compatibility/scope/Scope_1_18_R2.java | 56 -- .../compatibility/v1_18_R2.java | 83 --- .../Weapon_1_19_R3/build.gradle.kts | 20 - .../compatibility/scope/Scope_1_19_R3.java | 58 -- .../compatibility/v1_19_R3.java | 93 --- .../Weapon_1_20_R1/build.gradle.kts | 19 - .../compatibility/scope/Scope_1_20_R1.java | 58 -- .../compatibility/v1_20_R1.java | 91 --- .../Weapon_1_20_R2/build.gradle.kts | 19 - .../compatibility/scope/Scope_1_20_R2.java | 60 -- .../compatibility/v1_20_R2.java | 91 --- .../Weapon_1_20_R3/build.gradle.kts | 19 - .../compatibility/scope/Scope_1_20_R3.java | 60 -- .../compatibility/v1_20_R3.java | 81 --- .../Weapon_1_20_R4/build.gradle.kts | 19 - .../compatibility/scope/Scope_1_20_R4.java | 61 -- .../compatibility/v1_20_R4.java | 81 --- .../weaponmechanics/WeaponMechanics.java | 33 - 132 files changed, 18563 deletions(-) delete mode 100644 CoreCompatibility/Core_1_12_R1/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_12_R1.java delete mode 100644 CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_12_R1.java delete mode 100644 CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_12_R1.java delete mode 100644 CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_12_R1.java delete mode 100644 CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_12_R1.java delete mode 100644 CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/v1_12_R1.java delete mode 100644 CoreCompatibility/Core_1_13_R2/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_13_R2.java delete mode 100644 CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_13_R2.java delete mode 100644 CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_13_R2.java delete mode 100644 CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_13_R2.java delete mode 100644 CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_13_R2.java delete mode 100644 CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_13_R2.java delete mode 100644 CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/v1_13_R2.java delete mode 100644 CoreCompatibility/Core_1_14_R1/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_14_R1.java delete mode 100644 CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_14_R1.java delete mode 100644 CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_14_R1.java delete mode 100644 CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_14_R1.java delete mode 100644 CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_14_R1.java delete mode 100644 CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_14_R1.java delete mode 100644 CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/v1_14_R1.java delete mode 100644 CoreCompatibility/Core_1_15_R1/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_15_R1.java delete mode 100644 CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_15_R1.java delete mode 100644 CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_15_R1.java delete mode 100644 CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_15_R1.java delete mode 100644 CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_15_R1.java delete mode 100644 CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_15_R1.java delete mode 100644 CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/v1_15_R1.java delete mode 100644 CoreCompatibility/Core_1_16_R3/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_16_R3.java delete mode 100644 CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_16_R3.java delete mode 100644 CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_16_R3.java delete mode 100644 CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_16_R3.java delete mode 100644 CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_16_R3.java delete mode 100644 CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_16_R3.java delete mode 100644 CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/v1_16_R3.java delete mode 100644 CoreCompatibility/Core_1_17_R1/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_17_R1.java delete mode 100644 CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_17_R1.java delete mode 100644 CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_17_R1.java delete mode 100644 CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_17_R1.java delete mode 100644 CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_17_R1.java delete mode 100644 CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_17_R1.java delete mode 100644 CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/v1_17_R1.java delete mode 100644 CoreCompatibility/Core_1_18_R2/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_18_R2.java delete mode 100644 CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_18_R2.java delete mode 100644 CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_18_R2.java delete mode 100644 CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_18_R2.java delete mode 100644 CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_18_R2.java delete mode 100644 CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_18_R2.java delete mode 100644 CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/v1_18_R2.java delete mode 100644 CoreCompatibility/Core_1_19_R3/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_19_R3.java delete mode 100644 CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_19_R3.java delete mode 100644 CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_19_R3.java delete mode 100644 CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_19_R3.java delete mode 100644 CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_19_R3.java delete mode 100644 CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_19_R3.java delete mode 100644 CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/v1_19_R3.java delete mode 100644 CoreCompatibility/Core_1_20_R1/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R1.java delete mode 100644 CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R1.java delete mode 100644 CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R1.java delete mode 100644 CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R1.java delete mode 100644 CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R1.java delete mode 100644 CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R1.java delete mode 100644 CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/v1_20_R1.java delete mode 100644 CoreCompatibility/Core_1_20_R2/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R2.java delete mode 100644 CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R2.java delete mode 100644 CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R2.java delete mode 100644 CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R2.java delete mode 100644 CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R2.java delete mode 100644 CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R2.java delete mode 100644 CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/v1_20_R2.java delete mode 100644 CoreCompatibility/Core_1_20_R3/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R3.java delete mode 100644 CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R3.java delete mode 100644 CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R3.java delete mode 100644 CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R3.java delete mode 100644 CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R3.java delete mode 100644 CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R3.java delete mode 100644 CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/v1_20_R3.java delete mode 100644 CoreCompatibility/Core_1_20_R4/build.gradle.kts delete mode 100644 CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R4.java delete mode 100644 CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R4.java delete mode 100644 CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R4.java delete mode 100644 CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R4.java delete mode 100644 CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R4.java delete mode 100644 CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R4.java delete mode 100644 CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/v1_20_R4.java delete mode 100644 WeaponCompatibility/Weapon_1_12_R1/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_12_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_12_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_12_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_12_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_13_R2/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_13_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_13_R2.java delete mode 100644 WeaponCompatibility/Weapon_1_13_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_13_R2.java delete mode 100644 WeaponCompatibility/Weapon_1_14_R1/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_14_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_14_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_14_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_14_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_15_R1/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_15_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_15_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_15_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_15_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_16_R3/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_16_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_16_R3.java delete mode 100644 WeaponCompatibility/Weapon_1_16_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_16_R3.java delete mode 100644 WeaponCompatibility/Weapon_1_17_R1/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_17_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_17_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_17_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_17_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_18_R2/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_18_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_18_R2.java delete mode 100644 WeaponCompatibility/Weapon_1_18_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_18_R2.java delete mode 100644 WeaponCompatibility/Weapon_1_19_R3/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_19_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_19_R3.java delete mode 100644 WeaponCompatibility/Weapon_1_19_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_19_R3.java delete mode 100644 WeaponCompatibility/Weapon_1_20_R1/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_20_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_20_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R1.java delete mode 100644 WeaponCompatibility/Weapon_1_20_R2/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_20_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R2.java delete mode 100644 WeaponCompatibility/Weapon_1_20_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R2.java delete mode 100644 WeaponCompatibility/Weapon_1_20_R3/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_20_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R3.java delete mode 100644 WeaponCompatibility/Weapon_1_20_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R3.java delete mode 100644 WeaponCompatibility/Weapon_1_20_R4/build.gradle.kts delete mode 100644 WeaponCompatibility/Weapon_1_20_R4/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R4.java delete mode 100644 WeaponCompatibility/Weapon_1_20_R4/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R4.java diff --git a/CoreCompatibility/Core_1_12_R1/build.gradle.kts b/CoreCompatibility/Core_1_12_R1/build.gradle.kts deleted file mode 100644 index 92ccd133c..000000000 --- a/CoreCompatibility/Core_1_12_R1/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - compileOnly(files(file("../../lib/nms/spigot-1.12.2.jar"))) - adventureChatAPI() -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_12_R1.java b/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_12_R1.java deleted file mode 100644 index c0a49d52e..000000000 --- a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_12_R1.java +++ /dev/null @@ -1,128 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import me.deecaad.core.compatibility.HitBox; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_12_R1.AxisAlignedBB; -import net.minecraft.server.v1_12_R1.BlockPosition; -import net.minecraft.server.v1_12_R1.IBlockData; -import net.minecraft.server.v1_12_R1.MinecraftKey; -import net.minecraft.server.v1_12_R1.PacketPlayOutBlockBreakAnimation; -import net.minecraft.server.v1_12_R1.SoundEffect; -import net.minecraft.server.v1_12_R1.SoundEffectType; -import net.minecraft.server.v1_12_R1.WorldServer; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.material.MaterialData; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.Locale; - -public class Block_1_12_R1 implements BlockCompatibility { - - private static final Field durabilityField; - private static final Field[] soundFields; - - static { - Class blockClass = ReflectionUtil.getNMSClass("", "Block"); - durabilityField = ReflectionUtil.getField(blockClass, "durability"); - - soundFields = new Field[SoundType.values().length]; // 5 - for (int i = 0; i < soundFields.length; i++) { - soundFields[i] = ReflectionUtil.getField(SoundEffectType.class, SoundEffect.class, i); - } - } - - @Override - public HitBox getHitBox(@NotNull Block block, boolean allowLiquid) { - if (!block.getChunk().isLoaded()) - return null; - if (block.isEmpty()) - return null; - - boolean isLiquid = block.isLiquid(); - if (!allowLiquid && isLiquid) - return null; - - if (isLiquid) { - HitBox hitBox = new HitBox(block.getX(), block.getY(), block.getZ(), block.getX() + 1, block.getY() + 1, block.getZ() + 1); - hitBox.setBlockHitBox(block); - return hitBox; - } - - WorldServer worldServer = ((CraftWorld) block.getWorld()).getHandle(); - BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ()); - IBlockData blockData = worldServer.getType(blockPosition); - net.minecraft.server.v1_12_R1.Block nmsBlock = blockData.getBlock(); - - // Passable block check -> false means passable (thats why !) - if (!(blockData.d(worldServer, blockPosition) != net.minecraft.server.v1_12_R1.Block.k && nmsBlock.a(blockData, false))) - return null; - - AxisAlignedBB aabb = blockData.e(worldServer, blockPosition); - // 1.12 -> e - // 1.11 -> d - // 1.9 - 1.10 -> c - - int x = blockPosition.getX(), y = blockPosition.getY(), z = blockPosition.getZ(); - HitBox hitBox = new HitBox(x + aabb.a, y + aabb.b, z + aabb.c, x + aabb.d, y + aabb.e, z + aabb.f); - hitBox.setBlockHitBox(block); - return hitBox; - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ()); - return new PacketPlayOutBlockBreakAnimation(id, pos, crack); - } - - @Override - public float getBlastResistance(Block block) { - WorldServer world = ((CraftWorld) block.getWorld()).getHandle(); - BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ()); - net.minecraft.server.v1_12_R1.Block nmsBlock = world.c(pos).getBlock(); - - return (float) ReflectionUtil.invokeField(durabilityField, nmsBlock) / 5.0f; - } - - @Override - public SoundData getBlockSound(Object blockData, SoundType type) { - MaterialData mat = (MaterialData) blockData; - IBlockData block = net.minecraft.server.v1_12_R1.Block.getByCombinedId(mat.getItemTypeId() & mat.getData() << 12); - SoundEffectType sounds = block.getBlock().getStepSound(); - - SoundData soundData = new SoundData(); - soundData.type = type; - soundData.pitch = sounds.n; - soundData.volume = sounds.m; - - switch (type) { - case BREAK -> soundData.sound = bukkit(sounds, 0); - case STEP -> soundData.sound = bukkit(sounds, 1); - case PLACE -> soundData.sound = bukkit(sounds, 2); - case HIT -> soundData.sound = bukkit(sounds, 3); - case FALL -> soundData.sound = bukkit(sounds, 4); - default -> throw new InternalError("unreachable code"); - } - - return soundData; - } - - private Sound bukkit(SoundEffectType sounds, int index) { - SoundEffect sound = (SoundEffect) ReflectionUtil.invokeField(soundFields[index], sounds); - MinecraftKey key = SoundEffect.a.b(sound); - return Sound.valueOf(key.getKey().replaceAll("\\.", "_").toUpperCase(Locale.ROOT)); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_12_R1.java b/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_12_R1.java deleted file mode 100644 index bca4f2493..000000000 --- a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_12_R1.java +++ /dev/null @@ -1,153 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import me.deecaad.core.compatibility.HitBox; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_12_R1; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_12_R1.AxisAlignedBB; -import net.minecraft.server.v1_12_R1.DataWatcher; -import net.minecraft.server.v1_12_R1.EnumItemSlot; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityMetadata; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; -import org.bukkit.entity.ComplexEntityPart; -import org.bukkit.entity.ComplexLivingEntity; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.List; - -public class Entity_1_12_R1 implements EntityCompatibility { - - @Override - public HitBox getHitBox(Entity entity) { - if (entity.isInvulnerable() || !entity.getType().isAlive() || entity.isDead()) - return null; - - HitBox hitBox = new HitBox(entity.getLocation().toVector(), getLastLocation(entity)) - .grow(entity.getWidth(), entity.getHeight()); - hitBox.setLivingEntity((LivingEntity) entity); - - if (entity instanceof ComplexLivingEntity) { - for (ComplexEntityPart entityPart : ((ComplexLivingEntity) entity).getParts()) { - AxisAlignedBB boxPart = ((CraftEntity) entityPart).getHandle().getBoundingBox(); - hitBox.addVoxelShapePart(new HitBox(boxPart.a, boxPart.b, boxPart.c, boxPart.d, boxPart.e, boxPart.f)); - } - } - return hitBox; - } - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.server.v1_12_R1.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.lastX, nms.lastY, nms.lastZ); - } - - @Override - public double getAbsorption(@NotNull LivingEntity entity) { - return ((CraftLivingEntity) entity).getHandle().getAbsorptionHearts(); - } - - @Override - public void setAbsorption(@NotNull LivingEntity entity, double absorption) { - ((CraftLivingEntity) entity).getHandle().setAbsorptionHearts((float) absorption); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_12_R1(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_12_R1(location, type, data); - } - - private static final Field ID = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, int.class); - private static final Field DATA = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, List.class); - - @Override - public int getId(Object obj) { - return (int) ReflectionUtil.invokeField(ID, obj); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - EntityEquipment equipment = bukkit.getEquipment(); - - int id = bukkit.getEntityId(); - EnumItemSlot nmsSlot; - switch (slot) { - case HEAD -> { - nmsSlot = EnumItemSlot.HEAD; - item = item == null ? equipment.getHelmet() : item; - } - case CHEST -> { - nmsSlot = EnumItemSlot.CHEST; - item = item == null ? equipment.getChestplate() : item; - } - case LEGS -> { - nmsSlot = EnumItemSlot.LEGS; - item = item == null ? equipment.getLeggings() : item; - } - case FEET -> { - nmsSlot = EnumItemSlot.FEET; - item = item == null ? equipment.getBoots() : item; - } - case HAND -> { - nmsSlot = EnumItemSlot.MAINHAND; - item = item == null ? equipment.getItemInMainHand() : item; - } - case OFF_HAND -> { - nmsSlot = EnumItemSlot.OFFHAND; - item = item == null ? equipment.getItemInOffHand() : item; - } - default -> throw new RuntimeException("unreachable"); - } - - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(id, nmsSlot, CraftItemStack.asNMSCopy(item)); - ((CraftPlayer) bukkit).getHandle().playerConnection.sendPacket(packet); - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.server.v1_12_R1.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - PacketPlayOutEntityMetadata packet = (PacketPlayOutEntityMetadata) obj; - List> list = (List>) ReflectionUtil.invokeField(DATA, packet); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).b().getClass() != Byte.class) - return; - - // noinspection unchecked - DataWatcher.Item item = (DataWatcher.Item) list.get(0); - byte data = item.b(); - data = meta.set(data, enabled); - item.a(data); - } -} diff --git a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_12_R1.java b/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_12_R1.java deleted file mode 100644 index d9775e03d..000000000 --- a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_12_R1.java +++ /dev/null @@ -1,350 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.server.v1_12_R1.Block; -import net.minecraft.server.v1_12_R1.Entity; -import net.minecraft.server.v1_12_R1.EntityArmorStand; -import net.minecraft.server.v1_12_R1.EntityFallingBlock; -import net.minecraft.server.v1_12_R1.EntityFireworks; -import net.minecraft.server.v1_12_R1.EntityItem; -import net.minecraft.server.v1_12_R1.EntityLiving; -import net.minecraft.server.v1_12_R1.EnumItemSlot; -import net.minecraft.server.v1_12_R1.IBlockData; -import net.minecraft.server.v1_12_R1.ItemStack; -import net.minecraft.server.v1_12_R1.Packet; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityHeadRotation; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityMetadata; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityStatus; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityVelocity; -import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntity; -import net.minecraft.server.v1_12_R1.PacketPlayOutSpawnEntityLiving; -import net.minecraft.server.v1_12_R1.PlayerConnection; -import net.minecraft.server.v1_12_R1.Vector3f; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_12_R1.util.CraftMagicNumbers; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.material.MaterialData; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static net.minecraft.server.v1_12_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; -import static net.minecraft.server.v1_12_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook; - -public class FakeEntity_1_12_R1 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EnumItemSlot[] SLOTS = EnumItemSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private IBlockData block; - private ItemStack item; - - public FakeEntity_1_12_R1(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new EntityItem(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> { - if (data.getClass() == Material.class) { - yield new EntityFallingBlock(world.getHandle(), x, y, z, block = CraftMagicNumbers.getBlock((Material) data).fromLegacyData(0)); - } else { - MaterialData state = ((org.bukkit.block.BlockState) data).getData(); - yield new EntityFallingBlock(world.getHandle(), x, y, z, block = CraftMagicNumbers.getBlock(state.getItemType()).fromLegacyData(state.getData())); - } - } - case FIREWORK -> new EntityFireworks(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - EntityArmorStand armorStand = (EntityArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> CraftItemStack.asBukkitCopy(item); - case FALLING_BLOCK -> { - int combined = Block.getCombinedId(block); - int mat = combined & 4095; - int data = combined >> 12 & 15; - yield new MaterialData(mat, (byte) data); - } - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((EntityItem) entity).setItemStack(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(display); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosition(x, y, z); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - } - - @Override - public void setMotion(double dx, double dy, double dz) { - PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(cache, dx, dy, dz); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - - byte byteYaw = convertYaw(yaw); - PacketPlayOutEntityLook packet = new PacketPlayOutEntityLook(cache, byteYaw, convertPitch(pitch), false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(entity); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(cache, dx, dy, dz, yaw, pitch, false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - public void show() { - - // Construct the packets out of the loop to save resources, they will - // be the same for each Player. - Packet spawn = type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, getSpawnId(), type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0); - PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())); - PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, motion.getX(), motion.getY(), motion.getZ()); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection; - if (connections.contains(connection)) { - continue; - } - - connection.sendPacket(spawn); - connection.sendPacket(meta); - connection.sendPacket(head); - connection.sendPacket(velocity); - connection.sendPacket(look); - PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket(); - if (equipment != null) { - for (PacketPlayOutEntityEquipment packet : equipment) { - connection.sendPacket(packet); - } - } - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - if (connections.contains(connection)) - throw new IllegalArgumentException(); - - connection.sendPacket(type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, getSpawnId(), type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0)); - connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true)); - connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.sendPacket(new PacketPlayOutEntityVelocity(cache, motion.getX(), motion.getY(), motion.getZ())); - connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()))); - PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket(); - if (equipment != null) { - for (PacketPlayOutEntityEquipment packet : equipment) { - connection.sendPacket(packet); - } - } - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((EntityArmorStand) entity).setHeadPose(new Vector3f(getPitch(), 0, 0)); - - sendPackets(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), false)); - } - - @Override - public void remove() { - sendPackets(new PacketPlayOutEntityDestroy(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(new PacketPlayOutEntityDestroy(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new PacketPlayOutEntityStatus(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EnumItemSlot slot = switch (equipmentSlot) { - case HAND -> EnumItemSlot.MAINHAND; - case OFF_HAND -> EnumItemSlot.OFFHAND; - case FEET -> EnumItemSlot.FEET; - case CHEST -> EnumItemSlot.CHEST; - case LEGS -> EnumItemSlot.LEGS; - case HEAD -> EnumItemSlot.HEAD; - }; - - EntityLiving livingEntity = (EntityLiving) entity; - livingEntity.setSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - PacketPlayOutEntityEquipment[] packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private PacketPlayOutEntityEquipment[] getEquipmentPacket() { - if (!type.isAlive()) - return null; - EntityLiving livingEntity = (EntityLiving) entity; - - List temp = new ArrayList<>(SLOTS.length); - for (EnumItemSlot slot : SLOTS) { - ItemStack item = livingEntity.getEquipment(slot); - - if (item != null && !item.isEmpty()) { - temp.add(new PacketPlayOutEntityEquipment(cache, slot, item)); - } - } - - return temp.isEmpty() ? null : temp.toArray(new PacketPlayOutEntityEquipment[0]); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - PlayerConnection connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.sendPacket(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_12_R1.java b/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_12_R1.java deleted file mode 100644 index 00651edce..000000000 --- a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_12_R1.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_12_R1.Item; -import net.minecraft.server.v1_12_R1.ItemStack; -import net.minecraft.server.v1_12_R1.NonNullList; -import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -public class NonNullList_1_12_R1 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_12_R1(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.a); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.a); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_12_R1.java b/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_12_R1.java deleted file mode 100644 index 0a389316d..000000000 --- a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_12_R1.java +++ /dev/null @@ -1,331 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import me.deecaad.core.utils.AttributeType; -import me.deecaad.core.utils.StringUtil; -import net.minecraft.server.v1_12_R1.NBTBase; -import net.minecraft.server.v1_12_R1.NBTTagCompound; -import net.minecraft.server.v1_12_R1.NBTTagList; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Objects; -import java.util.UUID; - -public class NBT_1_12_R1 implements NBTCompatibility { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.server.v1_12_R1.ItemStack nms = getNMSStack(toItem); - NBTTagCompound from = getNMSStack(fromItem).getTag(); - NBTTagCompound to = nms.getTag(); - - if (path == null) { - nms.setTag((NBTTagCompound) from.clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - return; - } - - to.set(path, from.getCompound(path).clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - } - - @Override - public boolean hasString(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key) { - return getBukkitCompound(getNMSStack(bukkitItem)).hasKey(getTagName(plugin, key)); - } - - @Override - public String getString(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key, String def) { - String value = getBukkitCompound(getNMSStack(bukkitItem)).getString(getTagName(plugin, key)); - return value != null && !value.isEmpty() ? value : def; - } - - @NotNull @Override - public void setString(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key, String value) { - net.minecraft.server.v1_12_R1.ItemStack nmsStack = getNMSStack(bukkitItem); - getBukkitCompound(nmsStack).setString(getTagName(plugin, key), value); - - bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsStack)); - } - - @Override - public boolean hasInt(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key) { - return getBukkitCompound(getNMSStack(bukkitItem)).hasKey(getTagName(plugin, key)); - } - - @Override - public int getInt(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key, int def) { - NBTTagCompound nbt = getBukkitCompound(getNMSStack(bukkitItem)); - String tag = getTagName(plugin, key); - if (!nbt.hasKey(tag)) - return def; - return nbt.getInt(tag); - } - - @NotNull @Override - public void setInt(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key, int value) { - net.minecraft.server.v1_12_R1.ItemStack nmsStack = getNMSStack(bukkitItem); - getBukkitCompound(nmsStack).setInt(getTagName(plugin, key), value); - - bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsStack)); - } - - @Override - public boolean hasDouble(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key) { - return getBukkitCompound(getNMSStack(bukkitItem)).hasKey(getTagName(plugin, key)); - } - - @Override - public double getDouble(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key, double def) { - NBTTagCompound nbt = getBukkitCompound(getNMSStack(bukkitItem)); - String tag = getTagName(plugin, key); - if (!nbt.hasKey(tag)) - return def; - return nbt.getDouble(tag); - } - - @Override - public void setDouble(@NotNull ItemStack bukkitItem, @Nullable String plugin, @NotNull String key, double value) { - net.minecraft.server.v1_12_R1.ItemStack nmsStack = getNMSStack(bukkitItem); - getBukkitCompound(nmsStack).setDouble(getTagName(plugin, key), value); - - bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsStack)); - } - - @Override - public boolean hasArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - return getBukkitCompound(getNMSStack(bukkitItem)).hasKey(getTagName(plugin, key)); - } - - @Override - public int[] getArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int[] def) { - NBTTagCompound nbt = getBukkitCompound(getNMSStack(bukkitItem)); - String tag = getTagName(plugin, key); - if (!nbt.hasKey(tag)) - return def; - return nbt.getIntArray(tag); - } - - @Override - public void setArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int[] value) { - net.minecraft.server.v1_12_R1.ItemStack nmsStack = getNMSStack(bukkitItem); - getBukkitCompound(nmsStack).setIntArray(getTagName(plugin, key), value); - - bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsStack)); - } - - @Override - public boolean hasStringArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - return getBukkitCompound(getNMSStack(bukkitItem)).hasKey(getTagName(plugin, key)); - } - - @Override - public String[] getStringArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String[] def) { - NBTTagCompound nbt = getBukkitCompound(getNMSStack(bukkitItem)); - String tag = getTagName(plugin, key); - if (!nbt.hasKey(tag)) - return def; - - byte[] primitive = nbt.getByteArray(tag); - final ByteBuffer buffer = ByteBuffer.wrap(primitive); - final List list = new ArrayList<>(); - - while (buffer.remaining() > 0) { - if (buffer.remaining() < 4) - break; - final int stringLength = buffer.getInt(); - if (buffer.remaining() < stringLength) - break; - - final byte[] stringBytes = new byte[stringLength]; - buffer.get(stringBytes); - - list.add(new String(stringBytes, StandardCharsets.UTF_8)); - } - - return list.toArray(new String[0]); - } - - @Override - public void setStringArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String[] complex) { - net.minecraft.server.v1_12_R1.ItemStack nmsStack = getNMSStack(bukkitItem); - - final byte[][] allBytes = new byte[complex.length][]; - int total = 0; - for (int i = 0; i < allBytes.length; i++) { - final byte[] bytes = complex[i].getBytes(StandardCharsets.UTF_8); - allBytes[i] = bytes; - total += bytes.length; - } - - final ByteBuffer buffer = ByteBuffer.allocate(total + allBytes.length * 4); // stores integers - for (final byte[] bytes : allBytes) { - buffer.putInt(bytes.length); - buffer.put(bytes); - } - - getBukkitCompound(nmsStack).setByteArray(getTagName(plugin, key), buffer.array()); - - bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsStack)); - } - - @Override - public void remove(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - net.minecraft.server.v1_12_R1.ItemStack nmsStack = getNMSStack(bukkitItem); - getBukkitCompound(nmsStack).remove(getTagName(plugin, key)); - - bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsStack)); - } - - @Override - public void setAttribute(@NotNull ItemStack bukkitItem, @NotNull AttributeType attribute, @Nullable AttributeSlot slot, double value) { - net.minecraft.server.v1_12_R1.ItemStack nmsItem = getNMSStack(bukkitItem); - if (nmsItem.getTag() == null) { - nmsItem.setTag(new NBTTagCompound()); - } - - NBTTagCompound compound = nmsItem.getTag(); - if (!compound.hasKey("AttributeModifiers")) { - compound.set("AttributeModifiers", new NBTTagList()); - } - - NBTTagList list = (NBTTagList) compound.get("AttributeModifiers"); - - // Attributes have a UUID which is used by Minecraft... If we have - // a duplicate UUID, an undefined attribute will be ignored - UUID uuid = slot == null ? attribute.getUUID() : slot.modify(attribute.getUUID()); - - // NBT lists don't have an indexOf method, so we need to loop - // through each attribute, and determine if it is one we want to - // modify. We want to modify an attribute if the attribute was - // set using MechanicsCore, and it's attribute type matches the - // parameter attribute type. - boolean isModifiedAttribute = false; - for (int i = 0; i < list.size(); i++) { - - // 10 is the id for nbt lists - if (list.get(i).getTypeId() != 10) { - continue; - } - - NBTTagCompound nbt = list.get(i); - String name = nbt.getString("Name"); - String attributeName = nbt.getString("AttributeName"); - long uuidLeast = nbt.getLong("UUIDLeast"); - long uuidMost = nbt.getLong("UUIDMost"); - - if (!"MechanicsCoreAttribute".equals(name) - || !attribute.getMinecraftName().equals(attributeName) - || uuid.getLeastSignificantBits() != uuidLeast - || uuid.getMostSignificantBits() != uuidMost) { - continue; - } - - // Since this attribute already exists, we only need to modify - // the existing value. No need to set the name/uuid - nbt.setDouble("Amount", value); - isModifiedAttribute = true; - break; - } - - if (!isModifiedAttribute) { - NBTTagCompound nbt = new NBTTagCompound(); - nbt.setString("AttributeName", attribute.getMinecraftName()); - nbt.setString("Name", "MechanicsCoreAttribute"); - nbt.setDouble("Amount", value); - nbt.setInt("Operation", 0); // 0 == add - - nbt.setLong("UUIDLeast", uuid.getLeastSignificantBits()); - nbt.setLong("UUIDMost", uuid.getMostSignificantBits()); - - if (slot != null) { - nbt.setString("Slot", slot.getSlotName()); - } - list.add(nbt); - } - - bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsItem)); - } - - @NotNull @Override - public net.minecraft.server.v1_12_R1.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_12_R1.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - NBTTagCompound nbt = getNMSStack(bukkitStack).getTag(); - if (nbt == null) - return "null"; - - return visit(nbt, 0, 0).toString(); - } - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - - private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - StringBuilder builder = new StringBuilder(braceColor).append('{'); - - List keys = new ArrayList<>(nbt.c()); - Collections.sort(keys); - - for (int i = 0; i < keys.size(); i++) { - String key = keys.get(i); - NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible"); - - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - builder.append(color).append(key).append("&f&l: ").append(color); - - if (value instanceof NBTTagCompound) - builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i)); - else - builder.append(value); - } - - return builder.append(braceColor).append("}\n"); - } - - private NBTTagCompound getBukkitCompound(net.minecraft.server.v1_12_R1.ItemStack nmsStack) { - if (nmsStack.getTag() == null) { - nmsStack.setTag(new NBTTagCompound()); - } - - NBTTagCompound nbt = nmsStack.getTag().getCompound("PublicBukkitValues"); - - // If the nbt compound was just created, make sure it is added to the - // internal map. - if (nbt.isEmpty()) { - nmsStack.getTag().set("PublicBukkitValues", nbt); - } - return nbt; - } - - private String getTagName(String plugin, String key) { - return plugin.toLowerCase(Locale.ROOT) + ":" + key.toLowerCase(Locale.ROOT); - } - - @Override - public @NotNull ItemStack getPlacementItem(@NotNull Block block) { - return block.getState().getData().toItemStack(1); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/v1_12_R1.java b/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/v1_12_R1.java deleted file mode 100644 index 96f13e139..000000000 --- a/CoreCompatibility/Core_1_12_R1/src/main/java/me/deecaad/core/compatibility/v1_12_R1.java +++ /dev/null @@ -1,74 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_12_R1; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_12_R1; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_12_R1; -import net.minecraft.server.v1_12_R1.EntityPlayer; -import net.minecraft.server.v1_12_R1.Packet; -import net.minecraft.server.v1_12_R1.PlayerConnection; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_12_R1 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - - public v1_12_R1() { - entityCompatibility = new Entity_1_12_R1(); - blockCompatibility = new Block_1_12_R1(); - nbtCompatibility = new NBT_1_12_R1(); - } - - @Override - public int getPing(@NotNull Player player) { - return getEntityPlayer(player).ping; - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.server.v1_12_R1.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).playerConnection.sendPacket((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - PlayerConnection playerConnection = getEntityPlayer(player).playerConnection; - for (Object packet : packets) { - playerConnection.sendPacket((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @Override - public @NotNull EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} diff --git a/CoreCompatibility/Core_1_13_R2/build.gradle.kts b/CoreCompatibility/Core_1_13_R2/build.gradle.kts deleted file mode 100644 index b5e2eedb7..000000000 --- a/CoreCompatibility/Core_1_13_R2/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - compileOnly(files(file("../../lib/nms/spigot-1.13.2.jar"))) - adventureChatAPI() -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_13_R2.java b/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_13_R2.java deleted file mode 100644 index 78527e071..000000000 --- a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_13_R2.java +++ /dev/null @@ -1,118 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import me.deecaad.core.compatibility.HitBox; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_13_R2.AxisAlignedBB; -import net.minecraft.server.v1_13_R2.BlockPosition; -import net.minecraft.server.v1_13_R2.IRegistry; -import net.minecraft.server.v1_13_R2.MinecraftKey; -import net.minecraft.server.v1_13_R2.PacketPlayOutBlockBreakAnimation; -import net.minecraft.server.v1_13_R2.SoundEffect; -import net.minecraft.server.v1_13_R2.SoundEffectType; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock; -import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData; -import org.bukkit.util.BoundingBox; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.List; -import java.util.Locale; - -public class Block_1_13_R2 implements BlockCompatibility { - - private static final Field[] soundFields; - - static { - soundFields = new Field[SoundType.values().length]; // 5 - for (int i = 0; i < soundFields.length; i++) { - soundFields[i] = ReflectionUtil.getField(SoundEffectType.class, SoundEffect.class, i); - } - } - - @Override - public HitBox getHitBox(@NotNull Block block, boolean allowLiquid) { - if (!block.getChunk().isLoaded()) - return null; - if (block.isEmpty()) - return null; - - boolean isLiquid = block.isLiquid(); - if (!allowLiquid) { - if (block.isPassable() || block.isLiquid()) - return null; - } else if (!isLiquid && block.isPassable()) { - // Check like this because liquid is also passable... - return null; - } - - HitBox hitBox; - if (isLiquid) { - hitBox = new HitBox(block.getX(), block.getY(), block.getZ(), block.getX() + 1, block.getY() + 1, block.getZ() + 1); - } else { - BoundingBox boundingBox = block.getBoundingBox(); - hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ()); - } - hitBox.setBlockHitBox(block); - - CraftBlock craftBlock = (CraftBlock) block; - List voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d(); - if (voxelShape.size() > 1) { - int x = block.getX(); - int y = block.getY(); - int z = block.getZ(); - for (AxisAlignedBB boxPart : voxelShape) { - hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, - x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ)); - } - } - - return hitBox; - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ()); - return new PacketPlayOutBlockBreakAnimation(id, pos, crack); - } - - @Override - public SoundData getBlockSound(Object blockData, SoundType type) { - CraftBlockData block = (CraftBlockData) blockData; - SoundEffectType sounds = block.getState().getBlock().getStepSound(); - - SoundData soundData = new SoundData(); - soundData.type = type; - soundData.pitch = sounds.p; - soundData.volume = sounds.o; - - switch (type) { - case BREAK -> soundData.sound = bukkit(sounds, 0); - case STEP -> soundData.sound = bukkit(sounds, 1); - case PLACE -> soundData.sound = bukkit(sounds, 2); - case HIT -> soundData.sound = bukkit(sounds, 3); - case FALL -> soundData.sound = bukkit(sounds, 4); - default -> throw new InternalError("unreachable code"); - } - - return soundData; - } - - private Sound bukkit(SoundEffectType sounds, int index) { - SoundEffect sound = (SoundEffect) ReflectionUtil.invokeField(soundFields[index], sounds); - MinecraftKey key = IRegistry.SOUND_EVENT.getKey(sound); - return Sound.valueOf(key.getKey().replaceAll("\\.", "_").toUpperCase(Locale.ROOT)); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_13_R2.java b/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_13_R2.java deleted file mode 100644 index 7ccb5642d..000000000 --- a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_13_R2.java +++ /dev/null @@ -1,596 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_13_R2.*; -import org.bukkit.World; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_13_R2.CraftLootTable; -import org.bukkit.craftbukkit.v1_13_R2.CraftParticle; -import org.bukkit.craftbukkit.v1_13_R2.CraftServer; -import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_13_R2.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_13_R2.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_13_R2 implements CommandCompatibility { - - public static final MinecraftServer SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - EntityPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.a(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentRegistry.a(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandListenerWrapper) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.a(); - } - - @Override - public ArgumentType angle() { - throw new IllegalStateException("Unavailable in 1.13"); - } - - @Override - public ArgumentType axis() { - return ArgumentRotationAxis.a(); - } - - @Override - public ArgumentType blockPredicate() { - return ArgumentBlockPredicate.a(); - } - - @Override - public ArgumentType blockState() { - return ArgumentTile.a(); - } - - @Override - public ArgumentType chat() { - return ArgumentChat.a(); - } - - @Override - public ArgumentType chatComponent() { - return ArgumentChatComponent.a(); - } - - @Override - public ArgumentType chatFormat() { - return ArgumentChatFormat.a(); - } - - @Override - public ArgumentType dimension() { - return ArgumentDimension.a(); - } - - @Override - public ArgumentType enchantment() { - return ArgumentEnchantment.a(); - } - - @Override - public ArgumentType entity() { - return ArgumentEntity.a(); - } - - @Override - public ArgumentType entities() { - return ArgumentEntity.b(); - } - - @Override - public ArgumentType player() { - return ArgumentEntity.c(); - } - - @Override - public ArgumentType players() { - return ArgumentEntity.d(); - } - - @Override - public ArgumentType entitySummon() { - return ArgumentEntitySummon.a(); - } - - @Override - public ArgumentType itemPredicate() { - return ArgumentItemPredicate.a(); - } - - @Override - public ArgumentType itemStack() { - return ArgumentItemStack.a(); - } - - @Override - public ArgumentType mathOperation() { - return ArgumentMathOperation.a(); - } - - @Override - public ArgumentType mobEffect() { - return ArgumentMobEffect.a(); - } - - @Override - public ArgumentType nbtCompound() { - return ArgumentNBTTag.a(); - } - - @Override - public ArgumentType particle() { - return ArgumentParticle.a(); - } - - @Override - public ArgumentType profile() { - return ArgumentProfile.a(); - } - - @Override - public ArgumentType rotation() { - return ArgumentRotation.a(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ArgumentScoreboardCriteria.a(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ArgumentScoreboardObjective.a(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ArgumentScoreboardSlot.a(); - } - - @Override - public ArgumentType scoreboardTeam() { - return ArgumentScoreboardTeam.a(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ArgumentScoreholder.a() : ArgumentScoreholder.b(); - } - - @Override - public ArgumentType tag() { - return ArgumentTag.a(); - } - - @Override - public ArgumentType time() { - return IntegerArgumentType.integer(); - } - - @Override - public ArgumentType uuid() { - throw new IllegalStateException("Unavailable in 1.13"); - } - - @Override - public ArgumentType location() { - return ArgumentVec3.a(); - } - - @Override - public ArgumentType location2() { - return ArgumentVec2.a(); - } - - @Override - public ArgumentType block() { - return ArgumentPosition.a(); - } - - @Override - public ArgumentType block2() { - return ArgumentVec2I.a(); - } - - @Override - public ArgumentType biome() { - return key(); // this is actually only changed 1.18R2 and up - } - - @Override - public ArgumentType key() { - return ArgumentMinecraftKeyRegistered.a(); - } - - @Override - public SuggestionProvider biomeKey() { - throw new IllegalStateException("Unavailable in 1.13"); - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) CompletionProviders.b; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) CompletionProviders.c; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) CompletionProviders.d; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> ICompletionProvider.a(SERVER.getAdvancementData().b().stream().map(net.minecraft.server.v1_13_R2.Advancement::getName), builder); - } - - @Override - public SuggestionProvider lootKey() { - throw new IllegalStateException("Unavailable in 1.13"); - // return (context, builder) -> ICompletionProvider.a(SERVER.getLootTableRegistry().a(), builder); - } - - private static NamespacedKey fromResourceLocation(MinecraftKey key) { - return new NamespacedKey(key.b(), key.getKey()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentMinecraftKeyRegistered.a(cast(context), key).bukkit; - } - - @Override - public float getAngle(CommandContext context, String key) { - throw new IllegalStateException("Unavailable in 1.13"); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = ArgumentRotationAxis.a(cast(context), key); - - for (EnumDirection.EnumAxis axis : nmsAxis) { - switch (axis) { - case X -> bukkitAxis.add(Axis.X); - case Y -> bukkitAxis.add(Axis.Y); - case Z -> bukkitAxis.add(Axis.Z); - } - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - MinecraftKey location = cast(context).getArgument(key, MinecraftKey.class); - NamespacedKey namespaced = new NamespacedKey(location.b(), location.getKey()); - Biome biome = EnumUtil.getIfPresent(Biome.class, namespaced.getKey()).orElseThrow(); - return new BiomeHolder(biome, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ArgumentBlockPredicate.a(cast(context), key); - return (Block block) -> { - return predicate.test(new ShapeDetectorBlock(cast(context).getSource().getWorld(), - new BlockPosition(block.getX(), block.getY(), block.getZ()), true)); - }; - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(ArgumentTile.a(cast(context), key).a()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - throw new IllegalStateException("Unavailable in 1.13"); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) { - return new CraftEnchantment(ArgumentEnchantment.a(cast(context), key)); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.a(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.b(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.c(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.d(source).stream() - .map(EntityPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - return EntityType.fromName(EntityTypes.getName(IRegistry.ENTITY_TYPE.get(ArgumentEntitySummon.a(cast(context), key))).getKey()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - CriterionConditionValue.FloatRange range = cast(context).getArgument(key, CriterionConditionValue.FloatRange.class); - double min = range.a() == null ? Double.MIN_VALUE : range.a(); - double max = range.b() == null ? Double.MAX_VALUE : range.b(); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - CriterionConditionValue.IntegerRange range = cast(context).getArgument(key, CriterionConditionValue.IntegerRange.class); - int min = range.a() == null ? Integer.MIN_VALUE : range.a(); - int max = range.b() == null ? Integer.MAX_VALUE : range.b(); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ArgumentItemStack.a(cast(context), key).a(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ArgumentItemPredicate.a(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentMinecraftKeyRegistered.a(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - ArgumentVec2I.a column = ArgumentVec2I.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Column(world, column.a, column.b); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2F vector = ArgumentVec2.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Location2d(world, vector.i, vector.j); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPosition block = ArgumentPosition.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3D vector = ArgumentVec3.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - MinecraftKey minecraft = ArgumentMinecraftKeyRegistered.c(cast(context), key); - return new CraftLootTable(fromResourceLocation(minecraft), SERVER.getLootTableRegistry().getLootTable(minecraft)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ArgumentScoreboardObjective.a(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ArgumentScoreboardCriteria.a(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleParam particle = ArgumentParticle.a(cast(context), key); - return new ParticleHolder(CraftParticle.toBukkit(particle), particle, particle.a()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(ArgumentProfile.a(cast(context), key).iterator().next().getId()); - if (target == null) - throw ArgumentProfile.a.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(ArgumentProfile.a(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(ArgumentMobEffect.a(cast(context), key)); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - IRecipe recipe = ArgumentMinecraftKeyRegistered.b(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2F rotation = ArgumentRotation.a(cast(context), key).b(cast(context).getSource()); - return new Rotation(rotation.i, rotation.j); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - MinecraftKey mc = ArgumentMinecraftKeyRegistered.c(cast(context), key); - String name = mc.getKey().replaceAll("\\.", "_").toUpperCase(Locale.ROOT); - return new SoundHolder(EnumUtil.getIfPresent(Sound.class, name).orElse(null), new NamespacedKey(mc.b(), mc.getKey())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentScoreboardTeam.a(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - throw new IllegalStateException("Unavailable in 1.13"); - } - - @Override - public Map getCompound(CommandContext context, String key) { - NBTTagCompound nbt = ArgumentNBTTag.a(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(NBTBase tag) { - return switch (tag.getTypeId()) { - case 1, 2, 3, 4 -> ((NBTNumber) tag).asInt(); - case 5, 6 -> ((NBTNumber) tag).asDouble(); - case 8 -> ((NBTTagString) tag).asString(); - case 7, 11, 12, 9 -> convertList((NBTList) tag); - case 10 -> convertMap((NBTTagCompound) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(NBTTagCompound nbt) { - Map temp = new HashMap<>(); - - for (String key : nbt.getKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(NBTList values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_13_R2.java b/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_13_R2.java deleted file mode 100644 index 3f369846a..000000000 --- a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_13_R2.java +++ /dev/null @@ -1,131 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import me.deecaad.core.compatibility.equipevent.NonNullList_1_13_R2; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_13_R2.DataWatcher; -import net.minecraft.server.v1_13_R2.EnumItemSlot; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.List; - -public class Entity_1_13_R2 implements EntityCompatibility { - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.server.v1_13_R2.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.lastX, nms.lastY, nms.lastZ); - } - - @Override - public double getAbsorption(@NotNull LivingEntity entity) { - return ((CraftLivingEntity) entity).getHandle().getAbsorptionHearts(); - } - - @Override - public void setAbsorption(@NotNull LivingEntity entity, double absorption) { - ((CraftLivingEntity) entity).getHandle().setAbsorptionHearts((float) absorption); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_13_R2(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_13_R2(location, type, data); - } - - private static final Field ID = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, int.class); - private static final Field DATA = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, List.class); - - @Override - public int getId(Object obj) { - return (int) ReflectionUtil.invokeField(ID, obj); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - EntityEquipment equipment = bukkit.getEquipment(); - - int id = bukkit.getEntityId(); - EnumItemSlot nmsSlot; - switch (slot) { - case HEAD -> { - nmsSlot = EnumItemSlot.HEAD; - item = item == null ? equipment.getHelmet() : item; - } - case CHEST -> { - nmsSlot = EnumItemSlot.CHEST; - item = item == null ? equipment.getChestplate() : item; - } - case LEGS -> { - nmsSlot = EnumItemSlot.LEGS; - item = item == null ? equipment.getLeggings() : item; - } - case FEET -> { - nmsSlot = EnumItemSlot.FEET; - item = item == null ? equipment.getBoots() : item; - } - case HAND -> { - nmsSlot = EnumItemSlot.MAINHAND; - item = item == null ? equipment.getItemInMainHand() : item; - } - case OFF_HAND -> { - nmsSlot = EnumItemSlot.OFFHAND; - item = item == null ? equipment.getItemInOffHand() : item; - } - default -> throw new RuntimeException("unreachable"); - } - - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(id, nmsSlot, CraftItemStack.asNMSCopy(item)); - ((CraftPlayer) bukkit).getHandle().playerConnection.sendPacket(packet); - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.server.v1_13_R2.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - PacketPlayOutEntityMetadata packet = (PacketPlayOutEntityMetadata) obj; - List> list = (List>) ReflectionUtil.invokeField(DATA, packet); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).b().getClass() != Byte.class) - return; - - // noinspection unchecked - DataWatcher.Item item = (DataWatcher.Item) list.get(0); - byte data = item.b(); - data = meta.set(data, enabled); - item.a(data); - } -} diff --git a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_13_R2.java b/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_13_R2.java deleted file mode 100644 index 0b1fc91a0..000000000 --- a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_13_R2.java +++ /dev/null @@ -1,341 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.server.v1_13_R2.Block; -import net.minecraft.server.v1_13_R2.Entity; -import net.minecraft.server.v1_13_R2.EntityArmorStand; -import net.minecraft.server.v1_13_R2.EntityFallingBlock; -import net.minecraft.server.v1_13_R2.EntityFireworks; -import net.minecraft.server.v1_13_R2.EntityItem; -import net.minecraft.server.v1_13_R2.EntityLiving; -import net.minecraft.server.v1_13_R2.EnumItemSlot; -import net.minecraft.server.v1_13_R2.IBlockData; -import net.minecraft.server.v1_13_R2.ItemStack; -import net.minecraft.server.v1_13_R2.Packet; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityHeadRotation; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityStatus; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityVelocity; -import net.minecraft.server.v1_13_R2.PacketPlayOutSpawnEntity; -import net.minecraft.server.v1_13_R2.PacketPlayOutSpawnEntityLiving; -import net.minecraft.server.v1_13_R2.PlayerConnection; -import net.minecraft.server.v1_13_R2.Vector3f; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_13_R2.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static net.minecraft.server.v1_13_R2.PacketPlayOutEntity.PacketPlayOutEntityLook; -import static net.minecraft.server.v1_13_R2.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook; - -public class FakeEntity_1_13_R2 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EnumItemSlot[] SLOTS = EnumItemSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private IBlockData block; - private ItemStack item; - - public FakeEntity_1_13_R2(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new EntityItem(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> new EntityFallingBlock(world.getHandle(), x, y, z, block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle())); - case FIREWORK -> new EntityFireworks(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - EntityArmorStand armorStand = (EntityArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> CraftItemStack.asBukkitCopy(item); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((EntityItem) entity).setItemStack(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosition(x, y, z); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - } - - @Override - public void setMotion(double dx, double dy, double dz) { - PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(cache, dx, dy, dz); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - - byte byteYaw = convertYaw(yaw); - PacketPlayOutEntityLook packet = new PacketPlayOutEntityLook(cache, byteYaw, convertPitch(pitch), false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(entity); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(cache, dx, dy, dz, yaw, pitch, false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - public void show() { - - // Construct the packets out of the loop to save resources, they will - // be the same for each Player. - Packet spawn = type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, getSpawnId(), type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0); - PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())); - PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, motion.getX(), motion.getY(), motion.getZ()); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection; - if (connections.contains(connection)) { - continue; - } - - connection.sendPacket(spawn); - connection.sendPacket(meta); - connection.sendPacket(head); - connection.sendPacket(velocity); - connection.sendPacket(look); - PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket(); - if (equipment != null) { - for (PacketPlayOutEntityEquipment packet : equipment) { - connection.sendPacket(packet); - } - } - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - if (connections.contains(connection)) - throw new IllegalArgumentException(); - - connection.sendPacket(type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, getSpawnId(), type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0)); - connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true)); - connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.sendPacket(new PacketPlayOutEntityVelocity(cache, motion.getX(), motion.getY(), motion.getZ())); - connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()))); - PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket(); - if (equipment != null) { - for (PacketPlayOutEntityEquipment packet : equipment) { - connection.sendPacket(packet); - } - } - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((EntityArmorStand) entity).setHeadPose(new Vector3f(getPitch(), 0, 0)); - - sendPackets(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), false)); - } - - @Override - public void remove() { - sendPackets(new PacketPlayOutEntityDestroy(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(new PacketPlayOutEntityDestroy(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new PacketPlayOutEntityStatus(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EnumItemSlot slot = switch (equipmentSlot) { - case HAND -> EnumItemSlot.MAINHAND; - case OFF_HAND -> EnumItemSlot.OFFHAND; - case FEET -> EnumItemSlot.FEET; - case CHEST -> EnumItemSlot.CHEST; - case LEGS -> EnumItemSlot.LEGS; - case HEAD -> EnumItemSlot.HEAD; - }; - - EntityLiving livingEntity = (EntityLiving) entity; - livingEntity.setSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - PacketPlayOutEntityEquipment[] packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private PacketPlayOutEntityEquipment[] getEquipmentPacket() { - if (!type.isAlive()) - return null; - EntityLiving livingEntity = (EntityLiving) entity; - - List temp = new ArrayList<>(SLOTS.length); - for (EnumItemSlot slot : SLOTS) { - ItemStack item = livingEntity.getEquipment(slot); - - if (item != null && !item.isEmpty()) { - temp.add(new PacketPlayOutEntityEquipment(cache, slot, item)); - } - } - - return temp.isEmpty() ? null : temp.toArray(new PacketPlayOutEntityEquipment[0]); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - PlayerConnection connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.sendPacket(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_13_R2.java b/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_13_R2.java deleted file mode 100644 index 1af042e4a..000000000 --- a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_13_R2.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_13_R2.Item; -import net.minecraft.server.v1_13_R2.ItemStack; -import net.minecraft.server.v1_13_R2.NonNullList; -import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -public class NonNullList_1_13_R2 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_13_R2(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.a); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.a); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_13_R2.java b/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_13_R2.java deleted file mode 100644 index 7eb738997..000000000 --- a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_13_R2.java +++ /dev/null @@ -1,214 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import me.deecaad.core.utils.StringUtil; -import net.minecraft.server.v1_13_R2.NBTBase; -import net.minecraft.server.v1_13_R2.NBTTagCompound; -import org.bukkit.NamespacedKey; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.tags.CustomItemTagContainer; -import org.bukkit.inventory.meta.tags.ItemTagType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -public class NBT_1_13_R2 implements NBTCompatibility { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.server.v1_13_R2.ItemStack nms = getNMSStack(toItem); - NBTTagCompound from = getNMSStack(fromItem).getTag(); - NBTTagCompound to = nms.getTag(); - - if (path == null) { - nms.setTag(from.clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - return; - } - - to.set(path, from.getCompound(path).clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - } - - @Override - public boolean hasString(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - return getBukkitCompound(bukkitItem.getItemMeta()).hasCustomTag(getKey(plugin, key), ItemTagType.STRING); - } - - @Override - public String getString(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String def) { - CustomItemTagContainer nbt = getBukkitCompound(bukkitItem.getItemMeta()); - NamespacedKey tag = getKey(plugin, key); - - return nbt.hasCustomTag(tag, ItemTagType.STRING) ? nbt.getCustomTag(tag, ItemTagType.STRING) : def; - } - - @Override - public void setString(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String value) { - ItemMeta meta = bukkitItem.getItemMeta(); - CustomItemTagContainer nbt = getBukkitCompound(meta); - - nbt.setCustomTag(getKey(plugin, key), ItemTagType.STRING, value); - bukkitItem.setItemMeta(meta); - } - - @Override - public boolean hasInt(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - return getBukkitCompound(bukkitItem.getItemMeta()).hasCustomTag(getKey(plugin, key), ItemTagType.INTEGER); - } - - @Override - public int getInt(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int def) { - CustomItemTagContainer nbt = getBukkitCompound(bukkitItem.getItemMeta()); - NamespacedKey tag = getKey(plugin, key); - - return nbt.hasCustomTag(tag, ItemTagType.INTEGER) ? nbt.getCustomTag(tag, ItemTagType.INTEGER) : def; - } - - @Override - public void setInt(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int value) { - ItemMeta meta = bukkitItem.getItemMeta(); - CustomItemTagContainer nbt = getBukkitCompound(meta); - - nbt.setCustomTag(getKey(plugin, key), ItemTagType.INTEGER, value); - bukkitItem.setItemMeta(meta); - } - - @Override - public boolean hasDouble(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - return getBukkitCompound(bukkitItem.getItemMeta()).hasCustomTag(getKey(plugin, key), ItemTagType.DOUBLE); - } - - @Override - public double getDouble(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, double def) { - CustomItemTagContainer nbt = getBukkitCompound(bukkitItem.getItemMeta()); - NamespacedKey tag = getKey(plugin, key); - - return nbt.hasCustomTag(tag, ItemTagType.DOUBLE) ? nbt.getCustomTag(tag, ItemTagType.DOUBLE) : def; - } - - @Override - public void setDouble(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, double value) { - ItemMeta meta = bukkitItem.getItemMeta(); - CustomItemTagContainer nbt = getBukkitCompound(meta); - - nbt.setCustomTag(getKey(plugin, key), ItemTagType.DOUBLE, value); - bukkitItem.setItemMeta(meta); - } - - @Override - public boolean hasArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - return getBukkitCompound(bukkitItem.getItemMeta()).hasCustomTag(getKey(plugin, key), ItemTagType.INTEGER_ARRAY); - } - - @Override - public int[] getArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int[] def) { - CustomItemTagContainer nbt = getBukkitCompound(bukkitItem.getItemMeta()); - NamespacedKey tag = getKey(plugin, key); - - return nbt.hasCustomTag(tag, ItemTagType.INTEGER_ARRAY) ? nbt.getCustomTag(tag, ItemTagType.INTEGER_ARRAY) : def; - } - - @Override - public void setArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int[] value) { - ItemMeta meta = bukkitItem.getItemMeta(); - CustomItemTagContainer nbt = getBukkitCompound(meta); - - nbt.setCustomTag(getKey(plugin, key), ItemTagType.INTEGER_ARRAY, value); - bukkitItem.setItemMeta(meta); - } - - @Override - public boolean hasStringArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - return getBukkitCompound(bukkitItem.getItemMeta()).hasCustomTag(getKey(plugin, key), StringTagType.INSTANCE); - } - - @Override - public String[] getStringArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String[] def) { - CustomItemTagContainer nbt = getBukkitCompound(bukkitItem.getItemMeta()); - NamespacedKey tag = getKey(plugin, key); - - return nbt.hasCustomTag(tag, StringTagType.INSTANCE) ? nbt.getCustomTag(tag, StringTagType.INSTANCE) : def; - } - - @Override - public void setStringArray(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String[] value) { - ItemMeta meta = bukkitItem.getItemMeta(); - CustomItemTagContainer nbt = getBukkitCompound(meta); - - nbt.setCustomTag(getKey(plugin, key), StringTagType.INSTANCE, value); - bukkitItem.setItemMeta(meta); - } - - @Override - public void remove(@NotNull ItemStack bukkitItem, @NotNull String plugin, @NotNull String key) { - ItemMeta meta = bukkitItem.getItemMeta(); - CustomItemTagContainer nbt = getBukkitCompound(meta); - - nbt.removeCustomTag(getKey(plugin, key)); - } - - @NotNull @Override - public net.minecraft.server.v1_13_R2.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_13_R2.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - NBTTagCompound nbt = getNMSStack(bukkitStack).getTag(); - if (nbt == null) - return "null"; - - return visit(nbt, 0, 0).toString(); - } - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - - private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - StringBuilder builder = new StringBuilder(braceColor).append('{'); - - List keys = new ArrayList<>(nbt.getKeys()); - Collections.sort(keys); - - for (int i = 0; i < keys.size(); i++) { - String key = keys.get(i); - NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible"); - - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - builder.append(color).append(key).append("&f&l: ").append(color); - - if (value instanceof NBTTagCompound) - builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i)); - else - builder.append(value); - } - - return builder.append(braceColor).append("}\n"); - } - - private CustomItemTagContainer getBukkitCompound(ItemMeta meta) { - return meta.getCustomTagContainer(); - } - - @Override - public @NotNull ItemStack getPlacementItem(@NotNull Block block) { - return new ItemStack(block.getBlockData().getMaterial()); - } -} diff --git a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/v1_13_R2.java b/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/v1_13_R2.java deleted file mode 100644 index 8c8d20b5c..000000000 --- a/CoreCompatibility/Core_1_13_R2/src/main/java/me/deecaad/core/compatibility/v1_13_R2.java +++ /dev/null @@ -1,83 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_13_R2; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_13_R2; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_13_R2; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_13_R2; -import net.minecraft.server.v1_13_R2.EntityPlayer; -import net.minecraft.server.v1_13_R2.Packet; -import net.minecraft.server.v1_13_R2.PlayerConnection; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_13_R2 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_13_R2() { - entityCompatibility = new Entity_1_13_R2(); - blockCompatibility = new Block_1_13_R2(); - nbtCompatibility = new NBT_1_13_R2(); - commandCompatibility = new Command_1_13_R2(); - } - - @Override - public int getPing(@NotNull Player player) { - return getEntityPlayer(player).ping; - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.server.v1_13_R2.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).playerConnection.sendPacket((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - PlayerConnection playerConnection = getEntityPlayer(player).playerConnection; - for (Object packet : packets) { - playerConnection.sendPacket((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_14_R1/build.gradle.kts b/CoreCompatibility/Core_1_14_R1/build.gradle.kts deleted file mode 100644 index c45d5b6f5..000000000 --- a/CoreCompatibility/Core_1_14_R1/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - compileOnly(files(file("../../lib/nms/spigot-1.14.4.jar"))) - adventureChatAPI() -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_14_R1.java b/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_14_R1.java deleted file mode 100644 index c0ee0f7c3..000000000 --- a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_14_R1.java +++ /dev/null @@ -1,118 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import me.deecaad.core.compatibility.HitBox; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_14_R1.AxisAlignedBB; -import net.minecraft.server.v1_14_R1.BlockPosition; -import net.minecraft.server.v1_14_R1.IRegistry; -import net.minecraft.server.v1_14_R1.MinecraftKey; -import net.minecraft.server.v1_14_R1.PacketPlayOutBlockBreakAnimation; -import net.minecraft.server.v1_14_R1.SoundEffect; -import net.minecraft.server.v1_14_R1.SoundEffectType; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock; -import org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData; -import org.bukkit.util.BoundingBox; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.List; -import java.util.Locale; - -public class Block_1_14_R1 implements BlockCompatibility { - - private static final Field[] soundFields; - - static { - soundFields = new Field[SoundType.values().length]; // 5 - for (int i = 0; i < soundFields.length; i++) { - soundFields[i] = ReflectionUtil.getField(SoundEffectType.class, SoundEffect.class, i); - } - } - - @Override - public HitBox getHitBox(@NotNull Block block, boolean allowLiquid) { - if (!block.getChunk().isLoaded()) - return null; - if (block.isEmpty()) - return null; - - boolean isLiquid = block.isLiquid(); - if (!allowLiquid) { - if (block.isPassable() || block.isLiquid()) - return null; - } else if (!isLiquid && block.isPassable()) { - // Check like this because liquid is also passable... - return null; - } - - HitBox hitBox; - if (isLiquid) { - hitBox = new HitBox(block.getX(), block.getY(), block.getZ(), block.getX() + 1, block.getY() + 1, block.getZ() + 1); - } else { - BoundingBox boundingBox = block.getBoundingBox(); - hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ()); - } - hitBox.setBlockHitBox(block); - - CraftBlock craftBlock = (CraftBlock) block; - List voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d(); - if (voxelShape.size() > 1) { - int x = block.getX(); - int y = block.getY(); - int z = block.getZ(); - for (AxisAlignedBB boxPart : voxelShape) { - hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, - x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ)); - } - } - - return hitBox; - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ()); - return new PacketPlayOutBlockBreakAnimation(id, pos, crack); - } - - @Override - public SoundData getBlockSound(Object blockData, SoundType type) { - CraftBlockData block = (CraftBlockData) blockData; - SoundEffectType sounds = block.getState().r(); - - SoundData soundData = new SoundData(); - soundData.type = type; - soundData.pitch = sounds.x; - soundData.volume = sounds.w; - - switch (type) { - case BREAK -> soundData.sound = bukkit(sounds, 0); - case STEP -> soundData.sound = bukkit(sounds, 1); - case PLACE -> soundData.sound = bukkit(sounds, 2); - case HIT -> soundData.sound = bukkit(sounds, 3); - case FALL -> soundData.sound = bukkit(sounds, 4); - default -> throw new InternalError("unreachable code"); - } - - return soundData; - } - - private Sound bukkit(SoundEffectType sounds, int index) { - SoundEffect sound = (SoundEffect) ReflectionUtil.invokeField(soundFields[index], sounds); - MinecraftKey key = IRegistry.SOUND_EVENT.getKey(sound); - return Sound.valueOf(key.getKey().replaceAll("\\.", "_").toUpperCase(Locale.ROOT)); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_14_R1.java b/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_14_R1.java deleted file mode 100644 index 8a347d8f9..000000000 --- a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_14_R1.java +++ /dev/null @@ -1,594 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_14_R1.*; -import org.bukkit.World; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_14_R1.CraftLootTable; -import org.bukkit.craftbukkit.v1_14_R1.CraftParticle; -import org.bukkit.craftbukkit.v1_14_R1.CraftServer; -import org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_14_R1.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_14_R1.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_14_R1 implements CommandCompatibility { - - public static final MinecraftServer SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - EntityPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.a(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentRegistry.a(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandListenerWrapper) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.a(); - } - - @Override - public ArgumentType angle() { - throw new IllegalStateException("Unavailable in 1.14"); - } - - @Override - public ArgumentType axis() { - return ArgumentRotationAxis.a(); - } - - @Override - public ArgumentType blockPredicate() { - return ArgumentBlockPredicate.a(); - } - - @Override - public ArgumentType blockState() { - return ArgumentTile.a(); - } - - @Override - public ArgumentType chat() { - return ArgumentChat.a(); - } - - @Override - public ArgumentType chatComponent() { - return ArgumentChatComponent.a(); - } - - @Override - public ArgumentType chatFormat() { - return ArgumentChatFormat.a(); - } - - @Override - public ArgumentType dimension() { - return ArgumentDimension.a(); - } - - @Override - public ArgumentType enchantment() { - return ArgumentEnchantment.a(); - } - - @Override - public ArgumentType entity() { - return ArgumentEntity.a(); - } - - @Override - public ArgumentType entities() { - return ArgumentEntity.multipleEntities(); - } - - @Override - public ArgumentType player() { - return ArgumentEntity.c(); - } - - @Override - public ArgumentType players() { - return ArgumentEntity.d(); - } - - @Override - public ArgumentType entitySummon() { - return ArgumentEntitySummon.a(); - } - - @Override - public ArgumentType itemPredicate() { - return ArgumentItemPredicate.a(); - } - - @Override - public ArgumentType itemStack() { - return ArgumentItemStack.a(); - } - - @Override - public ArgumentType mathOperation() { - return ArgumentMathOperation.a(); - } - - @Override - public ArgumentType mobEffect() { - return ArgumentMobEffect.a(); - } - - @Override - public ArgumentType nbtCompound() { - return ArgumentNBTTag.a(); - } - - @Override - public ArgumentType particle() { - return ArgumentParticle.a(); - } - - @Override - public ArgumentType profile() { - return ArgumentProfile.a(); - } - - @Override - public ArgumentType rotation() { - return ArgumentRotation.a(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ArgumentScoreboardCriteria.a(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ArgumentScoreboardObjective.a(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ArgumentScoreboardSlot.a(); - } - - @Override - public ArgumentType scoreboardTeam() { - return ArgumentScoreboardTeam.a(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ArgumentScoreholder.a() : ArgumentScoreholder.b(); - } - - @Override - public ArgumentType tag() { - return ArgumentTag.a(); - } - - @Override - public ArgumentType time() { - return ArgumentTime.a(); - } - - @Override - public ArgumentType uuid() { - throw new IllegalStateException("Unavailable in 1.14"); - } - - @Override - public ArgumentType location() { - return ArgumentVec3.a(); - } - - @Override - public ArgumentType location2() { - return ArgumentVec2.a(); - } - - @Override - public ArgumentType block() { - return ArgumentPosition.a(); - } - - @Override - public ArgumentType block2() { - return ArgumentVec2I.a(); - } - - @Override - public ArgumentType biome() { - return key(); // this is actually only changed 1.18R2 and up - } - - @Override - public ArgumentType key() { - return ArgumentMinecraftKeyRegistered.a(); - } - - @Override - public SuggestionProvider biomeKey() { - throw new IllegalStateException("Unavailable in 1.14"); - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) CompletionProviders.b; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) CompletionProviders.c; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) CompletionProviders.d; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> ICompletionProvider.a(SERVER.getAdvancementData().a().stream().map(net.minecraft.server.v1_14_R1.Advancement::getName), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> ICompletionProvider.a(SERVER.getLootTableRegistry().a(), builder); - } - - private static NamespacedKey fromResourceLocation(MinecraftKey key) { - return new NamespacedKey(key.getNamespace(), key.getKey()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentMinecraftKeyRegistered.a(cast(context), key).bukkit; - } - - @Override - public float getAngle(CommandContext context, String key) { - throw new IllegalStateException("Unavailable in 1.14"); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = ArgumentRotationAxis.a(cast(context), key); - - for (EnumDirection.EnumAxis axis : nmsAxis) { - switch (axis) { - case X -> bukkitAxis.add(Axis.X); - case Y -> bukkitAxis.add(Axis.Y); - case Z -> bukkitAxis.add(Axis.Z); - } - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - MinecraftKey location = cast(context).getArgument(key, MinecraftKey.class); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getKey()); - Biome biome = EnumUtil.getIfPresent(Biome.class, namespaced.getKey()).orElseThrow(); - return new BiomeHolder(biome, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ArgumentBlockPredicate.a(cast(context), key); - return (Block block) -> { - return predicate.test(new ShapeDetectorBlock(cast(context).getSource().getWorld(), - new BlockPosition(block.getX(), block.getY(), block.getZ()), true)); - }; - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(ArgumentTile.a(cast(context), key).a()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - throw new IllegalStateException("Unavailable in 1.14"); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) { - return new CraftEnchantment(ArgumentEnchantment.a(cast(context), key)); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.a(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.getEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.c(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.d(source).stream() - .map(EntityPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - return EntityType.fromName(EntityTypes.getName(IRegistry.ENTITY_TYPE.get(ArgumentEntitySummon.a(cast(context), key))).getKey()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - CriterionConditionValue.FloatRange range = cast(context).getArgument(key, CriterionConditionValue.FloatRange.class); - double min = range.a() == null ? Double.MIN_VALUE : range.a(); - double max = range.b() == null ? Double.MAX_VALUE : range.b(); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - CriterionConditionValue.IntegerRange range = cast(context).getArgument(key, CriterionConditionValue.IntegerRange.class); - int min = range.a() == null ? Integer.MIN_VALUE : range.a(); - int max = range.b() == null ? Integer.MAX_VALUE : range.b(); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ArgumentItemStack.a(cast(context), key).a(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ArgumentItemPredicate.a(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentMinecraftKeyRegistered.a(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPosition2D column = ArgumentVec2I.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Column(world, column.a, column.b); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2F vector = ArgumentVec2.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Location2d(world, vector.i, vector.j); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPosition block = ArgumentPosition.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3D vector = ArgumentVec3.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - MinecraftKey minecraft = ArgumentMinecraftKeyRegistered.c(cast(context), key); - return new CraftLootTable(fromResourceLocation(minecraft), SERVER.getLootTableRegistry().getLootTable(minecraft)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ArgumentScoreboardObjective.a(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ArgumentScoreboardCriteria.a(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleParam particle = ArgumentParticle.a(cast(context), key); - return new ParticleHolder(CraftParticle.toBukkit(particle), particle, particle.a()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(ArgumentProfile.a(cast(context), key).iterator().next().getId()); - if (target == null) - throw ArgumentProfile.a.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(ArgumentProfile.a(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(ArgumentMobEffect.a(cast(context), key)); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - IRecipe recipe = ArgumentMinecraftKeyRegistered.b(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2F rotation = ArgumentRotation.a(cast(context), key).b(cast(context).getSource()); - return new Rotation(rotation.i, rotation.j); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - MinecraftKey mc = ArgumentMinecraftKeyRegistered.c(cast(context), key); - String name = mc.getKey().replaceAll("\\.", "_").toUpperCase(Locale.ROOT); - return new SoundHolder(EnumUtil.getIfPresent(Sound.class, name).orElse(null), new NamespacedKey(mc.getNamespace(), mc.getKey())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentScoreboardTeam.a(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - throw new IllegalStateException("Unavailable in 1.14"); - } - - @Override - public Map getCompound(CommandContext context, String key) { - NBTTagCompound nbt = ArgumentNBTTag.a(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(NBTBase tag) { - return switch (tag.getTypeId()) { - case 1, 2, 3, 4 -> ((NBTNumber) tag).asInt(); - case 5, 6 -> ((NBTNumber) tag).asDouble(); - case 8 -> ((NBTTagString) tag).asString(); - case 7, 11, 12, 9 -> convertList((NBTList) tag); - case 10 -> convertMap((NBTTagCompound) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(NBTTagCompound nbt) { - Map temp = new HashMap<>(); - - for (String key : nbt.getKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(NBTList values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_14_R1.java b/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_14_R1.java deleted file mode 100644 index 74e343ace..000000000 --- a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_14_R1.java +++ /dev/null @@ -1,118 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import me.deecaad.core.compatibility.equipevent.NonNullList_1_14_R1; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_14_R1.DataWatcher; -import net.minecraft.server.v1_14_R1.EnumItemSlot; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.List; - -public class Entity_1_14_R1 implements EntityCompatibility { - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.server.v1_14_R1.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.lastX, nms.lastY, nms.lastZ); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_14_R1(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_14_R1(location, type, data); - } - - private static final Field ID = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, int.class); - private static final Field DATA = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, List.class); - - @Override - public int getId(Object obj) { - return (int) ReflectionUtil.invokeField(ID, obj); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - EntityEquipment equipment = bukkit.getEquipment(); - - int id = bukkit.getEntityId(); - EnumItemSlot nmsSlot; - switch (slot) { - case HEAD -> { - nmsSlot = EnumItemSlot.HEAD; - item = item == null ? equipment.getHelmet() : item; - } - case CHEST -> { - nmsSlot = EnumItemSlot.CHEST; - item = item == null ? equipment.getChestplate() : item; - } - case LEGS -> { - nmsSlot = EnumItemSlot.LEGS; - item = item == null ? equipment.getLeggings() : item; - } - case FEET -> { - nmsSlot = EnumItemSlot.FEET; - item = item == null ? equipment.getBoots() : item; - } - case HAND -> { - nmsSlot = EnumItemSlot.MAINHAND; - item = item == null ? equipment.getItemInMainHand() : item; - } - case OFF_HAND -> { - nmsSlot = EnumItemSlot.OFFHAND; - item = item == null ? equipment.getItemInOffHand() : item; - } - default -> throw new RuntimeException("unreachable"); - } - - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(id, nmsSlot, CraftItemStack.asNMSCopy(item)); - ((CraftPlayer) bukkit).getHandle().playerConnection.sendPacket(packet); - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.server.v1_14_R1.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - PacketPlayOutEntityMetadata packet = (PacketPlayOutEntityMetadata) obj; - List> list = (List>) ReflectionUtil.invokeField(DATA, packet); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).b().getClass() != Byte.class) - return; - - // noinspection unchecked - DataWatcher.Item item = (DataWatcher.Item) list.get(0); - byte data = item.b(); - data = meta.set(data, enabled); - item.a(data); - } -} diff --git a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_14_R1.java b/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_14_R1.java deleted file mode 100644 index e6294077c..000000000 --- a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_14_R1.java +++ /dev/null @@ -1,342 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.server.v1_14_R1.Block; -import net.minecraft.server.v1_14_R1.Entity; -import net.minecraft.server.v1_14_R1.EntityArmorStand; -import net.minecraft.server.v1_14_R1.EntityFallingBlock; -import net.minecraft.server.v1_14_R1.EntityFireworks; -import net.minecraft.server.v1_14_R1.EntityItem; -import net.minecraft.server.v1_14_R1.EntityLiving; -import net.minecraft.server.v1_14_R1.EnumItemSlot; -import net.minecraft.server.v1_14_R1.IBlockData; -import net.minecraft.server.v1_14_R1.ItemStack; -import net.minecraft.server.v1_14_R1.Packet; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityHeadRotation; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityMetadata; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityStatus; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityVelocity; -import net.minecraft.server.v1_14_R1.PacketPlayOutSpawnEntity; -import net.minecraft.server.v1_14_R1.PacketPlayOutSpawnEntityLiving; -import net.minecraft.server.v1_14_R1.PlayerConnection; -import net.minecraft.server.v1_14_R1.Vec3D; -import net.minecraft.server.v1_14_R1.Vector3f; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static net.minecraft.server.v1_14_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; -import static net.minecraft.server.v1_14_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook; - -public class FakeEntity_1_14_R1 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EnumItemSlot[] SLOTS = EnumItemSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private IBlockData block; - private ItemStack item; - - public FakeEntity_1_14_R1(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new EntityItem(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> new EntityFallingBlock(world.getHandle(), x, y, z, block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle())); - case FIREWORK -> new EntityFireworks(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - EntityArmorStand armorStand = (EntityArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> CraftItemStack.asBukkitCopy(item); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((EntityItem) entity).setItemStack(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosition(x, y, z); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - } - - @Override - public void setMotion(double dx, double dy, double dz) { - PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(cache, new Vec3D(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - - byte byteYaw = convertYaw(yaw); - PacketPlayOutEntityLook packet = new PacketPlayOutEntityLook(cache, byteYaw, convertPitch(pitch), false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(entity); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(cache, dx, dy, dz, yaw, pitch, false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - public void show() { - - // Construct the packets out of the loop to save resources, they will - // be the same for each Player. - Packet spawn = type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0); - PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())); - PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ())); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection; - if (connections.contains(connection)) { - continue; - } - - connection.sendPacket(spawn); - connection.sendPacket(meta); - connection.sendPacket(head); - connection.sendPacket(velocity); - connection.sendPacket(look); - PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket(); - if (equipment != null) { - for (PacketPlayOutEntityEquipment packet : equipment) { - connection.sendPacket(packet); - } - } - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - if (connections.contains(connection)) - throw new IllegalArgumentException(); - - connection.sendPacket(type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0)); - connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true)); - connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.sendPacket(new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ()))); - connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()))); - PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket(); - if (equipment != null) { - for (PacketPlayOutEntityEquipment packet : equipment) { - connection.sendPacket(packet); - } - } - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((EntityArmorStand) entity).setHeadPose(new Vector3f(getPitch(), 0, 0)); - - sendPackets(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), false)); - } - - @Override - public void remove() { - sendPackets(new PacketPlayOutEntityDestroy(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(new PacketPlayOutEntityDestroy(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new PacketPlayOutEntityStatus(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EnumItemSlot slot = switch (equipmentSlot) { - case HAND -> EnumItemSlot.MAINHAND; - case OFF_HAND -> EnumItemSlot.OFFHAND; - case FEET -> EnumItemSlot.FEET; - case CHEST -> EnumItemSlot.CHEST; - case LEGS -> EnumItemSlot.LEGS; - case HEAD -> EnumItemSlot.HEAD; - }; - - EntityLiving livingEntity = (EntityLiving) entity; - livingEntity.setSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - PacketPlayOutEntityEquipment[] packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private PacketPlayOutEntityEquipment[] getEquipmentPacket() { - if (!type.isAlive()) - return null; - EntityLiving livingEntity = (EntityLiving) entity; - - List temp = new ArrayList<>(SLOTS.length); - for (EnumItemSlot slot : SLOTS) { - ItemStack item = livingEntity.getEquipment(slot); - - if (item != null && !item.isEmpty()) { - temp.add(new PacketPlayOutEntityEquipment(cache, slot, item)); - } - } - - return temp.isEmpty() ? null : temp.toArray(new PacketPlayOutEntityEquipment[0]); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - PlayerConnection connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.sendPacket(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_14_R1.java b/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_14_R1.java deleted file mode 100644 index 5289ef72a..000000000 --- a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_14_R1.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_14_R1.Item; -import net.minecraft.server.v1_14_R1.ItemStack; -import net.minecraft.server.v1_14_R1.NonNullList; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -public class NonNullList_1_14_R1 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_14_R1(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.a); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.a); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_14_R1.java b/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_14_R1.java deleted file mode 100644 index 547439acc..000000000 --- a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_14_R1.java +++ /dev/null @@ -1,88 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import me.deecaad.core.utils.StringUtil; -import net.minecraft.server.v1_14_R1.NBTBase; -import net.minecraft.server.v1_14_R1.NBTTagCompound; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -public class NBT_1_14_R1 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.server.v1_14_R1.ItemStack nms = getNMSStack(toItem); - NBTTagCompound from = getNMSStack(fromItem).getTag(); - NBTTagCompound to = nms.getTag(); - - if (path == null) { - nms.setTag(from.clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - return; - } - - to.set(path, from.getCompound(path).clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.server.v1_14_R1.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_14_R1.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - NBTTagCompound nbt = getNMSStack(bukkitStack).getTag(); - if (nbt == null) - return "null"; - - return visit(nbt, 0, 0).toString(); - } - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - - private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - StringBuilder builder = new StringBuilder(braceColor).append('{'); - - List keys = new ArrayList<>(nbt.getKeys()); - Collections.sort(keys); - - for (int i = 0; i < keys.size(); i++) { - String key = keys.get(i); - NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible"); - - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - builder.append(color).append(key).append("&f&l: ").append(color); - - if (value instanceof NBTTagCompound) - builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i)); - else - builder.append(value); - } - - return builder.append(braceColor).append("}\n"); - } - - @Override - public @NotNull ItemStack getPlacementItem(@NotNull Block block) { - return new ItemStack(block.getBlockData().getMaterial()); - } -} diff --git a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/v1_14_R1.java b/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/v1_14_R1.java deleted file mode 100644 index 09ed4be39..000000000 --- a/CoreCompatibility/Core_1_14_R1/src/main/java/me/deecaad/core/compatibility/v1_14_R1.java +++ /dev/null @@ -1,83 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_14_R1; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_14_R1; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_14_R1; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_14_R1; -import net.minecraft.server.v1_14_R1.EntityPlayer; -import net.minecraft.server.v1_14_R1.Packet; -import net.minecraft.server.v1_14_R1.PlayerConnection; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_14_R1 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_14_R1() { - entityCompatibility = new Entity_1_14_R1(); - blockCompatibility = new Block_1_14_R1(); - nbtCompatibility = new NBT_1_14_R1(); - commandCompatibility = new Command_1_14_R1(); - } - - @Override - public int getPing(@NotNull Player player) { - return getEntityPlayer(player).ping; - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.server.v1_14_R1.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).playerConnection.sendPacket((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - PlayerConnection playerConnection = getEntityPlayer(player).playerConnection; - for (Object packet : packets) { - playerConnection.sendPacket((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_15_R1/build.gradle.kts b/CoreCompatibility/Core_1_15_R1/build.gradle.kts deleted file mode 100644 index 6ba9b6c43..000000000 --- a/CoreCompatibility/Core_1_15_R1/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - compileOnly(files(file("../../lib/nms/spigot-1.15.2.jar"))) - adventureChatAPI() -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_15_R1.java b/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_15_R1.java deleted file mode 100644 index a23b9a67e..000000000 --- a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_15_R1.java +++ /dev/null @@ -1,117 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import me.deecaad.core.compatibility.HitBox; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_15_R1.AxisAlignedBB; -import net.minecraft.server.v1_15_R1.BlockPosition; -import net.minecraft.server.v1_15_R1.IRegistry; -import net.minecraft.server.v1_15_R1.MinecraftKey; -import net.minecraft.server.v1_15_R1.PacketPlayOutBlockBreakAnimation; -import net.minecraft.server.v1_15_R1.SoundEffect; -import net.minecraft.server.v1_15_R1.SoundEffectType; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; -import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; -import org.bukkit.util.BoundingBox; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.List; -import java.util.Locale; - -public class Block_1_15_R1 implements BlockCompatibility { - - private static final Field[] soundFields; - - static { - soundFields = new Field[SoundType.values().length]; // 5 - for (int i = 0; i < soundFields.length; i++) { - soundFields[i] = ReflectionUtil.getField(SoundEffectType.class, SoundEffect.class, i); - } - } - - @Override - public HitBox getHitBox(@NotNull Block block, boolean allowLiquid) { - if (!block.getChunk().isLoaded()) - return null; - if (block.isEmpty()) - return null; - - boolean isLiquid = block.isLiquid(); - if (!allowLiquid) { - if (block.isPassable() || block.isLiquid()) - return null; - } else if (!isLiquid && block.isPassable()) { - // Check like this because liquid is also passable... - return null; - } - - HitBox hitBox; - if (isLiquid) { - hitBox = new HitBox(block.getX(), block.getY(), block.getZ(), block.getX() + 1, block.getY() + 1, block.getZ() + 1); - } else { - BoundingBox boundingBox = block.getBoundingBox(); - hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ()); - } - hitBox.setBlockHitBox(block); - - CraftBlock craftBlock = (CraftBlock) block; - List voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d(); - if (voxelShape.size() > 1) { - int x = block.getX(); - int y = block.getY(); - int z = block.getZ(); - for (AxisAlignedBB boxPart : voxelShape) { - hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, - x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ)); - } - } - - return hitBox; - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ()); - return new PacketPlayOutBlockBreakAnimation(id, pos, crack); - } - - @Override - public SoundData getBlockSound(Object blockData, SoundType type) { - CraftBlockData block = (CraftBlockData) blockData; - SoundEffectType sounds = block.getState().r(); - - SoundData soundData = new SoundData(); - soundData.type = type; - soundData.pitch = sounds.y; - soundData.volume = sounds.x; - - soundData.sound = switch (type) { - case BREAK -> bukkit(sounds, 0); - case STEP -> bukkit(sounds, 1); - case PLACE -> bukkit(sounds, 2); - case HIT -> bukkit(sounds, 3); - case FALL -> bukkit(sounds, 4); - }; - - return soundData; - } - - private Sound bukkit(SoundEffectType sounds, int index) { - SoundEffect sound = (SoundEffect) ReflectionUtil.invokeField(soundFields[index], sounds); - MinecraftKey key = IRegistry.SOUND_EVENT.getKey(sound); - return Sound.valueOf(key.getKey().replaceAll("\\.", "_").toUpperCase(Locale.ROOT)); - } -} diff --git a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_15_R1.java b/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_15_R1.java deleted file mode 100644 index 6233660d7..000000000 --- a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_15_R1.java +++ /dev/null @@ -1,607 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.World; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_15_R1.CraftLootTable; -import org.bukkit.craftbukkit.v1_15_R1.CraftParticle; -import org.bukkit.craftbukkit.v1_15_R1.CraftServer; -import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_15_R1.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_15_R1.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_15_R1 implements CommandCompatibility { - - public static final MinecraftServer SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - EntityPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.a(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentRegistry.a(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandListenerWrapper) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.a(); - } - - @Override - public ArgumentType angle() { - throw new IllegalStateException("Unavailable in 1.15"); - } - - @Override - public ArgumentType axis() { - return ArgumentRotationAxis.a(); - } - - @Override - public ArgumentType blockPredicate() { - return ArgumentBlockPredicate.a(); - } - - @Override - public ArgumentType blockState() { - return ArgumentTile.a(); - } - - @Override - public ArgumentType chat() { - return ArgumentChat.a(); - } - - @Override - public ArgumentType chatComponent() { - return ArgumentChatComponent.a(); - } - - @Override - public ArgumentType chatFormat() { - return ArgumentChatFormat.a(); - } - - @Override - public ArgumentType dimension() { - return ArgumentDimension.a(); - } - - @Override - public ArgumentType enchantment() { - return ArgumentEnchantment.a(); - } - - @Override - public ArgumentType entity() { - return ArgumentEntity.a(); - } - - @Override - public ArgumentType entities() { - return ArgumentEntity.multipleEntities(); - } - - @Override - public ArgumentType player() { - return ArgumentEntity.c(); - } - - @Override - public ArgumentType players() { - return ArgumentEntity.d(); - } - - @Override - public ArgumentType entitySummon() { - return ArgumentEntitySummon.a(); - } - - @Override - public ArgumentType itemPredicate() { - return ArgumentItemPredicate.a(); - } - - @Override - public ArgumentType itemStack() { - return ArgumentItemStack.a(); - } - - @Override - public ArgumentType mathOperation() { - return ArgumentMathOperation.a(); - } - - @Override - public ArgumentType mobEffect() { - return ArgumentMobEffect.a(); - } - - @Override - public ArgumentType nbtCompound() { - return ArgumentNBTTag.a(); - } - - @Override - public ArgumentType particle() { - return ArgumentParticle.a(); - } - - @Override - public ArgumentType profile() { - return ArgumentProfile.a(); - } - - @Override - public ArgumentType rotation() { - return ArgumentRotation.a(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ArgumentScoreboardCriteria.a(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ArgumentScoreboardObjective.a(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ArgumentScoreboardSlot.a(); - } - - @Override - public ArgumentType scoreboardTeam() { - return ArgumentScoreboardTeam.a(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ArgumentScoreholder.a() : ArgumentScoreholder.b(); - } - - @Override - public ArgumentType tag() { - return ArgumentTag.a(); - } - - @Override - public ArgumentType time() { - return ArgumentTime.a(); - } - - @Override - public ArgumentType uuid() { - throw new IllegalStateException("Unavailable in 1.15"); - } - - @Override - public ArgumentType location() { - return ArgumentVec3.a(); - } - - @Override - public ArgumentType location2() { - return ArgumentVec2.a(); - } - - @Override - public ArgumentType block() { - return ArgumentPosition.a(); - } - - @Override - public ArgumentType block2() { - return ArgumentVec2I.a(); - } - - @Override - public ArgumentType biome() { - return key(); // this is actually only changed 1.18R2 and up - } - - @Override - public ArgumentType key() { - return ArgumentMinecraftKeyRegistered.a(); - } - - @Override - public SuggestionProvider biomeKey() { - return (SuggestionProvider) CompletionProviders.d; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) CompletionProviders.b; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) CompletionProviders.c; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) CompletionProviders.d; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> ICompletionProvider.a(SERVER.getAdvancementData().getAdvancements().stream().map(net.minecraft.server.v1_15_R1.Advancement::getName), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> ICompletionProvider.a(SERVER.getLootTableRegistry().a(), builder); - } - - private static NamespacedKey fromResourceLocation(MinecraftKey key) { - return new NamespacedKey(key.getNamespace(), key.getKey()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentMinecraftKeyRegistered.a(cast(context), key).bukkit; - } - - @Override - public float getAngle(CommandContext context, String key) { - throw new IllegalStateException("Unavailable in 1.15"); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = ArgumentRotationAxis.a(cast(context), key); - - for (EnumDirection.EnumAxis axis : nmsAxis) { - switch (axis) { - case X -> bukkitAxis.add(Axis.X); - case Y -> bukkitAxis.add(Axis.Y); - case Z -> bukkitAxis.add(Axis.Z); - } - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - MinecraftKey location = cast(context).getArgument(key, MinecraftKey.class); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getKey()); - Biome biome = EnumUtil.getIfPresent(Biome.class, namespaced.getKey()).orElseThrow(); - return new BiomeHolder(biome, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ArgumentBlockPredicate.a(cast(context), key); - return (Block block) -> { - return predicate.test(new ShapeDetectorBlock(cast(context).getSource().getWorld(), - new BlockPosition(block.getX(), block.getY(), block.getZ()), true)); - }; - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(ArgumentTile.a(cast(context), key).a()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - throw new IllegalStateException("Unavailable in 1.15"); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) { - return new CraftEnchantment(ArgumentEnchantment.a(cast(context), key)); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.a(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.getEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.c(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.d(source).stream() - .map(EntityPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - return EntityType.fromName(EntityTypes.getName(IRegistry.ENTITY_TYPE.get(ArgumentEntitySummon.a(cast(context), key))).getKey()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - CriterionConditionValue.FloatRange range = cast(context).getArgument(key, CriterionConditionValue.FloatRange.class); - double min = range.a() == null ? Double.MIN_VALUE : range.a(); - double max = range.b() == null ? Double.MAX_VALUE : range.b(); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - CriterionConditionValue.IntegerRange range = cast(context).getArgument(key, CriterionConditionValue.IntegerRange.class); - int min = range.a() == null ? Integer.MIN_VALUE : range.a(); - int max = range.b() == null ? Integer.MAX_VALUE : range.b(); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ArgumentItemStack.a(cast(context), key).a(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ArgumentItemPredicate.a(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentMinecraftKeyRegistered.a(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPosition2D column = ArgumentVec2I.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Column(world, column.a, column.b); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2F vector = ArgumentVec2.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Location2d(world, vector.i, vector.j); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPosition block = ArgumentPosition.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3D vector = ArgumentVec3.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - MinecraftKey minecraft = ArgumentMinecraftKeyRegistered.d(cast(context), key); - return new CraftLootTable(fromResourceLocation(minecraft), SERVER.getLootTableRegistry().getLootTable(minecraft)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ArgumentScoreboardObjective.a(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ArgumentScoreboardCriteria.a(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleParam particle = ArgumentParticle.a(cast(context), key); - return new ParticleHolder(CraftParticle.toBukkit(particle), particle, particle.a()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(ArgumentProfile.a(cast(context), key).iterator().next().getId()); - if (target == null) - throw ArgumentProfile.a.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(ArgumentProfile.a(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(ArgumentMobEffect.a(cast(context), key)); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - IRecipe recipe = ArgumentMinecraftKeyRegistered.b(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2F rotation = ArgumentRotation.a(cast(context), key).b(cast(context).getSource()); - return new Rotation(rotation.i, rotation.j); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - MinecraftKey mc = ArgumentMinecraftKeyRegistered.d(cast(context), key); - String name = mc.getKey().replaceAll("\\.", "_").toUpperCase(Locale.ROOT); - return new SoundHolder(EnumUtil.getIfPresent(Sound.class, name).orElse(null), new NamespacedKey(mc.getNamespace(), mc.getKey())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentScoreboardTeam.a(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - throw new IllegalStateException("Unavailable in 1.15"); - } - - @Override - public Map getCompound(CommandContext context, String key) { - NBTTagCompound nbt = ArgumentNBTTag.a(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(NBTBase tag) { - switch (tag.getTypeId()) { - case 1: - case 2: - case 3: - case 4: - return ((NBTNumber) tag).asInt(); - case 5: - case 6: - return ((NBTNumber) tag).asDouble(); - case 8: - return ((NBTTagString) tag).asString(); - case 7: - case 11: - case 12: - case 9: - return convertList((NBTList) tag); - case 10: - return convertMap((NBTTagCompound) tag); - default : - throw new IllegalStateException("Unexpected value: " + tag); - } - } - - private Map convertMap(NBTTagCompound nbt) { - Map temp = new HashMap<>(); - - for (String key : nbt.getKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(NBTList values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_15_R1.java b/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_15_R1.java deleted file mode 100644 index 7215e7d6a..000000000 --- a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_15_R1.java +++ /dev/null @@ -1,99 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import me.deecaad.core.compatibility.equipevent.NonNullList_1_15_R1; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_15_R1.DataWatcher; -import net.minecraft.server.v1_15_R1.EnumItemSlot; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.List; - -public class Entity_1_15_R1 implements EntityCompatibility { - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.server.v1_15_R1.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.lastX, nms.lastY, nms.lastZ); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_15_R1(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_15_R1(location, type, data); - } - - private static final Field ID = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, int.class); - private static final Field DATA = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, List.class); - - @Override - public int getId(Object obj) { - return (int) ReflectionUtil.invokeField(ID, obj); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - EnumItemSlot nmsSlot = switch (slot) { - case HEAD -> EnumItemSlot.HEAD; - case CHEST -> EnumItemSlot.CHEST; - case LEGS -> EnumItemSlot.LEGS; - case FEET -> EnumItemSlot.FEET; - case HAND -> EnumItemSlot.MAINHAND; - case OFF_HAND -> EnumItemSlot.OFFHAND; - }; - - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(id, nmsSlot, CraftItemStack.asNMSCopy(item)); - ((CraftPlayer) bukkit).getHandle().playerConnection.sendPacket(packet); - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.server.v1_15_R1.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - PacketPlayOutEntityMetadata packet = (PacketPlayOutEntityMetadata) obj; - List> list = (List>) ReflectionUtil.invokeField(DATA, packet); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).b().getClass() != Byte.class) - return; - - // noinspection unchecked - DataWatcher.Item item = (DataWatcher.Item) list.get(0); - byte data = item.b(); - data = meta.set(data, enabled); - item.a(data); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_15_R1.java b/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_15_R1.java deleted file mode 100644 index 46d6f26f7..000000000 --- a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_15_R1.java +++ /dev/null @@ -1,359 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.server.v1_15_R1.Block; -import net.minecraft.server.v1_15_R1.Entity; -import net.minecraft.server.v1_15_R1.EntityArmorStand; -import net.minecraft.server.v1_15_R1.EntityFallingBlock; -import net.minecraft.server.v1_15_R1.EntityFireworks; -import net.minecraft.server.v1_15_R1.EntityItem; -import net.minecraft.server.v1_15_R1.EntityLiving; -import net.minecraft.server.v1_15_R1.EnumItemSlot; -import net.minecraft.server.v1_15_R1.IBlockData; -import net.minecraft.server.v1_15_R1.ItemStack; -import net.minecraft.server.v1_15_R1.Packet; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityHeadRotation; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityStatus; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityVelocity; -import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity; -import net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntityLiving; -import net.minecraft.server.v1_15_R1.PlayerConnection; -import net.minecraft.server.v1_15_R1.Vec3D; -import net.minecraft.server.v1_15_R1.Vector3f; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_15_R1.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook; -import static net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook; - -public class FakeEntity_1_15_R1 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EnumItemSlot[] SLOTS = EnumItemSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private IBlockData block; - private ItemStack item; - - public FakeEntity_1_15_R1(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new EntityItem(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> - new EntityFallingBlock(world.getHandle(), x, y, z, block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle())); - case FIREWORK -> new EntityFireworks(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - EntityArmorStand armorStand = (EntityArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> CraftItemStack.asBukkitCopy(item); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> - ((EntityItem) entity).setItemStack(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPositionRaw(x, y, z); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - } - - @Override - public void setMotion(double dx, double dy, double dz) { - PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(cache, new Vec3D(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - - byte byteYaw = convertYaw(yaw); - PacketPlayOutEntityLook packet = new PacketPlayOutEntityLook(cache, byteYaw, convertPitch(pitch), false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(entity); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(cache, dx, dy, dz, yaw, pitch, false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - public void show() { - - // Construct the packets out of the loop to save resources, they will - // be the same for each Player. - Packet spawn = type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0); - PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())); - PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ())); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection; - if (connections.contains(connection)) { - continue; - } - - connection.sendPacket(spawn); - connection.sendPacket(meta); - connection.sendPacket(head); - connection.sendPacket(velocity); - connection.sendPacket(look); - PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket(); - if (equipment != null) { - for (PacketPlayOutEntityEquipment packet : equipment) { - connection.sendPacket(packet); - } - } - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - if (connections.contains(connection)) - throw new IllegalArgumentException(); - - connection.sendPacket(type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0)); - connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true)); - connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.sendPacket(new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ()))); - connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()))); - PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket(); - if (equipment != null) { - for (PacketPlayOutEntityEquipment packet : equipment) { - connection.sendPacket(packet); - } - } - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((EntityArmorStand) entity).setHeadPose(new Vector3f(getPitch(), 0, 0)); - - sendPackets(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), false)); - } - - @Override - public void remove() { - sendPackets(new PacketPlayOutEntityDestroy(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(new PacketPlayOutEntityDestroy(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new PacketPlayOutEntityStatus(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EnumItemSlot slot; - switch (equipmentSlot) { - case HAND: - slot = EnumItemSlot.MAINHAND; - break; - case OFF_HAND: - slot = EnumItemSlot.OFFHAND; - break; - case FEET: - slot = EnumItemSlot.FEET; - break; - case CHEST: - slot = EnumItemSlot.CHEST; - break; - case LEGS: - slot = EnumItemSlot.LEGS; - break; - case HEAD: - slot = EnumItemSlot.HEAD; - break; - default : - throw new IllegalArgumentException(); - } - - EntityLiving livingEntity = (EntityLiving) entity; - livingEntity.setSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - PacketPlayOutEntityEquipment[] packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private PacketPlayOutEntityEquipment[] getEquipmentPacket() { - if (!type.isAlive()) - return null; - EntityLiving livingEntity = (EntityLiving) entity; - - List temp = new ArrayList<>(SLOTS.length); - for (EnumItemSlot slot : SLOTS) { - ItemStack item = livingEntity.getEquipment(slot); - - if (item != null && !item.isEmpty()) { - temp.add(new PacketPlayOutEntityEquipment(cache, slot, item)); - } - } - - return temp.isEmpty() ? null : temp.toArray(new PacketPlayOutEntityEquipment[0]); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - PlayerConnection connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.sendPacket(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_15_R1.java b/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_15_R1.java deleted file mode 100644 index 93d6093aa..000000000 --- a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_15_R1.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_15_R1.Item; -import net.minecraft.server.v1_15_R1.ItemStack; -import net.minecraft.server.v1_15_R1.NonNullList; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -public class NonNullList_1_15_R1 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_15_R1(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.a); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.a); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_15_R1.java b/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_15_R1.java deleted file mode 100644 index d5e63bd58..000000000 --- a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_15_R1.java +++ /dev/null @@ -1,88 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import me.deecaad.core.utils.StringUtil; -import net.minecraft.server.v1_15_R1.NBTBase; -import net.minecraft.server.v1_15_R1.NBTTagCompound; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -public class NBT_1_15_R1 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.server.v1_15_R1.ItemStack nms = getNMSStack(toItem); - NBTTagCompound from = getNMSStack(fromItem).getTag(); - NBTTagCompound to = nms.getTag(); - - if (path == null) { - nms.setTag(from.clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - return; - } - - to.set(path, from.getCompound(path).clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.server.v1_15_R1.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_15_R1.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - NBTTagCompound nbt = getNMSStack(bukkitStack).getTag(); - if (nbt == null) - return "null"; - - return visit(nbt, 0, 0).toString(); - } - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - - private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - StringBuilder builder = new StringBuilder(braceColor).append('{'); - - List keys = new ArrayList<>(nbt.getKeys()); - Collections.sort(keys); - - for (int i = 0; i < keys.size(); i++) { - String key = keys.get(i); - NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible"); - - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - builder.append(color).append(key).append("&f&l: ").append(color); - - if (value instanceof NBTTagCompound) - builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i)); - else - builder.append(value); - } - - return builder.append(braceColor).append("}\n"); - } - - @Override - public @NotNull ItemStack getPlacementItem(@NotNull Block block) { - return new ItemStack(block.getBlockData().getMaterial()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/v1_15_R1.java b/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/v1_15_R1.java deleted file mode 100644 index b4f3f29ee..000000000 --- a/CoreCompatibility/Core_1_15_R1/src/main/java/me/deecaad/core/compatibility/v1_15_R1.java +++ /dev/null @@ -1,83 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_15_R1; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_15_R1; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_15_R1; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_15_R1; -import net.minecraft.server.v1_15_R1.EntityPlayer; -import net.minecraft.server.v1_15_R1.Packet; -import net.minecraft.server.v1_15_R1.PlayerConnection; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_15_R1 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_15_R1() { - entityCompatibility = new Entity_1_15_R1(); - blockCompatibility = new Block_1_15_R1(); - nbtCompatibility = new NBT_1_15_R1(); - commandCompatibility = new Command_1_15_R1(); - } - - @Override - public int getPing(@NotNull Player player) { - return getEntityPlayer(player).ping; - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.server.v1_15_R1.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).playerConnection.sendPacket((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - PlayerConnection playerConnection = getEntityPlayer(player).playerConnection; - for (Object packet : packets) { - playerConnection.sendPacket((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_16_R3/build.gradle.kts b/CoreCompatibility/Core_1_16_R3/build.gradle.kts deleted file mode 100644 index d76755960..000000000 --- a/CoreCompatibility/Core_1_16_R3/build.gradle.kts +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - compileOnly(files(file("../../lib/nms/spigot-1.16.5.jar"))) - adventureChatAPI() -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_16_R3.java b/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_16_R3.java deleted file mode 100644 index e1f561891..000000000 --- a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_16_R3.java +++ /dev/null @@ -1,71 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import me.deecaad.core.compatibility.HitBox; -import net.minecraft.server.v1_16_R3.AxisAlignedBB; -import net.minecraft.server.v1_16_R3.BlockPosition; -import net.minecraft.server.v1_16_R3.PacketPlayOutBlockBreakAnimation; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock; -import org.bukkit.util.BoundingBox; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class Block_1_16_R3 implements BlockCompatibility { - - @Override - public HitBox getHitBox(@NotNull Block block, boolean allowLiquid) { - if (!block.getChunk().isLoaded()) - return null; - if (block.isEmpty()) - return null; - - boolean isLiquid = block.isLiquid(); - if (!allowLiquid) { - if (block.isPassable() || block.isLiquid()) - return null; - } else if (!isLiquid && block.isPassable()) { - // Check like this because liquid is also passable... - return null; - } - - HitBox hitBox; - if (isLiquid) { - hitBox = new HitBox(block.getX(), block.getY(), block.getZ(), block.getX() + 1, block.getY() + 1, block.getZ() + 1); - } else { - BoundingBox boundingBox = block.getBoundingBox(); - hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ()); - } - hitBox.setBlockHitBox(block); - - CraftBlock craftBlock = (CraftBlock) block; - List voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d(); - if (voxelShape.size() > 1) { - int x = block.getX(); - int y = block.getY(); - int z = block.getZ(); - for (AxisAlignedBB boxPart : voxelShape) { - hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, - x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ)); - } - } - - return hitBox; - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPosition pos = new BlockPosition(block.getX(), block.getY(), block.getZ()); - return new PacketPlayOutBlockBreakAnimation(id, pos, crack); - } -} diff --git a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_16_R3.java b/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_16_R3.java deleted file mode 100644 index bbf77b9ea..000000000 --- a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_16_R3.java +++ /dev/null @@ -1,610 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.IntRange; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_16_R3.*; -import org.bukkit.World; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_16_R3.CraftLootTable; -import org.bukkit.craftbukkit.v1_16_R3.CraftParticle; -import org.bukkit.craftbukkit.v1_16_R3.CraftServer; -import org.bukkit.craftbukkit.v1_16_R3.CraftSound; -import org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_16_R3.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_R3.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_16_R3 implements CommandCompatibility { - - public static final MinecraftServer SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - EntityPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.a(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentRegistry.a(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandListenerWrapper) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.a(); - } - - @Override - public ArgumentType angle() { - return ArgumentAngle.a(); - } - - @Override - public ArgumentType axis() { - return ArgumentRotationAxis.a(); - } - - @Override - public ArgumentType blockPredicate() { - return ArgumentBlockPredicate.a(); - } - - @Override - public ArgumentType blockState() { - return ArgumentTile.a(); - } - - @Override - public ArgumentType chat() { - return ArgumentChat.a(); - } - - @Override - public ArgumentType chatComponent() { - return ArgumentChatComponent.a(); - } - - @Override - public ArgumentType chatFormat() { - return ArgumentChatFormat.a(); - } - - @Override - public ArgumentType dimension() { - return ArgumentDimension.a(); - } - - @Override - public ArgumentType enchantment() { - return ArgumentEnchantment.a(); - } - - @Override - public ArgumentType entity() { - return ArgumentEntity.a(); - } - - @Override - public ArgumentType entities() { - return ArgumentEntity.multipleEntities(); - } - - @Override - public ArgumentType player() { - return ArgumentEntity.c(); - } - - @Override - public ArgumentType players() { - return ArgumentEntity.d(); - } - - @Override - public ArgumentType entitySummon() { - return ArgumentEntitySummon.a(); - } - - @Override - public ArgumentType itemPredicate() { - return ArgumentItemPredicate.a(); - } - - @Override - public ArgumentType itemStack() { - return ArgumentItemStack.a(); - } - - @Override - public ArgumentType mathOperation() { - return ArgumentMathOperation.a(); - } - - @Override - public ArgumentType mobEffect() { - return ArgumentMobEffect.a(); - } - - @Override - public ArgumentType nbtCompound() { - return ArgumentNBTTag.a(); - } - - @Override - public ArgumentType particle() { - return ArgumentParticle.a(); - } - - @Override - public ArgumentType profile() { - return ArgumentProfile.a(); - } - - @Override - public ArgumentType rotation() { - return ArgumentRotation.a(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ArgumentScoreboardCriteria.a(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ArgumentScoreboardObjective.a(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ArgumentScoreboardSlot.a(); - } - - @Override - public ArgumentType scoreboardTeam() { - return ArgumentScoreboardTeam.a(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ArgumentScoreholder.a() : ArgumentScoreholder.b(); - } - - @Override - public ArgumentType tag() { - return ArgumentTag.a(); - } - - @Override - public ArgumentType time() { - return ArgumentTime.a(); - } - - @Override - public ArgumentType uuid() { - return ArgumentUUID.a(); - } - - @Override - public ArgumentType location() { - return ArgumentVec3.a(); - } - - @Override - public ArgumentType location2() { - return ArgumentVec2.a(); - } - - @Override - public ArgumentType block() { - return ArgumentPosition.a(); - } - - @Override - public ArgumentType block2() { - return ArgumentVec2I.a(); - } - - @Override - public ArgumentType biome() { - return key(); // this is actually only changed 1.18R2 and up - } - - @Override - public ArgumentType key() { - return ArgumentMinecraftKeyRegistered.a(); - } - - @Override - public SuggestionProvider biomeKey() { - return (SuggestionProvider) CompletionProviders.d; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) CompletionProviders.b; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) CompletionProviders.c; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) CompletionProviders.e; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> ICompletionProvider.a(SERVER.getAdvancementData().getAdvancements().stream().map(net.minecraft.server.v1_16_R3.Advancement::getName), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> ICompletionProvider.a(SERVER.getLootTableRegistry().a(), builder); - } - - private static NamespacedKey fromResourceLocation(MinecraftKey key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getKey()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentMinecraftKeyRegistered.a(cast(context), key).bukkit; - } - - @Override - public float getAngle(CommandContext context, String key) { - return ArgumentAngle.a(cast(context), key); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = ArgumentRotationAxis.a(cast(context), key); - - for (EnumDirection.EnumAxis axis : nmsAxis) { - switch (axis) { - case X -> bukkitAxis.add(Axis.X); - case Y -> bukkitAxis.add(Axis.Y); - case Z -> bukkitAxis.add(Axis.Z); - } - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - MinecraftKey location = cast(context).getArgument(key, MinecraftKey.class); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getKey()); - Biome biome = EnumUtil.getIfPresent(Biome.class, namespaced.getKey()).orElse(Biome.CUSTOM); - return new BiomeHolder(biome, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ArgumentBlockPredicate.a(cast(context), key); - return (Block block) -> { - return predicate.test(new ShapeDetectorBlock(cast(context).getSource().getWorld(), - new BlockPosition(block.getX(), block.getY(), block.getZ()), true)); - }; - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(ArgumentTile.a(cast(context), key).a()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentDimension.a(cast(context), key).getWorld().getEnvironment(); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) { - return new CraftEnchantment(ArgumentEnchantment.a(cast(context), key)); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.a(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.getEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.c(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandListenerWrapper source = (CommandListenerWrapper) context.getSource(); - return selector.d(source).stream() - .map(EntityPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - return EntityType.fromName(EntityTypes.getName(IRegistry.ENTITY_TYPE.get(ArgumentEntitySummon.a(cast(context), key))).getKey()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - CriterionConditionValue.FloatRange range = cast(context).getArgument(key, CriterionConditionValue.FloatRange.class); - double min = range.a() == null ? Double.MIN_VALUE : range.a(); - double max = range.b() == null ? Double.MAX_VALUE : range.b(); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - CriterionConditionValue.IntegerRange range = cast(context).getArgument(key, CriterionConditionValue.IntegerRange.class); - int min = range.a() == null ? Integer.MIN_VALUE : range.a(); - int max = range.b() == null ? Integer.MAX_VALUE : range.b(); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ArgumentItemStack.a(cast(context), key).a(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ArgumentItemPredicate.a(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentMinecraftKeyRegistered.a(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPosition2D column = ArgumentVec2I.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Column(world, column.a, column.b); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2F vector = ArgumentVec2.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Location2d(world, vector.i, vector.j); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPosition block = ArgumentPosition.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3D vector = ArgumentVec3.a(cast(context), key); - World world = cast(context).getSource().getWorld().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - MinecraftKey minecraft = ArgumentMinecraftKeyRegistered.e(cast(context), key); - return new CraftLootTable(fromResourceLocation(minecraft), SERVER.getLootTableRegistry().getLootTable(minecraft)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ArgumentScoreboardObjective.a(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ArgumentScoreboardCriteria.a(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleParam particle = ArgumentParticle.a(cast(context), key); - return new ParticleHolder(CraftParticle.toBukkit(particle), particle, particle.a()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(ArgumentProfile.a(cast(context), key).iterator().next().getId()); - if (target == null) - throw ArgumentProfile.a.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(ArgumentProfile.a(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(ArgumentMobEffect.a(cast(context), key)); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - IRecipe recipe = ArgumentMinecraftKeyRegistered.b(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2F rotation = ArgumentRotation.a(cast(context), key).b(cast(context).getSource()); - return new Rotation(rotation.i, rotation.j); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - MinecraftKey location = ArgumentMinecraftKeyRegistered.e(cast(context), key); - SoundEffect sound = IRegistry.SOUND_EVENT.get(location); - Sound bukkit = sound == null ? null : CraftSound.getBukkit(sound); - return new SoundHolder(bukkit, new NamespacedKey(location.getNamespace(), location.getKey())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return ArgumentScoreboardTeam.a(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - return ArgumentUUID.a(cast(context), key); - } - - @Override - public Map getCompound(CommandContext context, String key) { - NBTTagCompound nbt = ArgumentNBTTag.a(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(NBTBase tag) { - switch (tag.getTypeId()) { - case 1: - case 2: - case 3: - case 4: - return ((NBTNumber) tag).asInt(); - case 5: - case 6: - return ((NBTNumber) tag).asDouble(); - case 8: - return ((NBTTagString) tag).asString(); - case 7: - case 11: - case 12: - case 9: - return convertList((NBTList) tag); - case 10: - return convertMap((NBTTagCompound) tag); - default : - throw new IllegalStateException("Unexpected value: " + tag); - } - } - - private Map convertMap(NBTTagCompound nbt) { - Map temp = new HashMap<>(); - - for (String key : nbt.getKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(NBTList values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_16_R3.java b/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_16_R3.java deleted file mode 100644 index f1b95172e..000000000 --- a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_16_R3.java +++ /dev/null @@ -1,103 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_16_R3; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_16_R3.DataWatcher; -import net.minecraft.server.v1_16_R3.EnumItemSlot; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -public class Entity_1_16_R3 implements EntityCompatibility { - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.server.v1_16_R3.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.lastX, nms.lastY, nms.lastZ); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_16_R3(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_16_R3(location, type, data); - } - - private static final Field ID = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, int.class); - private static final Field DATA = ReflectionUtil.getField(PacketPlayOutEntityMetadata.class, List.class); - - @Override - public int getId(Object obj) { - return (int) ReflectionUtil.invokeField(ID, obj); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - EnumItemSlot nmsSlot = switch (slot) { - case HEAD -> EnumItemSlot.HEAD; - case CHEST -> EnumItemSlot.CHEST; - case LEGS -> EnumItemSlot.LEGS; - case FEET -> EnumItemSlot.FEET; - case HAND -> EnumItemSlot.MAINHAND; - case OFF_HAND -> EnumItemSlot.OFFHAND; - }; - - List> temp = new ArrayList<>(1); - temp.add(new Pair<>(nmsSlot, CraftItemStack.asNMSCopy(item))); - PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(id, temp); - ((CraftPlayer) bukkit).getHandle().playerConnection.sendPacket(packet); - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.server.v1_16_R3.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - PacketPlayOutEntityMetadata packet = (PacketPlayOutEntityMetadata) obj; - List> list = (List>) ReflectionUtil.invokeField(DATA, packet); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).b().getClass() != Byte.class) - return; - - // noinspection unchecked - DataWatcher.Item item = (DataWatcher.Item) list.get(0); - byte data = item.b(); - data = meta.set(data, enabled); - item.a(data); - } -} diff --git a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_16_R3.java b/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_16_R3.java deleted file mode 100644 index 4895cedf1..000000000 --- a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_16_R3.java +++ /dev/null @@ -1,336 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.server.v1_16_R3.Block; -import net.minecraft.server.v1_16_R3.Entity; -import net.minecraft.server.v1_16_R3.EntityArmorStand; -import net.minecraft.server.v1_16_R3.EntityFallingBlock; -import net.minecraft.server.v1_16_R3.EntityFireworks; -import net.minecraft.server.v1_16_R3.EntityItem; -import net.minecraft.server.v1_16_R3.EntityLiving; -import net.minecraft.server.v1_16_R3.EnumItemSlot; -import net.minecraft.server.v1_16_R3.IBlockData; -import net.minecraft.server.v1_16_R3.ItemStack; -import net.minecraft.server.v1_16_R3.Packet; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityStatus; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityVelocity; -import net.minecraft.server.v1_16_R3.PacketPlayOutSpawnEntity; -import net.minecraft.server.v1_16_R3.PacketPlayOutSpawnEntityLiving; -import net.minecraft.server.v1_16_R3.PlayerConnection; -import net.minecraft.server.v1_16_R3.Vec3D; -import net.minecraft.server.v1_16_R3.Vector3f; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_16_R3.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook; -import static net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook; - -public class FakeEntity_1_16_R3 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EnumItemSlot[] SLOTS = EnumItemSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private IBlockData block; - private ItemStack item; - - public FakeEntity_1_16_R3(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new EntityItem(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> - new EntityFallingBlock(world.getHandle(), x, y, z, block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle())); - case FIREWORK -> new EntityFireworks(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - EntityArmorStand armorStand = (EntityArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> CraftItemStack.asBukkitCopy(item); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((EntityItem) entity).setItemStack(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPositionRaw(x, y, z); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - } - - @Override - public void setMotion(double dx, double dy, double dz) { - PacketPlayOutEntityVelocity packet = new PacketPlayOutEntityVelocity(cache, new Vec3D(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setHeadRotation(yaw); - entity.yaw = yaw; - entity.pitch = pitch; - - byte byteYaw = convertYaw(yaw); - PacketPlayOutEntityLook packet = new PacketPlayOutEntityLook(cache, byteYaw, convertPitch(pitch), false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(entity); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(cache, dx, dy, dz, yaw, pitch, false); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - public void show() { - - // Construct the packets out of the loop to save resources, they will - // be the same for each Player. - Packet spawn = type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0); - PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true); - PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())); - PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ())); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection; - if (connections.contains(connection)) { - continue; - } - - connection.sendPacket(spawn); - connection.sendPacket(meta); - connection.sendPacket(head); - connection.sendPacket(velocity); - connection.sendPacket(look); - PacketPlayOutEntityEquipment equipment = getEquipmentPacket(); - if (equipment != null) - connection.sendPacket(equipment); - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - if (connections.contains(connection)) - throw new IllegalArgumentException(); - - connection.sendPacket(type.isAlive() - ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) - : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0)); - connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true)); - connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.sendPacket(new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ()))); - connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()))); - PacketPlayOutEntityEquipment equipment = getEquipmentPacket(); - if (equipment != null) - connection.sendPacket(equipment); - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((EntityArmorStand) entity).setHeadPose(new Vector3f(getPitch(), 0, 0)); - - sendPackets(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), false)); - } - - @Override - public void remove() { - sendPackets(new PacketPlayOutEntityDestroy(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; - connection.sendPacket(new PacketPlayOutEntityDestroy(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new PacketPlayOutEntityStatus(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EnumItemSlot slot = switch (equipmentSlot) { - case HAND -> EnumItemSlot.MAINHAND; - case OFF_HAND -> EnumItemSlot.OFFHAND; - case FEET -> EnumItemSlot.FEET; - case CHEST -> EnumItemSlot.CHEST; - case LEGS -> EnumItemSlot.LEGS; - case HEAD -> EnumItemSlot.HEAD; - }; - - EntityLiving livingEntity = (EntityLiving) entity; - livingEntity.setSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - PacketPlayOutEntityEquipment packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private PacketPlayOutEntityEquipment getEquipmentPacket() { - if (!type.isAlive()) - return null; - EntityLiving livingEntity = (EntityLiving) entity; - - List> equipmentList = new ArrayList<>(6); - for (EnumItemSlot slot : SLOTS) { - ItemStack itemStack = livingEntity.getEquipment(slot); - if (!itemStack.isEmpty()) { - equipmentList.add(Pair.of(slot, itemStack)); - } - } - return equipmentList.isEmpty() ? null : new PacketPlayOutEntityEquipment(cache, equipmentList); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - PlayerConnection connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.sendPacket(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_16_R3.java b/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_16_R3.java deleted file mode 100644 index 1c3bd7ae5..000000000 --- a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_16_R3.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_16_R3.Item; -import net.minecraft.server.v1_16_R3.ItemStack; -import net.minecraft.server.v1_16_R3.NonNullList; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -public class NonNullList_1_16_R3 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_16_R3(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.b); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.b); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_16_R3.java b/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_16_R3.java deleted file mode 100644 index 66283f013..000000000 --- a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_16_R3.java +++ /dev/null @@ -1,88 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import me.deecaad.core.utils.StringUtil; -import net.minecraft.server.v1_16_R3.NBTBase; -import net.minecraft.server.v1_16_R3.NBTTagCompound; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -public class NBT_1_16_R3 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.server.v1_16_R3.ItemStack nms = getNMSStack(toItem); - NBTTagCompound from = getNMSStack(fromItem).getTag(); - NBTTagCompound to = nms.getTag(); - - if (path == null) { - nms.setTag(from.clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - return; - } - - to.set(path, from.getCompound(path).clone()); - toItem.setItemMeta(CraftItemStack.asBukkitCopy(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.server.v1_16_R3.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_16_R3.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - NBTTagCompound nbt = getNMSStack(bukkitStack).getTag(); - if (nbt == null) - return "null"; - - return visit(nbt, 0, 0).toString(); - } - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - - private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - StringBuilder builder = new StringBuilder(braceColor).append('{'); - - List keys = new ArrayList<>(nbt.getKeys()); - Collections.sort(keys); - - for (int i = 0; i < keys.size(); i++) { - String key = keys.get(i); - NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible"); - - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - builder.append(color).append(key).append("&f&l: ").append(color); - - if (value instanceof NBTTagCompound) - builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i)); - else - builder.append(value); - } - - return builder.append(braceColor).append("}\n"); - } - - @Override - public @NotNull ItemStack getPlacementItem(@NotNull Block block) { - return new ItemStack(block.getBlockData().getMaterial()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/v1_16_R3.java b/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/v1_16_R3.java deleted file mode 100644 index fbaf2892b..000000000 --- a/CoreCompatibility/Core_1_16_R3/src/main/java/me/deecaad/core/compatibility/v1_16_R3.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_16_R3; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_16_R3; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_16_R3; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_16_R3; -import net.minecraft.server.v1_16_R3.EntityPlayer; -import net.minecraft.server.v1_16_R3.Packet; -import net.minecraft.server.v1_16_R3.PlayerConnection; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_16_R3 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_16_R3() { - entityCompatibility = new Entity_1_16_R3(); - blockCompatibility = new Block_1_16_R3(); - nbtCompatibility = new NBT_1_16_R3(); - commandCompatibility = new Command_1_16_R3(); - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.server.v1_16_R3.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).playerConnection.sendPacket((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - PlayerConnection playerConnection = getEntityPlayer(player).playerConnection; - for (Object packet : packets) { - playerConnection.sendPacket((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull EntityPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_17_R1/build.gradle.kts b/CoreCompatibility/Core_1_17_R1/build.gradle.kts deleted file mode 100644 index 038bcedb6..000000000 --- a/CoreCompatibility/Core_1_17_R1/build.gradle.kts +++ /dev/null @@ -1,21 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - adventureChatAPI() - - paperweight.paperDevBundle("1.17.1-R0.1-SNAPSHOT") -} - -// These older -java.toolchain.languageVersion.set(JavaLanguageVersion.of(16)) - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(16) - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_17_R1.java b/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_17_R1.java deleted file mode 100644 index 3392b83ed..000000000 --- a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_17_R1.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import org.bukkit.block.Block; -import org.jetbrains.annotations.NotNull; - -// https://nms.screamingsandals.org/1.17.1/ -public class Block_1_17_R1 implements BlockCompatibility { - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPos pos = new BlockPos(block.getX(), block.getY(), block.getZ()); - return new ClientboundBlockDestructionPacket(id, pos, crack); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_17_R1.java b/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_17_R1.java deleted file mode 100644 index 3489fb40f..000000000 --- a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_17_R1.java +++ /dev/null @@ -1,621 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.*; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.*; -import net.minecraft.commands.arguments.item.FunctionArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemPredicateArgument; -import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentTypes; -import net.minecraft.commands.synchronization.SuggestionProviders; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Registry; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.nbt.Tag; -import net.minecraft.nbt.*; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ColumnPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.Vec3; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_17_R1.CraftLootTable; -import org.bukkit.craftbukkit.v1_17_R1.CraftParticle; -import org.bukkit.craftbukkit.v1_17_R1.CraftServer; -import org.bukkit.craftbukkit.v1_17_R1.CraftSound; -import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_17_R1.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_17_R1.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_17_R1 implements CommandCompatibility { - - public static final MinecraftServer SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - ServerPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.sendCommands(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentTypes.serializeNodeToJson(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandSourceStack) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.getDispatcher(); - } - - @Override - public ArgumentType angle() { - return AngleArgument.angle(); - } - - @Override - public ArgumentType axis() { - return SwizzleArgument.swizzle(); - } - - @Override - public ArgumentType blockPredicate() { - return BlockPredicateArgument.blockPredicate(); - } - - @Override - public ArgumentType blockState() { - return BlockStateArgument.block(); - } - - @Override - public ArgumentType chat() { - return MessageArgument.message(); - } - - @Override - public ArgumentType chatComponent() { - return ComponentArgument.textComponent(); - } - - @Override - public ArgumentType chatFormat() { - return ColorArgument.color(); - } - - @Override - public ArgumentType dimension() { - return DimensionArgument.dimension(); - } - - @Override - public ArgumentType enchantment() { - return ItemEnchantmentArgument.enchantment(); - } - - @Override - public ArgumentType entity() { - return EntityArgument.entity(); - } - - @Override - public ArgumentType entities() { - return EntityArgument.entities(); - } - - @Override - public ArgumentType player() { - return EntityArgument.player(); - } - - @Override - public ArgumentType players() { - return EntityArgument.players(); - } - - @Override - public ArgumentType entitySummon() { - return EntitySummonArgument.id(); - } - - @Override - public ArgumentType itemPredicate() { - return ItemPredicateArgument.itemPredicate(); - } - - @Override - public ArgumentType itemStack() { - return ItemArgument.item(); - } - - @Override - public ArgumentType mathOperation() { - return OperationArgument.operation(); - } - - @Override - public ArgumentType mobEffect() { - return MobEffectArgument.effect(); - } - - @Override - public ArgumentType nbtCompound() { - return CompoundTagArgument.compoundTag(); - } - - @Override - public ArgumentType particle() { - return ParticleArgument.particle(); - } - - @Override - public ArgumentType profile() { - return GameProfileArgument.gameProfile(); - } - - @Override - public ArgumentType rotation() { - return RotationArgument.rotation(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ObjectiveCriteriaArgument.criteria(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ObjectiveArgument.objective(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ScoreboardSlotArgument.displaySlot(); - } - - @Override - public ArgumentType scoreboardTeam() { - return TeamArgument.team(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ScoreHolderArgument.scoreHolder() : ScoreHolderArgument.scoreHolders(); - } - - @Override - public ArgumentType tag() { - return FunctionArgument.functions(); - } - - @Override - public ArgumentType time() { - return TimeArgument.time(); - } - - @Override - public ArgumentType uuid() { - return UuidArgument.uuid(); - } - - @Override - public ArgumentType location() { - return Vec3Argument.vec3(); - } - - @Override - public ArgumentType location2() { - return Vec2Argument.vec2(); - } - - @Override - public ArgumentType block() { - return BlockPosArgument.blockPos(); - } - - @Override - public ArgumentType block2() { - return ColumnPosArgument.columnPos(); - } - - @Override - public ArgumentType biome() { - return key(); // this is actually only changed 1.18R2 and up - } - - @Override - public ArgumentType key() { - return ResourceLocationArgument.id(); - } - - @Override - public SuggestionProvider biomeKey() { - return (SuggestionProvider) SuggestionProviders.AVAILABLE_BIOMES; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) SuggestionProviders.ALL_RECIPES; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) SuggestionProviders.AVAILABLE_SOUNDS; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) SuggestionProviders.SUMMONABLE_ENTITIES; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getAdvancements().getAllAdvancements().stream().map(net.minecraft.advancements.Advancement::getId), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getLootTables().getIds(), builder); - } - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getAdvancement(cast(context), key).bukkit; - } - - @Override - public float getAngle(CommandContext context, String key) { - return AngleArgument.getAngle(cast(context), key); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = SwizzleArgument.getSwizzle(cast(context), key); - - for (Direction.Axis axis : nmsAxis) { - bukkitAxis.add(switch (axis) { - case X -> Axis.X; - case Y -> Axis.Y; - case Z -> Axis.Z; - }); - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - ResourceLocation location = cast(context).getArgument(key, ResourceLocation.class); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getPath()); - Biome biome = EnumUtil.getIfPresent(Biome.class, namespaced.getKey()).orElse(Biome.CUSTOM); - return new BiomeHolder(biome, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cast(context), key); - return block -> predicate.test(new BlockInWorld(cast(context).getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cast(context), key).getState()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - return DimensionArgument.getDimension(cast(context), key).getWorld().getEnvironment(); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) { - return new CraftEnchantment(ItemEnchantmentArgument.getEnchantment(cast(context), key)); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSingleEntity(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSinglePlayer(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findPlayers(source).stream() - .map(ServerPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.entity.EntityType type = Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(cast(context), key)); - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(type).getPath()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cast(context), key); - double min = range.getMin() == null ? Double.MIN_VALUE : range.getMin(); - double max = range.getMax() == null ? Double.MAX_VALUE : range.getMax(); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cast(context), key); - int min = range.getMin() == null ? Integer.MIN_VALUE : range.getMin(); - int max = range.getMax() == null ? Integer.MAX_VALUE : range.getMax(); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ItemArgument.getItem(cast(context), key).createItemStack(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ItemPredicateArgument.getItemPredicate(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getId(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - ColumnPos column = ColumnPosArgument.getColumnPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Column(world, column.x, column.z); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2 vector = Vec2Argument.getVec2(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location2d(world, vector.x, vector.y); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPos block = BlockPosArgument.getLoadedBlockPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3 vector = Vec3Argument.getVec3(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - ResourceLocation resourceLocation = ResourceLocationArgument.getId(cast(context), key); - return new CraftLootTable(fromResourceLocation(resourceLocation), SERVER.getLootTables().get(resourceLocation)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ObjectiveArgument.getObjective(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ObjectiveCriteriaArgument.getCriteria(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleOptions particle = ParticleArgument.getParticle(cast(context), key); - return new ParticleHolder(CraftParticle.toBukkit(particle), particle, particle.writeToString()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - if (target == null) - throw GameProfileArgument.ERROR_UNKNOWN_PLAYER.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(MobEffectArgument.getEffect(cast(context), key)); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.item.crafting.Recipe recipe = ResourceLocationArgument.getRecipe(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2 rotation = RotationArgument.getRotation(cast(context), key).getRotation(cast(context).getSource()); - return new Rotation(rotation.x, rotation.y); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - ResourceLocation location = ResourceLocationArgument.getId(cast(context), key); - SoundEvent sound = Registry.SOUND_EVENT.get(location); - Sound bukkit = sound == null ? null : CraftSound.getBukkit(sound); - return new SoundHolder(bukkit, new NamespacedKey(location.getNamespace(), location.getPath())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return TeamArgument.getTeam(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - return UuidArgument.getUuid(cast(context), key); - } - - @Override - public Map getCompound(CommandContext context, String key) { - CompoundTag nbt = CompoundTagArgument.getCompoundTag(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(Tag tag) { - return switch (tag.getId()) { - case Tag.TAG_BYTE, Tag.TAG_SHORT, Tag.TAG_INT, Tag.TAG_LONG -> ((NumericTag) tag).getAsInt(); - case Tag.TAG_FLOAT, Tag.TAG_DOUBLE -> ((NumericTag) tag).getAsDouble(); - case Tag.TAG_STRING -> ((StringTag) tag).getAsString(); - case Tag.TAG_BYTE_ARRAY, Tag.TAG_INT_ARRAY, Tag.TAG_LONG_ARRAY, Tag.TAG_LIST -> convertList((CollectionTag) tag); - case Tag.TAG_COMPOUND -> (CompoundTag) convertMap((CompoundTag) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(CompoundTag nbt) { - Map temp = new HashMap<>(nbt.size()); - - for (String key : nbt.getAllKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(CollectionTag values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_17_R1.java b/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_17_R1.java deleted file mode 100644 index 93619e6dc..000000000 --- a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_17_R1.java +++ /dev/null @@ -1,98 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_17_R1; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.syncher.SynchedEntityData; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -public class Entity_1_17_R1 implements EntityCompatibility { - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.xOld, nms.yOld, nms.zOld); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_17_R1(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_17_R1(location, type, data); - } - - @Override - public int getId(Object obj) { - return ((ClientboundSetEntityDataPacket) obj).getId(); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - net.minecraft.world.entity.EquipmentSlot nmsSlot = switch (slot) { - case HEAD -> net.minecraft.world.entity.EquipmentSlot.HEAD; - case CHEST -> net.minecraft.world.entity.EquipmentSlot.CHEST; - case LEGS -> net.minecraft.world.entity.EquipmentSlot.LEGS; - case FEET -> net.minecraft.world.entity.EquipmentSlot.FEET; - case HAND -> net.minecraft.world.entity.EquipmentSlot.MAINHAND; - case OFF_HAND -> net.minecraft.world.entity.EquipmentSlot.OFFHAND; - }; - - List> temp = new ArrayList<>(1); - temp.add(new Pair<>(nmsSlot, CraftItemStack.asNMSCopy(item))); - ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(id, temp); - ((CraftPlayer) bukkit).getHandle().connection.send(packet); - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new ClientboundSetEntityDataPacket(entity.getId(), entity.getEntityData(), true); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) obj; - List> list = packet.getUnpackedData(); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).getValue().getClass() != Byte.class) - return; - - // noinspection unchecked - SynchedEntityData.DataItem item = (SynchedEntityData.DataItem) list.get(0); - byte data = item.getValue(); - data = meta.set(data, enabled); - item.setValue(data); - } - -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_17_R1.java b/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_17_R1.java deleted file mode 100644 index f44187317..000000000 --- a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_17_R1.java +++ /dev/null @@ -1,337 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.core.Rotations; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundAddMobPacket; -import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.decoration.ArmorStand; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FireworkRocketEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.PosRot; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.Rot; - -public class FakeEntity_1_17_R1 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EquipmentSlot[] SLOTS = EquipmentSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private BlockState block; - private ItemStack item; - - public FakeEntity_1_17_R1(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new ItemEntity(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> new FallingBlockEntity(world.getHandle(), x, y, z, block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle())); - case FIREWORK -> new FireworkRocketEntity(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - ArmorStand armorStand = (ArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getSharedFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setSharedFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> item.asBukkitCopy(); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((ItemEntity) entity).setItem(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosRaw(x, y, z); - entity.setYHeadRot(yaw); - entity.setYRot(yaw); - entity.setXRot(pitch); - } - - @Override - public void setMotion(double dx, double dy, double dz) { - ClientboundSetEntityMotionPacket packet = new ClientboundSetEntityMotionPacket(cache, new Vec3(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setYHeadRot(yaw); - entity.setXRot(yaw); - entity.setYRot(pitch); - - byte byteYaw = convertYaw(yaw); - Rot packet = new Rot(cache, byteYaw, convertPitch(pitch), false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket(entity); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PosRot packet = new PosRot(cache, dx, dy, dz, yaw, pitch, false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void show() { - Packet spawn = type.isAlive() - ? new ClientboundAddMobPacket((LivingEntity) entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0); - ClientboundSetEntityDataPacket meta = new ClientboundSetEntityDataPacket(cache, entity.getEntityData(), true); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(getYaw())); - Rot look = new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - ClientboundSetEntityMotionPacket velocity = new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ())); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - ServerGamePacketListenerImpl connection = ((CraftPlayer) temp).getHandle().connection; - if (connections.contains(connection)) { - continue; - } - - connection.send(spawn); - connection.send(meta); - connection.send(head); - connection.send(velocity); - connection.send(look); - if (equipment != null) - connection.send(equipment); - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - if (!player.isOnline()) - return; - - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - - connection.send(type.isAlive() - ? new ClientboundAddMobPacket((LivingEntity) entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0)); - connection.send(new ClientboundSetEntityDataPacket(cache, entity.getEntityData(), true)); - connection.send(new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.send(new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ()))); - connection.send(new ClientboundRotateHeadPacket(entity, convertYaw(getYaw()))); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - if (equipment != null) - connection.send(equipment); - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((ArmorStand) entity).setHeadPose(new Rotations(getPitch(), 0, 0)); - - sendPackets(new ClientboundSetEntityDataPacket(cache, entity.getEntityData(), false)); - } - - @Override - public void remove() { - sendPackets(new ClientboundRemoveEntitiesPacket(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - if (!player.isOnline()) - return; - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - connection.send(new ClientboundRemoveEntitiesPacket(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(@NotNull EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new ClientboundEntityEventPacket(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EquipmentSlot slot = switch (equipmentSlot) { - case HAND -> EquipmentSlot.MAINHAND; - case OFF_HAND -> EquipmentSlot.OFFHAND; - case FEET -> EquipmentSlot.FEET; - case CHEST -> EquipmentSlot.CHEST; - case LEGS -> EquipmentSlot.LEGS; - case HEAD -> EquipmentSlot.HEAD; - }; - - LivingEntity livingEntity = (LivingEntity) entity; - livingEntity.setItemSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - ClientboundSetEquipmentPacket packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private ClientboundSetEquipmentPacket getEquipmentPacket() { - if (!type.isAlive()) - return null; - LivingEntity livingEntity = (LivingEntity) entity; - - List> equipmentList = new ArrayList<>(6); - for (EquipmentSlot slot : SLOTS) { - ItemStack itemStack = livingEntity.getItemBySlot(slot); - if (!itemStack.isEmpty()) { - equipmentList.add(Pair.of(slot, itemStack)); - } - } - return equipmentList.isEmpty() ? null : new ClientboundSetEquipmentPacket(cache, equipmentList); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - ServerGamePacketListenerImpl connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.send(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_17_R1.java b/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_17_R1.java deleted file mode 100644 index cef11f76e..000000000 --- a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_17_R1.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -public class NonNullList_1_17_R1 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_17_R1(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.EMPTY); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.EMPTY); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_17_R1.java b/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_17_R1.java deleted file mode 100644 index a94de15db..000000000 --- a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_17_R1.java +++ /dev/null @@ -1,119 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import com.google.common.collect.Lists; -import com.google.gson.JsonElement; -import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.core.utils.StringUtil; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.StringTagVisitor; -import net.minecraft.nbt.Tag; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -public class NBT_1_17_R1 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.world.item.ItemStack nms = getNMSStack(toItem); - CompoundTag from = getNMSStack(fromItem).getTag(); - CompoundTag to = nms.getTag(); - - if (path == null) { - nms.setTag(from.copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - return; - } - - to.put(path, from.getCompound(path).copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.world.item.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - CompoundTag nbt = getNMSStack(bukkitStack).getTag(); - return nbt == null ? "null" : new TagColorVisitor().visit(nbt); - } - - @Override - public @NotNull Component getDisplayName(@NotNull ItemStack item) { - net.minecraft.network.chat.Component component = CraftItemStack.asNMSCopy(item).getDisplayName(); - JsonElement json = net.minecraft.network.chat.Component.Serializer.toJsonTree(component); - return GsonComponentSerializer.gson().serializer().fromJson(json, Component.class); - } - - private static class TagColorVisitor extends StringTagVisitor { - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - private final StringBuilder builder; - - // Stores how many nested compound tags there currently are. Used to - // determine curly brace color, as well as spacing. - private final int indents; - private final int colorOffset; - - public TagColorVisitor() { - this(0, 0); - } - - public TagColorVisitor(int indents, int colorOffset) { - Field field = ReflectionUtil.getField(StringTagVisitor.class, StringBuilder.class); - this.builder = (StringBuilder) ReflectionUtil.invokeField(field, this); - this.indents = indents; - this.colorOffset = colorOffset; - } - - @Override - public void visitCompound(CompoundTag compound) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - builder.append(braceColor).append("{\n"); - List list = Lists.newArrayList(compound.getAllKeys()); - Collections.sort(list); - - for (int i = 0; i < list.size(); i++) { - - // Add a new line after each element, and indent each line - // depending on the number of nested CompoundTags. - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - - String key = list.get(i); - Tag value = Objects.requireNonNull(compound.get(key), "This is impossible"); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - - builder.append(color).append(handleEscape(key)) - .append("&f&l: ").append(color) - .append(new TagColorVisitor(value instanceof CompoundTag ? indents + 1 : indents, colorOffset + i).visit(value)); - } - - builder.append(braceColor).append("}\n"); - } - } - - @Override - public @NotNull ItemStack getPlacementItem(@NotNull Block block) { - return new ItemStack(block.getBlockData().getMaterial()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/v1_17_R1.java b/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/v1_17_R1.java deleted file mode 100644 index 77605258c..000000000 --- a/CoreCompatibility/Core_1_17_R1/src/main/java/me/deecaad/core/compatibility/v1_17_R1.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_17_R1; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_17_R1; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_17_R1; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_17_R1; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_17_R1 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_17_R1() { - entityCompatibility = new Entity_1_17_R1(); - blockCompatibility = new Block_1_17_R1(); - nbtCompatibility = new NBT_1_17_R1(); - commandCompatibility = new Command_1_17_R1(); - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.world.entity.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).connection.send((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - ServerGamePacketListenerImpl playerConnection = getEntityPlayer(player).connection; - for (Object packet : packets) { - playerConnection.send((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull ServerPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_18_R2/build.gradle.kts b/CoreCompatibility/Core_1_18_R2/build.gradle.kts deleted file mode 100644 index 3587f8a5b..000000000 --- a/CoreCompatibility/Core_1_18_R2/build.gradle.kts +++ /dev/null @@ -1,20 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - adventureChatAPI() - - paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") -} - -java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_18_R2.java b/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_18_R2.java deleted file mode 100644 index d8b64ac5b..000000000 --- a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_18_R2.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import org.bukkit.block.Block; -import org.jetbrains.annotations.NotNull; - -// https://nms.screamingsandals.org/1.18.1/ -public class Block_1_18_R2 implements BlockCompatibility { - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPos pos = new BlockPos(block.getX(), block.getY(), block.getZ()); - return new ClientboundBlockDestructionPacket(id, pos, crack); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_18_R2.java b/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_18_R2.java deleted file mode 100644 index f244c052f..000000000 --- a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_18_R2.java +++ /dev/null @@ -1,633 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.*; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.*; -import net.minecraft.commands.arguments.item.FunctionArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemPredicateArgument; -import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentTypes; -import net.minecraft.commands.synchronization.SuggestionProviders; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Registry; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.nbt.Tag; -import net.minecraft.nbt.*; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ColumnPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.Vec3; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_18_R2.CraftLootTable; -import org.bukkit.craftbukkit.v1_18_R2.CraftParticle; -import org.bukkit.craftbukkit.v1_18_R2.CraftServer; -import org.bukkit.craftbukkit.v1_18_R2.CraftSound; -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_18_R2.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_18_R2.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_18_R2 implements CommandCompatibility { - - public static final MinecraftServer SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - private static final DynamicCommandExceptionType ERROR_BIOME_INVALID = new DynamicCommandExceptionType(arg -> new TranslatableComponent("commands.locate.biome.invalid", arg)); - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - ServerPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.sendCommands(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentTypes.serializeNodeToJson(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandSourceStack) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.getDispatcher(); - } - - @Override - public ArgumentType angle() { - return AngleArgument.angle(); - } - - @Override - public ArgumentType axis() { - return SwizzleArgument.swizzle(); - } - - @Override - public ArgumentType blockPredicate() { - return BlockPredicateArgument.blockPredicate(); - } - - @Override - public ArgumentType blockState() { - return BlockStateArgument.block(); - } - - @Override - public ArgumentType chat() { - return MessageArgument.message(); - } - - @Override - public ArgumentType chatComponent() { - return ComponentArgument.textComponent(); - } - - @Override - public ArgumentType chatFormat() { - return ColorArgument.color(); - } - - @Override - public ArgumentType dimension() { - return DimensionArgument.dimension(); - } - - @Override - public ArgumentType enchantment() { - return ItemEnchantmentArgument.enchantment(); - } - - @Override - public ArgumentType entity() { - return EntityArgument.entity(); - } - - @Override - public ArgumentType entities() { - return EntityArgument.entities(); - } - - @Override - public ArgumentType player() { - return EntityArgument.player(); - } - - @Override - public ArgumentType players() { - return EntityArgument.players(); - } - - @Override - public ArgumentType entitySummon() { - return EntitySummonArgument.id(); - } - - @Override - public ArgumentType itemPredicate() { - return ItemPredicateArgument.itemPredicate(); - } - - @Override - public ArgumentType itemStack() { - return ItemArgument.item(); - } - - @Override - public ArgumentType mathOperation() { - return OperationArgument.operation(); - } - - @Override - public ArgumentType mobEffect() { - return MobEffectArgument.effect(); - } - - @Override - public ArgumentType nbtCompound() { - return CompoundTagArgument.compoundTag(); - } - - @Override - public ArgumentType particle() { - return ParticleArgument.particle(); - } - - @Override - public ArgumentType profile() { - return GameProfileArgument.gameProfile(); - } - - @Override - public ArgumentType rotation() { - return RotationArgument.rotation(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ObjectiveCriteriaArgument.criteria(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ObjectiveArgument.objective(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ScoreboardSlotArgument.displaySlot(); - } - - @Override - public ArgumentType scoreboardTeam() { - return TeamArgument.team(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ScoreHolderArgument.scoreHolder() : ScoreHolderArgument.scoreHolders(); - } - - @Override - public ArgumentType tag() { - return FunctionArgument.functions(); - } - - @Override - public ArgumentType time() { - return TimeArgument.time(); - } - - @Override - public ArgumentType uuid() { - return UuidArgument.uuid(); - } - - @Override - public ArgumentType location() { - return Vec3Argument.vec3(); - } - - @Override - public ArgumentType location2() { - return Vec2Argument.vec2(); - } - - @Override - public ArgumentType block() { - return BlockPosArgument.blockPos(); - } - - @Override - public ArgumentType block2() { - return ColumnPosArgument.columnPos(); - } - - @Override - public ArgumentType biome() { - return ResourceOrTagLocationArgument.resourceOrTag(Registry.BIOME_REGISTRY); // this is actually only changed 1.18R2 and up - } - - @Override - public ArgumentType key() { - return ResourceLocationArgument.id(); - } - - @Override - public SuggestionProvider biomeKey() { - return biome()::listSuggestions; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) SuggestionProviders.ALL_RECIPES; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) SuggestionProviders.AVAILABLE_SOUNDS; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) SuggestionProviders.SUMMONABLE_ENTITIES; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getAdvancements().getAllAdvancements().stream().map(net.minecraft.advancements.Advancement::getId), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getLootTables().getIds(), builder); - } - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getAdvancement(cast(context), key).bukkit; - } - - @Override - public float getAngle(CommandContext context, String key) { - return AngleArgument.getAngle(cast(context), key); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = SwizzleArgument.getSwizzle(cast(context), key); - - for (Direction.Axis axis : nmsAxis) { - bukkitAxis.add(switch (axis) { - case X -> Axis.X; - case Y -> Axis.Y; - case Z -> Axis.Z; - }); - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - ResourceOrTagLocationArgument.Result biomeResult = ResourceOrTagLocationArgument.getBiome(cast(context), key); - - String name = biomeResult.asPrintable(); - - if (biomeResult.unwrap().left().isPresent()) { - ResourceKey resource = biomeResult.unwrap().left().get(); - Biome biome = EnumUtil.getIfPresent(Biome.class, resource.location().getPath()).orElse(Biome.CUSTOM); - NamespacedKey namespaced = new NamespacedKey(resource.location().getNamespace(), resource.location().getPath()); - return new BiomeHolder(biome, namespaced); - } else { - throw ERROR_BIOME_INVALID.create(name); - } - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cast(context), key); - return block -> predicate.test(new BlockInWorld(cast(context).getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cast(context), key).getState()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - return DimensionArgument.getDimension(cast(context), key).getWorld().getEnvironment(); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) { - return new CraftEnchantment(ItemEnchantmentArgument.getEnchantment(cast(context), key)); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSingleEntity(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSinglePlayer(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findPlayers(source).stream() - .map(ServerPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.entity.EntityType type = Registry.ENTITY_TYPE.get(EntitySummonArgument.getSummonableEntity(cast(context), key)); - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(type).getPath()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cast(context), key); - double min = range.getMin() == null ? Double.MIN_VALUE : range.getMin(); - double max = range.getMax() == null ? Double.MAX_VALUE : range.getMax(); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cast(context), key); - int min = range.getMin() == null ? Integer.MIN_VALUE : range.getMin(); - int max = range.getMax() == null ? Integer.MAX_VALUE : range.getMax(); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ItemArgument.getItem(cast(context), key).createItemStack(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ItemPredicateArgument.getItemPredicate(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getId(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - ColumnPos column = ColumnPosArgument.getColumnPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Column(world, column.x, column.z); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2 vector = Vec2Argument.getVec2(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location2d(world, vector.x, vector.y); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPos block = BlockPosArgument.getLoadedBlockPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3 vector = Vec3Argument.getVec3(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - ResourceLocation resourceLocation = ResourceLocationArgument.getId(cast(context), key); - return new CraftLootTable(fromResourceLocation(resourceLocation), SERVER.getLootTables().get(resourceLocation)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ObjectiveArgument.getObjective(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ObjectiveCriteriaArgument.getCriteria(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleOptions particle = ParticleArgument.getParticle(cast(context), key); - return new ParticleHolder(CraftParticle.toBukkit(particle), particle, particle.writeToString()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - if (target == null) - throw GameProfileArgument.ERROR_UNKNOWN_PLAYER.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(MobEffectArgument.getEffect(cast(context), key)); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.item.crafting.Recipe recipe = ResourceLocationArgument.getRecipe(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2 rotation = RotationArgument.getRotation(cast(context), key).getRotation(cast(context).getSource()); - return new Rotation(rotation.x, rotation.y); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - ResourceLocation location = ResourceLocationArgument.getId(cast(context), key); - SoundEvent sound = Registry.SOUND_EVENT.get(location); - Sound bukkit = sound == null ? null : CraftSound.getBukkit(sound); - return new SoundHolder(bukkit, new NamespacedKey(location.getNamespace(), location.getPath())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return TeamArgument.getTeam(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - return UuidArgument.getUuid(cast(context), key); - } - - @Override - public Map getCompound(CommandContext context, String key) { - CompoundTag nbt = CompoundTagArgument.getCompoundTag(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(Tag tag) { - return switch (tag.getId()) { - case Tag.TAG_BYTE, Tag.TAG_SHORT, Tag.TAG_INT, Tag.TAG_LONG -> ((NumericTag) tag).getAsInt(); - case Tag.TAG_FLOAT, Tag.TAG_DOUBLE -> ((NumericTag) tag).getAsDouble(); - case Tag.TAG_STRING -> ((StringTag) tag).getAsString(); - case Tag.TAG_BYTE_ARRAY, Tag.TAG_INT_ARRAY, Tag.TAG_LONG_ARRAY, Tag.TAG_LIST -> convertList((CollectionTag) tag); - case Tag.TAG_COMPOUND -> convertMap((CompoundTag) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(CompoundTag nbt) { - Map temp = new HashMap<>(nbt.size()); - - for (String key : nbt.getAllKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(CollectionTag values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_18_R2.java b/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_18_R2.java deleted file mode 100644 index eb4a7930e..000000000 --- a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_18_R2.java +++ /dev/null @@ -1,98 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_18_R2; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.syncher.SynchedEntityData; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -// https://nms.screamingsandals.org/1.18.1/ -public class Entity_1_18_R2 implements EntityCompatibility { - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.xOld, nms.yOld, nms.zOld); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_18_R2(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_18_R2(location, type, data); - } - - @Override - public int getId(Object obj) { - return ((ClientboundSetEntityDataPacket) obj).getId(); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - net.minecraft.world.entity.EquipmentSlot nmsSlot = switch (slot) { - case HEAD -> net.minecraft.world.entity.EquipmentSlot.HEAD; - case CHEST -> net.minecraft.world.entity.EquipmentSlot.CHEST; - case LEGS -> net.minecraft.world.entity.EquipmentSlot.LEGS; - case FEET -> net.minecraft.world.entity.EquipmentSlot.FEET; - case HAND -> net.minecraft.world.entity.EquipmentSlot.MAINHAND; - case OFF_HAND -> net.minecraft.world.entity.EquipmentSlot.OFFHAND; - }; - - List> temp = new ArrayList<>(1); - temp.add(new Pair<>(nmsSlot, CraftItemStack.asNMSCopy(item))); - ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(id, temp); - ((CraftPlayer) bukkit).getHandle().connection.send(packet); - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new ClientboundSetEntityDataPacket(entity.getId(), entity.getEntityData(), true); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) obj; - List> list = packet.getUnpackedData(); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).getValue().getClass() != Byte.class) - return; - - // noinspection unchecked - SynchedEntityData.DataItem item = (SynchedEntityData.DataItem) list.get(0); - byte data = item.getValue(); - data = meta.set(data, enabled); - item.setValue(data); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_18_R2.java b/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_18_R2.java deleted file mode 100644 index ce5129ef1..000000000 --- a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_18_R2.java +++ /dev/null @@ -1,342 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.core.Rotations; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundAddMobPacket; -import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.decoration.ArmorStand; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FireworkRocketEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_18_R2.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.PosRot; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.Rot; - -public class FakeEntity_1_18_R2 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EquipmentSlot[] SLOTS = EquipmentSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private BlockState block; - private ItemStack item; - - public FakeEntity_1_18_R2(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new ItemEntity(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> { - FallingBlockEntity temp = new FallingBlockEntity(net.minecraft.world.entity.EntityType.FALLING_BLOCK, world.getHandle()); - temp.setPosRaw(x, y, z); - block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle()); - yield temp; - } - case FIREWORK -> new FireworkRocketEntity(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - ArmorStand armorStand = (ArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getSharedFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setSharedFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> item.asBukkitCopy(); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((ItemEntity) entity).setItem(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosRaw(x, y, z); - entity.setYHeadRot(yaw); - entity.setYRot(yaw); - entity.setXRot(pitch); - } - - @Override - public void setMotion(double dx, double dy, double dz) { - ClientboundSetEntityMotionPacket packet = new ClientboundSetEntityMotionPacket(cache, new Vec3(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setYHeadRot(yaw); - entity.setXRot(yaw); - entity.setYRot(pitch); - - byte byteYaw = convertYaw(yaw); - Rot packet = new Rot(cache, byteYaw, convertPitch(pitch), false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket(entity); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PosRot packet = new PosRot(cache, dx, dy, dz, yaw, pitch, false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void show() { - Packet spawn = type.isAlive() - ? new ClientboundAddMobPacket((LivingEntity) entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0); - ClientboundSetEntityDataPacket meta = new ClientboundSetEntityDataPacket(cache, entity.getEntityData(), true); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(getYaw())); - Rot look = new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - ClientboundSetEntityMotionPacket velocity = new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ())); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - ServerGamePacketListenerImpl connection = ((CraftPlayer) temp).getHandle().connection; - if (connections.contains(connection)) { - continue; - } - - connection.send(spawn); - connection.send(meta); - connection.send(head); - connection.send(velocity); - connection.send(look); - if (equipment != null) - connection.send(equipment); - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - if (!player.isOnline()) - return; - - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - - connection.send(type.isAlive() - ? new ClientboundAddMobPacket((LivingEntity) entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0)); - connection.send(new ClientboundSetEntityDataPacket(cache, entity.getEntityData(), true)); - connection.send(new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.send(new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ()))); - connection.send(new ClientboundRotateHeadPacket(entity, convertYaw(getYaw()))); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - if (equipment != null) - connection.send(equipment); - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((ArmorStand) entity).setHeadPose(new Rotations(getPitch(), 0, 0)); - - sendPackets(new ClientboundSetEntityDataPacket(cache, entity.getEntityData(), false)); - } - - @Override - public void remove() { - sendPackets(new ClientboundRemoveEntitiesPacket(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - if (!player.isOnline()) - return; - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - connection.send(new ClientboundRemoveEntitiesPacket(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(@NotNull EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new ClientboundEntityEventPacket(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EquipmentSlot slot = switch (equipmentSlot) { - case HAND -> EquipmentSlot.MAINHAND; - case OFF_HAND -> EquipmentSlot.OFFHAND; - case FEET -> EquipmentSlot.FEET; - case CHEST -> EquipmentSlot.CHEST; - case LEGS -> EquipmentSlot.LEGS; - case HEAD -> EquipmentSlot.HEAD; - }; - - LivingEntity livingEntity = (LivingEntity) entity; - livingEntity.setItemSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - ClientboundSetEquipmentPacket packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private ClientboundSetEquipmentPacket getEquipmentPacket() { - if (!type.isAlive()) - return null; - LivingEntity livingEntity = (LivingEntity) entity; - - List> equipmentList = new ArrayList<>(6); - for (EquipmentSlot slot : SLOTS) { - ItemStack itemStack = livingEntity.getItemBySlot(slot); - if (!itemStack.isEmpty()) { - equipmentList.add(Pair.of(slot, itemStack)); - } - } - return equipmentList.isEmpty() ? null : new ClientboundSetEquipmentPacket(cache, equipmentList); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - ServerGamePacketListenerImpl connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.send(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_18_R2.java b/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_18_R2.java deleted file mode 100644 index 4a2512cb5..000000000 --- a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_18_R2.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -// https://nms.screamingsandals.org/1.18.1/ -public class NonNullList_1_18_R2 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_18_R2(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.EMPTY); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.EMPTY); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_18_R2.java b/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_18_R2.java deleted file mode 100644 index 0b8db3dc0..000000000 --- a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_18_R2.java +++ /dev/null @@ -1,120 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import com.google.common.collect.Lists; -import com.google.gson.JsonElement; -import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.core.utils.StringUtil; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.StringTagVisitor; -import net.minecraft.nbt.Tag; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -// https://nms.screamingsandals.org/1.18.1/ -public class NBT_1_18_R2 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.world.item.ItemStack nms = getNMSStack(toItem); - CompoundTag from = getNMSStack(fromItem).getTag(); - CompoundTag to = nms.getTag(); - - if (path == null) { - nms.setTag(from.copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - return; - } - - to.put(path, from.getCompound(path).copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.world.item.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - CompoundTag nbt = getNMSStack(bukkitStack).getTag(); - return nbt == null ? "null" : new TagColorVisitor().visit(nbt); - } - - @Override - public @NotNull Component getDisplayName(@NotNull ItemStack item) { - net.minecraft.network.chat.Component component = CraftItemStack.asNMSCopy(item).getDisplayName(); - JsonElement json = net.minecraft.network.chat.Component.Serializer.toJsonTree(component); - return GsonComponentSerializer.gson().serializer().fromJson(json, Component.class); - } - - private static class TagColorVisitor extends StringTagVisitor { - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - private final StringBuilder builder; - - // Stores how many nested compound tags there currently are. Used to - // determine curly brace color, as well as spacing. - private final int indents; - private final int colorOffset; - - public TagColorVisitor() { - this(0, 0); - } - - public TagColorVisitor(int indents, int colorOffset) { - Field field = ReflectionUtil.getField(StringTagVisitor.class, StringBuilder.class); - this.builder = (StringBuilder) ReflectionUtil.invokeField(field, this); - this.indents = indents; - this.colorOffset = colorOffset; - } - - @Override - public void visitCompound(CompoundTag compound) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - builder.append(braceColor).append("{\n"); - List list = Lists.newArrayList(compound.getAllKeys()); - Collections.sort(list); - - for (int i = 0; i < list.size(); i++) { - - // Add a new line after each element, and indent each line - // depending on the number of nested CompoundTags. - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - - String key = list.get(i); - Tag value = Objects.requireNonNull(compound.get(key), "This is impossible"); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - - builder.append(color).append(handleEscape(key)) - .append("&f&l: ").append(color) - .append(new TagColorVisitor(value instanceof CompoundTag ? indents + 1 : indents, colorOffset + i).visit(value)); - } - - builder.append(braceColor).append("}\n"); - } - } - - @Override - public @NotNull ItemStack getPlacementItem(@NotNull Block block) { - return new ItemStack(block.getBlockData().getMaterial()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/v1_18_R2.java b/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/v1_18_R2.java deleted file mode 100644 index 5a686f39e..000000000 --- a/CoreCompatibility/Core_1_18_R2/src/main/java/me/deecaad/core/compatibility/v1_18_R2.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_18_R2; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_18_R2; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_18_R2; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_18_R2; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_18_R2 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_18_R2() { - entityCompatibility = new Entity_1_18_R2(); - blockCompatibility = new Block_1_18_R2(); - nbtCompatibility = new NBT_1_18_R2(); - commandCompatibility = new Command_1_18_R2(); - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.world.entity.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).connection.send((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - ServerGamePacketListenerImpl playerConnection = getEntityPlayer(player).connection; - for (Object packet : packets) { - playerConnection.send((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull ServerPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_19_R3/build.gradle.kts b/CoreCompatibility/Core_1_19_R3/build.gradle.kts deleted file mode 100644 index e5542906a..000000000 --- a/CoreCompatibility/Core_1_19_R3/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - adventureChatAPI() - - paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") -} - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_19_R3.java b/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_19_R3.java deleted file mode 100644 index edeb5ef98..000000000 --- a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_19_R3.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import org.bukkit.block.Block; -import org.jetbrains.annotations.NotNull; - -// https://nms.screamingsandals.org/1.19.1/ -public class Block_1_19_R3 implements BlockCompatibility { - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPos pos = new BlockPos(block.getX(), block.getY(), block.getZ()); - return new ClientboundBlockDestructionPacket(id, pos, crack); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_19_R3.java b/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_19_R3.java deleted file mode 100644 index fcfcea773..000000000 --- a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_19_R3.java +++ /dev/null @@ -1,635 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.commands.CommandBuildContext; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.*; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.*; -import net.minecraft.commands.arguments.item.FunctionArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemPredicateArgument; -import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentUtils; -import net.minecraft.commands.synchronization.SuggestionProviders; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Holder; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.Tag; -import net.minecraft.nbt.*; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ColumnPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.Vec3; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_19_R3.CraftLootTable; -import org.bukkit.craftbukkit.v1_19_R3.CraftParticle; -import org.bukkit.craftbukkit.v1_19_R3.CraftServer; -import org.bukkit.craftbukkit.v1_19_R3.CraftSound; -import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_19_R3.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_19_R3.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_19_R3 implements CommandCompatibility { - - public static final MinecraftServer SERVER; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; - private static final DynamicCommandExceptionType ERROR_BIOME_INVALID; - - static { - SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - COMMAND_BUILD_CONTEXT = CommandBuildContext.configurable(SERVER.registryAccess(), SERVER.getWorldData().getDataConfiguration().enabledFeatures()); - ERROR_BIOME_INVALID = new DynamicCommandExceptionType( - arg -> net.minecraft.network.chat.Component.translatable("commands.locate.biome.invalid", arg)); - } - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - ServerPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.sendCommands(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandSourceStack) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.getDispatcher(); - } - - @Override - public ArgumentType angle() { - return AngleArgument.angle(); - } - - @Override - public ArgumentType axis() { - return SwizzleArgument.swizzle(); - } - - @Override - public ArgumentType blockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType blockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType chat() { - return MessageArgument.message(); - } - - @Override - public ArgumentType chatComponent() { - return ComponentArgument.textComponent(); - } - - @Override - public ArgumentType chatFormat() { - return ColorArgument.color(); - } - - @Override - public ArgumentType dimension() { - return DimensionArgument.dimension(); - } - - @Override - public ArgumentType enchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); - } - - @Override - public ArgumentType entity() { - return EntityArgument.entity(); - } - - @Override - public ArgumentType entities() { - return EntityArgument.entities(); - } - - @Override - public ArgumentType player() { - return EntityArgument.player(); - } - - @Override - public ArgumentType players() { - return EntityArgument.players(); - } - - @Override - public ArgumentType entitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public ArgumentType itemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType itemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType mathOperation() { - return OperationArgument.operation(); - } - - @Override - public ArgumentType mobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); - } - - @Override - public ArgumentType nbtCompound() { - return CompoundTagArgument.compoundTag(); - } - - @Override - public ArgumentType particle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType profile() { - return GameProfileArgument.gameProfile(); - } - - @Override - public ArgumentType rotation() { - return RotationArgument.rotation(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ObjectiveCriteriaArgument.criteria(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ObjectiveArgument.objective(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ScoreboardSlotArgument.displaySlot(); - } - - @Override - public ArgumentType scoreboardTeam() { - return TeamArgument.team(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ScoreHolderArgument.scoreHolder() : ScoreHolderArgument.scoreHolders(); - } - - @Override - public ArgumentType tag() { - return FunctionArgument.functions(); - } - - @Override - public ArgumentType time() { - return TimeArgument.time(); - } - - @Override - public ArgumentType uuid() { - return UuidArgument.uuid(); - } - - @Override - public ArgumentType location() { - return Vec3Argument.vec3(); - } - - @Override - public ArgumentType location2() { - return Vec2Argument.vec2(); - } - - @Override - public ArgumentType block() { - return BlockPosArgument.blockPos(); - } - - @Override - public ArgumentType block2() { - return ColumnPosArgument.columnPos(); - } - - @Override - public ArgumentType biome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); - } - - @Override - public ArgumentType key() { - return ResourceLocationArgument.id(); - } - - @Override - public SuggestionProvider biomeKey() { - return biome()::listSuggestions; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) SuggestionProviders.ALL_RECIPES; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) SuggestionProviders.AVAILABLE_SOUNDS; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) SuggestionProviders.SUMMONABLE_ENTITIES; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getAdvancements().getAllAdvancements().stream().map(net.minecraft.advancements.Advancement::getId), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getLootTables().getIds(), builder); - } - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getAdvancement(cast(context), key).bukkit; - } - - @Override - public float getAngle(CommandContext context, String key) { - return AngleArgument.getAngle(cast(context), key); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = SwizzleArgument.getSwizzle(cast(context), key); - - for (Direction.Axis axis : nmsAxis) { - bukkitAxis.add(switch (axis) { - case X -> Axis.X; - case Y -> Axis.Y; - case Z -> Axis.Z; - }); - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference holder = ResourceArgument.getResource(cast(context), key, Registries.BIOME); - ResourceLocation location = holder.key().location(); - Biome bukkit = EnumUtil.getIfPresent(Biome.class, location.getPath()).orElse(Biome.CUSTOM); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getPath()); - return new BiomeHolder(bukkit, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cast(context), key); - return block -> predicate.test(new BlockInWorld(cast(context).getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cast(context), key).getState()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - return DimensionArgument.getDimension(cast(context), key).getWorld().getEnvironment(); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) throws CommandSyntaxException { - return new CraftEnchantment(ResourceArgument.getEnchantment(cast(context), key).value()); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSingleEntity(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSinglePlayer(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findPlayers(source).stream() - .map(ServerPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.entity.EntityType type = ResourceArgument.getEntityType(cast(context), key).value(); - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(type).getPath()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cast(context), key); - double min = range.getMin() == null ? Double.MIN_VALUE : range.getMin(); - double max = range.getMax() == null ? Double.MAX_VALUE : range.getMax(); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cast(context), key); - int min = range.getMin() == null ? Integer.MIN_VALUE : range.getMin(); - int max = range.getMax() == null ? Integer.MAX_VALUE : range.getMax(); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ItemArgument.getItem(cast(context), key).createItemStack(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ItemPredicateArgument.getItemPredicate(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getId(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - ColumnPos column = ColumnPosArgument.getColumnPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Column(world, column.x(), column.z()); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2 vector = Vec2Argument.getVec2(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location2d(world, vector.x, vector.y); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPos block = BlockPosArgument.getLoadedBlockPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3 vector = Vec3Argument.getVec3(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - ResourceLocation resourceLocation = ResourceLocationArgument.getId(cast(context), key); - return new CraftLootTable(fromResourceLocation(resourceLocation), SERVER.getLootTables().get(resourceLocation)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ObjectiveArgument.getObjective(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ObjectiveCriteriaArgument.getCriteria(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleOptions particle = ParticleArgument.getParticle(cast(context), key); - return new ParticleHolder(CraftParticle.toBukkit(particle), particle, particle.writeToString()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - if (target == null) - throw GameProfileArgument.ERROR_UNKNOWN_PLAYER.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(ResourceArgument.getMobEffect(cast(context), key).value()); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.item.crafting.Recipe recipe = ResourceLocationArgument.getRecipe(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2 rotation = RotationArgument.getRotation(cast(context), key).getRotation(cast(context).getSource()); - return new Rotation(rotation.x, rotation.y); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - ResourceLocation location = ResourceLocationArgument.getId(cast(context), key); - SoundEvent sound = BuiltInRegistries.SOUND_EVENT.get(location); - Sound bukkit = sound == null ? null : CraftSound.getBukkit(sound); - return new SoundHolder(bukkit, new NamespacedKey(location.getNamespace(), location.getPath())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return TeamArgument.getTeam(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - return UuidArgument.getUuid(cast(context), key); - } - - @Override - public Map getCompound(CommandContext context, String key) { - CompoundTag nbt = CompoundTagArgument.getCompoundTag(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(Tag tag) { - return switch (tag.getId()) { - case Tag.TAG_BYTE, Tag.TAG_SHORT, Tag.TAG_INT, Tag.TAG_LONG -> ((NumericTag) tag).getAsInt(); - case Tag.TAG_FLOAT, Tag.TAG_DOUBLE -> ((NumericTag) tag).getAsDouble(); - case Tag.TAG_STRING -> ((StringTag) tag).getAsString(); - case Tag.TAG_BYTE_ARRAY, Tag.TAG_INT_ARRAY, Tag.TAG_LONG_ARRAY, Tag.TAG_LIST -> convertList((CollectionTag) tag); - case Tag.TAG_COMPOUND -> convertMap((CompoundTag) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(CompoundTag nbt) { - Map temp = new HashMap<>(nbt.size()); - - for (String key : nbt.getAllKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(CollectionTag values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_19_R3.java b/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_19_R3.java deleted file mode 100644 index 79fb9068b..000000000 --- a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_19_R3.java +++ /dev/null @@ -1,120 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_19_R3; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.syncher.SynchedEntityData; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -// https://nms.screamingsandals.org/1.18.1/ -public class Entity_1_19_R3 implements EntityCompatibility { - - public static final Field itemsById = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.xOld, nms.yOld, nms.zOld); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_19_R3(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_19_R3(location, type, data); - } - - @Override - public int getId(Object obj) { - return ((ClientboundSetEntityDataPacket) obj).id(); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - net.minecraft.world.entity.EquipmentSlot nmsSlot = switch (slot) { - case HEAD -> net.minecraft.world.entity.EquipmentSlot.HEAD; - case CHEST -> net.minecraft.world.entity.EquipmentSlot.CHEST; - case LEGS -> net.minecraft.world.entity.EquipmentSlot.LEGS; - case FEET -> net.minecraft.world.entity.EquipmentSlot.FEET; - case HAND -> net.minecraft.world.entity.EquipmentSlot.MAINHAND; - case OFF_HAND -> net.minecraft.world.entity.EquipmentSlot.OFFHAND; - }; - - List> temp = new ArrayList<>(1); - temp.add(new Pair<>(nmsSlot, CraftItemStack.asNMSCopy(item))); - ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(id, temp); - ((CraftPlayer) bukkit).getHandle().connection.send(packet); - } - - public static List> getEntityData(SynchedEntityData data, boolean forceUpdateAll) { - if (!forceUpdateAll) { - List> dirty = data.packDirty(); - return dirty == null ? List.of() : dirty; - } - - // 1.19.3 changed the packet arguments, so in order to unpack ALL data - // (not just the dirty data) we need to manually get it and unpack it. - Int2ObjectMap> metaData = (Int2ObjectMap>) ReflectionUtil.invokeField(itemsById, data); - List> packed = new ArrayList<>(metaData.size()); - for (SynchedEntityData.DataItem element : metaData.values()) - packed.add(element.value()); - return packed; - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new ClientboundSetEntityDataPacket(entity.getId(), getEntityData(entity.getEntityData(), true)); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) obj; - List> list = packet.packedItems(); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).value().getClass() != Byte.class) - return; - - // noinspection unchecked - SynchedEntityData.DataValue item = (SynchedEntityData.DataValue) list.get(0); - byte data = item.value(); - data = meta.set(data, enabled); - - // 1.19.3 changed this to a record - list.set(0, new SynchedEntityData.DataValue<>(item.id(), item.serializer(), data)); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_19_R3.java b/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_19_R3.java deleted file mode 100644 index 5806f73f5..000000000 --- a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_19_R3.java +++ /dev/null @@ -1,343 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.core.Rotations; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.decoration.ArmorStand; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FireworkRocketEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_19_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_19_R3.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static me.deecaad.core.compatibility.entity.Entity_1_19_R3.getEntityData; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.PosRot; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.Rot; - -public class FakeEntity_1_19_R3 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EquipmentSlot[] SLOTS = EquipmentSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private BlockState block; - private ItemStack item; - - public FakeEntity_1_19_R3(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new ItemEntity(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> { - FallingBlockEntity temp = new FallingBlockEntity(net.minecraft.world.entity.EntityType.FALLING_BLOCK, world.getHandle()); - temp.setPosRaw(x, y, z); - block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle()); - yield temp; - } - case FIREWORK -> new FireworkRocketEntity(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - ArmorStand armorStand = (ArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getSharedFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setSharedFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> item.asBukkitCopy(); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((ItemEntity) entity).setItem(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosRaw(x, y, z); - entity.setYHeadRot(yaw); - entity.setYRot(yaw); - entity.setXRot(pitch); - } - - @Override - public void setMotion(double dx, double dy, double dz) { - ClientboundSetEntityMotionPacket packet = new ClientboundSetEntityMotionPacket(cache, new Vec3(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setYHeadRot(yaw); - entity.setXRot(yaw); - entity.setYRot(pitch); - - byte byteYaw = convertYaw(yaw); - Rot packet = new Rot(cache, byteYaw, convertPitch(pitch), false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket(entity); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PosRot packet = new PosRot(cache, dx, dy, dz, yaw, pitch, false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void show() { - Packet spawn = type.isAlive() - ? new ClientboundAddEntityPacket(entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0); - - ClientboundSetEntityDataPacket meta = new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false)); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(getYaw())); - Rot look = new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - ClientboundSetEntityMotionPacket velocity = new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ())); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - ServerGamePacketListenerImpl connection = ((CraftPlayer) temp).getHandle().connection; - if (connections.contains(connection)) { - continue; - } - - connection.send(spawn); - connection.send(meta); - connection.send(head); - connection.send(velocity); - connection.send(look); - if (equipment != null) - connection.send(equipment); - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - if (!player.isOnline()) - return; - - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - - connection.send(type.isAlive() - ? new ClientboundAddEntityPacket(entity) // TODO CHECK THIS... used to be "addmob", changed in 1.19? - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0)); - connection.send(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), true))); - connection.send(new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.send(new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ()))); - connection.send(new ClientboundRotateHeadPacket(entity, convertYaw(getYaw()))); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - if (equipment != null) - connection.send(equipment); - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((ArmorStand) entity).setHeadPose(new Rotations(getPitch(), 0, 0)); - - sendPackets(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false))); - } - - @Override - public void remove() { - sendPackets(new ClientboundRemoveEntitiesPacket(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - if (!player.isOnline()) - return; - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - connection.send(new ClientboundRemoveEntitiesPacket(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(@NotNull EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new ClientboundEntityEventPacket(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EquipmentSlot slot = switch (equipmentSlot) { - case HAND -> EquipmentSlot.MAINHAND; - case OFF_HAND -> EquipmentSlot.OFFHAND; - case FEET -> EquipmentSlot.FEET; - case CHEST -> EquipmentSlot.CHEST; - case LEGS -> EquipmentSlot.LEGS; - case HEAD -> EquipmentSlot.HEAD; - }; - - LivingEntity livingEntity = (LivingEntity) entity; - livingEntity.setItemSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - ClientboundSetEquipmentPacket packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private ClientboundSetEquipmentPacket getEquipmentPacket() { - if (!type.isAlive()) - return null; - LivingEntity livingEntity = (LivingEntity) entity; - - List> equipmentList = new ArrayList<>(6); - for (EquipmentSlot slot : SLOTS) { - ItemStack itemStack = livingEntity.getItemBySlot(slot); - if (!itemStack.isEmpty()) { - equipmentList.add(Pair.of(slot, itemStack)); - } - } - return equipmentList.isEmpty() ? null : new ClientboundSetEquipmentPacket(cache, equipmentList); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - ServerGamePacketListenerImpl connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.send(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_19_R3.java b/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_19_R3.java deleted file mode 100644 index 7b13b6aba..000000000 --- a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_19_R3.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -// https://nms.screamingsandals.org/1.19.1/ -public class NonNullList_1_19_R3 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_19_R3(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.EMPTY); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.EMPTY); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_19_R3.java b/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_19_R3.java deleted file mode 100644 index 25960a32e..000000000 --- a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_19_R3.java +++ /dev/null @@ -1,114 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import com.google.common.collect.Lists; -import com.google.gson.JsonElement; -import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.core.utils.StringUtil; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.StringTagVisitor; -import net.minecraft.nbt.Tag; -import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -// https://nms.screamingsandals.org/1.19_R1 -public class NBT_1_19_R3 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.world.item.ItemStack nms = getNMSStack(toItem); - CompoundTag from = getNMSStack(fromItem).getTag(); - CompoundTag to = nms.getTag(); - - if (path == null) { - nms.setTag(from.copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - return; - } - - to.put(path, from.getCompound(path).copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.world.item.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - CompoundTag nbt = getNMSStack(bukkitStack).getTag(); - return nbt == null ? "null" : new TagColorVisitor().visit(nbt); - } - - @Override - public @NotNull Component getDisplayName(@NotNull ItemStack item) { - net.minecraft.network.chat.Component component = CraftItemStack.asNMSCopy(item).getDisplayName(); - JsonElement json = net.minecraft.network.chat.Component.Serializer.toJsonTree(component); - return GsonComponentSerializer.gson().serializer().fromJson(json, Component.class); - } - - private static class TagColorVisitor extends StringTagVisitor { - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - private final StringBuilder builder; - - // Stores how many nested compound tags there currently are. Used to - // determine curly brace color, as well as spacing. - private final int indents; - private final int colorOffset; - - public TagColorVisitor() { - this(0, 0); - } - - public TagColorVisitor(int indents, int colorOffset) { - Field field = ReflectionUtil.getField(StringTagVisitor.class, StringBuilder.class); - this.builder = (StringBuilder) ReflectionUtil.invokeField(field, this); - this.indents = indents; - this.colorOffset = colorOffset; - } - - @Override - public void visitCompound(CompoundTag compound) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - builder.append(braceColor).append("{\n"); - List list = Lists.newArrayList(compound.getAllKeys()); - Collections.sort(list); - - for (int i = 0; i < list.size(); i++) { - - // Add a new line after each element, and indent each line - // depending on the number of nested CompoundTags. - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - - String key = list.get(i); - Tag value = Objects.requireNonNull(compound.get(key), "This is impossible"); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - - builder.append(color).append(handleEscape(key)) - .append("&f&l: ").append(color) - .append(new TagColorVisitor(value instanceof CompoundTag ? indents + 1 : indents, colorOffset + i).visit(value)); - } - - builder.append(braceColor).append("}\n"); - } - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/v1_19_R3.java b/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/v1_19_R3.java deleted file mode 100644 index 2c5c03f65..000000000 --- a/CoreCompatibility/Core_1_19_R3/src/main/java/me/deecaad/core/compatibility/v1_19_R3.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_19_R3; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_19_R3; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_19_R3; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_19_R3; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_19_R3 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_19_R3() { - entityCompatibility = new Entity_1_19_R3(); - blockCompatibility = new Block_1_19_R3(); - nbtCompatibility = new NBT_1_19_R3(); - commandCompatibility = new Command_1_19_R3(); - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.world.entity.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).connection.send((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - ServerGamePacketListenerImpl playerConnection = getEntityPlayer(player).connection; - for (Object packet : packets) { - playerConnection.send((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull ServerPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R1/build.gradle.kts b/CoreCompatibility/Core_1_20_R1/build.gradle.kts deleted file mode 100644 index 7139c0128..000000000 --- a/CoreCompatibility/Core_1_20_R1/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - adventureChatAPI() - - paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT") -} - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R1.java b/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R1.java deleted file mode 100644 index 48e8ec1a1..000000000 --- a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R1.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import org.bukkit.block.Block; -import org.jetbrains.annotations.NotNull; - -// https://nms.screamingsandals.org/1.19.1/ -public class Block_1_20_R1 implements BlockCompatibility { - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPos pos = new BlockPos(block.getX(), block.getY(), block.getZ()); - return new ClientboundBlockDestructionPacket(id, pos, crack); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R1.java b/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R1.java deleted file mode 100644 index b74843545..000000000 --- a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R1.java +++ /dev/null @@ -1,637 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.commands.CommandBuildContext; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.*; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.*; -import net.minecraft.commands.arguments.item.FunctionArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemPredicateArgument; -import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentUtils; -import net.minecraft.commands.synchronization.SuggestionProviders; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Holder; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.Tag; -import net.minecraft.nbt.*; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ColumnPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; -import net.minecraft.world.level.storage.loot.LootDataType; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.Vec3; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_20_R1.CraftLootTable; -import org.bukkit.craftbukkit.v1_20_R1.CraftParticle; -import org.bukkit.craftbukkit.v1_20_R1.CraftServer; -import org.bukkit.craftbukkit.v1_20_R1.CraftSound; -import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R1.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R1.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_20_R1 implements CommandCompatibility { - - public static final MinecraftServer SERVER; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; - private static final DynamicCommandExceptionType ERROR_BIOME_INVALID; - - static { - SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - COMMAND_BUILD_CONTEXT = CommandBuildContext.configurable(SERVER.registryAccess(), SERVER.getWorldData().getDataConfiguration().enabledFeatures()); - ERROR_BIOME_INVALID = new DynamicCommandExceptionType( - arg -> net.minecraft.network.chat.Component.translatable("commands.locate.biome.invalid", arg)); - } - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - ServerPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.sendCommands(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandSourceStack) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.getDispatcher(); - } - - @Override - public ArgumentType angle() { - return AngleArgument.angle(); - } - - @Override - public ArgumentType axis() { - return SwizzleArgument.swizzle(); - } - - @Override - public ArgumentType blockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType blockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType chat() { - return MessageArgument.message(); - } - - @Override - public ArgumentType chatComponent() { - return ComponentArgument.textComponent(); - } - - @Override - public ArgumentType chatFormat() { - return ColorArgument.color(); - } - - @Override - public ArgumentType dimension() { - return DimensionArgument.dimension(); - } - - @Override - public ArgumentType enchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); - } - - @Override - public ArgumentType entity() { - return EntityArgument.entity(); - } - - @Override - public ArgumentType entities() { - return EntityArgument.entities(); - } - - @Override - public ArgumentType player() { - return EntityArgument.player(); - } - - @Override - public ArgumentType players() { - return EntityArgument.players(); - } - - @Override - public ArgumentType entitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public ArgumentType itemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType itemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType mathOperation() { - return OperationArgument.operation(); - } - - @Override - public ArgumentType mobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); - } - - @Override - public ArgumentType nbtCompound() { - return CompoundTagArgument.compoundTag(); - } - - @Override - public ArgumentType particle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType profile() { - return GameProfileArgument.gameProfile(); - } - - @Override - public ArgumentType rotation() { - return RotationArgument.rotation(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ObjectiveCriteriaArgument.criteria(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ObjectiveArgument.objective(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ScoreboardSlotArgument.displaySlot(); - } - - @Override - public ArgumentType scoreboardTeam() { - return TeamArgument.team(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ScoreHolderArgument.scoreHolder() : ScoreHolderArgument.scoreHolders(); - } - - @Override - public ArgumentType tag() { - return FunctionArgument.functions(); - } - - @Override - public ArgumentType time() { - return TimeArgument.time(); - } - - @Override - public ArgumentType uuid() { - return UuidArgument.uuid(); - } - - @Override - public ArgumentType location() { - return Vec3Argument.vec3(); - } - - @Override - public ArgumentType location2() { - return Vec2Argument.vec2(); - } - - @Override - public ArgumentType block() { - return BlockPosArgument.blockPos(); - } - - @Override - public ArgumentType block2() { - return ColumnPosArgument.columnPos(); - } - - @Override - public ArgumentType biome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); - } - - @Override - public ArgumentType key() { - return ResourceLocationArgument.id(); - } - - @Override - public SuggestionProvider biomeKey() { - return biome()::listSuggestions; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) SuggestionProviders.ALL_RECIPES; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) SuggestionProviders.AVAILABLE_SOUNDS; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) SuggestionProviders.SUMMONABLE_ENTITIES; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getAdvancements().getAllAdvancements().stream().map(net.minecraft.advancements.Advancement::getId), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getLootData().getKeys(LootDataType.TABLE), builder); - } - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getAdvancement(cast(context), key).bukkit; - } - - @Override - public float getAngle(CommandContext context, String key) { - return AngleArgument.getAngle(cast(context), key); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = SwizzleArgument.getSwizzle(cast(context), key); - - for (Direction.Axis axis : nmsAxis) { - bukkitAxis.add(switch (axis) { - case X -> Axis.X; - case Y -> Axis.Y; - case Z -> Axis.Z; - }); - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference holder = ResourceArgument.getResource(cast(context), key, Registries.BIOME); - ResourceLocation location = holder.key().location(); - Biome bukkit = EnumUtil.getIfPresent(Biome.class, location.getPath()).orElse(Biome.CUSTOM); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getPath()); - return new BiomeHolder(bukkit, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cast(context), key); - return block -> predicate.test(new BlockInWorld(cast(context).getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cast(context), key).getState()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - return DimensionArgument.getDimension(cast(context), key).getWorld().getEnvironment(); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) throws CommandSyntaxException { - return new CraftEnchantment(ResourceArgument.getEnchantment(cast(context), key).value()); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSingleEntity(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSinglePlayer(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findPlayers(source).stream() - .map(ServerPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.entity.EntityType type = ResourceArgument.getEntityType(cast(context), key).value(); - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(type).getPath()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cast(context), key); - double min = range.getMin() == null ? Double.MIN_VALUE : range.getMin(); - double max = range.getMax() == null ? Double.MAX_VALUE : range.getMax(); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cast(context), key); - int min = range.getMin() == null ? Integer.MIN_VALUE : range.getMin(); - int max = range.getMax() == null ? Integer.MAX_VALUE : range.getMax(); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ItemArgument.getItem(cast(context), key).createItemStack(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ItemPredicateArgument.getItemPredicate(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getId(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - ColumnPos column = ColumnPosArgument.getColumnPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Column(world, column.x(), column.z()); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2 vector = Vec2Argument.getVec2(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location2d(world, vector.x, vector.y); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPos block = BlockPosArgument.getLoadedBlockPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3 vector = Vec3Argument.getVec3(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - ResourceLocation resourceLocation = ResourceLocationArgument.getId(cast(context), key); - return new CraftLootTable(fromResourceLocation(resourceLocation), SERVER.getLootData().getLootTable(resourceLocation)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ObjectiveArgument.getObjective(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ObjectiveCriteriaArgument.getCriteria(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleOptions particle = ParticleArgument.getParticle(cast(context), key); - - return new ParticleHolder(CraftParticle.toBukkit(particle), particle, particle.writeToString()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - if (target == null) - throw GameProfileArgument.ERROR_UNKNOWN_PLAYER.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(ResourceArgument.getMobEffect(cast(context), key).value()); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.item.crafting.Recipe recipe = ResourceLocationArgument.getRecipe(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2 rotation = RotationArgument.getRotation(cast(context), key).getRotation(cast(context).getSource()); - return new Rotation(rotation.x, rotation.y); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - ResourceLocation location = ResourceLocationArgument.getId(cast(context), key); - SoundEvent sound = BuiltInRegistries.SOUND_EVENT.get(location); - Sound bukkit = sound == null ? null : CraftSound.getBukkit(sound); - return new SoundHolder(bukkit, new NamespacedKey(location.getNamespace(), location.getPath())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return TeamArgument.getTeam(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - return UuidArgument.getUuid(cast(context), key); - } - - @Override - public Map getCompound(CommandContext context, String key) { - CompoundTag nbt = CompoundTagArgument.getCompoundTag(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(Tag tag) { - return switch (tag.getId()) { - case Tag.TAG_BYTE, Tag.TAG_SHORT, Tag.TAG_INT, Tag.TAG_LONG -> ((NumericTag) tag).getAsInt(); - case Tag.TAG_FLOAT, Tag.TAG_DOUBLE -> ((NumericTag) tag).getAsDouble(); - case Tag.TAG_STRING -> ((StringTag) tag).getAsString(); - case Tag.TAG_BYTE_ARRAY, Tag.TAG_INT_ARRAY, Tag.TAG_LONG_ARRAY, Tag.TAG_LIST -> convertList((CollectionTag) tag); - case Tag.TAG_COMPOUND -> convertMap((CompoundTag) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(CompoundTag nbt) { - Map temp = new HashMap<>(nbt.size()); - - for (String key : nbt.getAllKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(CollectionTag values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R1.java b/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R1.java deleted file mode 100644 index b6c950786..000000000 --- a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R1.java +++ /dev/null @@ -1,120 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_20_R1; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.syncher.SynchedEntityData; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -// https://nms.screamingsandals.org/1.18.1/ -public class Entity_1_20_R1 implements EntityCompatibility { - - public static final Field itemsById = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.xOld, nms.yOld, nms.zOld); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_20_R1(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_20_R1(location, type, data); - } - - @Override - public int getId(Object obj) { - return ((ClientboundSetEntityDataPacket) obj).id(); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - net.minecraft.world.entity.EquipmentSlot nmsSlot = switch (slot) { - case HEAD -> net.minecraft.world.entity.EquipmentSlot.HEAD; - case CHEST -> net.minecraft.world.entity.EquipmentSlot.CHEST; - case LEGS -> net.minecraft.world.entity.EquipmentSlot.LEGS; - case FEET -> net.minecraft.world.entity.EquipmentSlot.FEET; - case HAND -> net.minecraft.world.entity.EquipmentSlot.MAINHAND; - case OFF_HAND -> net.minecraft.world.entity.EquipmentSlot.OFFHAND; - }; - - List> temp = new ArrayList<>(1); - temp.add(new Pair<>(nmsSlot, CraftItemStack.asNMSCopy(item))); - ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(id, temp); - ((CraftPlayer) bukkit).getHandle().connection.send(packet); - } - - public static List> getEntityData(SynchedEntityData data, boolean forceUpdateAll) { - if (!forceUpdateAll) { - List> dirty = data.packDirty(); - return dirty == null ? List.of() : dirty; - } - - // 1.19.3 changed the packet arguments, so in order to unpack ALL data - // (not just the dirty data) we need to manually get it and unpack it. - Int2ObjectMap> metaData = (Int2ObjectMap>) ReflectionUtil.invokeField(itemsById, data); - List> packed = new ArrayList<>(metaData.size()); - for (SynchedEntityData.DataItem element : metaData.values()) - packed.add(element.value()); - return packed; - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new ClientboundSetEntityDataPacket(entity.getId(), getEntityData(entity.getEntityData(), true)); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) obj; - List> list = packet.packedItems(); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).value().getClass() != Byte.class) - return; - - // noinspection unchecked - SynchedEntityData.DataValue item = (SynchedEntityData.DataValue) list.get(0); - byte data = item.value(); - data = meta.set(data, enabled); - - // 1.19.3 changed this to a record - list.set(0, new SynchedEntityData.DataValue<>(item.id(), item.serializer(), data)); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R1.java b/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R1.java deleted file mode 100644 index 0d59d3c83..000000000 --- a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R1.java +++ /dev/null @@ -1,350 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.core.Rotations; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.decoration.ArmorStand; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FireworkRocketEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R1.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static me.deecaad.core.compatibility.entity.Entity_1_20_R1.getEntityData; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.PosRot; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.Rot; - -public class FakeEntity_1_20_R1 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EquipmentSlot[] SLOTS = EquipmentSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private BlockState block; - private ItemStack item; - - public FakeEntity_1_20_R1(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new ItemEntity(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> { - FallingBlockEntity temp = new FallingBlockEntity(net.minecraft.world.entity.EntityType.FALLING_BLOCK, world.getHandle()); - temp.setPosRaw(x, y, z); - block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle()); - yield temp; - } - case FIREWORK -> new FireworkRocketEntity(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - case ITEM_DISPLAY -> { - Display.ItemDisplay temp = net.minecraft.world.entity.EntityType.ITEM_DISPLAY.create(world.getHandle()); - temp.setPos(x, y, z); - temp.setItemStack(CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - yield temp; - } - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - ArmorStand armorStand = (ArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getSharedFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setSharedFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> item.asBukkitCopy(); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((ItemEntity) entity).setItem(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !"".equals(display)); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosRaw(x, y, z); - entity.setYHeadRot(yaw); - entity.setYRot(yaw); - entity.setXRot(pitch); - } - - @Override - public void setMotion(double dx, double dy, double dz) { - ClientboundSetEntityMotionPacket packet = new ClientboundSetEntityMotionPacket(cache, new Vec3(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setYHeadRot(yaw); - entity.setXRot(yaw); - entity.setYRot(pitch); - - byte byteYaw = convertYaw(yaw); - Rot packet = new Rot(cache, byteYaw, convertPitch(pitch), false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND || entity instanceof Display) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket(entity); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PosRot packet = new PosRot(cache, dx, dy, dz, yaw, pitch, false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void show() { - Packet spawn = type.isAlive() - ? new ClientboundAddEntityPacket(entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0); - - ClientboundSetEntityDataPacket meta = new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false)); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(getYaw())); - Rot look = new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - ClientboundSetEntityMotionPacket velocity = new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ())); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - ServerGamePacketListenerImpl connection = ((CraftPlayer) temp).getHandle().connection; - if (connections.contains(connection)) { - continue; - } - - connection.send(spawn); - connection.send(meta); - connection.send(head); - connection.send(velocity); - connection.send(look); - if (equipment != null) - connection.send(equipment); - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - if (!player.isOnline()) - return; - - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - - connection.send(type.isAlive() - ? new ClientboundAddEntityPacket(entity) // TODO CHECK THIS... used to be "addmob", changed in 1.19? - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0)); - connection.send(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), true))); - connection.send(new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.send(new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ()))); - connection.send(new ClientboundRotateHeadPacket(entity, convertYaw(getYaw()))); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - if (equipment != null) - connection.send(equipment); - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((ArmorStand) entity).setHeadPose(new Rotations(getPitch(), 0, 0)); - - sendPackets(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false))); - } - - @Override - public void remove() { - sendPackets(new ClientboundRemoveEntitiesPacket(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - if (!player.isOnline()) - return; - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - connection.send(new ClientboundRemoveEntitiesPacket(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(@NotNull EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new ClientboundEntityEventPacket(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EquipmentSlot slot = switch (equipmentSlot) { - case HAND -> EquipmentSlot.MAINHAND; - case OFF_HAND -> EquipmentSlot.OFFHAND; - case FEET -> EquipmentSlot.FEET; - case CHEST -> EquipmentSlot.CHEST; - case LEGS -> EquipmentSlot.LEGS; - case HEAD -> EquipmentSlot.HEAD; - }; - - LivingEntity livingEntity = (LivingEntity) entity; - livingEntity.setItemSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - ClientboundSetEquipmentPacket packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private ClientboundSetEquipmentPacket getEquipmentPacket() { - if (!type.isAlive()) - return null; - LivingEntity livingEntity = (LivingEntity) entity; - - List> equipmentList = new ArrayList<>(6); - for (EquipmentSlot slot : SLOTS) { - ItemStack itemStack = livingEntity.getItemBySlot(slot); - if (!itemStack.isEmpty()) { - equipmentList.add(Pair.of(slot, itemStack)); - } - } - return equipmentList.isEmpty() ? null : new ClientboundSetEquipmentPacket(cache, equipmentList); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - ServerGamePacketListenerImpl connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.send(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R1.java b/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R1.java deleted file mode 100644 index 670f0bab4..000000000 --- a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R1.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -// https://nms.screamingsandals.org/1.19.1/ -public class NonNullList_1_20_R1 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_20_R1(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.EMPTY); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.EMPTY); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R1.java b/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R1.java deleted file mode 100644 index 59d1b0092..000000000 --- a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R1.java +++ /dev/null @@ -1,114 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import com.google.common.collect.Lists; -import com.google.gson.JsonElement; -import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.core.utils.StringUtil; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.StringTagVisitor; -import net.minecraft.nbt.Tag; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -// https://nms.screamingsandals.org/1.19_R1 -public class NBT_1_20_R1 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.world.item.ItemStack nms = getNMSStack(toItem); - CompoundTag from = getNMSStack(fromItem).getTag(); - CompoundTag to = nms.getTag(); - - if (path == null) { - nms.setTag(from.copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - return; - } - - to.put(path, from.getCompound(path).copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.world.item.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - CompoundTag nbt = getNMSStack(bukkitStack).getTag(); - return nbt == null ? "null" : new TagColorVisitor().visit(nbt); - } - - @Override - public @NotNull Component getDisplayName(@NotNull ItemStack item) { - net.minecraft.network.chat.Component component = CraftItemStack.asNMSCopy(item).getDisplayName(); - JsonElement json = net.minecraft.network.chat.Component.Serializer.toJsonTree(component); - return GsonComponentSerializer.gson().serializer().fromJson(json, Component.class); - } - - private static class TagColorVisitor extends StringTagVisitor { - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - private final StringBuilder builder; - - // Stores how many nested compound tags there currently are. Used to - // determine curly brace color, as well as spacing. - private final int indents; - private final int colorOffset; - - public TagColorVisitor() { - this(0, 0); - } - - public TagColorVisitor(int indents, int colorOffset) { - Field field = ReflectionUtil.getField(StringTagVisitor.class, StringBuilder.class); - this.builder = (StringBuilder) ReflectionUtil.invokeField(field, this); - this.indents = indents; - this.colorOffset = colorOffset; - } - - @Override - public void visitCompound(CompoundTag compound) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - builder.append(braceColor).append("{\n"); - List list = Lists.newArrayList(compound.getAllKeys()); - Collections.sort(list); - - for (int i = 0; i < list.size(); i++) { - - // Add a new line after each element, and indent each line - // depending on the number of nested CompoundTags. - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - - String key = list.get(i); - Tag value = Objects.requireNonNull(compound.get(key), "This is impossible"); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - - builder.append(color).append(handleEscape(key)) - .append("&f&l: ").append(color) - .append(new TagColorVisitor(value instanceof CompoundTag ? indents + 1 : indents, colorOffset + i).visit(value)); - } - - builder.append(braceColor).append("}\n"); - } - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/v1_20_R1.java b/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/v1_20_R1.java deleted file mode 100644 index 7b75fdf7b..000000000 --- a/CoreCompatibility/Core_1_20_R1/src/main/java/me/deecaad/core/compatibility/v1_20_R1.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_20_R1; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_20_R1; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_20_R1; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_20_R1; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_20_R1 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_20_R1() { - entityCompatibility = new Entity_1_20_R1(); - blockCompatibility = new Block_1_20_R1(); - nbtCompatibility = new NBT_1_20_R1(); - commandCompatibility = new Command_1_20_R1(); - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.world.entity.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).connection.send((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - ServerGamePacketListenerImpl playerConnection = getEntityPlayer(player).connection; - for (Object packet : packets) { - playerConnection.send((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull ServerPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R2/build.gradle.kts b/CoreCompatibility/Core_1_20_R2/build.gradle.kts deleted file mode 100644 index 2b64cd414..000000000 --- a/CoreCompatibility/Core_1_20_R2/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - adventureChatAPI() - - paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") -} - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R2.java b/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R2.java deleted file mode 100644 index 94b28254e..000000000 --- a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R2.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import org.bukkit.block.Block; -import org.jetbrains.annotations.NotNull; - -// https://nms.screamingsandals.org/1.19.1/ -public class Block_1_20_R2 implements BlockCompatibility { - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPos pos = new BlockPos(block.getX(), block.getY(), block.getZ()); - return new ClientboundBlockDestructionPacket(id, pos, crack); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R2.java b/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R2.java deleted file mode 100644 index 5179152d9..000000000 --- a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R2.java +++ /dev/null @@ -1,638 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.advancements.AdvancementHolder; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.commands.CommandBuildContext; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.*; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.*; -import net.minecraft.commands.arguments.item.FunctionArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemPredicateArgument; -import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentUtils; -import net.minecraft.commands.synchronization.SuggestionProviders; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Holder; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.Tag; -import net.minecraft.nbt.*; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ColumnPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; -import net.minecraft.world.level.storage.loot.LootDataType; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.Vec3; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_20_R2.CraftLootTable; -import org.bukkit.craftbukkit.v1_20_R2.CraftParticle; -import org.bukkit.craftbukkit.v1_20_R2.CraftServer; -import org.bukkit.craftbukkit.v1_20_R2.CraftSound; -import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R2.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R2.potion.CraftPotionEffectType; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_20_R2 implements CommandCompatibility { - - public static final MinecraftServer SERVER; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; - private static final DynamicCommandExceptionType ERROR_BIOME_INVALID; - - static { - SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - COMMAND_BUILD_CONTEXT = CommandBuildContext.configurable(SERVER.registryAccess(), SERVER.getWorldData().getDataConfiguration().enabledFeatures()); - ERROR_BIOME_INVALID = new DynamicCommandExceptionType( - arg -> net.minecraft.network.chat.Component.translatable("commands.locate.biome.invalid", arg)); - } - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - ServerPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.sendCommands(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandSourceStack) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.getDispatcher(); - } - - @Override - public ArgumentType angle() { - return AngleArgument.angle(); - } - - @Override - public ArgumentType axis() { - return SwizzleArgument.swizzle(); - } - - @Override - public ArgumentType blockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType blockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType chat() { - return MessageArgument.message(); - } - - @Override - public ArgumentType chatComponent() { - return ComponentArgument.textComponent(); - } - - @Override - public ArgumentType chatFormat() { - return ColorArgument.color(); - } - - @Override - public ArgumentType dimension() { - return DimensionArgument.dimension(); - } - - @Override - public ArgumentType enchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); - } - - @Override - public ArgumentType entity() { - return EntityArgument.entity(); - } - - @Override - public ArgumentType entities() { - return EntityArgument.entities(); - } - - @Override - public ArgumentType player() { - return EntityArgument.player(); - } - - @Override - public ArgumentType players() { - return EntityArgument.players(); - } - - @Override - public ArgumentType entitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public ArgumentType itemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType itemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType mathOperation() { - return OperationArgument.operation(); - } - - @Override - public ArgumentType mobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); - } - - @Override - public ArgumentType nbtCompound() { - return CompoundTagArgument.compoundTag(); - } - - @Override - public ArgumentType particle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType profile() { - return GameProfileArgument.gameProfile(); - } - - @Override - public ArgumentType rotation() { - return RotationArgument.rotation(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ObjectiveCriteriaArgument.criteria(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ObjectiveArgument.objective(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ScoreboardSlotArgument.displaySlot(); - } - - @Override - public ArgumentType scoreboardTeam() { - return TeamArgument.team(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ScoreHolderArgument.scoreHolder() : ScoreHolderArgument.scoreHolders(); - } - - @Override - public ArgumentType tag() { - return FunctionArgument.functions(); - } - - @Override - public ArgumentType time() { - return TimeArgument.time(); - } - - @Override - public ArgumentType uuid() { - return UuidArgument.uuid(); - } - - @Override - public ArgumentType location() { - return Vec3Argument.vec3(); - } - - @Override - public ArgumentType location2() { - return Vec2Argument.vec2(); - } - - @Override - public ArgumentType block() { - return BlockPosArgument.blockPos(); - } - - @Override - public ArgumentType block2() { - return ColumnPosArgument.columnPos(); - } - - @Override - public ArgumentType biome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); - } - - @Override - public ArgumentType key() { - return ResourceLocationArgument.id(); - } - - @Override - public SuggestionProvider biomeKey() { - return biome()::listSuggestions; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) SuggestionProviders.ALL_RECIPES; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) SuggestionProviders.AVAILABLE_SOUNDS; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) SuggestionProviders.SUMMONABLE_ENTITIES; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getAdvancements().getAllAdvancements().stream().map(AdvancementHolder::id), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getLootData().getKeys(LootDataType.TABLE), builder); - } - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getAdvancement(cast(context), key).toBukkit(); - } - - @Override - public float getAngle(CommandContext context, String key) { - return AngleArgument.getAngle(cast(context), key); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = SwizzleArgument.getSwizzle(cast(context), key); - - for (Direction.Axis axis : nmsAxis) { - bukkitAxis.add(switch (axis) { - case X -> Axis.X; - case Y -> Axis.Y; - case Z -> Axis.Z; - }); - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference holder = ResourceArgument.getResource(cast(context), key, Registries.BIOME); - ResourceLocation location = holder.key().location(); - Biome bukkit = EnumUtil.getIfPresent(Biome.class, location.getPath()).orElse(Biome.CUSTOM); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getPath()); - return new BiomeHolder(bukkit, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cast(context), key); - return block -> predicate.test(new BlockInWorld(cast(context).getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cast(context), key).getState()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - return DimensionArgument.getDimension(cast(context), key).getWorld().getEnvironment(); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) throws CommandSyntaxException { - return new CraftEnchantment(ResourceArgument.getEnchantment(cast(context), key).value()); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSingleEntity(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSinglePlayer(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findPlayers(source).stream() - .map(ServerPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.entity.EntityType type = ResourceArgument.getEntityType(cast(context), key).value(); - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(type).getPath()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cast(context), key); - double min = range.min().orElse(Double.MIN_VALUE); - double max = range.max().orElse(Double.MAX_VALUE); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cast(context), key); - int min = range.min().orElse(Integer.MIN_VALUE); - int max = range.max().orElse(Integer.MAX_VALUE); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ItemArgument.getItem(cast(context), key).createItemStack(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ItemPredicateArgument.getItemPredicate(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getId(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - ColumnPos column = ColumnPosArgument.getColumnPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Column(world, column.x(), column.z()); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2 vector = Vec2Argument.getVec2(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location2d(world, vector.x, vector.y); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPos block = BlockPosArgument.getLoadedBlockPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3 vector = Vec3Argument.getVec3(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - ResourceLocation resourceLocation = ResourceLocationArgument.getId(cast(context), key); - return new CraftLootTable(fromResourceLocation(resourceLocation), SERVER.getLootData().getLootTable(resourceLocation)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ObjectiveArgument.getObjective(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ObjectiveCriteriaArgument.getCriteria(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleOptions particle = ParticleArgument.getParticle(cast(context), key); - - return new ParticleHolder(CraftParticle.minecraftToBukkit(particle.getType()), particle, particle.writeToString()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - if (target == null) - throw GameProfileArgument.ERROR_UNKNOWN_PLAYER.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - return new CraftPotionEffectType(ResourceArgument.getMobEffect(cast(context), key).value()); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.item.crafting.RecipeHolder recipe = ResourceLocationArgument.getRecipe(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2 rotation = RotationArgument.getRotation(cast(context), key).getRotation(cast(context).getSource()); - return new Rotation(rotation.x, rotation.y); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - ResourceLocation location = ResourceLocationArgument.getId(cast(context), key); - SoundEvent sound = BuiltInRegistries.SOUND_EVENT.get(location); - Sound bukkit = sound == null ? null : CraftSound.minecraftToBukkit(sound); - return new SoundHolder(bukkit, new NamespacedKey(location.getNamespace(), location.getPath())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return TeamArgument.getTeam(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - return UuidArgument.getUuid(cast(context), key); - } - - @Override - public Map getCompound(CommandContext context, String key) { - CompoundTag nbt = CompoundTagArgument.getCompoundTag(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(Tag tag) { - return switch (tag.getId()) { - case Tag.TAG_BYTE, Tag.TAG_SHORT, Tag.TAG_INT, Tag.TAG_LONG -> ((NumericTag) tag).getAsInt(); - case Tag.TAG_FLOAT, Tag.TAG_DOUBLE -> ((NumericTag) tag).getAsDouble(); - case Tag.TAG_STRING -> ((StringTag) tag).getAsString(); - case Tag.TAG_BYTE_ARRAY, Tag.TAG_INT_ARRAY, Tag.TAG_LONG_ARRAY, Tag.TAG_LIST -> convertList((CollectionTag) tag); - case Tag.TAG_COMPOUND -> convertMap((CompoundTag) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(CompoundTag nbt) { - Map temp = new HashMap<>(nbt.size()); - - for (String key : nbt.getAllKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(CollectionTag values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R2.java b/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R2.java deleted file mode 100644 index 9005ff4ee..000000000 --- a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R2.java +++ /dev/null @@ -1,120 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_20_R2; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.syncher.SynchedEntityData; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -// https://nms.screamingsandals.org/1.18.1/ -public class Entity_1_20_R2 implements EntityCompatibility { - - public static final Field itemsById = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.xOld, nms.yOld, nms.zOld); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_20_R2(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_20_R2(location, type, data); - } - - @Override - public int getId(Object obj) { - return ((ClientboundSetEntityDataPacket) obj).id(); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - net.minecraft.world.entity.EquipmentSlot nmsSlot = switch (slot) { - case HEAD -> net.minecraft.world.entity.EquipmentSlot.HEAD; - case CHEST -> net.minecraft.world.entity.EquipmentSlot.CHEST; - case LEGS -> net.minecraft.world.entity.EquipmentSlot.LEGS; - case FEET -> net.minecraft.world.entity.EquipmentSlot.FEET; - case HAND -> net.minecraft.world.entity.EquipmentSlot.MAINHAND; - case OFF_HAND -> net.minecraft.world.entity.EquipmentSlot.OFFHAND; - }; - - List> temp = new ArrayList<>(1); - temp.add(new Pair<>(nmsSlot, CraftItemStack.asNMSCopy(item))); - ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(id, temp); - ((CraftPlayer) bukkit).getHandle().connection.send(packet); - } - - public static List> getEntityData(SynchedEntityData data, boolean forceUpdateAll) { - if (!forceUpdateAll) { - List> dirty = data.packDirty(); - return dirty == null ? List.of() : dirty; - } - - // 1.19.3 changed the packet arguments, so in order to unpack ALL data - // (not just the dirty data) we need to manually get it and unpack it. - Int2ObjectMap> metaData = (Int2ObjectMap>) ReflectionUtil.invokeField(itemsById, data); - List> packed = new ArrayList<>(metaData.size()); - for (SynchedEntityData.DataItem element : metaData.values()) - packed.add(element.value()); - return packed; - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new ClientboundSetEntityDataPacket(entity.getId(), getEntityData(entity.getEntityData(), true)); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) obj; - List> list = packet.packedItems(); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).value().getClass() != Byte.class) - return; - - // noinspection unchecked - SynchedEntityData.DataValue item = (SynchedEntityData.DataValue) list.get(0); - byte data = item.value(); - data = meta.set(data, enabled); - - // 1.19.3 changed this to a record - list.set(0, new SynchedEntityData.DataValue<>(item.id(), item.serializer(), data)); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R2.java b/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R2.java deleted file mode 100644 index 03829f8eb..000000000 --- a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R2.java +++ /dev/null @@ -1,350 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.core.Rotations; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.decoration.ArmorStand; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FireworkRocketEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R2.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static me.deecaad.core.compatibility.entity.Entity_1_20_R2.getEntityData; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.PosRot; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.Rot; - -public class FakeEntity_1_20_R2 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EquipmentSlot[] SLOTS = EquipmentSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private BlockState block; - private ItemStack item; - - public FakeEntity_1_20_R2(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new ItemEntity(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> { - FallingBlockEntity temp = new FallingBlockEntity(net.minecraft.world.entity.EntityType.FALLING_BLOCK, world.getHandle()); - temp.setPosRaw(x, y, z); - block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle()); - yield temp; - } - case FIREWORK -> new FireworkRocketEntity(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - case ITEM_DISPLAY -> { - Display.ItemDisplay temp = net.minecraft.world.entity.EntityType.ITEM_DISPLAY.create(world.getHandle()); - temp.setPos(x, y, z); - temp.setItemStack(CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - yield temp; - } - default -> world.createEntity(location, type.getEntityClass()); - }; - } else { - entity = world.createEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - ArmorStand armorStand = (ArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getSharedFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setSharedFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> item.asBukkitCopy(); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((ItemEntity) entity).setItem(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !display.isEmpty()); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosRaw(x, y, z); - entity.setYHeadRot(yaw); - entity.setYRot(yaw); - entity.setXRot(pitch); - } - - @Override - public void setMotion(double dx, double dy, double dz) { - ClientboundSetEntityMotionPacket packet = new ClientboundSetEntityMotionPacket(cache, new Vec3(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setYHeadRot(yaw); - entity.setXRot(yaw); - entity.setYRot(pitch); - - byte byteYaw = convertYaw(yaw); - Rot packet = new Rot(cache, byteYaw, convertPitch(pitch), false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND || entity instanceof Display) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket(entity); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PosRot packet = new PosRot(cache, dx, dy, dz, yaw, pitch, false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void show() { - Packet spawn = type.isAlive() - ? new ClientboundAddEntityPacket(entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0); - - ClientboundSetEntityDataPacket meta = new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false)); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(getYaw())); - Rot look = new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - ClientboundSetEntityMotionPacket velocity = new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ())); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - ServerGamePacketListenerImpl connection = ((CraftPlayer) temp).getHandle().connection; - if (connections.contains(connection)) { - continue; - } - - connection.send(spawn); - connection.send(meta); - connection.send(head); - connection.send(velocity); - connection.send(look); - if (equipment != null) - connection.send(equipment); - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - if (!player.isOnline()) - return; - - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - - connection.send(type.isAlive() - ? new ClientboundAddEntityPacket(entity) // TODO CHECK THIS... used to be "addmob", changed in 1.19? - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0)); - connection.send(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), true))); - connection.send(new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.send(new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ()))); - connection.send(new ClientboundRotateHeadPacket(entity, convertYaw(getYaw()))); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - if (equipment != null) - connection.send(equipment); - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((ArmorStand) entity).setHeadPose(new Rotations(getPitch(), 0, 0)); - - sendPackets(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false))); - } - - @Override - public void remove() { - sendPackets(new ClientboundRemoveEntitiesPacket(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - if (!player.isOnline()) - return; - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - connection.send(new ClientboundRemoveEntitiesPacket(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(@NotNull EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new ClientboundEntityEventPacket(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EquipmentSlot slot = switch (equipmentSlot) { - case HAND -> EquipmentSlot.MAINHAND; - case OFF_HAND -> EquipmentSlot.OFFHAND; - case FEET -> EquipmentSlot.FEET; - case CHEST -> EquipmentSlot.CHEST; - case LEGS -> EquipmentSlot.LEGS; - case HEAD -> EquipmentSlot.HEAD; - }; - - LivingEntity livingEntity = (LivingEntity) entity; - livingEntity.setItemSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - ClientboundSetEquipmentPacket packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private ClientboundSetEquipmentPacket getEquipmentPacket() { - if (!type.isAlive()) - return null; - LivingEntity livingEntity = (LivingEntity) entity; - - List> equipmentList = new ArrayList<>(6); - for (EquipmentSlot slot : SLOTS) { - ItemStack itemStack = livingEntity.getItemBySlot(slot); - if (!itemStack.isEmpty()) { - equipmentList.add(Pair.of(slot, itemStack)); - } - } - return equipmentList.isEmpty() ? null : new ClientboundSetEquipmentPacket(cache, equipmentList); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - ServerGamePacketListenerImpl connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.send(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R2.java b/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R2.java deleted file mode 100644 index e5ebb09f7..000000000 --- a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R2.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -// https://nms.screamingsandals.org/1.19.1/ -public class NonNullList_1_20_R2 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_20_R2(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.EMPTY); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.EMPTY); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R2.java b/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R2.java deleted file mode 100644 index 745139f0b..000000000 --- a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R2.java +++ /dev/null @@ -1,114 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import com.google.common.collect.Lists; -import com.google.gson.JsonElement; -import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.core.utils.StringUtil; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.StringTagVisitor; -import net.minecraft.nbt.Tag; -import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -// https://nms.screamingsandals.org/1.19_R1 -public class NBT_1_20_R2 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.world.item.ItemStack nms = getNMSStack(toItem); - CompoundTag from = getNMSStack(fromItem).getTag(); - CompoundTag to = nms.getTag(); - - if (path == null) { - nms.setTag(from.copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - return; - } - - to.put(path, from.getCompound(path).copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.world.item.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - CompoundTag nbt = getNMSStack(bukkitStack).getTag(); - return nbt == null ? "null" : new TagColorVisitor().visit(nbt); - } - - @Override - public @NotNull Component getDisplayName(@NotNull ItemStack item) { - net.minecraft.network.chat.Component component = CraftItemStack.asNMSCopy(item).getDisplayName(); - JsonElement json = net.minecraft.network.chat.Component.Serializer.toJsonTree(component); - return GsonComponentSerializer.gson().serializer().fromJson(json, Component.class); - } - - private static class TagColorVisitor extends StringTagVisitor { - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - private final StringBuilder builder; - - // Stores how many nested compound tags there currently are. Used to - // determine curly brace color, as well as spacing. - private final int indents; - private final int colorOffset; - - public TagColorVisitor() { - this(0, 0); - } - - public TagColorVisitor(int indents, int colorOffset) { - Field field = ReflectionUtil.getField(StringTagVisitor.class, StringBuilder.class); - this.builder = (StringBuilder) ReflectionUtil.invokeField(field, this); - this.indents = indents; - this.colorOffset = colorOffset; - } - - @Override - public void visitCompound(CompoundTag compound) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - builder.append(braceColor).append("{\n"); - List list = Lists.newArrayList(compound.getAllKeys()); - Collections.sort(list); - - for (int i = 0; i < list.size(); i++) { - - // Add a new line after each element, and indent each line - // depending on the number of nested CompoundTags. - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - - String key = list.get(i); - Tag value = Objects.requireNonNull(compound.get(key), "This is impossible"); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - - builder.append(color).append(handleEscape(key)) - .append("&f&l: ").append(color) - .append(new TagColorVisitor(value instanceof CompoundTag ? indents + 1 : indents, colorOffset + i).visit(value)); - } - - builder.append(braceColor).append("}\n"); - } - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/v1_20_R2.java b/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/v1_20_R2.java deleted file mode 100644 index dfa892555..000000000 --- a/CoreCompatibility/Core_1_20_R2/src/main/java/me/deecaad/core/compatibility/v1_20_R2.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_20_R2; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_20_R2; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_20_R2; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_20_R2; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_20_R2 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_20_R2() { - entityCompatibility = new Entity_1_20_R2(); - blockCompatibility = new Block_1_20_R2(); - nbtCompatibility = new NBT_1_20_R2(); - commandCompatibility = new Command_1_20_R2(); - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.world.entity.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).connection.send((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - ServerGamePacketListenerImpl playerConnection = getEntityPlayer(player).connection; - for (Object packet : packets) { - playerConnection.send((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull ServerPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R3/build.gradle.kts b/CoreCompatibility/Core_1_20_R3/build.gradle.kts deleted file mode 100644 index e90809b23..000000000 --- a/CoreCompatibility/Core_1_20_R3/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - adventureChatAPI() - - paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") -} - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R3.java b/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R3.java deleted file mode 100644 index 62308e670..000000000 --- a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R3.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import org.bukkit.block.Block; -import org.jetbrains.annotations.NotNull; - -// https://nms.screamingsandals.org/1.19.1/ -public class Block_1_20_R3 implements BlockCompatibility { - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPos pos = new BlockPos(block.getX(), block.getY(), block.getZ()); - return new ClientboundBlockDestructionPacket(id, pos, crack); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R3.java b/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R3.java deleted file mode 100644 index c407253b3..000000000 --- a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R3.java +++ /dev/null @@ -1,645 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.*; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.advancements.AdvancementHolder; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.commands.CommandBuildContext; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.*; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.*; -import net.minecraft.commands.arguments.item.FunctionArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemPredicateArgument; -import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentUtils; -import net.minecraft.commands.synchronization.SuggestionProviders; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Holder; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.Tag; -import net.minecraft.nbt.*; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ColumnPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; -import net.minecraft.world.level.storage.loot.LootDataType; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.Vec3; -import org.bukkit.*; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.v1_20_R3.CraftLootTable; -import org.bukkit.craftbukkit.v1_20_R3.CraftParticle; -import org.bukkit.craftbukkit.v1_20_R3.CraftServer; -import org.bukkit.craftbukkit.v1_20_R3.CraftSound; -import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R3.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R3.potion.CraftPotionEffectType; -import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_20_R3 implements CommandCompatibility { - - public static final MinecraftServer SERVER; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; - private static final DynamicCommandExceptionType ERROR_BIOME_INVALID; - - static { - SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - COMMAND_BUILD_CONTEXT = CommandBuildContext.configurable(SERVER.registryAccess(), SERVER.getWorldData().getDataConfiguration().enabledFeatures()); - ERROR_BIOME_INVALID = new DynamicCommandExceptionType( - arg -> net.minecraft.network.chat.Component.translatable("commands.locate.biome.invalid", arg)); - } - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - ServerPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.vanillaCommandDispatcher.sendCommands(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandSourceStack) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.vanillaCommandDispatcher.getDispatcher(); - } - - @Override - public ArgumentType angle() { - return AngleArgument.angle(); - } - - @Override - public ArgumentType axis() { - return SwizzleArgument.swizzle(); - } - - @Override - public ArgumentType blockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType blockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType chat() { - return MessageArgument.message(); - } - - @Override - public ArgumentType chatComponent() { - return ComponentArgument.textComponent(); - } - - @Override - public ArgumentType chatFormat() { - return ColorArgument.color(); - } - - @Override - public ArgumentType dimension() { - return DimensionArgument.dimension(); - } - - @Override - public ArgumentType enchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); - } - - @Override - public ArgumentType entity() { - return EntityArgument.entity(); - } - - @Override - public ArgumentType entities() { - return EntityArgument.entities(); - } - - @Override - public ArgumentType player() { - return EntityArgument.player(); - } - - @Override - public ArgumentType players() { - return EntityArgument.players(); - } - - @Override - public ArgumentType entitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public ArgumentType itemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType itemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType mathOperation() { - return OperationArgument.operation(); - } - - @Override - public ArgumentType mobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); - } - - @Override - public ArgumentType nbtCompound() { - return CompoundTagArgument.compoundTag(); - } - - @Override - public ArgumentType particle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType profile() { - return GameProfileArgument.gameProfile(); - } - - @Override - public ArgumentType rotation() { - return RotationArgument.rotation(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ObjectiveCriteriaArgument.criteria(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ObjectiveArgument.objective(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ScoreboardSlotArgument.displaySlot(); - } - - @Override - public ArgumentType scoreboardTeam() { - return TeamArgument.team(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ScoreHolderArgument.scoreHolder() : ScoreHolderArgument.scoreHolders(); - } - - @Override - public ArgumentType tag() { - return FunctionArgument.functions(); - } - - @Override - public ArgumentType time() { - return TimeArgument.time(); - } - - @Override - public ArgumentType uuid() { - return UuidArgument.uuid(); - } - - @Override - public ArgumentType location() { - return Vec3Argument.vec3(); - } - - @Override - public ArgumentType location2() { - return Vec2Argument.vec2(); - } - - @Override - public ArgumentType block() { - return BlockPosArgument.blockPos(); - } - - @Override - public ArgumentType block2() { - return ColumnPosArgument.columnPos(); - } - - @Override - public ArgumentType biome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); - } - - @Override - public ArgumentType key() { - return ResourceLocationArgument.id(); - } - - @Override - public SuggestionProvider biomeKey() { - return biome()::listSuggestions; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) SuggestionProviders.ALL_RECIPES; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) SuggestionProviders.AVAILABLE_SOUNDS; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) SuggestionProviders.SUMMONABLE_ENTITIES; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getAdvancements().getAllAdvancements().stream().map(AdvancementHolder::id), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getLootData().getKeys(LootDataType.TABLE), builder); - } - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getAdvancement(cast(context), key).toBukkit(); - } - - @Override - public float getAngle(CommandContext context, String key) { - return AngleArgument.getAngle(cast(context), key); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = SwizzleArgument.getSwizzle(cast(context), key); - - for (Direction.Axis axis : nmsAxis) { - bukkitAxis.add(switch (axis) { - case X -> Axis.X; - case Y -> Axis.Y; - case Z -> Axis.Z; - }); - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference holder = ResourceArgument.getResource(cast(context), key, Registries.BIOME); - ResourceLocation location = holder.key().location(); - Biome bukkit = EnumUtil.getIfPresent(Biome.class, location.getPath()).orElse(Biome.CUSTOM); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getPath()); - return new BiomeHolder(bukkit, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cast(context), key); - return block -> predicate.test(new BlockInWorld(cast(context).getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cast(context), key).getState()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - return DimensionArgument.getDimension(cast(context), key).getWorld().getEnvironment(); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference ench = ResourceArgument.getEnchantment(cast(context), key); - NamespacedKey namespace = CraftNamespacedKey.fromMinecraft(ench.key().location()); - - return new CraftEnchantment(namespace, ench.value()); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSingleEntity(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSinglePlayer(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findPlayers(source).stream() - .map(ServerPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.entity.EntityType type = ResourceArgument.getEntityType(cast(context), key).value(); - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(type).getPath()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cast(context), key); - double min = range.min().orElse(Double.MIN_VALUE); - double max = range.max().orElse(Double.MAX_VALUE); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cast(context), key); - int min = range.min().orElse(Integer.MIN_VALUE); - int max = range.max().orElse(Integer.MAX_VALUE); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ItemArgument.getItem(cast(context), key).createItemStack(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ItemPredicateArgument.getItemPredicate(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getId(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - ColumnPos column = ColumnPosArgument.getColumnPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Column(world, column.x(), column.z()); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2 vector = Vec2Argument.getVec2(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location2d(world, vector.x, vector.y); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPos block = BlockPosArgument.getLoadedBlockPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3 vector = Vec3Argument.getVec3(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - ResourceLocation resourceLocation = ResourceLocationArgument.getId(cast(context), key); - return new CraftLootTable(fromResourceLocation(resourceLocation), SERVER.getLootData().getLootTable(resourceLocation)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ObjectiveArgument.getObjective(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ObjectiveCriteriaArgument.getCriteria(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleOptions particle = ParticleArgument.getParticle(cast(context), key); - - return new ParticleHolder(CraftParticle.minecraftToBukkit(particle.getType()), particle, particle.writeToString()); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - if (target == null) - throw GameProfileArgument.ERROR_UNKNOWN_PLAYER.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference effect = ResourceArgument.getMobEffect(cast(context), key); - NamespacedKey bukkit = CraftNamespacedKey.fromMinecraft(effect.key().location()); - return new CraftPotionEffectType(bukkit, effect.value()); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.item.crafting.RecipeHolder recipe = ResourceLocationArgument.getRecipe(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2 rotation = RotationArgument.getRotation(cast(context), key).getRotation(cast(context).getSource()); - return new Rotation(rotation.x, rotation.y); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - ResourceLocation location = ResourceLocationArgument.getId(cast(context), key); - SoundEvent sound = BuiltInRegistries.SOUND_EVENT.get(location); - Sound bukkit = sound == null ? null : CraftSound.minecraftToBukkit(sound); - return new SoundHolder(bukkit, new NamespacedKey(location.getNamespace(), location.getPath())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return TeamArgument.getTeam(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - return UuidArgument.getUuid(cast(context), key); - } - - @Override - public Map getCompound(CommandContext context, String key) { - CompoundTag nbt = CompoundTagArgument.getCompoundTag(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(Tag tag) { - return switch (tag.getId()) { - case Tag.TAG_BYTE, Tag.TAG_SHORT, Tag.TAG_INT, Tag.TAG_LONG -> ((NumericTag) tag).getAsInt(); - case Tag.TAG_FLOAT, Tag.TAG_DOUBLE -> ((NumericTag) tag).getAsDouble(); - case Tag.TAG_STRING -> ((StringTag) tag).getAsString(); - case Tag.TAG_BYTE_ARRAY, Tag.TAG_INT_ARRAY, Tag.TAG_LONG_ARRAY, Tag.TAG_LIST -> convertList((CollectionTag) tag); - case Tag.TAG_COMPOUND -> convertMap((CompoundTag) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(CompoundTag nbt) { - Map temp = new HashMap<>(nbt.size()); - - for (String key : nbt.getAllKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(CollectionTag values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R3.java b/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R3.java deleted file mode 100644 index 1c275b783..000000000 --- a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R3.java +++ /dev/null @@ -1,120 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_20_R3; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.syncher.SynchedEntityData; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -// https://nms.screamingsandals.org/1.18.1/ -public class Entity_1_20_R3 implements EntityCompatibility { - - public static final Field itemsById = ReflectionUtil.getField(SynchedEntityData.class, Int2ObjectMap.class); - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.xOld, nms.yOld, nms.zOld); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_20_R3(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_20_R3(location, type, data); - } - - @Override - public int getId(Object obj) { - return ((ClientboundSetEntityDataPacket) obj).id(); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - net.minecraft.world.entity.EquipmentSlot nmsSlot = switch (slot) { - case HEAD -> net.minecraft.world.entity.EquipmentSlot.HEAD; - case CHEST -> net.minecraft.world.entity.EquipmentSlot.CHEST; - case LEGS -> net.minecraft.world.entity.EquipmentSlot.LEGS; - case FEET -> net.minecraft.world.entity.EquipmentSlot.FEET; - case HAND -> net.minecraft.world.entity.EquipmentSlot.MAINHAND; - case OFF_HAND -> net.minecraft.world.entity.EquipmentSlot.OFFHAND; - }; - - List> temp = new ArrayList<>(1); - temp.add(new Pair<>(nmsSlot, CraftItemStack.asNMSCopy(item))); - ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(id, temp); - ((CraftPlayer) bukkit).getHandle().connection.send(packet); - } - - public static List> getEntityData(SynchedEntityData data, boolean forceUpdateAll) { - if (!forceUpdateAll) { - List> dirty = data.packDirty(); - return dirty == null ? List.of() : dirty; - } - - // 1.19.3 changed the packet arguments, so in order to unpack ALL data - // (not just the dirty data) we need to manually get it and unpack it. - Int2ObjectMap> metaData = (Int2ObjectMap>) ReflectionUtil.invokeField(itemsById, data); - List> packed = new ArrayList<>(metaData.size()); - for (SynchedEntityData.DataItem element : metaData.values()) - packed.add(element.value()); - return packed; - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new ClientboundSetEntityDataPacket(entity.getId(), getEntityData(entity.getEntityData(), true)); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) obj; - List> list = packet.packedItems(); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).value().getClass() != Byte.class) - return; - - // noinspection unchecked - SynchedEntityData.DataValue item = (SynchedEntityData.DataValue) list.get(0); - byte data = item.value(); - data = meta.set(data, enabled); - - // 1.19.3 changed this to a record - list.set(0, new SynchedEntityData.DataValue<>(item.id(), item.serializer(), data)); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R3.java b/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R3.java deleted file mode 100644 index 8c2f256b3..000000000 --- a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R3.java +++ /dev/null @@ -1,350 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.core.Rotations; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.decoration.ArmorStand; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FireworkRocketEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockState; -import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R3.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static me.deecaad.core.compatibility.entity.Entity_1_20_R3.getEntityData; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.PosRot; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.Rot; - -public class FakeEntity_1_20_R3 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EquipmentSlot[] SLOTS = EquipmentSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private BlockState block; - private ItemStack item; - - public FakeEntity_1_20_R3(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case DROPPED_ITEM -> new ItemEntity(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> { - FallingBlockEntity temp = new FallingBlockEntity(net.minecraft.world.entity.EntityType.FALLING_BLOCK, world.getHandle()); - temp.setPosRaw(x, y, z); - block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle()); - yield temp; - } - case FIREWORK -> new FireworkRocketEntity(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - case ITEM_DISPLAY -> { - Display.ItemDisplay temp = net.minecraft.world.entity.EntityType.ITEM_DISPLAY.create(world.getHandle()); - temp.setPos(x, y, z); - temp.setItemStack(CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - yield temp; - } - default -> world.makeEntity(location, type.getEntityClass()); - }; - } else { - entity = world.makeEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - ArmorStand armorStand = (ArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getSharedFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setSharedFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case DROPPED_ITEM -> item.asBukkitCopy(); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case DROPPED_ITEM -> ((ItemEntity) entity).setItem(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !display.isEmpty()); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosRaw(x, y, z); - entity.setYHeadRot(yaw); - entity.setYRot(yaw); - entity.setXRot(pitch); - } - - @Override - public void setMotion(double dx, double dy, double dz) { - ClientboundSetEntityMotionPacket packet = new ClientboundSetEntityMotionPacket(cache, new Vec3(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setYHeadRot(yaw); - entity.setXRot(yaw); - entity.setYRot(pitch); - - byte byteYaw = convertYaw(yaw); - Rot packet = new Rot(cache, byteYaw, convertPitch(pitch), false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND || entity instanceof Display) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket(entity); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PosRot packet = new PosRot(cache, dx, dy, dz, yaw, pitch, false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void show() { - Packet spawn = type.isAlive() - ? new ClientboundAddEntityPacket(entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0); - - ClientboundSetEntityDataPacket meta = new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false)); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(getYaw())); - Rot look = new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - ClientboundSetEntityMotionPacket velocity = new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ())); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - ServerGamePacketListenerImpl connection = ((CraftPlayer) temp).getHandle().connection; - if (connections.contains(connection)) { - continue; - } - - connection.send(spawn); - connection.send(meta); - connection.send(head); - connection.send(velocity); - connection.send(look); - if (equipment != null) - connection.send(equipment); - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - if (!player.isOnline()) - return; - - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - - connection.send(type.isAlive() - ? new ClientboundAddEntityPacket(entity) // TODO CHECK THIS... used to be "addmob", changed in 1.19? - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0)); - connection.send(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), true))); - connection.send(new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.send(new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ()))); - connection.send(new ClientboundRotateHeadPacket(entity, convertYaw(getYaw()))); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - if (equipment != null) - connection.send(equipment); - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((ArmorStand) entity).setHeadPose(new Rotations(getPitch(), 0, 0)); - - sendPackets(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false))); - } - - @Override - public void remove() { - sendPackets(new ClientboundRemoveEntitiesPacket(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - if (!player.isOnline()) - return; - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - connection.send(new ClientboundRemoveEntitiesPacket(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(@NotNull EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new ClientboundEntityEventPacket(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EquipmentSlot slot = switch (equipmentSlot) { - case HAND -> EquipmentSlot.MAINHAND; - case OFF_HAND -> EquipmentSlot.OFFHAND; - case FEET -> EquipmentSlot.FEET; - case CHEST -> EquipmentSlot.CHEST; - case LEGS -> EquipmentSlot.LEGS; - case HEAD -> EquipmentSlot.HEAD; - }; - - LivingEntity livingEntity = (LivingEntity) entity; - livingEntity.setItemSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - ClientboundSetEquipmentPacket packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private ClientboundSetEquipmentPacket getEquipmentPacket() { - if (!type.isAlive()) - return null; - LivingEntity livingEntity = (LivingEntity) entity; - - List> equipmentList = new ArrayList<>(6); - for (EquipmentSlot slot : SLOTS) { - ItemStack itemStack = livingEntity.getItemBySlot(slot); - if (!itemStack.isEmpty()) { - equipmentList.add(Pair.of(slot, itemStack)); - } - } - return equipmentList.isEmpty() ? null : new ClientboundSetEquipmentPacket(cache, equipmentList); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - ServerGamePacketListenerImpl connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.send(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R3.java b/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R3.java deleted file mode 100644 index 58eea40d2..000000000 --- a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R3.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -// https://nms.screamingsandals.org/1.19.1/ -public class NonNullList_1_20_R3 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_20_R3(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.EMPTY); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.EMPTY); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R3.java b/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R3.java deleted file mode 100644 index 560af9cf9..000000000 --- a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R3.java +++ /dev/null @@ -1,114 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import com.google.common.collect.Lists; -import com.google.gson.JsonElement; -import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.core.utils.StringUtil; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.StringTagVisitor; -import net.minecraft.nbt.Tag; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -// https://nms.screamingsandals.org/1.19_R1 -public class NBT_1_20_R3 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - net.minecraft.world.item.ItemStack nms = getNMSStack(toItem); - CompoundTag from = getNMSStack(fromItem).getTag(); - CompoundTag to = nms.getTag(); - - if (path == null) { - nms.setTag(from.copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - return; - } - - to.put(path, from.getCompound(path).copy()); - toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - } - - @NotNull @Override - public net.minecraft.world.item.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - CompoundTag nbt = getNMSStack(bukkitStack).getTag(); - return nbt == null ? "null" : new TagColorVisitor().visit(nbt); - } - - @Override - public @NotNull Component getDisplayName(@NotNull ItemStack item) { - net.minecraft.network.chat.Component component = CraftItemStack.asNMSCopy(item).getDisplayName(); - JsonElement json = net.minecraft.network.chat.Component.Serializer.toJsonTree(component); - return GsonComponentSerializer.gson().serializer().fromJson(json, Component.class); - } - - private static class TagColorVisitor extends StringTagVisitor { - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - private final StringBuilder builder; - - // Stores how many nested compound tags there currently are. Used to - // determine curly brace color, as well as spacing. - private final int indents; - private final int colorOffset; - - public TagColorVisitor() { - this(0, 0); - } - - public TagColorVisitor(int indents, int colorOffset) { - Field field = ReflectionUtil.getField(StringTagVisitor.class, StringBuilder.class); - this.builder = (StringBuilder) ReflectionUtil.invokeField(field, this); - this.indents = indents; - this.colorOffset = colorOffset; - } - - @Override - public void visitCompound(CompoundTag compound) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - builder.append(braceColor).append("{\n"); - List list = Lists.newArrayList(compound.getAllKeys()); - Collections.sort(list); - - for (int i = 0; i < list.size(); i++) { - - // Add a new line after each element, and indent each line - // depending on the number of nested CompoundTags. - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - - String key = list.get(i); - Tag value = Objects.requireNonNull(compound.get(key), "This is impossible"); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - - builder.append(color).append(handleEscape(key)) - .append("&f&l: ").append(color) - .append(new TagColorVisitor(value instanceof CompoundTag ? indents + 1 : indents, colorOffset + i).visit(value)); - } - - builder.append(braceColor).append("}\n"); - } - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/v1_20_R3.java b/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/v1_20_R3.java deleted file mode 100644 index 03ccc0fca..000000000 --- a/CoreCompatibility/Core_1_20_R3/src/main/java/me/deecaad/core/compatibility/v1_20_R3.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_20_R3; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_20_R3; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_20_R3; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_20_R3; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_20_R3 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_20_R3() { - entityCompatibility = new Entity_1_20_R3(); - blockCompatibility = new Block_1_20_R3(); - nbtCompatibility = new NBT_1_20_R3(); - commandCompatibility = new Command_1_20_R3(); - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.world.entity.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).connection.send((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - ServerGamePacketListenerImpl playerConnection = getEntityPlayer(player).connection; - for (Object packet : packets) { - playerConnection.send((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull ServerPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R4/build.gradle.kts b/CoreCompatibility/Core_1_20_R4/build.gradle.kts deleted file mode 100644 index 0f96286ca..000000000 --- a/CoreCompatibility/Core_1_20_R4/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - adventureChatAPI() - - paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") -} - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(21) - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R4.java b/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R4.java deleted file mode 100644 index cfca95257..000000000 --- a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/block/Block_1_20_R4.java +++ /dev/null @@ -1,41 +0,0 @@ -package me.deecaad.core.compatibility.block; - -import it.unimi.dsi.fastutil.shorts.ShortArraySet; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.core.BlockPos; -import net.minecraft.core.SectionPos; -import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket; -import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket; -import net.minecraft.world.level.block.state.BlockState; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.block.CraftBlock; -import org.bukkit.craftbukkit.block.CraftBlockState; -import org.bukkit.craftbukkit.block.data.CraftBlockData; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -// https://nms.screamingsandals.org/1.19.1/ -public class Block_1_20_R4 implements BlockCompatibility { - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack) { - int id = IDS.incrementAndGet(); - if (id == Integer.MAX_VALUE) { - IDS.set(0); - } - - return getCrackPacket(block, crack, id); - } - - @Override - public @NotNull Object getCrackPacket(@NotNull Block block, int crack, int id) { - BlockPos pos = new BlockPos(block.getX(), block.getY(), block.getZ()); - return new ClientboundBlockDestructionPacket(id, pos, crack); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R4.java b/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R4.java deleted file mode 100644 index edd4e2135..000000000 --- a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/command/Command_1_20_R4.java +++ /dev/null @@ -1,687 +0,0 @@ -package me.deecaad.core.compatibility.command; - -import com.google.common.io.Files; -import com.google.gson.GsonBuilder; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import me.deecaad.core.commands.wrappers.BiomeHolder; -import me.deecaad.core.commands.wrappers.Column; -import me.deecaad.core.commands.wrappers.DoubleRange; -import me.deecaad.core.commands.wrappers.IntRange; -import me.deecaad.core.commands.wrappers.Location2d; -import me.deecaad.core.commands.wrappers.ParticleHolder; -import me.deecaad.core.commands.wrappers.Rotation; -import me.deecaad.core.commands.wrappers.SoundHolder; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.advancements.AdvancementHolder; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.commands.CommandBuildContext; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.commands.arguments.AngleArgument; -import net.minecraft.commands.arguments.ColorArgument; -import net.minecraft.commands.arguments.ComponentArgument; -import net.minecraft.commands.arguments.CompoundTagArgument; -import net.minecraft.commands.arguments.DimensionArgument; -import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.GameProfileArgument; -import net.minecraft.commands.arguments.MessageArgument; -import net.minecraft.commands.arguments.ObjectiveArgument; -import net.minecraft.commands.arguments.ObjectiveCriteriaArgument; -import net.minecraft.commands.arguments.OperationArgument; -import net.minecraft.commands.arguments.ParticleArgument; -import net.minecraft.commands.arguments.RangeArgument; -import net.minecraft.commands.arguments.ResourceArgument; -import net.minecraft.commands.arguments.ResourceLocationArgument; -import net.minecraft.commands.arguments.ScoreHolderArgument; -import net.minecraft.commands.arguments.ScoreboardSlotArgument; -import net.minecraft.commands.arguments.TeamArgument; -import net.minecraft.commands.arguments.TimeArgument; -import net.minecraft.commands.arguments.UuidArgument; -import net.minecraft.commands.arguments.blocks.BlockPredicateArgument; -import net.minecraft.commands.arguments.blocks.BlockStateArgument; -import net.minecraft.commands.arguments.coordinates.BlockPosArgument; -import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; -import net.minecraft.commands.arguments.coordinates.RotationArgument; -import net.minecraft.commands.arguments.coordinates.SwizzleArgument; -import net.minecraft.commands.arguments.coordinates.Vec2Argument; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; -import net.minecraft.commands.arguments.item.FunctionArgument; -import net.minecraft.commands.arguments.item.ItemArgument; -import net.minecraft.commands.arguments.item.ItemPredicateArgument; -import net.minecraft.commands.arguments.selector.EntitySelector; -import net.minecraft.commands.synchronization.ArgumentUtils; -import net.minecraft.commands.synchronization.SuggestionProviders; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.Holder; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.CollectionTag; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NumericTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ColumnPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.level.block.state.pattern.BlockInWorld; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.Vec3; -import org.bukkit.Axis; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.NamespacedKey; -import org.bukkit.OfflinePlayer; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.advancement.Advancement; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.craftbukkit.CraftLootTable; -import org.bukkit.craftbukkit.CraftParticle; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.CraftSound; -import org.bukkit.craftbukkit.block.data.CraftBlockData; -import org.bukkit.craftbukkit.enchantments.CraftEnchantment; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.craftbukkit.potion.CraftPotionEffectType; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; -import org.bukkit.loot.LootTable; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@SuppressWarnings({"rawtypes", "unchecked"}) -public class Command_1_20_R4 implements CommandCompatibility { - - public static final MinecraftServer SERVER; - private static final CommandBuildContext COMMAND_BUILD_CONTEXT; - private static final DynamicCommandExceptionType ERROR_BIOME_INVALID; - - static { - SERVER = ((CraftServer) Bukkit.getServer()).getServer(); - COMMAND_BUILD_CONTEXT = CommandBuildContext.simple(SERVER.registryAccess(), SERVER.getWorldData().getDataConfiguration().enabledFeatures()); - ERROR_BIOME_INVALID = new DynamicCommandExceptionType( - arg -> net.minecraft.network.chat.Component.translatable("commands.locate.biome.invalid", arg)); - } - - @Override - public SimpleCommandMap getCommandMap() { - return SERVER.server.getCommandMap(); - } - - @Override - public void resendCommandRegistry(Player player) { - ServerPlayer p = ((CraftPlayer) player).getHandle(); - SERVER.getCommands().sendCommands(p); - } - - @Override - public void generateFile(File file) { - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(new GsonBuilder().setPrettyPrinting().create() - .toJson(ArgumentUtils.serializeNodeToJson(getCommandDispatcher(), getCommandDispatcher().getRoot()))); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public CommandSender getCommandSender(CommandContext context) { - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return source.getBukkitSender(); - } - - @Override - public CommandSender getCommandSenderRaw(Object nms) { - return ((CommandSourceStack) nms).getBukkitSender(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public CommandDispatcher getCommandDispatcher() { - return (CommandDispatcher) SERVER.getCommands().getDispatcher(); - } - - @Override - public ArgumentType angle() { - return AngleArgument.angle(); - } - - @Override - public ArgumentType axis() { - return SwizzleArgument.swizzle(); - } - - @Override - public ArgumentType blockPredicate() { - return BlockPredicateArgument.blockPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType blockState() { - return BlockStateArgument.block(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType chat() { - return MessageArgument.message(); - } - - @Override - public ArgumentType chatComponent() { - return ComponentArgument.textComponent(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType chatFormat() { - return ColorArgument.color(); - } - - @Override - public ArgumentType dimension() { - return DimensionArgument.dimension(); - } - - @Override - public ArgumentType enchantment() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENCHANTMENT); - } - - @Override - public ArgumentType entity() { - return EntityArgument.entity(); - } - - @Override - public ArgumentType entities() { - return EntityArgument.entities(); - } - - @Override - public ArgumentType player() { - return EntityArgument.player(); - } - - @Override - public ArgumentType players() { - return EntityArgument.players(); - } - - @Override - public ArgumentType entitySummon() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.ENTITY_TYPE); - } - - @Override - public ArgumentType itemPredicate() { - return ItemPredicateArgument.itemPredicate(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType itemStack() { - return ItemArgument.item(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType mathOperation() { - return OperationArgument.operation(); - } - - @Override - public ArgumentType mobEffect() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.MOB_EFFECT); - } - - @Override - public ArgumentType nbtCompound() { - return CompoundTagArgument.compoundTag(); - } - - @Override - public ArgumentType particle() { - return ParticleArgument.particle(COMMAND_BUILD_CONTEXT); - } - - @Override - public ArgumentType profile() { - return GameProfileArgument.gameProfile(); - } - - @Override - public ArgumentType rotation() { - return RotationArgument.rotation(); - } - - @Override - public ArgumentType scoreboardCriteria() { - return ObjectiveCriteriaArgument.criteria(); - } - - @Override - public ArgumentType scoreboardObjective() { - return ObjectiveArgument.objective(); - } - - @Override - public ArgumentType scoreboardSlot() { - return ScoreboardSlotArgument.displaySlot(); - } - - @Override - public ArgumentType scoreboardTeam() { - return TeamArgument.team(); - } - - @Override - public ArgumentType scoreholder(boolean single) { - return single ? ScoreHolderArgument.scoreHolder() : ScoreHolderArgument.scoreHolders(); - } - - @Override - public ArgumentType tag() { - return FunctionArgument.functions(); - } - - @Override - public ArgumentType time() { - return TimeArgument.time(); - } - - @Override - public ArgumentType uuid() { - return UuidArgument.uuid(); - } - - @Override - public ArgumentType location() { - return Vec3Argument.vec3(); - } - - @Override - public ArgumentType location2() { - return Vec2Argument.vec2(); - } - - @Override - public ArgumentType block() { - return BlockPosArgument.blockPos(); - } - - @Override - public ArgumentType block2() { - return ColumnPosArgument.columnPos(); - } - - @Override - public ArgumentType biome() { - return ResourceArgument.resource(COMMAND_BUILD_CONTEXT, Registries.BIOME); - } - - @Override - public ArgumentType key() { - return ResourceLocationArgument.id(); - } - - @Override - public SuggestionProvider biomeKey() { - return biome()::listSuggestions; - } - - @Override - public SuggestionProvider recipeKey() { - return (SuggestionProvider) SuggestionProviders.ALL_RECIPES; - } - - @Override - public SuggestionProvider soundKey() { - return (SuggestionProvider) SuggestionProviders.AVAILABLE_SOUNDS; - } - - @Override - public SuggestionProvider entityKey() { - return (SuggestionProvider) SuggestionProviders.SUMMONABLE_ENTITIES; - } - - @Override - public SuggestionProvider advancementKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.getAdvancements().getAllAdvancements().stream().map(AdvancementHolder::id), builder); - } - - @Override - public SuggestionProvider lootKey() { - return (context, builder) -> SharedSuggestionProvider.suggestResource(SERVER.reloadableRegistries().getKeys(Registries.LOOT_TABLE), builder); - } - - private static NamespacedKey fromResourceLocation(ResourceLocation key) { - return NamespacedKey.fromString(key.getNamespace() + ":" + key.getPath()); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private CommandContext cast(CommandContext context) { - return (CommandContext) context; - } - - @Override - public Advancement getAdvancement(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getAdvancement(cast(context), key).toBukkit(); - } - - @Override - public float getAngle(CommandContext context, String key) { - return AngleArgument.getAngle(cast(context), key); - } - - @Override - public EnumSet getAxis(CommandContext context, String key) { - EnumSet bukkitAxis = EnumSet.noneOf(Axis.class); - EnumSet nmsAxis = SwizzleArgument.getSwizzle(cast(context), key); - - for (Direction.Axis axis : nmsAxis) { - bukkitAxis.add(switch (axis) { - case X -> Axis.X; - case Y -> Axis.Y; - case Z -> Axis.Z; - }); - } - - return bukkitAxis; - } - - @Override - public BiomeHolder getBiome(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference holder = ResourceArgument.getResource(cast(context), key, Registries.BIOME); - ResourceLocation location = holder.key().location(); - Biome bukkit = EnumUtil.getIfPresent(Biome.class, location.getPath()).orElse(Biome.CUSTOM); - NamespacedKey namespaced = new NamespacedKey(location.getNamespace(), location.getPath()); - return new BiomeHolder(bukkit, namespaced); - } - - @Override - public Predicate getBlockPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = BlockPredicateArgument.getBlockPredicate(cast(context), key); - return block -> predicate.test(new BlockInWorld(cast(context).getSource().getLevel(), - new BlockPos(block.getX(), block.getY(), block.getZ()), true)); - } - - @Override - public BlockData getBlockState(CommandContext context, String key) { - return CraftBlockData.fromData(BlockStateArgument.getBlock(cast(context), key).getState()); - } - - @Override - public World.Environment getDimension(CommandContext context, String key) throws CommandSyntaxException { - return DimensionArgument.getDimension(cast(context), key).getWorld().getEnvironment(); - } - - @Override - public Enchantment getEnchantment(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference ench = ResourceArgument.getEnchantment(cast(context), key); - NamespacedKey namespace = CraftNamespacedKey.fromMinecraft(ench.key().location()); - - return new CraftEnchantment(namespace, ench.value()); - } - - @Override - public org.bukkit.entity.Entity getEntitySelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSingleEntity(source).getBukkitEntity(); - } - - @Override - public List getEntitiesSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findEntities(source).stream() - .map(Entity::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public Player getPlayerSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findSinglePlayer(source).getBukkitEntity(); - } - - @Override - public List getPlayersSelector(CommandContext context, String key) throws CommandSyntaxException { - EntitySelector selector = cast(context).getArgument(key, EntitySelector.class); - - // Setting this field allows non-op users to use entity selectors. - // We let command permissions handle the permission system. We may have - // to check if a vanished player can be seen in this list. TODO. - ReflectionUtil.setField(ReflectionUtil.getField(EntitySelector.class, boolean.class, 3), selector, false); - - CommandSourceStack source = (CommandSourceStack) context.getSource(); - return selector.findPlayers(source).stream() - .map(ServerPlayer::getBukkitEntity) - .collect(Collectors.toList()); - } - - @Override - public EntityType getEntityType(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.entity.EntityType type = ResourceArgument.getEntityType(cast(context), key).value(); - return EntityType.fromName(net.minecraft.world.entity.EntityType.getKey(type).getPath()); - } - - @Override - public DoubleRange getDoubleRange(CommandContext context, String key) { - MinMaxBounds.Doubles range = RangeArgument.Floats.getRange(cast(context), key); - double min = range.min().orElse(Double.MIN_VALUE); - double max = range.max().orElse(Double.MAX_VALUE); - return new DoubleRange(min, max); - } - - @Override - public IntRange getIntRange(CommandContext context, String key) { - MinMaxBounds.Ints range = RangeArgument.Ints.getRange(cast(context), key); - int min = range.min().orElse(Integer.MIN_VALUE); - int max = range.max().orElse(Integer.MAX_VALUE); - return new IntRange(min, max); - } - - @Override - public ItemStack getItemStack(CommandContext context, String key) throws CommandSyntaxException { - return CraftItemStack.asBukkitCopy(ItemArgument.getItem(cast(context), key).createItemStack(1, false)); - } - - @Override - public Predicate getItemStackPredicate(CommandContext context, String key) throws CommandSyntaxException { - Predicate predicate = ItemPredicateArgument.getItemPredicate(cast(context), key); - return (item) -> predicate.test(CraftItemStack.asNMSCopy(item)); - } - - @Override - public String getKeyedAsString(CommandContext context, String key) throws CommandSyntaxException { - return ResourceLocationArgument.getId(cast(context), key).toString(); - } - - @Override - public Column getLocation2DBlock(CommandContext context, String key) throws CommandSyntaxException { - ColumnPos column = ColumnPosArgument.getColumnPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Column(world, column.x(), column.z()); - } - - @Override - public Location2d getLocation2DPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec2 vector = Vec2Argument.getVec2(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location2d(world, vector.x, vector.y); - } - - @Override - public Block getLocationBlock(CommandContext context, String key) throws CommandSyntaxException { - BlockPos block = BlockPosArgument.getLoadedBlockPos(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return world.getBlockAt(block.getX(), block.getY(), block.getZ()); - } - - @Override - public Location getLocationPrecise(CommandContext context, String key) throws CommandSyntaxException { - Vec3 vector = Vec3Argument.getVec3(cast(context), key); - World world = cast(context).getSource().getLevel().getWorld(); - return new Location(world, vector.x, vector.y, vector.z); - } - - @Override - public LootTable getLootTable(CommandContext context, String key) { - return CraftLootTable.minecraftToBukkit(ResourceLocationArgument.getId(cast(context), key)); - } - - @Override - public String getObjective(CommandContext context, String key) throws IllegalArgumentException, CommandSyntaxException { - return ObjectiveArgument.getObjective(cast(context), key).getName(); - } - - @Override - public String getObjectiveCriteria(CommandContext context, String key) { - return ObjectiveCriteriaArgument.getCriteria(cast(context), key).getName(); - } - - @Override - public ParticleHolder getParticle(CommandContext context, String key) { - ParticleOptions particle = ParticleArgument.getParticle(cast(context), key); - - return new ParticleHolder(CraftParticle.minecraftToBukkit(particle.getType()), particle, null); - } - - @Override - public Player getPlayer(CommandContext context, String key) throws CommandSyntaxException { - Player target = Bukkit.getPlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - if (target == null) - throw GameProfileArgument.ERROR_UNKNOWN_PLAYER.create(); - - return target; - } - - @Override - public OfflinePlayer getOfflinePlayer(CommandContext context, String key) throws CommandSyntaxException { - return Bukkit.getOfflinePlayer(GameProfileArgument.getGameProfiles(cast(context), key).iterator().next().getId()); - } - - @Override - public PotionEffectType getPotionEffect(CommandContext context, String key) throws CommandSyntaxException { - Holder.Reference effect = ResourceArgument.getMobEffect(cast(context), key); - NamespacedKey bukkit = CraftNamespacedKey.fromMinecraft(effect.key().location()); - return new CraftPotionEffectType(bukkit, effect.value()); - } - - @Override - public Recipe getRecipe(CommandContext context, String key) throws CommandSyntaxException { - net.minecraft.world.item.crafting.RecipeHolder recipe = ResourceLocationArgument.getRecipe(cast(context), key); - return recipe.toBukkitRecipe(); - } - - @Override - public Rotation getRotation(CommandContext context, String key) { - Vec2 rotation = RotationArgument.getRotation(cast(context), key).getRotation(cast(context).getSource()); - return new Rotation(rotation.x, rotation.y); - } - - @Override - public SoundHolder getSound(CommandContext context, String key) { - ResourceLocation location = ResourceLocationArgument.getId(cast(context), key); - SoundEvent sound = BuiltInRegistries.SOUND_EVENT.get(location); - Sound bukkit = sound == null ? null : CraftSound.minecraftToBukkit(sound); - return new SoundHolder(bukkit, new NamespacedKey(location.getNamespace(), location.getPath())); - } - - @Override - public String getTeam(CommandContext context, String key) throws CommandSyntaxException { - return TeamArgument.getTeam(cast(context), key).getName(); - } - - @Override - public int getTime(CommandContext context, String key) { - return cast(context).getArgument(key, Integer.class); - } - - @Override - public UUID getUUID(CommandContext context, String key) { - return UuidArgument.getUuid(cast(context), key); - } - - @Override - public Map getCompound(CommandContext context, String key) { - CompoundTag nbt = CompoundTagArgument.getCompoundTag(context, key); - return convertMap(nbt); - } - - @SuppressWarnings("unchecked") - private Object convert(Tag tag) { - return switch (tag.getId()) { - case Tag.TAG_BYTE, Tag.TAG_SHORT, Tag.TAG_INT, Tag.TAG_LONG -> ((NumericTag) tag).getAsInt(); - case Tag.TAG_FLOAT, Tag.TAG_DOUBLE -> ((NumericTag) tag).getAsDouble(); - case Tag.TAG_STRING -> ((StringTag) tag).getAsString(); - case Tag.TAG_BYTE_ARRAY, Tag.TAG_INT_ARRAY, Tag.TAG_LONG_ARRAY, Tag.TAG_LIST -> convertList((CollectionTag) tag); - case Tag.TAG_COMPOUND -> convertMap((CompoundTag) tag); - default -> throw new IllegalStateException("Unexpected value: " + tag); - }; - } - - private Map convertMap(CompoundTag nbt) { - Map temp = new HashMap<>(nbt.size()); - - for (String key : nbt.getAllKeys()) { - Object value = convert(Objects.requireNonNull(nbt.get(key))); - temp.put(key, value); - } - - return temp; - } - - private List convertList(CollectionTag values) { - return values.stream().map(this::convert).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R4.java b/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R4.java deleted file mode 100644 index 89af5210a..000000000 --- a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/entity/Entity_1_20_R4.java +++ /dev/null @@ -1,120 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.compatibility.equipevent.NonNullList_1_20_R4; -import me.deecaad.core.compatibility.equipevent.TriIntConsumer; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.syncher.SynchedEntityData; -import org.bukkit.Location; -import org.bukkit.craftbukkit.entity.CraftEntity; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -// https://nms.screamingsandals.org/1.18.1/ -public class Entity_1_20_R4 implements EntityCompatibility { - - public static final Field itemsById = ReflectionUtil.getField(SynchedEntityData.class, SynchedEntityData.DataItem[].class); - - @Override - public Vector getLastLocation(Entity entity) { - net.minecraft.world.entity.Entity nms = ((CraftEntity) entity).getHandle(); - return new Vector(nms.xOld, nms.yOld, nms.zOld); - } - - @Override - public List generateNonNullList(int size, TriIntConsumer consumer) { - return new NonNullList_1_20_R4(size, consumer); - } - - @Override - public FakeEntity generateFakeEntity(Location location, EntityType type, Object data) { - return new FakeEntity_1_20_R4(location, type, data); - } - - @Override - public int getId(Object obj) { - return ((ClientboundSetEntityDataPacket) obj).id(); - } - - @Override - public void setSlot(Player bukkit, EquipmentSlot slot, @Nullable ItemStack item) { - if (item == null) { - item = bukkit.getEquipment().getItem(slot); // added in 1.15 - } - - int id = bukkit.getEntityId(); - net.minecraft.world.entity.EquipmentSlot nmsSlot = switch (slot) { - case HEAD -> net.minecraft.world.entity.EquipmentSlot.HEAD; - case CHEST -> net.minecraft.world.entity.EquipmentSlot.CHEST; - case LEGS -> net.minecraft.world.entity.EquipmentSlot.LEGS; - case FEET -> net.minecraft.world.entity.EquipmentSlot.FEET; - case HAND -> net.minecraft.world.entity.EquipmentSlot.MAINHAND; - case OFF_HAND -> net.minecraft.world.entity.EquipmentSlot.OFFHAND; - case BODY -> net.minecraft.world.entity.EquipmentSlot.BODY; - }; - - List> temp = new ArrayList<>(1); - temp.add(new Pair<>(nmsSlot, CraftItemStack.asNMSCopy(item))); - ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(id, temp); - ((CraftPlayer) bukkit).getHandle().connection.send(packet); - } - - public static List> getEntityData(SynchedEntityData data, boolean forceUpdateAll) { - if (!forceUpdateAll) { - List> dirty = data.packDirty(); - return dirty == null ? List.of() : dirty; - } - - // 1.19.3 changed the packet arguments, so in order to unpack ALL data - // (not just the dirty data) we need to manually get it and unpack it. - SynchedEntityData.DataItem[] metaData = (SynchedEntityData.DataItem[]) ReflectionUtil.invokeField(itemsById, data); - List> packed = new ArrayList<>(metaData.length); - for (SynchedEntityData.DataItem element : metaData) - packed.add(element.value()); - return packed; - } - - @Override - public Object generateMetaPacket(Entity bukkit) { - net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkit).getHandle(); - return new ClientboundSetEntityDataPacket(entity.getId(), getEntityData(entity.getEntityData(), true)); - } - - @Override - public void modifyMetaPacket(Object obj, EntityMeta meta, boolean enabled) { - ClientboundSetEntityDataPacket packet = (ClientboundSetEntityDataPacket) obj; - List> list = packet.packedItems(); - - if (list == null || list.isEmpty()) - return; - - // The "shared byte data" is applied to every entity, and it is always - // the first item (It can never be the second, third, etc.). However, - // if no modifications are made to the "shared byte data" before this - // packet is sent, that item will not be present. This is implemented - // in vanilla's dirty meta system. - if (list.get(0) == null || list.get(0).value().getClass() != Byte.class) - return; - - // noinspection unchecked - SynchedEntityData.DataValue item = (SynchedEntityData.DataValue) list.get(0); - byte data = item.value(); - data = meta.set(data, enabled); - - // 1.19.3 changed this to a record - list.set(0, new SynchedEntityData.DataValue<>(item.id(), item.serializer(), data)); - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R4.java b/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R4.java deleted file mode 100644 index 279ca600b..000000000 --- a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/entity/FakeEntity_1_20_R4.java +++ /dev/null @@ -1,351 +0,0 @@ -package me.deecaad.core.compatibility.entity; - -import com.mojang.datafixers.util.Pair; -import me.deecaad.core.utils.DistanceUtil; -import net.minecraft.core.Rotations; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; -import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; -import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; -import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.decoration.ArmorStand; -import net.minecraft.world.entity.item.FallingBlockEntity; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.entity.projectile.FireworkRocketEntity; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.bukkit.EntityEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.craftbukkit.CraftWorld; -import org.bukkit.craftbukkit.block.CraftBlockState; -import org.bukkit.craftbukkit.block.data.CraftBlockData; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.craftbukkit.util.CraftChatMessage; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static me.deecaad.core.compatibility.entity.Entity_1_20_R4.getEntityData; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.PosRot; -import static net.minecraft.network.protocol.game.ClientboundMoveEntityPacket.Rot; - -public class FakeEntity_1_20_R4 extends FakeEntity { - - // Store this since using Enum#values() is especially slow - public static final EquipmentSlot[] SLOTS = EquipmentSlot.values(); - - private final Entity entity; - private final List connections; // store the player connection to avoid type cast - - // Only 1 of these can be used at a time - private BlockState block; - private ItemStack item; - - public FakeEntity_1_20_R4(@NotNull Location location, @NotNull EntityType type, @Nullable Object data) { - super(location, type); - - if (location.getWorld() == null) - throw new IllegalArgumentException(); - - CraftWorld world = (CraftWorld) location.getWorld(); - - // Location vars - final double x = location.getX(); - final double y = location.getY(); - final double z = location.getZ(); - - // Some entity types (dropped items and falling blocks, for example) - // require extra data in order to display. We only need to use these - // constructors when we are given the data (data != null). - if (data != null) { - entity = switch (type) { - case ITEM -> new ItemEntity(world.getHandle(), x, y, z, item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - case FALLING_BLOCK -> { - FallingBlockEntity temp = new FallingBlockEntity(net.minecraft.world.entity.EntityType.FALLING_BLOCK, world.getHandle()); - temp.setPosRaw(x, y, z); - block = (data.getClass() == Material.class - ? ((CraftBlockData) ((Material) data).createBlockData()).getState() - : ((CraftBlockState) data).getHandle()); - yield temp; - } - case FIREWORK_ROCKET -> new FireworkRocketEntity(world.getHandle(), item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data), x, y, z, true); - case ITEM_DISPLAY -> { - Display.ItemDisplay temp = net.minecraft.world.entity.EntityType.ITEM_DISPLAY.create(world.getHandle()); - temp.setPos(x, y, z); - temp.setItemStack(CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - yield temp; - } - default -> world.makeEntity(location, type.getEntityClass()); - }; - } else { - entity = world.makeEntity(location, type.getEntityClass()); - } - - if (type == EntityType.ARMOR_STAND) { - ArmorStand armorStand = (ArmorStand) entity; - armorStand.setMarker(true); - } - - this.setLocation(x, y, z, location.getYaw(), location.getPitch()); - this.cache = entity.getId(); - this.connections = new LinkedList<>(); // We only need to iterate/remove, so LinkedList is best - } - - @Override - public boolean getMeta(int metaFlag) { - return entity.getSharedFlag(metaFlag); - } - - @Override - public void setMeta(int metaFlag, boolean isEnabled) { - entity.setSharedFlag(metaFlag, isEnabled); - } - - @Override - public Object getData() { - return switch (type) { - case ITEM -> item.asBukkitCopy(); - case FALLING_BLOCK -> CraftBlockData.fromData(block); - default -> null; - }; - } - - @Override - public void setData(@Nullable Object data) { - switch (type) { - case ITEM -> ((ItemEntity) entity).setItem(item = CraftItemStack.asNMSCopy((org.bukkit.inventory.ItemStack) data)); - } - } - - @Override - public void setDisplay(@Nullable String display) { - entity.setCustomName(CraftChatMessage.fromStringOrNull(display)); - entity.setCustomNameVisible(display != null && !display.isEmpty()); - } - - @Override - public void setGravity(boolean gravity) { - entity.setNoGravity(!gravity); - } - - @Override - protected void setLocation(double x, double y, double z, float yaw, float pitch) { - super.setLocation(x, y, z, yaw, pitch); - - // Needed for teleport packet. - entity.setPosRaw(x, y, z); - entity.setYHeadRot(yaw); - entity.setYRot(yaw); - entity.setXRot(pitch); - } - - @Override - public void setMotion(double dx, double dy, double dz) { - ClientboundSetEntityMotionPacket packet = new ClientboundSetEntityMotionPacket(cache, new Vec3(dx, dy, dz)); - motion.setX(dx); - motion.setY(dy); - motion.setZ(dz); - - sendPackets(packet); - } - - @Override - public void setRotation(float yaw, float pitch) { - if (offset != null) { - yaw += offset.getYaw(); - pitch += offset.getPitch(); - } - - location.setYaw(yaw); - location.setPitch(pitch); - entity.setYHeadRot(yaw); - entity.setXRot(yaw); - entity.setYRot(pitch); - - byte byteYaw = convertYaw(yaw); - Rot packet = new Rot(cache, byteYaw, convertPitch(pitch), false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, byteYaw); - - sendPackets(packet, head); - - if (type == EntityType.ARMOR_STAND || entity instanceof Display) - updateMeta(); - } - - @Override - public void setPositionRaw(double x, double y, double z, float yaw, float pitch) { - ClientboundTeleportEntityPacket packet = new ClientboundTeleportEntityPacket(entity); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch) { - PosRot packet = new PosRot(cache, dx, dy, dz, yaw, pitch, false); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(yaw)); - - sendPackets(packet, head); - } - - @Override - public void show() { - Packet spawn = type.isAlive() - ? new ClientboundAddEntityPacket(entity) - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0); - - ClientboundSetEntityDataPacket meta = new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false)); - ClientboundRotateHeadPacket head = new ClientboundRotateHeadPacket(entity, convertYaw(getYaw())); - Rot look = new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false); - ClientboundSetEntityMotionPacket velocity = new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ())); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - - for (Player temp : DistanceUtil.getPlayersInRange(location)) { - ServerGamePacketListenerImpl connection = ((CraftPlayer) temp).getHandle().connection; - if (connections.contains(connection)) { - continue; - } - - connection.send(spawn); - connection.send(meta); - connection.send(head); - connection.send(velocity); - connection.send(look); - if (equipment != null) - connection.send(equipment); - - connections.add(connection); - } - } - - @Override - public void show(@NotNull Player player) { - if (!player.isOnline()) - return; - - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - - connection.send(type.isAlive() - ? new ClientboundAddEntityPacket(entity) // TODO CHECK THIS... used to be "addmob", changed in 1.19? - : new ClientboundAddEntityPacket(entity, type == EntityType.FALLING_BLOCK ? Block.getId(block) : 0)); - connection.send(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), true))); - connection.send(new Rot(cache, convertYaw(getYaw()), convertPitch(getPitch()), false)); - connection.send(new ClientboundSetEntityMotionPacket(cache, new Vec3(motion.getX(), motion.getY(), motion.getZ()))); - connection.send(new ClientboundRotateHeadPacket(entity, convertYaw(getYaw()))); - ClientboundSetEquipmentPacket equipment = getEquipmentPacket(); - if (equipment != null) - connection.send(equipment); - - // Inject the player's packet connection into this listener, so we can - // show the player position/velocity/rotation changes - connections.add(connection); - } - - @Override - public void updateMeta() { - if (type == EntityType.ARMOR_STAND) - ((ArmorStand) entity).setHeadPose(new Rotations(getPitch(), 0, 0)); - - sendPackets(new ClientboundSetEntityDataPacket(cache, getEntityData(entity.getEntityData(), false))); - } - - @Override - public void remove() { - sendPackets(new ClientboundRemoveEntitiesPacket(cache)); - connections.clear(); - } - - @Override - public void remove(@NotNull Player player) { - if (!player.isOnline()) - return; - ServerGamePacketListenerImpl connection = ((CraftPlayer) player).getHandle().connection; - connection.send(new ClientboundRemoveEntitiesPacket(cache)); - - // Uninject player from seeing position changes - if (!connections.remove(connection)) { - throw new IllegalStateException("Tried to remove player that was never added"); - } - } - - @Override - public void playEffect(@NotNull EntityEffect effect) { - if (!effect.getApplicable().isAssignableFrom(type.getEntityClass())) - return; - sendPackets(new ClientboundEntityEventPacket(entity, effect.getData())); - } - - @Override - public void setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, org.bukkit.inventory.ItemStack itemStack) { - if (!type.isAlive()) - throw new IllegalStateException("Cannot set equipment of " + type); - - EquipmentSlot slot = switch (equipmentSlot) { - case HAND -> EquipmentSlot.MAINHAND; - case OFF_HAND -> EquipmentSlot.OFFHAND; - case FEET -> EquipmentSlot.FEET; - case CHEST -> EquipmentSlot.CHEST; - case LEGS -> EquipmentSlot.LEGS; - case HEAD -> EquipmentSlot.HEAD; - case BODY -> EquipmentSlot.BODY; - }; - - LivingEntity livingEntity = (LivingEntity) entity; - livingEntity.setItemSlot(slot, CraftItemStack.asNMSCopy(itemStack)); - } - - @Override - public void updateEquipment() { - ClientboundSetEquipmentPacket packet = getEquipmentPacket(); - if (packet != null) - sendPackets(packet); - } - - private ClientboundSetEquipmentPacket getEquipmentPacket() { - if (!type.isAlive()) - return null; - LivingEntity livingEntity = (LivingEntity) entity; - - List> equipmentList = new ArrayList<>(6); - for (EquipmentSlot slot : SLOTS) { - ItemStack itemStack = livingEntity.getItemBySlot(slot); - if (!itemStack.isEmpty()) { - equipmentList.add(Pair.of(slot, itemStack)); - } - } - return equipmentList.isEmpty() ? null : new ClientboundSetEquipmentPacket(cache, equipmentList); - } - - private void sendPackets(Packet... packets) { - Iterator connectionIterator = connections.iterator(); - while (connectionIterator.hasNext()) { - ServerGamePacketListenerImpl connection = connectionIterator.next(); - if (connection.isDisconnected()) { - connectionIterator.remove(); - continue; - } - for (Packet packet : packets) { - connection.send(packet); - } - } - } -} diff --git a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R4.java b/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R4.java deleted file mode 100644 index dd2ecaced..000000000 --- a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/equipevent/NonNullList_1_20_R4.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.deecaad.core.compatibility.equipevent; - -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.core.NonNullList; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.bukkit.craftbukkit.inventory.CraftItemStack; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; - -// https://nms.screamingsandals.org/1.19.1/ -public class NonNullList_1_20_R4 extends NonNullList { - - private static final Field itemField = ReflectionUtil.getField(ItemStack.class, Item.class); - - private final TriIntConsumer consumer; - - public NonNullList_1_20_R4(int size, TriIntConsumer consumer) { - super(generate(size), ItemStack.EMPTY); - - this.consumer = consumer; - } - - @Override - public ItemStack set(int index, ItemStack newItem) { - ItemStack oldItem = get(index); - - if (newItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, newItem) != null) { - newItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - newItem.setCount(0); - } - - else if (oldItem.getCount() == 0 && ReflectionUtil.invokeField(itemField, oldItem) != null) { - oldItem.setCount(1); - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - oldItem.setCount(0); - } - - else if (!ItemStack.matches(oldItem, newItem)) { - consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index); - } - - return super.set(index, newItem); - } - - private static List generate(int size) { - ItemStack[] items = new ItemStack[size]; - Arrays.fill(items, ItemStack.EMPTY); - return Arrays.asList(items); - } -} diff --git a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R4.java b/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R4.java deleted file mode 100644 index f8cfcef42..000000000 --- a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/nbt/NBT_1_20_R4.java +++ /dev/null @@ -1,115 +0,0 @@ -package me.deecaad.core.compatibility.nbt; - -import com.google.common.collect.Lists; -import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.core.utils.StringUtil; -import net.kyori.adventure.text.Component; -import net.minecraft.core.component.DataComponentMap; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.StringTagVisitor; -import net.minecraft.nbt.Tag; -import net.minecraft.world.item.Item; -import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Field; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -// https://nms.screamingsandals.org/1.19_R1 -public class NBT_1_20_R4 extends NBT_Persistent { - - @Override - public void copyTagsFromTo(@NotNull ItemStack fromItem, @NotNull ItemStack toItem, @Nullable String path) { - Item nms = getNMSStack(toItem).getItem(); - DataComponentMap from = getNMSStack(fromItem).getItem().components(); - DataComponentMap to = nms.components(); - - /* - * if (path == null) { nms.setTag(from.copy()); - * toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); return; } - * - * to.put(path, from.getCompound(path).copy()); - * toItem.setItemMeta(getBukkitStack(nms).getItemMeta()); - */ - } - - @NotNull @Override - public net.minecraft.world.item.ItemStack getNMSStack(@NotNull ItemStack bukkitStack) { - return CraftItemStack.asNMSCopy(bukkitStack); - } - - @NotNull @Override - public ItemStack getBukkitStack(@NotNull Object nmsStack) { - return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsStack); - } - - @NotNull @Override - public String getNBTDebug(@NotNull ItemStack bukkitStack) { - // CompoundTag nbt = getNMSStack(bukkitStack).getTag(); - // return nbt == null ? "null" : new TagColorVisitor().visit(nbt); - return null; - } - - @Override - public @NotNull Component getDisplayName(@NotNull ItemStack item) { - // net.minecraft.network.chat.Component component = CraftItemStack.asNMSCopy(item).getDisplayName(); - // JsonElement json = net.minecraft.network.chat.Component.Serializer.toJsonTree(component); - // return GsonComponentSerializer.gson().serializer().fromJson(json, Component.class); - return null; - } - - private static class TagColorVisitor extends StringTagVisitor { - - private static final String BRACE_COLORS = "f780"; // grayscale colors - private static final String VALUE_COLORS = "6abcdef"; // bright colors - private final StringBuilder builder; - - // Stores how many nested compound tags there currently are. Used to - // determine curly brace color, as well as spacing. - private final int indents; - private final int colorOffset; - - public TagColorVisitor() { - this(0, 0); - } - - public TagColorVisitor(int indents, int colorOffset) { - Field field = ReflectionUtil.getField(StringTagVisitor.class, StringBuilder.class); - this.builder = (StringBuilder) ReflectionUtil.invokeField(field, this); - this.indents = indents; - this.colorOffset = colorOffset; - } - - @Override - public void visitCompound(CompoundTag compound) { - String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length()); - builder.append(braceColor).append("{\n"); - List list = Lists.newArrayList(compound.getAllKeys()); - Collections.sort(list); - - for (int i = 0; i < list.size(); i++) { - - // Add a new line after each element, and indent each line - // depending on the number of nested CompoundTags. - if (i != 0) - builder.append('\n'); - - builder.append(StringUtil.repeat(" ", indents)); - - String key = list.get(i); - Tag value = Objects.requireNonNull(compound.get(key), "This is impossible"); - String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length()); - - builder.append(color).append(handleEscape(key)) - .append("&f&l: ").append(color) - .append(new TagColorVisitor(value instanceof CompoundTag ? indents + 1 : indents, colorOffset + i).visit(value)); - } - - builder.append(braceColor).append("}\n"); - } - } -} \ No newline at end of file diff --git a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/v1_20_R4.java b/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/v1_20_R4.java deleted file mode 100644 index 492ad7854..000000000 --- a/CoreCompatibility/Core_1_20_R4/src/main/java/me/deecaad/core/compatibility/v1_20_R4.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.deecaad.core.compatibility; - -import me.deecaad.core.compatibility.block.BlockCompatibility; -import me.deecaad.core.compatibility.block.Block_1_20_R4; -import me.deecaad.core.compatibility.command.CommandCompatibility; -import me.deecaad.core.compatibility.command.Command_1_20_R4; -import me.deecaad.core.compatibility.entity.EntityCompatibility; -import me.deecaad.core.compatibility.entity.Entity_1_20_R4; -import me.deecaad.core.compatibility.nbt.NBTCompatibility; -import me.deecaad.core.compatibility.nbt.NBT_1_20_R4; -import net.minecraft.network.protocol.Packet; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.server.network.ServerGamePacketListenerImpl; -import org.bukkit.World; -import org.bukkit.craftbukkit.CraftWorld; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class v1_20_R4 implements ICompatibility { - - private final EntityCompatibility entityCompatibility; - private final BlockCompatibility blockCompatibility; - private final NBTCompatibility nbtCompatibility; - private final CommandCompatibility commandCompatibility; - - public v1_20_R4() { - entityCompatibility = new Entity_1_20_R4(); - blockCompatibility = new Block_1_20_R4(); - nbtCompatibility = new NBT_1_20_R4(); - commandCompatibility = new Command_1_20_R4(); - } - - @Override - public Entity getEntityById(@NotNull World world, int entityId) { - net.minecraft.world.entity.Entity e = ((CraftWorld) world).getHandle().getEntity(entityId); - return e == null ? null : e.getBukkitEntity(); - } - - @Override - public void sendPackets(Player player, Object packet) { - getEntityPlayer(player).connection.send((Packet) packet); - } - - @Override - public void sendPackets(Player player, Object... packets) { - ServerGamePacketListenerImpl playerConnection = getEntityPlayer(player).connection; - for (Object packet : packets) { - playerConnection.send((Packet) packet); - } - } - - @Override - public @NotNull NBTCompatibility getNBTCompatibility() { - return nbtCompatibility; - } - - @NotNull @Override - public EntityCompatibility getEntityCompatibility() { - return entityCompatibility; - } - - @NotNull @Override - public BlockCompatibility getBlockCompatibility() { - return blockCompatibility; - } - - @NotNull @Override - public CommandCompatibility getCommandCompatibility() { - return commandCompatibility; - } - - @Override - public @NotNull ServerPlayer getEntityPlayer(@NotNull Player player) { - return ((CraftPlayer) player).getHandle(); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_12_R1/build.gradle.kts b/WeaponCompatibility/Weapon_1_12_R1/build.gradle.kts deleted file mode 100644 index d02a0c188..000000000 --- a/WeaponCompatibility/Weapon_1_12_R1/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - implementation(project(":WeaponMechanics")) - compileOnly(files(file("../../lib/nms/spigot-1.12.2.jar"))) - - compileOnly(Dependencies.PROTOCOL_LIB) -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_12_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_12_R1.java b/WeaponCompatibility/Weapon_1_12_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_12_R1.java deleted file mode 100644 index c5f3a0469..000000000 --- a/WeaponCompatibility/Weapon_1_12_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_12_R1.java +++ /dev/null @@ -1,67 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_12_R1.EntityPlayer; -import net.minecraft.server.v1_12_R1.MobEffect; -import net.minecraft.server.v1_12_R1.MobEffectList; -import net.minecraft.server.v1_12_R1.MobEffects; -import net.minecraft.server.v1_12_R1.PacketPlayOutAbilities; -import net.minecraft.server.v1_12_R1.PacketPlayOutEntityEffect; -import net.minecraft.server.v1_12_R1.PacketPlayOutRemoveEntityEffect; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - -import java.lang.reflect.Field; - -public class Scope_1_12_R1 implements IScopeCompatibility { - - private static final Field effectsField; - - static { - Class effectsPacket = ReflectionUtil.getPacketClass("PacketPlayOutRemoveEntityEffect"); - - effectsField = ReflectionUtil.getField(effectsPacket, "b"); - } - - @Override - public void updateAbilities(Player player) { - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutAbilities(entityPlayer.abilities)); - } - - @Override - public void addNightVision(Player player) { - // 6000 = 5min - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(-player.getEntityId(), new MobEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId()), 6000, 2)); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - } - - @Override - public void removeNightVision(Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.playerConnection.sendPacket(removeEntityEffect); - - // resend the existing one - MobEffect mobEffect = entityPlayer.getEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - return; - } - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - return ReflectionUtil.invokeField(effectsField, event.getPacket().getHandle()) == MobEffects.NIGHT_VISION; - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_12_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_12_R1.java b/WeaponCompatibility/Weapon_1_12_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_12_R1.java deleted file mode 100644 index 8c8b9d1d2..000000000 --- a/WeaponCompatibility/Weapon_1_12_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_12_R1.java +++ /dev/null @@ -1,80 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_12_R1; -import net.minecraft.server.v1_12_R1.DamageSource; -import net.minecraft.server.v1_12_R1.EntityLiving; -import net.minecraft.server.v1_12_R1.PacketPlayOutPosition; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_12_R1 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z, - PacketPlayOutPosition.EnumPlayerTeleportFlags.X_ROT, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_12_R1() { - this.scopeCompatibility = new Scope_1_12_R1(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutPosition(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(LivingEntity victim, LivingEntity source, double health, double damage, boolean isMelee) { - DamageSource damageSource; - - if (isMelee) { - if (source instanceof Player) { - damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) source).getHandle()); - } else { - damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = DamageSource.projectile(null, ((CraftLivingEntity) source).getHandle()); - } - - EntityLiving nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.trackDamage(damageSource, (float) damage, (float) health); - nms.a(((CraftLivingEntity) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().killer = ((CraftPlayer) killer).getHandle(); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_13_R2/build.gradle.kts b/WeaponCompatibility/Weapon_1_13_R2/build.gradle.kts deleted file mode 100644 index 13568c9ff..000000000 --- a/WeaponCompatibility/Weapon_1_13_R2/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - implementation(project(":WeaponMechanics")) - compileOnly(files(file("../../lib/nms/spigot-1.13.2.jar"))) - - compileOnly(Dependencies.PROTOCOL_LIB) -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_13_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_13_R2.java b/WeaponCompatibility/Weapon_1_13_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_13_R2.java deleted file mode 100644 index 7959da9cf..000000000 --- a/WeaponCompatibility/Weapon_1_13_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_13_R2.java +++ /dev/null @@ -1,67 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_13_R2.EntityPlayer; -import net.minecraft.server.v1_13_R2.MobEffect; -import net.minecraft.server.v1_13_R2.MobEffectList; -import net.minecraft.server.v1_13_R2.MobEffects; -import net.minecraft.server.v1_13_R2.PacketPlayOutAbilities; -import net.minecraft.server.v1_13_R2.PacketPlayOutEntityEffect; -import net.minecraft.server.v1_13_R2.PacketPlayOutRemoveEntityEffect; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - -import java.lang.reflect.Field; - -public class Scope_1_13_R2 implements IScopeCompatibility { - - private static final Field effectsField; - - static { - Class effectsPacket = ReflectionUtil.getPacketClass("PacketPlayOutRemoveEntityEffect"); - - effectsField = ReflectionUtil.getField(effectsPacket, "b"); - } - - @Override - public void updateAbilities(Player player) { - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutAbilities(entityPlayer.abilities)); - } - - @Override - public void addNightVision(Player player) { - // 6000 = 5min - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(-player.getEntityId(), new MobEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId()), 6000, 2)); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - } - - @Override - public void removeNightVision(Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.playerConnection.sendPacket(removeEntityEffect); - - // resend the existing one - MobEffect mobEffect = entityPlayer.getEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - return; - } - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - return ReflectionUtil.invokeField(effectsField, event.getPacket().getHandle()) == MobEffects.NIGHT_VISION; - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_13_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_13_R2.java b/WeaponCompatibility/Weapon_1_13_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_13_R2.java deleted file mode 100644 index b7636d170..000000000 --- a/WeaponCompatibility/Weapon_1_13_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_13_R2.java +++ /dev/null @@ -1,80 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_13_R2; -import net.minecraft.server.v1_13_R2.DamageSource; -import net.minecraft.server.v1_13_R2.EntityLiving; -import net.minecraft.server.v1_13_R2.PacketPlayOutPosition; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_13_R2 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z, - PacketPlayOutPosition.EnumPlayerTeleportFlags.X_ROT, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_13_R2() { - this.scopeCompatibility = new Scope_1_13_R2(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutPosition(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(LivingEntity victim, LivingEntity source, double health, double damage, boolean isMelee) { - DamageSource damageSource; - - if (isMelee) { - if (source instanceof Player) { - damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) source).getHandle()); - } else { - damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = DamageSource.projectile(null, ((CraftLivingEntity) source).getHandle()); - } - - EntityLiving nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.trackDamage(damageSource, (float) damage, (float) health); - nms.setLastDamager(((CraftLivingEntity) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().killer = ((CraftPlayer) killer).getHandle(); - } -} diff --git a/WeaponCompatibility/Weapon_1_14_R1/build.gradle.kts b/WeaponCompatibility/Weapon_1_14_R1/build.gradle.kts deleted file mode 100644 index 4f5bd7e87..000000000 --- a/WeaponCompatibility/Weapon_1_14_R1/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - implementation(project(":WeaponMechanics")) - compileOnly(files(file("../../lib/nms/spigot-1.14.4.jar"))) - - compileOnly(Dependencies.PROTOCOL_LIB) -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_14_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_14_R1.java b/WeaponCompatibility/Weapon_1_14_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_14_R1.java deleted file mode 100644 index 94a8d1ad7..000000000 --- a/WeaponCompatibility/Weapon_1_14_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_14_R1.java +++ /dev/null @@ -1,67 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_14_R1.EntityPlayer; -import net.minecraft.server.v1_14_R1.MobEffect; -import net.minecraft.server.v1_14_R1.MobEffectList; -import net.minecraft.server.v1_14_R1.MobEffects; -import net.minecraft.server.v1_14_R1.PacketPlayOutAbilities; -import net.minecraft.server.v1_14_R1.PacketPlayOutEntityEffect; -import net.minecraft.server.v1_14_R1.PacketPlayOutRemoveEntityEffect; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - -import java.lang.reflect.Field; - -public class Scope_1_14_R1 implements IScopeCompatibility { - - private static final Field effectsField; - - static { - Class effectsPacket = ReflectionUtil.getPacketClass("PacketPlayOutRemoveEntityEffect"); - - effectsField = ReflectionUtil.getField(effectsPacket, "b"); - } - - @Override - public void updateAbilities(Player player) { - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutAbilities(entityPlayer.abilities)); - } - - @Override - public void addNightVision(Player player) { - // 6000 = 5min - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(-player.getEntityId(), new MobEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId()), 6000, 2)); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - } - - @Override - public void removeNightVision(Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.playerConnection.sendPacket(removeEntityEffect); - - // resend the existing one - MobEffect mobEffect = entityPlayer.getEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - return; - } - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - return ReflectionUtil.invokeField(effectsField, event.getPacket().getHandle()) == MobEffects.NIGHT_VISION; - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_14_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_14_R1.java b/WeaponCompatibility/Weapon_1_14_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_14_R1.java deleted file mode 100644 index 581deb5f9..000000000 --- a/WeaponCompatibility/Weapon_1_14_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_14_R1.java +++ /dev/null @@ -1,80 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_14_R1; -import net.minecraft.server.v1_14_R1.DamageSource; -import net.minecraft.server.v1_14_R1.EntityLiving; -import net.minecraft.server.v1_14_R1.PacketPlayOutPosition; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_14_R1 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z, - PacketPlayOutPosition.EnumPlayerTeleportFlags.X_ROT, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_14_R1() { - this.scopeCompatibility = new Scope_1_14_R1(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutPosition(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(LivingEntity victim, LivingEntity source, double health, double damage, boolean isMelee) { - DamageSource damageSource; - - if (isMelee) { - if (source instanceof Player) { - damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) source).getHandle()); - } else { - damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = DamageSource.projectile(null, ((CraftLivingEntity) source).getHandle()); - } - - EntityLiving nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.trackDamage(damageSource, (float) damage, (float) health); - nms.setLastDamager(((CraftLivingEntity) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().killer = ((CraftPlayer) killer).getHandle(); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_15_R1/build.gradle.kts b/WeaponCompatibility/Weapon_1_15_R1/build.gradle.kts deleted file mode 100644 index d71da380c..000000000 --- a/WeaponCompatibility/Weapon_1_15_R1/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - implementation(project(":WeaponMechanics")) - compileOnly(files(file("../../lib/nms/spigot-1.15.2.jar"))) - - compileOnly(Dependencies.PROTOCOL_LIB) -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_15_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_15_R1.java b/WeaponCompatibility/Weapon_1_15_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_15_R1.java deleted file mode 100644 index 880e979ac..000000000 --- a/WeaponCompatibility/Weapon_1_15_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_15_R1.java +++ /dev/null @@ -1,67 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_15_R1.EntityPlayer; -import net.minecraft.server.v1_15_R1.MobEffect; -import net.minecraft.server.v1_15_R1.MobEffectList; -import net.minecraft.server.v1_15_R1.MobEffects; -import net.minecraft.server.v1_15_R1.PacketPlayOutAbilities; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityEffect; -import net.minecraft.server.v1_15_R1.PacketPlayOutRemoveEntityEffect; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - -import java.lang.reflect.Field; - -public class Scope_1_15_R1 implements IScopeCompatibility { - - private static final Field effectsField; - - static { - Class effectsPacket = ReflectionUtil.getPacketClass("PacketPlayOutRemoveEntityEffect"); - - effectsField = ReflectionUtil.getField(effectsPacket, "b"); - } - - @Override - public void updateAbilities(Player player) { - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutAbilities(entityPlayer.abilities)); - } - - @Override - public void addNightVision(Player player) { - // 6000 = 5min - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(-player.getEntityId(), new MobEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId()), 6000, 2)); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - } - - @Override - public void removeNightVision(Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.playerConnection.sendPacket(removeEntityEffect); - - // resend the existing one - MobEffect mobEffect = entityPlayer.getEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - return; - } - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - return ReflectionUtil.invokeField(effectsField, event.getPacket().getHandle()) == MobEffects.NIGHT_VISION; - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_15_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_15_R1.java b/WeaponCompatibility/Weapon_1_15_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_15_R1.java deleted file mode 100644 index 695858f77..000000000 --- a/WeaponCompatibility/Weapon_1_15_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_15_R1.java +++ /dev/null @@ -1,80 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_15_R1; -import net.minecraft.server.v1_15_R1.DamageSource; -import net.minecraft.server.v1_15_R1.EntityLiving; -import net.minecraft.server.v1_15_R1.PacketPlayOutPosition; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_15_R1 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z, - PacketPlayOutPosition.EnumPlayerTeleportFlags.X_ROT, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_15_R1() { - this.scopeCompatibility = new Scope_1_15_R1(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutPosition(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(LivingEntity victim, LivingEntity source, double health, double damage, boolean isMelee) { - DamageSource damageSource; - - if (isMelee) { - if (source instanceof Player) { - damageSource = DamageSource.playerAttack(((CraftPlayer) source).getHandle()); - } else { - damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = DamageSource.projectile(null, ((CraftLivingEntity) source).getHandle()); - } - - EntityLiving nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.trackDamage(damageSource, (float) damage, (float) health); - nms.setLastDamager(((CraftLivingEntity) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().killer = ((CraftPlayer) killer).getHandle(); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_16_R3/build.gradle.kts b/WeaponCompatibility/Weapon_1_16_R3/build.gradle.kts deleted file mode 100644 index d4d3603db..000000000 --- a/WeaponCompatibility/Weapon_1_16_R3/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") -} - -dependencies { - implementation(project(":MechanicsCore")) - implementation(project(":WeaponMechanics")) - compileOnly(files(file("../../lib/nms/spigot-1.16.5.jar"))) - - compileOnly(Dependencies.PROTOCOL_LIB) -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_16_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_16_R3.java b/WeaponCompatibility/Weapon_1_16_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_16_R3.java deleted file mode 100644 index fc46fd9b1..000000000 --- a/WeaponCompatibility/Weapon_1_16_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_16_R3.java +++ /dev/null @@ -1,67 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import me.deecaad.core.utils.ReflectionUtil; -import net.minecraft.server.v1_16_R3.EntityPlayer; -import net.minecraft.server.v1_16_R3.MobEffect; -import net.minecraft.server.v1_16_R3.MobEffectList; -import net.minecraft.server.v1_16_R3.MobEffects; -import net.minecraft.server.v1_16_R3.PacketPlayOutAbilities; -import net.minecraft.server.v1_16_R3.PacketPlayOutEntityEffect; -import net.minecraft.server.v1_16_R3.PacketPlayOutRemoveEntityEffect; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - -import java.lang.reflect.Field; - -public class Scope_1_16_R3 implements IScopeCompatibility { - - private static final Field effectsField; - - static { - Class effectsPacket = ReflectionUtil.getPacketClass("PacketPlayOutRemoveEntityEffect"); - - effectsField = ReflectionUtil.getField(effectsPacket, "b"); - } - - @Override - public void updateAbilities(Player player) { - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - entityPlayer.playerConnection.sendPacket(new PacketPlayOutAbilities(entityPlayer.abilities)); - } - - @Override - public void addNightVision(Player player) { - // 6000 = 5min - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(-player.getEntityId(), new MobEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId()), 6000, 2)); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - } - - @Override - public void removeNightVision(Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.playerConnection.sendPacket(removeEntityEffect); - - // resend the existing one - MobEffect mobEffect = entityPlayer.getEffect(MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - PacketPlayOutEntityEffect entityEffect = new PacketPlayOutEntityEffect(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(entityEffect); - return; - } - - // Simply remove the entity effect - PacketPlayOutRemoveEntityEffect removeEntityEffect = new PacketPlayOutRemoveEntityEffect(player.getEntityId(), MobEffectList.fromId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - return ReflectionUtil.invokeField(effectsField, event.getPacket().getHandle()) == MobEffects.NIGHT_VISION; - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_16_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_16_R3.java b/WeaponCompatibility/Weapon_1_16_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_16_R3.java deleted file mode 100644 index dc917695e..000000000 --- a/WeaponCompatibility/Weapon_1_16_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_16_R3.java +++ /dev/null @@ -1,82 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_16_R3; -import net.minecraft.server.v1_16_R3.DamageSource; -import net.minecraft.server.v1_16_R3.EntityLiving; -import net.minecraft.server.v1_16_R3.PacketPlayOutPosition; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_16_R3 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z, - PacketPlayOutPosition.EnumPlayerTeleportFlags.X_ROT, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList(PacketPlayOutPosition.EnumPlayerTeleportFlags.X, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Y, - PacketPlayOutPosition.EnumPlayerTeleportFlags.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_16_R3() { - this.scopeCompatibility = new Scope_1_16_R3(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutPosition(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(LivingEntity victim, LivingEntity source, double health, double damage, boolean isMelee) { - DamageSource damageSource; - - if (isMelee) { - if (source instanceof Player) { - damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) source).getHandle()); - } else { - damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = DamageSource.projectile(null, ((CraftLivingEntity) source).getHandle()); - } - - EntityLiving nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.trackDamage(damageSource, (float) damage, (float) health); - nms.setLastDamager(((CraftLivingEntity) source).getHandle()); - if (source instanceof Player) - nms.e(((CraftPlayer) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().killer = ((CraftPlayer) killer).getHandle(); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_17_R1/build.gradle.kts b/WeaponCompatibility/Weapon_1_17_R1/build.gradle.kts deleted file mode 100644 index f5484dd51..000000000 --- a/WeaponCompatibility/Weapon_1_17_R1/build.gradle.kts +++ /dev/null @@ -1,22 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - compileOnly(project(":WeaponMechanics")) - - paperweight.paperDevBundle("1.17.1-R0.1-SNAPSHOT") - - compileOnly(Dependencies.PROTOCOL_LIB) -} - -java.toolchain.languageVersion.set(JavaLanguageVersion.of(16)) - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(16) - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_17_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_17_R1.java b/WeaponCompatibility/Weapon_1_17_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_17_R1.java deleted file mode 100644 index 36f04105f..000000000 --- a/WeaponCompatibility/Weapon_1_17_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_17_R1.java +++ /dev/null @@ -1,56 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectInstance; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.potion.PotionEffectType; - -public class Scope_1_17_R1 implements IScopeCompatibility { - - @Override - public void updateAbilities(org.bukkit.entity.Player player) { - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - entityPlayer.connection.send(new ClientboundPlayerAbilitiesPacket(entityPlayer.getAbilities())); - } - - @Override - public void addNightVision(org.bukkit.entity.Player player) { - // 6000 = 5min - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(-player.getEntityId(), new MobEffectInstance(MobEffect.byId(PotionEffectType.NIGHT_VISION.getId()), 6000, - 2)); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - } - - @Override - public void removeNightVision(org.bukkit.entity.Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.connection.send(removeEntityEffect); - - // resend the existing one - MobEffectInstance mobEffect = entityPlayer.getEffect(MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - return; - } - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().connection.send(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - // 16 = night vision - return ((ClientboundRemoveMobEffectPacket) event.getPacket().getHandle()).getEffect() == MobEffect.byId(16); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_17_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_17_R1.java b/WeaponCompatibility/Weapon_1_17_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_17_R1.java deleted file mode 100644 index c9c9b00f2..000000000 --- a/WeaponCompatibility/Weapon_1_17_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_17_R1.java +++ /dev/null @@ -1,82 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_17_R1; -import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; -import net.minecraft.world.damagesource.DamageSource; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_17_R1 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList( - ClientboundPlayerPositionPacket.RelativeArgument.X, - ClientboundPlayerPositionPacket.RelativeArgument.Y, - ClientboundPlayerPositionPacket.RelativeArgument.Z, - ClientboundPlayerPositionPacket.RelativeArgument.X_ROT, - ClientboundPlayerPositionPacket.RelativeArgument.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList( - ClientboundPlayerPositionPacket.RelativeArgument.X, - ClientboundPlayerPositionPacket.RelativeArgument.Y, - ClientboundPlayerPositionPacket.RelativeArgument.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_17_R1() { - this.scopeCompatibility = new Scope_1_17_R1(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().connection.send(new ClientboundPlayerPositionPacket(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0, false)); - } - - @Override - public void logDamage(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double health, double damage, boolean isMelee) { - DamageSource damageSource; - - if (isMelee) { - if (source instanceof Player) { - damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) source).getHandle()); - } else { - damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = DamageSource.thrown(null, ((CraftLivingEntity) source).getHandle()); - } - - net.minecraft.world.entity.LivingEntity nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.recordDamage(damageSource, (float) damage, (float) health); - nms.setLastHurtByMob(((CraftLivingEntity) source).getHandle()); - if (source instanceof Player) - nms.setLastHurtByPlayer(((CraftPlayer) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(org.bukkit.entity.LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().lastHurtByMob = ((CraftPlayer) killer).getHandle(); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_18_R2/build.gradle.kts b/WeaponCompatibility/Weapon_1_18_R2/build.gradle.kts deleted file mode 100644 index 9d247c2db..000000000 --- a/WeaponCompatibility/Weapon_1_18_R2/build.gradle.kts +++ /dev/null @@ -1,22 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - compileOnly(project(":WeaponMechanics")) - - paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") - - compileOnly(Dependencies.PROTOCOL_LIB) -} - -java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_18_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_18_R2.java b/WeaponCompatibility/Weapon_1_18_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_18_R2.java deleted file mode 100644 index 8f28e064c..000000000 --- a/WeaponCompatibility/Weapon_1_18_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_18_R2.java +++ /dev/null @@ -1,56 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectInstance; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.potion.PotionEffectType; - -public class Scope_1_18_R2 implements IScopeCompatibility { - - @Override - public void updateAbilities(org.bukkit.entity.Player player) { - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - entityPlayer.connection.send(new ClientboundPlayerAbilitiesPacket(entityPlayer.getAbilities())); - } - - @Override - public void addNightVision(org.bukkit.entity.Player player) { - // 6000 = 5min - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(-player.getEntityId(), new MobEffectInstance(MobEffect.byId(PotionEffectType.NIGHT_VISION.getId()), 6000, - 2)); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - } - - @Override - public void removeNightVision(org.bukkit.entity.Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.connection.send(removeEntityEffect); - - // resend the existing one - MobEffectInstance mobEffect = entityPlayer.getEffect(MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - return; - } - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().connection.send(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - // 16 = night vision - return ((ClientboundRemoveMobEffectPacket) event.getPacket().getHandle()).getEffect() == MobEffect.byId(16); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_18_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_18_R2.java b/WeaponCompatibility/Weapon_1_18_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_18_R2.java deleted file mode 100644 index 4dd828891..000000000 --- a/WeaponCompatibility/Weapon_1_18_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_18_R2.java +++ /dev/null @@ -1,83 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_18_R2; -import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.LivingEntity; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_18_R2 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList( - ClientboundPlayerPositionPacket.RelativeArgument.X, - ClientboundPlayerPositionPacket.RelativeArgument.Y, - ClientboundPlayerPositionPacket.RelativeArgument.Z, - ClientboundPlayerPositionPacket.RelativeArgument.X_ROT, - ClientboundPlayerPositionPacket.RelativeArgument.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList( - ClientboundPlayerPositionPacket.RelativeArgument.X, - ClientboundPlayerPositionPacket.RelativeArgument.Y, - ClientboundPlayerPositionPacket.RelativeArgument.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_18_R2() { - this.scopeCompatibility = new Scope_1_18_R2(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().connection.send(new ClientboundPlayerPositionPacket(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0, false)); - } - - @Override - public void logDamage(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double health, double damage, boolean isMelee) { - DamageSource damageSource; - - if (isMelee) { - if (source instanceof Player) { - damageSource = DamageSource.playerAttack(((org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) source).getHandle()); - } else { - damageSource = DamageSource.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = DamageSource.thrown(null, ((CraftLivingEntity) source).getHandle()); - } - - LivingEntity nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.recordDamage(damageSource, (float) damage, (float) health); - nms.setLastHurtByMob(((CraftLivingEntity) source).getHandle()); - if (source instanceof Player) - nms.setLastHurtByPlayer(((CraftPlayer) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(org.bukkit.entity.LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().lastHurtByMob = ((CraftPlayer) killer).getHandle(); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_19_R3/build.gradle.kts b/WeaponCompatibility/Weapon_1_19_R3/build.gradle.kts deleted file mode 100644 index f0886503c..000000000 --- a/WeaponCompatibility/Weapon_1_19_R3/build.gradle.kts +++ /dev/null @@ -1,20 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - compileOnly(project(":WeaponMechanics")) - - paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") - - compileOnly(Dependencies.PROTOCOL_LIB) -} - -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_19_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_19_R3.java b/WeaponCompatibility/Weapon_1_19_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_19_R3.java deleted file mode 100644 index 373ab4c37..000000000 --- a/WeaponCompatibility/Weapon_1_19_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_19_R3.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.player.Abilities; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; -import org.bukkit.potion.PotionEffectType; - -public class Scope_1_19_R3 implements IScopeCompatibility { - - @Override - public void updateAbilities(org.bukkit.entity.Player player) { - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - Abilities abilities = entityPlayer.getAbilities(); - entityPlayer.connection.send(new ClientboundPlayerAbilitiesPacket(abilities)); - } - - @Override - public void addNightVision(org.bukkit.entity.Player player) { - // 6000 = 5min - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(-player.getEntityId(), new MobEffectInstance(MobEffect.byId(PotionEffectType.NIGHT_VISION.getId()), 6000, - 2)); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - } - - @Override - public void removeNightVision(org.bukkit.entity.Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.connection.send(removeEntityEffect); - - // resend the existing one - MobEffectInstance mobEffect = entityPlayer.getEffect(MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - return; - } - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().connection.send(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - // 16 = night vision - return ((ClientboundRemoveMobEffectPacket) event.getPacket().getHandle()).getEffect() == MobEffect.byId(16); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_19_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_19_R3.java b/WeaponCompatibility/Weapon_1_19_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_19_R3.java deleted file mode 100644 index bb2e668de..000000000 --- a/WeaponCompatibility/Weapon_1_19_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_19_R3.java +++ /dev/null @@ -1,93 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_19_R3; -import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket; -import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageSources; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.RelativeMovement; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_19_R3 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z, - RelativeMovement.X_ROT, - RelativeMovement.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_19_R3() { - this.scopeCompatibility = new Scope_1_19_R3(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().connection.send(new ClientboundPlayerPositionPacket(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double health, double damage, boolean isMelee) { - DamageSources factory = ((CraftLivingEntity) source).getHandle().damageSources(); - DamageSource damageSource; - - if (isMelee) { - if (source instanceof CraftPlayer player) { - damageSource = factory.playerAttack(player.getHandle()); - } else { - damageSource = factory.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = factory.thrown(null, ((CraftLivingEntity) source).getHandle()); - } - - LivingEntity nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.recordDamage(damageSource, (float) damage, (float) health); - nms.setLastHurtByMob(((CraftLivingEntity) source).getHandle()); - if (source instanceof Player) - nms.setLastHurtByPlayer(((CraftPlayer) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(org.bukkit.entity.LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().lastHurtByMob = ((CraftPlayer) killer).getHandle(); - } - - @Override - public void playHurtAnimation(org.bukkit.entity.LivingEntity victim) { - LivingEntity handle = ((CraftLivingEntity) victim).getHandle(); - handle.getLevel().getServer().getPlayerList().broadcast(null, handle.getX(), handle.getY(), handle.getZ(), 50.0, handle.getLevel().dimension(), new ClientboundHurtAnimationPacket(handle)); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R1/build.gradle.kts b/WeaponCompatibility/Weapon_1_20_R1/build.gradle.kts deleted file mode 100644 index a7ae76bfe..000000000 --- a/WeaponCompatibility/Weapon_1_20_R1/build.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - compileOnly(project(":WeaponMechanics")) - - paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT") - - compileOnly(Dependencies.PROTOCOL_LIB) -} -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R1.java b/WeaponCompatibility/Weapon_1_20_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R1.java deleted file mode 100644 index 0f957d93e..000000000 --- a/WeaponCompatibility/Weapon_1_20_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R1.java +++ /dev/null @@ -1,58 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.player.Abilities; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; -import org.bukkit.potion.PotionEffectType; - -public class Scope_1_20_R1 implements IScopeCompatibility { - - @Override - public void updateAbilities(org.bukkit.entity.Player player) { - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - Abilities abilities = entityPlayer.getAbilities(); - entityPlayer.connection.send(new ClientboundPlayerAbilitiesPacket(abilities)); - } - - @Override - public void addNightVision(org.bukkit.entity.Player player) { - // 6000 = 5min - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(-player.getEntityId(), new MobEffectInstance(MobEffect.byId(PotionEffectType.NIGHT_VISION.getId()), 6000, - 2)); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - } - - @Override - public void removeNightVision(org.bukkit.entity.Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - entityPlayer.connection.send(removeEntityEffect); - - // resend the existing one - MobEffectInstance mobEffect = entityPlayer.getEffect(MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - return; - } - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), MobEffect.byId(PotionEffectType.NIGHT_VISION.getId())); - ((CraftPlayer) player).getHandle().connection.send(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - // 16 = night vision - return ((ClientboundRemoveMobEffectPacket) event.getPacket().getHandle()).getEffect() == MobEffect.byId(16); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R1.java b/WeaponCompatibility/Weapon_1_20_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R1.java deleted file mode 100644 index dbb4ec56b..000000000 --- a/WeaponCompatibility/Weapon_1_20_R1/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R1.java +++ /dev/null @@ -1,91 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_20_R1; -import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageSources; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.RelativeMovement; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_20_R1 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z, - RelativeMovement.X_ROT, - RelativeMovement.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_20_R1() { - this.scopeCompatibility = new Scope_1_20_R1(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().connection.send(new ClientboundPlayerPositionPacket(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double health, double damage, boolean isMelee) { - DamageSources factory = ((CraftLivingEntity) source).getHandle().damageSources(); - DamageSource damageSource; - - if (isMelee) { - if (source instanceof CraftPlayer player) { - damageSource = factory.playerAttack(player.getHandle()); - } else { - damageSource = factory.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = factory.thrown(null, ((CraftLivingEntity) source).getHandle()); - } - - LivingEntity nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.recordDamage(damageSource, (float) health); - nms.setLastHurtByMob(((CraftLivingEntity) source).getHandle()); - if (source instanceof Player) - nms.setLastHurtByPlayer(((CraftPlayer) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(org.bukkit.entity.LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().lastHurtByMob = ((CraftPlayer) killer).getHandle(); - } - - @Override - public void playHurtAnimation(org.bukkit.entity.LivingEntity victim) { - victim.playHurtAnimation(0); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R2/build.gradle.kts b/WeaponCompatibility/Weapon_1_20_R2/build.gradle.kts deleted file mode 100644 index 2e0b2db1d..000000000 --- a/WeaponCompatibility/Weapon_1_20_R2/build.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - compileOnly(project(":WeaponMechanics")) - - paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") - - compileOnly(Dependencies.PROTOCOL_LIB) -} -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R2.java b/WeaponCompatibility/Weapon_1_20_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R2.java deleted file mode 100644 index 4146a6890..000000000 --- a/WeaponCompatibility/Weapon_1_20_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R2.java +++ /dev/null @@ -1,60 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.player.Abilities; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R2.potion.CraftPotionEffectType; -import org.bukkit.potion.PotionEffectType; - -public class Scope_1_20_R2 implements IScopeCompatibility { - - private static final MobEffect NIGHT_VISION = CraftPotionEffectType.bukkitToMinecraft(PotionEffectType.NIGHT_VISION); - - @Override - public void updateAbilities(org.bukkit.entity.Player player) { - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - Abilities abilities = entityPlayer.getAbilities(); - entityPlayer.connection.send(new ClientboundPlayerAbilitiesPacket(abilities)); - } - - @Override - public void addNightVision(org.bukkit.entity.Player player) { - // 6000 = 5min - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(-player.getEntityId(), new MobEffectInstance(NIGHT_VISION, 6000, 2)); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - } - - @Override - public void removeNightVision(org.bukkit.entity.Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), NIGHT_VISION); - entityPlayer.connection.send(removeEntityEffect); - - // resend the existing one - MobEffectInstance mobEffect = entityPlayer.getEffect(NIGHT_VISION); - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - return; - } - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), NIGHT_VISION); - ((CraftPlayer) player).getHandle().connection.send(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - // 16 = night vision - return ((ClientboundRemoveMobEffectPacket) event.getPacket().getHandle()).getEffect() == NIGHT_VISION; - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R2.java b/WeaponCompatibility/Weapon_1_20_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R2.java deleted file mode 100644 index 5c85affa4..000000000 --- a/WeaponCompatibility/Weapon_1_20_R2/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R2.java +++ /dev/null @@ -1,91 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_20_R2; -import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageSources; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.RelativeMovement; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_20_R2 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z, - RelativeMovement.X_ROT, - RelativeMovement.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_20_R2() { - this.scopeCompatibility = new Scope_1_20_R2(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().connection.send(new ClientboundPlayerPositionPacket(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double health, double damage, boolean isMelee) { - DamageSources factory = ((CraftLivingEntity) source).getHandle().damageSources(); - DamageSource damageSource; - - if (isMelee) { - if (source instanceof CraftPlayer player) { - damageSource = factory.playerAttack(player.getHandle()); - } else { - damageSource = factory.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = factory.thrown(null, ((CraftLivingEntity) source).getHandle()); - } - - LivingEntity nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.recordDamage(damageSource, (float) health); - nms.setLastHurtByMob(((CraftLivingEntity) source).getHandle()); - if (source instanceof Player) - nms.setLastHurtByPlayer(((CraftPlayer) source).getHandle()); - } - - @Override - public EntityDamageByEntityEvent newEntityDamageByEntityEvent(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double damage, boolean isMelee) { - return new EntityDamageByEntityEvent( - source, - victim, - isMelee ? EntityDamageByEntityEvent.DamageCause.ENTITY_ATTACK : EntityDamageByEntityEvent.DamageCause.PROJECTILE, - damage); - } - - @Override - public void setKiller(org.bukkit.entity.LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().lastHurtByMob = ((CraftPlayer) killer).getHandle(); - } - - @Override - public void playHurtAnimation(org.bukkit.entity.LivingEntity victim) { - victim.playHurtAnimation(0); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R3/build.gradle.kts b/WeaponCompatibility/Weapon_1_20_R3/build.gradle.kts deleted file mode 100644 index 71a26631a..000000000 --- a/WeaponCompatibility/Weapon_1_20_R3/build.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - compileOnly(project(":WeaponMechanics")) - - paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") - - compileOnly(Dependencies.PROTOCOL_LIB) -} -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(17) - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R3.java b/WeaponCompatibility/Weapon_1_20_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R3.java deleted file mode 100644 index d62479df6..000000000 --- a/WeaponCompatibility/Weapon_1_20_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R3.java +++ /dev/null @@ -1,60 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.player.Abilities; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.potion.CraftPotionEffectType; -import org.bukkit.potion.PotionEffectType; - -public class Scope_1_20_R3 implements IScopeCompatibility { - - private static final MobEffect NIGHT_VISION = CraftPotionEffectType.bukkitToMinecraft(PotionEffectType.NIGHT_VISION); - - @Override - public void updateAbilities(org.bukkit.entity.Player player) { - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - Abilities abilities = entityPlayer.getAbilities(); - entityPlayer.connection.send(new ClientboundPlayerAbilitiesPacket(abilities)); - } - - @Override - public void addNightVision(org.bukkit.entity.Player player) { - // 6000 = 5min - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(-player.getEntityId(), new MobEffectInstance(NIGHT_VISION, 6000, 2)); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - } - - @Override - public void removeNightVision(org.bukkit.entity.Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), NIGHT_VISION); - entityPlayer.connection.send(removeEntityEffect); - - // resend the existing one - MobEffectInstance mobEffect = entityPlayer.getEffect(NIGHT_VISION); - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(player.getEntityId(), mobEffect); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - return; - } - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), NIGHT_VISION); - ((CraftPlayer) player).getHandle().connection.send(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - // 16 = night vision - return ((ClientboundRemoveMobEffectPacket) event.getPacket().getHandle()).getEffect() == NIGHT_VISION; - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R3.java b/WeaponCompatibility/Weapon_1_20_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R3.java deleted file mode 100644 index d33def507..000000000 --- a/WeaponCompatibility/Weapon_1_20_R3/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R3.java +++ /dev/null @@ -1,81 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_20_R3; -import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageSources; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.RelativeMovement; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_20_R3 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z, - RelativeMovement.X_ROT, - RelativeMovement.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_20_R3() { - this.scopeCompatibility = new Scope_1_20_R3(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().connection.send(new ClientboundPlayerPositionPacket(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double health, double damage, boolean isMelee) { - DamageSources factory = ((CraftLivingEntity) source).getHandle().damageSources(); - DamageSource damageSource; - - if (isMelee) { - if (source instanceof CraftPlayer player) { - damageSource = factory.playerAttack(player.getHandle()); - } else { - damageSource = factory.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = factory.thrown(null, ((CraftLivingEntity) source).getHandle()); - } - - LivingEntity nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.recordDamage(damageSource, (float) health); - nms.setLastHurtByMob(((CraftLivingEntity) source).getHandle()); - if (source instanceof Player) - nms.setLastHurtByPlayer(((CraftPlayer) source).getHandle()); - } - - @Override - public void setKiller(org.bukkit.entity.LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().lastHurtByMob = ((CraftPlayer) killer).getHandle(); - } - - @Override - public void playHurtAnimation(org.bukkit.entity.LivingEntity victim) { - victim.playHurtAnimation(0); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R4/build.gradle.kts b/WeaponCompatibility/Weapon_1_20_R4/build.gradle.kts deleted file mode 100644 index 1044085c8..000000000 --- a/WeaponCompatibility/Weapon_1_20_R4/build.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id("me.deecaad.mechanics-project") - id("io.papermc.paperweight.userdev") -} - -dependencies { - compileOnly(project(":MechanicsCore")) - compileOnly(project(":WeaponMechanics")) - - paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") - - compileOnly(Dependencies.PROTOCOL_LIB) -} -tasks { - compileJava { - options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything - options.release.set(21) - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R4/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R4.java b/WeaponCompatibility/Weapon_1_20_R4/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R4.java deleted file mode 100644 index 13388b7e7..000000000 --- a/WeaponCompatibility/Weapon_1_20_R4/src/main/java/me/deecaad/weaponmechanics/compatibility/scope/Scope_1_20_R4.java +++ /dev/null @@ -1,61 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility.scope; - -import com.comphenix.protocol.events.PacketEvent; -import net.minecraft.core.Holder; -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; -import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; -import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.entity.player.Abilities; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.potion.CraftPotionEffectType; -import org.bukkit.potion.PotionEffectType; - -public class Scope_1_20_R4 implements IScopeCompatibility { - - private static final Holder NIGHT_VISION = Holder.direct(CraftPotionEffectType.bukkitToMinecraft(PotionEffectType.NIGHT_VISION)); - - @Override - public void updateAbilities(org.bukkit.entity.Player player) { - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - Abilities abilities = entityPlayer.getAbilities(); - entityPlayer.connection.send(new ClientboundPlayerAbilitiesPacket(abilities)); - } - - @Override - public void addNightVision(org.bukkit.entity.Player player) { - // 6000 = 5min - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(-player.getEntityId(), new MobEffectInstance(NIGHT_VISION, 6000, 2), false); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - } - - @Override - public void removeNightVision(org.bukkit.entity.Player player) { - if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) { - - ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), NIGHT_VISION); - entityPlayer.connection.send(removeEntityEffect); - - // resend the existing one - MobEffectInstance mobEffect = entityPlayer.getEffect(NIGHT_VISION); - ClientboundUpdateMobEffectPacket entityEffect = new ClientboundUpdateMobEffectPacket(player.getEntityId(), mobEffect, false); - ((CraftPlayer) player).getHandle().connection.send(entityEffect); - return; - } - - // Simply remove the entity effect - ClientboundRemoveMobEffectPacket removeEntityEffect = new ClientboundRemoveMobEffectPacket(player.getEntityId(), NIGHT_VISION); - ((CraftPlayer) player).getHandle().connection.send(removeEntityEffect); - } - - @Override - public boolean isRemoveNightVisionPacket(PacketEvent event) { - // 16 = night vision - return ((ClientboundRemoveMobEffectPacket) event.getPacket().getHandle()).effect().value().equals(NIGHT_VISION.value()); - } -} \ No newline at end of file diff --git a/WeaponCompatibility/Weapon_1_20_R4/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R4.java b/WeaponCompatibility/Weapon_1_20_R4/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R4.java deleted file mode 100644 index 83fb72c48..000000000 --- a/WeaponCompatibility/Weapon_1_20_R4/src/main/java/me/deecaad/weaponmechanics/compatibility/v1_20_R4.java +++ /dev/null @@ -1,81 +0,0 @@ -package me.deecaad.weaponmechanics.compatibility; - -import me.deecaad.weaponmechanics.compatibility.scope.IScopeCompatibility; -import me.deecaad.weaponmechanics.compatibility.scope.Scope_1_20_R4; -import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.damagesource.DamageSources; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.RelativeMovement; -import org.bukkit.craftbukkit.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class v1_20_R4 implements IWeaponCompatibility { - - private final Set RELATIVE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z, - RelativeMovement.X_ROT, - RelativeMovement.Y_ROT)); - - private final Set ABSOLUTE_FLAGS = new HashSet<>(Arrays.asList( - RelativeMovement.X, - RelativeMovement.Y, - RelativeMovement.Z)); - - private final IScopeCompatibility scopeCompatibility; - - public v1_20_R4() { - this.scopeCompatibility = new Scope_1_20_R4(); - } - - @NotNull @Override - public IScopeCompatibility getScopeCompatibility() { - return scopeCompatibility; - } - - @Override - public void modifyCameraRotation(Player player, float yaw, float pitch, boolean absolute) { - pitch *= -1; - ((CraftPlayer) player).getHandle().connection.send(new ClientboundPlayerPositionPacket(0, 0, 0, yaw, pitch, absolute ? ABSOLUTE_FLAGS : RELATIVE_FLAGS, 0)); - } - - @Override - public void logDamage(org.bukkit.entity.LivingEntity victim, org.bukkit.entity.LivingEntity source, double health, double damage, boolean isMelee) { - DamageSources factory = ((CraftLivingEntity) source).getHandle().damageSources(); - DamageSource damageSource; - - if (isMelee) { - if (source instanceof CraftPlayer player) { - damageSource = factory.playerAttack(player.getHandle()); - } else { - damageSource = factory.mobAttack(((CraftLivingEntity) source).getHandle()); - } - } else { - damageSource = factory.thrown(null, ((CraftLivingEntity) source).getHandle()); - } - - LivingEntity nms = ((CraftLivingEntity) victim).getHandle(); - nms.combatTracker.recordDamage(damageSource, (float) health); - nms.setLastHurtByMob(((CraftLivingEntity) source).getHandle()); - if (source instanceof Player) - nms.setLastHurtByPlayer(((CraftPlayer) source).getHandle()); - } - - @Override - public void setKiller(org.bukkit.entity.LivingEntity victim, Player killer) { - ((CraftLivingEntity) victim).getHandle().lastHurtByMob = ((CraftPlayer) killer).getHandle(); - } - - @Override - public void playHurtAnimation(org.bukkit.entity.LivingEntity victim) { - victim.playHurtAnimation(0); - } -} \ No newline at end of file diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanics.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanics.java index 1a510d4ea..29708feee 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanics.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanics.java @@ -10,7 +10,6 @@ import com.jeff_media.updatechecker.UpdateChecker; import com.jeff_media.updatechecker.UserAgentBuilder; import me.deecaad.core.MechanicsCore; -import me.deecaad.core.commands.MainCommand; import me.deecaad.core.compatibility.CompatibilityAPI; import me.deecaad.core.compatibility.worldguard.WorldGuardCompatibility; import me.deecaad.core.database.Database; @@ -37,7 +36,6 @@ import me.deecaad.core.utils.NumberUtil; import me.deecaad.core.utils.ReflectionUtil; import me.deecaad.weaponmechanics.commands.WeaponMechanicsCommand; -import me.deecaad.weaponmechanics.commands.WeaponMechanicsMainCommand; import me.deecaad.weaponmechanics.lib.MythicMobsLoader; import me.deecaad.weaponmechanics.listeners.ExplosionInteractionListeners; import me.deecaad.weaponmechanics.listeners.RepairItemListener; @@ -68,8 +66,6 @@ import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.SimpleCommandMap; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -83,7 +79,6 @@ import java.io.File; import java.io.IOException; -import java.lang.reflect.Method; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; @@ -103,7 +98,6 @@ public class WeaponMechanics { Map entityWrappers; Configuration configurations; Configuration basicConfiguration; - MainCommand mainCommand; WeaponHandler weaponHandler; ResourcePackListener resourcePackListener; ProjectileSpawner projectileSpawner; @@ -430,25 +424,6 @@ void registerCommands() { WeaponMechanicsCommand.build(); return; } - - Method getCommandMap = ReflectionUtil.getMethod(ReflectionUtil.getCBClass("CraftServer"), "getCommandMap"); - SimpleCommandMap commands = (SimpleCommandMap) ReflectionUtil.invokeMethod(getCommandMap, Bukkit.getServer()); - - // This can occur onReload, or if another plugin registered the - // command. We use the try-catch to determine if the command was - // registered by another plugin. - Command registered = commands.getCommand("weaponmechanics"); - if (registered != null) { - try { - mainCommand = (MainCommand) registered; - } catch (ClassCastException ex) { - debug.error("/weaponmechanics command was already registered... does another plugin use /wm?", - "The registered command: " + registered, - "Do not ignore this error! The weapon mechanics commands will not work at all!"); - } - } else { - commands.register("weaponmechanics", mainCommand = new WeaponMechanicsMainCommand()); - } } void registerPermissions() { @@ -644,7 +619,6 @@ public void onDisable() { // updateChecker = null; do not reset update checker entityWrappers.clear(); // hint to JVM to free memory entityWrappers = null; - mainCommand = null; configurations = null; basicConfiguration = null; projectileSpawner = null; @@ -766,13 +740,6 @@ public static Configuration getBasicConfigurations() { return plugin.basicConfiguration; } - /** - * @return the main command instance of WeaponMechanics - */ - public static MainCommand getMainCommand() { - return plugin.mainCommand; - } - /** * @return the current weapon handler */ From b0071be1b2eed76d03f4de7756f40bfbb686e755 Mon Sep 17 00:00:00 2001 From: Collin Barber Date: Fri, 11 Oct 2024 23:31:02 -0400 Subject: [PATCH 02/32] remove 1.12 compatible commands --- .../core/commands/CommandPermission.java | 25 - .../me/deecaad/core/commands/MainCommand.java | 134 --- .../me/deecaad/core/commands/SubCommand.java | 253 ----- .../me/deecaad/core/commands/SubCommands.java | 196 ---- .../weaponmechanics/WeaponMechanics.java | 1 - .../WeaponMechanicsCommand.java | 107 +- .../commands/CrackShotConvertCommand.java | 25 - .../commands/LegacyGiveCommand.java | 81 -- .../commands/LegacyInfoCommand.java | 32 - .../commands/LegacyListWeaponsCommand.java | 42 - .../commands/LegacyReloadCommand.java | 24 - .../commands/LegacyWikiCommand.java | 19 - .../commands/WeaponMechanicsMainCommand.java | 23 - .../testcommands/ExplosionCommand.java | 143 --- .../testcommands/FakeEntityCommand.java | 50 - .../testcommands/FireworkCommand.java | 51 - .../commands/testcommands/HitboxCommand.java | 31 - .../commands/testcommands/NBTCommand.java | 26 - .../testcommands/RayTraceCommand.java | 36 - .../commands/testcommands/RecoilCommand.java | 65 -- .../commands/testcommands/ShootCommand.java | 58 -- .../commands/testcommands/TestCommand.java | 33 - .../lib/CrackShotConvert/Converter.java | 93 -- .../CrackShotConvert/CrackShotConverter.java | 978 ------------------ .../CrackShotPlusConverter.java | 662 ------------ 25 files changed, 69 insertions(+), 3119 deletions(-) delete mode 100644 MechanicsCore/src/main/java/me/deecaad/core/commands/CommandPermission.java delete mode 100644 MechanicsCore/src/main/java/me/deecaad/core/commands/MainCommand.java delete mode 100644 MechanicsCore/src/main/java/me/deecaad/core/commands/SubCommand.java delete mode 100644 MechanicsCore/src/main/java/me/deecaad/core/commands/SubCommands.java rename WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/{commands => }/WeaponMechanicsCommand.java (94%) delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/CrackShotConvertCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyGiveCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyInfoCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyListWeaponsCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyReloadCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyWikiCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/WeaponMechanicsMainCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/ExplosionCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/FakeEntityCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/FireworkCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/HitboxCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/NBTCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/RayTraceCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/RecoilCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/ShootCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/TestCommand.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/Converter.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/CrackShotConverter.java delete mode 100644 WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/lib/CrackShotConvert/CrackShotPlusConverter.java diff --git a/MechanicsCore/src/main/java/me/deecaad/core/commands/CommandPermission.java b/MechanicsCore/src/main/java/me/deecaad/core/commands/CommandPermission.java deleted file mode 100644 index d88584de6..000000000 --- a/MechanicsCore/src/main/java/me/deecaad/core/commands/CommandPermission.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.deecaad.core.commands; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation outlines which permission should be used for a command. All subclasses of the - * {@link SubCommand} class should utilise this annotation. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Deprecated() -public @interface CommandPermission { - - /** - * Returns the non-null {@link String} permission. It should follow a - * plugin.command.subcommand format, and the subcommand should be the same as the - * annotated class' name. - * - * @return The string value of a permission - */ - String permission(); -} diff --git a/MechanicsCore/src/main/java/me/deecaad/core/commands/MainCommand.java b/MechanicsCore/src/main/java/me/deecaad/core/commands/MainCommand.java deleted file mode 100644 index 543700b83..000000000 --- a/MechanicsCore/src/main/java/me/deecaad/core/commands/MainCommand.java +++ /dev/null @@ -1,134 +0,0 @@ -package me.deecaad.core.commands; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.defaults.BukkitCommand; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - -/** - * This abstract class outlines a bukkit plugin's main command that stores all subcommands. A plugin - * should only have 1 main command, and all implementations of {@link SubCommand} should be stored - * here. After instantiating this class, it needs to be registered to the bukkit server's main - * command map. - * - * @see SubCommand#register() - */ -@Deprecated() -public abstract class MainCommand extends BukkitCommand { - - protected String permission; - protected SubCommands commands; - - /** - * This constructor is only meant to be accessed from subclasses. - * - * @param name The name/appearance of the command. - * @param permission The readable value of a permission. - */ - protected MainCommand(String name, String permission) { - super(name); - - this.permission = permission; - this.commands = new SubCommands("/" + name); - - // Get the shortest alias for the help command - String prefix = name; - for (String string : super.getAliases()) { - if (string.length() < prefix.length()) - prefix = string; - } - - SubCommand dummy = new SubCommand(prefix, "help", "General help information for commands", "") { - @Override - public void execute(CommandSender sender, String[] args) { - } - }; - - this.commands.register(dummy); - } - - private boolean help(CommandSender sender, String[] args) { - return commands.sendHelp(sender, args); - } - - /** - * Finds a {@link SubCommand} from the args and attempts to execute it. If no command - * exists with the given information, the command executor is sent a help message. - * - * @param sender The console/block/entity that sent the command. - * @param label The label of this command. Will always be equal to this command's tag, or one of - * this command's aliases. - * @param args The arguments given to find the {@link SubCommand}. - * @return Returns true every time. - */ - @Override - public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) { - if (!sender.hasPermission(permission)) { - sender.sendMessage(ChatColor.RED + "Invalid permissions!"); - return true; - } - - // If this stays as false, send help message - boolean isSuccessful = false; - - if (args.length > 0) { - if (args[0].equals("help")) { - isSuccessful = help(sender, Arrays.copyOfRange(args, 1, args.length)); - } else { - isSuccessful = commands.execute(args[0], sender, Arrays.copyOfRange(args, 1, args.length)); - } - } - - if (!isSuccessful) { - help(sender, args); - } - return true; - } - - /** - * Finds a {@link SubCommand} from the args and attempts to find possible - * completions, or options for what is currently being typed. The options are filtered based - * on what is currently being typed, and is later sorted into alphabetical order by the server. - * - * @param sender Who is typing the command. - * @param alias The label of the command. - * @param args The arguments being typed. - * @return The possible options for arguments. - */ - @NotNull @Override - public List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - if (!sender.hasPermission(permission)) { - return new ArrayList<>(); - } - - List temp; - - // Command has arguments - if (args.length > 1) { - - // Should the we follow help command tab completions? - if (args[0].equals("help")) { - if (args.length == 2) - temp = commands.keys(); - else - temp = commands.tabCompletions(args[1], Arrays.copyOfRange(args, 2, args.length)); - - // Let subcommands handle tab completions - } else { - temp = commands.tabCompletions(args[0], Arrays.copyOfRange(args, 1, args.length)); - } - } else { - temp = commands.keys(); - } - - return temp.stream() - .filter(string -> string.toLowerCase(Locale.ROOT).startsWith(args[args.length - 1].toLowerCase(Locale.ROOT))) - .collect(Collectors.toList()); - } -} diff --git a/MechanicsCore/src/main/java/me/deecaad/core/commands/SubCommand.java b/MechanicsCore/src/main/java/me/deecaad/core/commands/SubCommand.java deleted file mode 100644 index 0ae0f16b3..000000000 --- a/MechanicsCore/src/main/java/me/deecaad/core/commands/SubCommand.java +++ /dev/null @@ -1,253 +0,0 @@ -package me.deecaad.core.commands; - -import me.deecaad.core.MechanicsCore; -import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.core.utils.StringUtil; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; -import net.kyori.adventure.text.format.NamedTextColor; -import org.apache.commons.lang3.ArrayUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.command.defaults.BukkitCommand; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Method; -import java.util.*; -import java.util.stream.Collectors; - -import static net.kyori.adventure.text.Component.text; - -/** - * This immutable abstract class outlines a subsection or small section of a plugin's command - * structure. A subcommand can be registered as a bukkit command, but it should instead belong to - * the instantiating plugin's {@link MainCommand}. - */ -@Deprecated() -public abstract class SubCommand extends BukkitCommand { - - protected static final String PLAYERS = ""; - protected static final String INTEGERS = ""; - protected static final String SUB_COMMANDS = ""; - - private static final SimpleCommandMap COMMAND_MAP; - - static { - Method getCommandMap = ReflectionUtil.getMethod(ReflectionUtil.getCBClass("CraftServer"), "getCommandMap"); - COMMAND_MAP = (SimpleCommandMap) ReflectionUtil.invokeMethod(getCommandMap, Bukkit.getServer()); - } - - protected final SubCommands commands; - private final String prefix; - private final String[] args; - - /** - * Constructor for simple subcommands that can only be used for 1 single purpose. Subcommands using - * this constructor should not use any arguments. E.x. Reload commands, plugin information commands. - * - * @param parentPrefix The arguments that come before the label. This is usually the main command's - * label, but it may also include parent subcommand's labels. If this subcommand is being - * used as a standalone command, this argument should be an empty {@link String}. - * @param label The unique name for this command. Should not be null. - * @param desc A simple readable description for what this command does. - */ - public SubCommand(String parentPrefix, String label, String desc) { - this(parentPrefix, label, desc, ""); - } - - /** - * Constructor for advanced subcommands that have different behaviors based on the command - * executor's arguments. - * - * @param parentPrefix The arguments that come before the label. This is usually the main command's - * label, but it may also include parent subcommand's labels. If this subcommand is being - * used as a standalone command, this argument should be an empty {@link String}. - * @param label The unique name for this command. Should not be null. - * @param desc A simple readable description for what this command does. - * @param usage The arguments that the command can take. Arguments should be separated by spaces. - * Commands which utilise custom tags need to override - * {@link #handleCustomTag(String[], String)}. E.x. <player> - * <amount>. - */ - public SubCommand(String parentPrefix, String label, String desc, String usage) { - super(label = label.toLowerCase(Locale.ROOT)); - - this.prefix = parentPrefix.toLowerCase(Locale.ROOT) + " " + label; - this.commands = new SubCommands(this.prefix); - this.args = StringUtil.splitAfterWord(usage).toArray(new String[0]); - - setDescription(desc); - - if (getClass().isAnnotationPresent(CommandPermission.class)) { - - // Create the bukkit permission from the command permission - CommandPermission perm = getClass().getAnnotation(CommandPermission.class); - String str = perm.permission(); - Permission permission = new Permission(str); - - // Setup the parent "*" stuff - permission.addParent(str.substring(0, str.lastIndexOf(".")) + ".*", true); - - // Register the permission - Bukkit.getPluginManager().addPermission(permission); - } - } - - /** - * Returns a non-null clone of the arguments that this subcommand accepts. - * - * @return A copy of the arguments. - */ - public String[] getArgs() { - return args.clone(); - } - - /** - * Gets the non-null text put before the command, useful for command lists. - * - * @return The prefix of the subcommand. - */ - public String getPrefix() { - return prefix; - } - - /** - * Gets the {@link String} value of the permission a command executor must have to use this - * subcommand. If the implementing class is not annotated by {@link CommandPermission}, this method - * may return null. - * - * @return The readable version of the permission - */ - @Override - public String getPermission() { - if (getClass().isAnnotationPresent(CommandPermission.class)) { - return getClass().getAnnotation(CommandPermission.class).permission(); - } else { - return super.getPermission(); - } - } - - protected boolean sendHelp(CommandSender sender, String[] args) { - if (commands.isEmpty()) { - TextComponent.Builder builder = text(); - - // ChatColor.GOLD + "/" + prefix + " " + String.join(" ", args) + ChatColor.GRAY + ": " + - // description - HoverEvent hover = HoverEvent.showText(text("Click to fill command").color(NamedTextColor.GRAY)); - ClickEvent click = ClickEvent.suggestCommand("/" + prefix); - - builder.append(text("/" + prefix + " " + String.join(" ", args)).color(NamedTextColor.GOLD).clickEvent(click).hoverEvent(hover)); - builder.append(text(": " + description).color(NamedTextColor.GRAY).clickEvent(click).hoverEvent(hover)); - - MechanicsCore.getPlugin().adventure.sender(sender).sendMessage(builder); - - return true; - } else { - return commands.sendHelp(sender, args); - } - } - - List tabCompletions(String[] args) { - - // Nothing is being typed, so we have no suggestions - if (args.length == 0) - return new ArrayList<>(); - - // The string from usage at the same index as what - // is being typed from args. If args.length is greater - // then usage.length, it is out of bounds. This probably - // means that subcommands are in use or the user is typing - // past what the command will take in - String current = this.args.length >= args.length ? this.args[args.length - 1] : "OUT_OF_BOUNDS"; - - switch (current) { - case PLAYERS: - return Bukkit.getOnlinePlayers().stream() - .map(Player::getName) - .collect(Collectors.toList()); - case INTEGERS: - return List.of("1", "16", "64", "128"); - case SUB_COMMANDS: - return commands.keys(); - case "OUT_OF_BOUNDS": - int index = ArrayUtils.indexOf(this.args, SUB_COMMANDS); - - // If this command does not have subcommands, give no info - if (index == -1) - return new ArrayList<>(); - // Else let subcommands handle tab completions - else - return commands.tabCompletions(args[index], Arrays.copyOfRange(args, index + 1, args.length)); - default : - if (current.contains(",")) { - String[] split = current.replaceAll("[<>]", "").split(","); - return Arrays.asList(split); - } else { - return handleCustomTag(args, current); - } - } - } - - /** - * Returns a list of strings for the custom tag tag. This method is called when an - * unrecognized tag is used during tab completion. - * - * @param args The arguments the user typed. - * @param current The custom tag to handle. - * @return The tab completions for the custom tag. - */ - protected List handleCustomTag(String[] args, String current) { - return List.of(current); - } - - /** - * What should be done when this command is executed. - * - * @param sender Who executed the command - * @param args The arguments input by the user - */ - public abstract void execute(CommandSender sender, String[] args); - - @Override - public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) { - if (getPermission() != null && !sender.hasPermission(getPermission())) { - sender.sendMessage(getPermissionMessage() == null ? ChatColor.RED + "Invalid Permissions" : getPermissionMessage()); - return false; - } - - if (args.length > 1) { - if (args[0].equals("help")) { - sendHelp(sender, Arrays.copyOfRange(args, 1, args.length)); - } else { - execute(sender, args); - } - } else { - execute(sender, args); - } - - return true; - } - - @Override - @NotNull public List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - if (getPermission() != null && !sender.hasPermission(getPermission())) { - return Collections.emptyList(); - } else { - return tabCompletions(args); - } - } - - @Override - public String toString() { - return ChatColor.GOLD + "/" + prefix + " " + String.join(" ", args) + ChatColor.GRAY + ": " + description; - } - - public void register() { - COMMAND_MAP.register(getLabel(), this); - } -} diff --git a/MechanicsCore/src/main/java/me/deecaad/core/commands/SubCommands.java b/MechanicsCore/src/main/java/me/deecaad/core/commands/SubCommands.java deleted file mode 100644 index 796219976..000000000 --- a/MechanicsCore/src/main/java/me/deecaad/core/commands/SubCommands.java +++ /dev/null @@ -1,196 +0,0 @@ -package me.deecaad.core.commands; - -import me.deecaad.core.MechanicsCore; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.event.ClickEvent; -import net.kyori.adventure.text.event.HoverEvent; -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextDecoration; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.defaults.BukkitCommand; - -import java.util.*; - -import static me.deecaad.core.MechanicsCore.debug; -import static net.kyori.adventure.text.Component.newline; -import static net.kyori.adventure.text.Component.text; - -@Deprecated() -public class SubCommands { - - public static char SYM = '\u27A2'; - private final Map commands; - private final String parentPrefix; - - public SubCommands(String parentPrefix) { - this.commands = new HashMap<>(8); // Half of default size to save RAM - this.parentPrefix = parentPrefix; - } - - /** - * Registers a given sub-command with its label as if it's key (for execution) - * - * @param command to register - */ - public void register(SubCommand command) { - commands.put(command.getLabel(), command); - } - - /** - * Registers a given sub-command with the given key (for execution) - * - * @param key The key to use for activation - * @param command to register - */ - public void register(String key, SubCommand command) { - commands.put(key, command); - } - - /** - * @return Command map - */ - public Map get() { - return commands; - } - - /** - * Gets the sub-command by it's activation key - * - * @param key The activation key - * @return The command - */ - public SubCommand get(String key) { - SubCommand command = commands.get(key); - - // If we couldn't find a command, check each registered command's aliases. - if (command == null) { - for (SubCommand cmd : commands.values()) - for (String alias : cmd.getAliases()) - if (Objects.equals(key, alias)) - return cmd; - } - - return command; - } - - /** - * Removes the command with the given activation key - * - * @param key The activation key - * @return The removed command - */ - public SubCommand remove(String key) { - return commands.remove(key); - } - - /** - * Gets the label + aliases of every registered {@link SubCommand}. Modifying the returned list does - * not modify the registered commands. - * - * @return The non-null list of keys. - */ - public List keys() { - List keys = new ArrayList<>(commands.keySet()); - - for (BukkitCommand command : commands.values()) { - keys.addAll(command.getAliases()); - } - - return keys; - } - - /** - * @return If there are any sub-commands registered - */ - public boolean isEmpty() { - return commands.isEmpty(); - } - - /** - * Sends information to the given sender about the command defined by this class and the given args - * - * @param sender Who to send help to - * @param args Command arguments - * @return Whether or not the command is valid - */ - boolean sendHelp(CommandSender sender, String[] args) { - if (args.length == 0) { - - NamedTextColor GOLD = NamedTextColor.GOLD; - NamedTextColor GRAY = NamedTextColor.GRAY; - TextComponent.Builder builder = text(); - - builder.append(text(parentPrefix).color(GRAY).decorate(TextDecoration.BOLD)); - builder.append(text(" Help ").color(GOLD).decorate(TextDecoration.BOLD)); - builder.append(text("(" + commands.size() + " Commands)").color(GRAY).decorate(TextDecoration.ITALIC)); - builder.append(newline()); - - int i = 0; - for (SubCommand command : commands.values()) { - - // Create a hoverable for the command - HoverEvent hover = HoverEvent.showText(text() - .append(text("Command: ").color(GOLD).append(text(command.getLabel()).color(GRAY).append(newline()))) - .append(text("Description: ").color(GOLD).append(text(command.getDescription()).color(GRAY)).append(newline())) - .append(text("Usage: ").color(GOLD).append(text("/" + command.getPrefix() + " " + String.join("", command.getArgs())).color(GRAY).append(newline()))) - .append(text("Permission: ").color(GOLD).append(text(command.getPermission() == null ? "N/A" : command.getPermission()).color(GRAY).append(newline()))) - .append(newline()) - .append(text("Click to auto-complete.").color(GRAY))); - - builder.append(text(" " + SYM + " ").color(GRAY)); - builder.append(text("/" + command.getPrefix()).color(GOLD).clickEvent(ClickEvent.suggestCommand("/" + command.getPrefix())).hoverEvent(hover)); - - if (++i != commands.size()) { - // Every command goes on a new line, expect if this is last command - builder.append(newline()); - } - } - - MechanicsCore.getPlugin().adventure.sender(sender).sendMessage(builder); - return true; - } - - SubCommand command = get(args[0]); - if (command == null) - return false; - - return command.sendHelp(sender, Arrays.copyOfRange(args, 1, args.length)); - } - - /** - * Executes the given command, if present. Else the default command is executed. - * - * @param key The command's activation key - * @param sender Who is executing the command - * @param args What is being typed - */ - public boolean execute(String key, CommandSender sender, String[] args) { - SubCommand command = get(key.toLowerCase(Locale.ROOT)); - if (command == null) { - return false; - } else if (command.getPermission() == null || sender.hasPermission(command.getPermission())) { - command.execute(sender, args); - } else { - sender.sendMessage(ChatColor.RED + "Invalid permissions"); - } - return true; - } - - /** - * Gets the tab completions for a given command, if present. Else an empty list is returned - * - * @param key the command's activation key - * @param args what is being typed - * @return tab completions - */ - List tabCompletions(String key, String[] args) { - SubCommand command = get(key.toLowerCase(Locale.ROOT)); - if (command == null) { - debug.debug("Unknown sub-command: " + key); - return new ArrayList<>(); - } else { - return command.tabCompletions(args); - } - } -} diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanics.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanics.java index 29708feee..58483d1d4 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanics.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanics.java @@ -35,7 +35,6 @@ import me.deecaad.core.utils.MinecraftVersions; import me.deecaad.core.utils.NumberUtil; import me.deecaad.core.utils.ReflectionUtil; -import me.deecaad.weaponmechanics.commands.WeaponMechanicsCommand; import me.deecaad.weaponmechanics.lib.MythicMobsLoader; import me.deecaad.weaponmechanics.listeners.ExplosionInteractionListeners; import me.deecaad.weaponmechanics.listeners.RepairItemListener; diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/WeaponMechanicsCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanicsCommand.java similarity index 94% rename from WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/WeaponMechanicsCommand.java rename to WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanicsCommand.java index 8e29428b1..a04cad910 100644 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/WeaponMechanicsCommand.java +++ b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/WeaponMechanicsCommand.java @@ -1,19 +1,46 @@ -package me.deecaad.weaponmechanics.commands; +package me.deecaad.weaponmechanics; import com.cjcrafter.foliascheduler.TaskImplementation; import me.deecaad.core.MechanicsCore; -import me.deecaad.core.commands.*; -import me.deecaad.core.commands.arguments.*; +import me.deecaad.core.commands.Argument; +import me.deecaad.core.commands.CommandBuilder; +import me.deecaad.core.commands.CommandData; +import me.deecaad.core.commands.CommandExecutor; +import me.deecaad.core.commands.HelpCommandBuilder; +import me.deecaad.core.commands.SuggestionsBuilder; +import me.deecaad.core.commands.Tooltip; +import me.deecaad.core.commands.arguments.BlockPredicateArgumentType; +import me.deecaad.core.commands.arguments.BooleanArgumentType; +import me.deecaad.core.commands.arguments.ColorArgumentType; +import me.deecaad.core.commands.arguments.DoubleArgumentType; +import me.deecaad.core.commands.arguments.EntityArgumentType; +import me.deecaad.core.commands.arguments.EntityListArgumentType; +import me.deecaad.core.commands.arguments.EntityTypeArgumentType; +import me.deecaad.core.commands.arguments.EnumArgumentType; +import me.deecaad.core.commands.arguments.GreedyArgumentType; +import me.deecaad.core.commands.arguments.IntegerArgumentType; +import me.deecaad.core.commands.arguments.ListArgumentType; +import me.deecaad.core.commands.arguments.LocationArgumentType; +import me.deecaad.core.commands.arguments.MapArgumentType; +import me.deecaad.core.commands.arguments.PlayerArgumentType; +import me.deecaad.core.commands.arguments.StringArgumentType; +import me.deecaad.core.commands.arguments.TimeArgumentType; import me.deecaad.core.compatibility.CompatibilityAPI; import me.deecaad.core.compatibility.HitBox; import me.deecaad.core.compatibility.entity.EntityCompatibility; import me.deecaad.core.compatibility.entity.FakeEntity; import me.deecaad.core.file.Configuration; -import me.deecaad.core.utils.*; +import me.deecaad.core.utils.EntityTransform; +import me.deecaad.core.utils.LogLevel; +import me.deecaad.core.utils.MinecraftVersions; +import me.deecaad.core.utils.NumberUtil; +import me.deecaad.core.utils.Quaternion; +import me.deecaad.core.utils.RandomUtil; +import me.deecaad.core.utils.ReflectionUtil; +import me.deecaad.core.utils.StringUtil; +import me.deecaad.core.utils.TableBuilder; +import me.deecaad.core.utils.Transform; import me.deecaad.core.utils.ray.RayTrace; -import me.deecaad.weaponmechanics.WeaponMechanics; -import me.deecaad.weaponmechanics.WeaponMechanicsAPI; -import me.deecaad.weaponmechanics.lib.CrackShotConvert.Converter; import me.deecaad.weaponmechanics.listeners.RepairItemListener; import me.deecaad.weaponmechanics.utils.CustomTag; import me.deecaad.weaponmechanics.weapon.damage.DamagePoint; @@ -23,7 +50,11 @@ import me.deecaad.weaponmechanics.weapon.explode.exposures.ExplosionExposure; import me.deecaad.weaponmechanics.weapon.explode.exposures.ExposureFactory; import me.deecaad.weaponmechanics.weapon.explode.regeneration.RegenerationData; -import me.deecaad.weaponmechanics.weapon.explode.shapes.*; +import me.deecaad.weaponmechanics.weapon.explode.shapes.CuboidExplosion; +import me.deecaad.weaponmechanics.weapon.explode.shapes.DefaultExplosion; +import me.deecaad.weaponmechanics.weapon.explode.shapes.ExplosionShape; +import me.deecaad.weaponmechanics.weapon.explode.shapes.ParabolicExplosion; +import me.deecaad.weaponmechanics.weapon.explode.shapes.SphericalExplosion; import me.deecaad.weaponmechanics.weapon.info.InfoHandler; import me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.Projectile; import me.deecaad.weaponmechanics.weapon.projectile.weaponprojectile.ProjectileSettings; @@ -40,20 +71,40 @@ import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.EntityEffect; +import org.bukkit.FireworkEffect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.inventory.*; +import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.util.Vector; -import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Random; +import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -64,7 +115,12 @@ import static me.deecaad.weaponmechanics.WeaponMechanics.debug; import static net.kyori.adventure.text.Component.empty; import static net.kyori.adventure.text.Component.text; -import static org.bukkit.ChatColor.*; +import static org.bukkit.ChatColor.BOLD; +import static org.bukkit.ChatColor.GOLD; +import static org.bukkit.ChatColor.GRAY; +import static org.bukkit.ChatColor.GREEN; +import static org.bukkit.ChatColor.ITALIC; +import static org.bukkit.ChatColor.RED; @SuppressWarnings("unchecked") public class WeaponMechanicsCommand { @@ -194,14 +250,6 @@ public static void build() { wiki(sender); }))) - .withSubcommand(new CommandBuilder("convert") - .withPermission("weaponmechanics.commands.convert") - .withDescription("Convert weapons from another plugin") - .withArgument(new Argument<>("plugin", new StringArgumentType().withLiterals("crackshot"))) - .executes(CommandExecutor.any((sender, args) -> { - convert(sender, (String) args[0]); - }))) - .withSubcommand(new CommandBuilder("reload") .withPermission("weaponmechanics.commands.reload") .withDescription("Reloads config") @@ -726,23 +774,6 @@ public static void wiki(CommandSender sender) { MechanicsCore.getPlugin().adventure.sender(sender).sendMessage(table); } - public static void convert(CommandSender sender, String plugin) { - if (plugin.equalsIgnoreCase("crackshot")) { - - sender.sendMessage(GREEN + "Converting config..."); - WeaponMechanics pl = WeaponMechanicsAPI.getInstance(); - File outputPath = new File(pl.getDataFolder().getPath() + "/weapons/crackshotconvert/"); - - sender.sendMessage(GREEN + "Starting CrackShot conversion"); - WeaponMechanics.getInstance().getFoliaScheduler().async().runNow(() -> new Converter(sender).convertAllFiles(outputPath)).asFuture().thenAccept(task -> sender.sendMessage(GREEN - + "Output converted files to " + outputPath)); - - return; - } - - sender.sendMessage(RED + "Conversion currently only supports CrackShot!"); - } - public static void nbt(CommandSender sender, Entity target) { LivingEntity entity; diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/CrackShotConvertCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/CrackShotConvertCommand.java deleted file mode 100644 index dec4a6716..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/CrackShotConvertCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package me.deecaad.weaponmechanics.commands; - -import me.deecaad.core.commands.CommandPermission; -import me.deecaad.core.commands.SubCommand; -import me.deecaad.weaponmechanics.WeaponMechanics; -import me.deecaad.weaponmechanics.WeaponMechanicsAPI; -import me.deecaad.weaponmechanics.lib.CrackShotConvert.Converter; -import org.bukkit.command.CommandSender; - -import java.io.File; - -@CommandPermission(permission = "weaponmechanics.commands.convert") -public class CrackShotConvertCommand extends SubCommand { - - public CrackShotConvertCommand() { - super("wm", "convert", "Converts CrackShot and CrackShotPlus files to WeaponMechanics"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - WeaponMechanics plugin = WeaponMechanicsAPI.getInstance(); - File outputPath = new File(plugin.getDataFolder().getPath() + "/weapons/crackshotconvert/"); - WeaponMechanics.getInstance().getFoliaScheduler().async().runNow(() -> new Converter(sender).convertAllFiles(outputPath)); - } -} \ No newline at end of file diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyGiveCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyGiveCommand.java deleted file mode 100644 index 58f2b4f83..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyGiveCommand.java +++ /dev/null @@ -1,81 +0,0 @@ -package me.deecaad.weaponmechanics.commands; - -import me.deecaad.core.commands.CommandPermission; -import me.deecaad.core.commands.SubCommand; -import me.deecaad.weaponmechanics.weapon.info.InfoHandler; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Collections; -import java.util.List; - -import static me.deecaad.weaponmechanics.WeaponMechanics.getWeaponHandler; - -@CommandPermission(permission = "weaponmechanics.commands.give") -@Deprecated -public class LegacyGiveCommand extends SubCommand { - - // wm give - - public LegacyGiveCommand() { - super("wm", "give", "Gives a given number of weapons to a given player", " "); - - setAliases(Collections.singletonList("get")); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if (args.length == 0 || args.length > 3) { - sender.sendMessage(toString()); - return; - } - - InfoHandler info = getWeaponHandler().getInfoHandler(); - String weaponTitle = info.getWeaponTitle(args[0]); - if (!getWeaponHandler().getInfoHandler().hasWeapon(weaponTitle)) { - sender.sendMessage(ChatColor.RED + "Could not find weapon " + args[0]); - return; - } - - int amount = 1; - if (args.length > 1) { - try { - amount = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Tried to use amount which wasn't number " + args[1]); - return; - } - if (amount < 0 || amount > 64) { - sender.sendMessage(ChatColor.RED + "Tried to use amount which was less than 1 or more than 64"); - return; - } - } - - Player player; - if (args.length > 2) { - player = Bukkit.getPlayer(args[2]); - if (player == null) { - sender.sendMessage(ChatColor.RED + "Could not find player " + args[2]); - return; - } - } else if (sender instanceof Player) { - player = (Player) sender; - } else { - // Not player - sender.sendMessage(ChatColor.RED + "You can't give weapons for console, sorry. :("); - return; - } - - info.giveOrDropWeapon(info.getWeaponTitle(weaponTitle), player, amount); - } - - @Override - public List handleCustomTag(String[] args, String current) { - return switch (current) { - case "" -> getWeaponHandler().getInfoHandler().getSortedWeaponList(); - default -> super.handleCustomTag(args, current); - }; - } -} \ No newline at end of file diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyInfoCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyInfoCommand.java deleted file mode 100644 index c9113923f..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyInfoCommand.java +++ /dev/null @@ -1,32 +0,0 @@ -package me.deecaad.weaponmechanics.commands; - -import me.deecaad.core.commands.CommandPermission; -import me.deecaad.core.commands.SubCommand; -import org.bukkit.command.CommandSender; - -import java.util.Collection; - -@CommandPermission(permission = "weaponmechanics.commands.info") -@Deprecated -public class LegacyInfoCommand extends SubCommand { - - public static char SYM = '\u27A2'; - - public LegacyInfoCommand() { - super("wm", "info", "General plugin information"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - WeaponMechanicsCommand.info(sender); - } - - public static String toString(Collection list) { - StringBuilder builder = new StringBuilder(); - for (Object obj : list) { - builder.append(obj).append(", "); - } - builder.setLength(builder.length() - 2); - return builder.toString(); - } -} diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyListWeaponsCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyListWeaponsCommand.java deleted file mode 100644 index 396f8cbd5..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyListWeaponsCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -package me.deecaad.weaponmechanics.commands; - -import me.deecaad.core.commands.CommandPermission; -import me.deecaad.core.commands.SubCommand; -import me.deecaad.weaponmechanics.WeaponMechanics; -import me.deecaad.weaponmechanics.weapon.info.InfoHandler; -import org.bukkit.command.CommandSender; - -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -@CommandPermission(permission = "weaponmechanics.commands.list") -@Deprecated -public class LegacyListWeaponsCommand extends SubCommand { - - // wm list - - public LegacyListWeaponsCommand() { - super("wm", "list", "List all weapons by weapon title", ""); - } - - @Override - public void execute(CommandSender sender, String[] args) { - int page = Integer.parseInt(args.length == 0 ? "1" : args[0]); - WeaponMechanicsCommand.list(sender, page); - } - - @Override - protected List handleCustomTag(String[] args, String current) { - InfoHandler info = WeaponMechanics.getWeaponHandler().getInfoHandler(); - - switch (current) { - case "": - int maxPerPage = 2 * 8; - int pages = 1 + info.getSortedWeaponList().size() / maxPerPage; - return IntStream.range(1, pages + 2).mapToObj(String::valueOf).collect(Collectors.toList()); - default : - return super.handleCustomTag(args, current); - } - } -} diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyReloadCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyReloadCommand.java deleted file mode 100644 index 6f92dfe10..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyReloadCommand.java +++ /dev/null @@ -1,24 +0,0 @@ -package me.deecaad.weaponmechanics.commands; - -import me.deecaad.core.commands.CommandPermission; -import me.deecaad.core.commands.SubCommand; -import me.deecaad.weaponmechanics.WeaponMechanics; -import me.deecaad.weaponmechanics.WeaponMechanicsAPI; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -@CommandPermission(permission = "weaponmechanics.commands.reload") -@Deprecated -public class LegacyReloadCommand extends SubCommand { - - public LegacyReloadCommand() { - super("wm", "reload", "Reloads the plugin's config"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - WeaponMechanics plugin = WeaponMechanicsAPI.getInstance(); - - plugin.onReload().thenAccept((task) -> sender.sendMessage(ChatColor.GREEN + "Reloaded configuration.")); - } -} diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyWikiCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyWikiCommand.java deleted file mode 100644 index 796009db4..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/LegacyWikiCommand.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.deecaad.weaponmechanics.commands; - -import me.deecaad.core.commands.CommandPermission; -import me.deecaad.core.commands.SubCommand; -import org.bukkit.command.CommandSender; - -@CommandPermission(permission = "weaponmechanics.command.wiki") -@Deprecated -public class LegacyWikiCommand extends SubCommand { - - public LegacyWikiCommand() { - super("wm", "wiki", "Shows links to the Wiki"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - WeaponMechanicsCommand.wiki(sender); - } -} diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/WeaponMechanicsMainCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/WeaponMechanicsMainCommand.java deleted file mode 100644 index 9b1a48900..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/WeaponMechanicsMainCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -package me.deecaad.weaponmechanics.commands; - -import me.deecaad.core.commands.MainCommand; -import me.deecaad.weaponmechanics.commands.testcommands.TestCommand; - -import java.util.List; - -public class WeaponMechanicsMainCommand extends MainCommand { - - public WeaponMechanicsMainCommand() { - super("weaponmechanics", "weaponmechanics.admin"); - setDescription("WeaponMechanics main command"); - setAliases(List.of("wea", "weapon", "wm")); - - commands.register(new TestCommand()); - commands.register(new LegacyGiveCommand()); - commands.register(new LegacyInfoCommand()); - commands.register(new LegacyReloadCommand()); - commands.register(new LegacyWikiCommand()); - commands.register(new LegacyListWeaponsCommand()); - commands.register(new CrackShotConvertCommand()); - } -} diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/ExplosionCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/ExplosionCommand.java deleted file mode 100644 index 4bb6c1d02..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/ExplosionCommand.java +++ /dev/null @@ -1,143 +0,0 @@ -package me.deecaad.weaponmechanics.commands.testcommands; - -import me.deecaad.core.commands.CommandPermission; -import me.deecaad.core.commands.SubCommand; -import me.deecaad.weaponmechanics.WeaponMechanics; -import me.deecaad.weaponmechanics.weapon.explode.BlockDamage; -import me.deecaad.weaponmechanics.weapon.explode.Explosion; -import me.deecaad.weaponmechanics.weapon.explode.Flashbang; -import me.deecaad.weaponmechanics.weapon.explode.exposures.OptimizedExposure; -import me.deecaad.weaponmechanics.weapon.explode.regeneration.RegenerationData; -import me.deecaad.weaponmechanics.weapon.explode.shapes.CuboidExplosion; -import me.deecaad.weaponmechanics.weapon.explode.shapes.DefaultExplosion; -import me.deecaad.weaponmechanics.weapon.explode.shapes.ExplosionShape; -import me.deecaad.weaponmechanics.weapon.explode.shapes.ParabolicExplosion; -import me.deecaad.weaponmechanics.weapon.explode.shapes.SphericalExplosion; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Arrays; -import java.util.Map; - -import static org.bukkit.ChatColor.GOLD; -import static org.bukkit.ChatColor.GRAY; - -/** - * Useful commands for testing different explosion sizes and shapes. This is a player only command, - * and should only be registered by the TestCommand. - * - * @see TestCommand - */ -@CommandPermission(permission = "weaponmechanics.commands.test.explosion") -public class ExplosionCommand extends SubCommand { - - public ExplosionCommand() { - super("wm test", "explosion", "Explode functions for devs", SUB_COMMANDS); - - commands.register(new SphereExplosionCommand()); - commands.register(new CubeExplosionCommand()); - commands.register(new ParabolaExplosionCommand()); - commands.register(new DefaultExplosionCommand()); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if (!(sender instanceof Player)) { - return; - } - if (args.length > 0) { - commands.execute(args[0], sender, Arrays.copyOfRange(args, 1, args.length)); - return; - } - sendHelp(sender, args); - } - - private void explode(ExplosionShape shape, Player player, Location loc) { - WeaponMechanics.getInstance().getFoliaScheduler().entity(player).runDelayed(() -> { - RegenerationData regeneration = new RegenerationData(160, 2, 1); - BlockDamage blockDamage = new BlockDamage(0.0, 1, 1, Material.AIR, BlockDamage.BreakMode.BREAK, Map.of()); - Explosion explosion = new Explosion(shape, new OptimizedExposure(), blockDamage, regeneration, null, 0.9, 1.0, - null, null, new Flashbang(10.0, null), null); - explosion.explode(player, loc, null); - }, 100); - } - - @CommandPermission(permission = "weaponmechanics.commands.test.explosion.sphere") - private class SphereExplosionCommand extends SubCommand { - - SphereExplosionCommand() { - super("wm test explosion", "sphere", "Spherical explosion", "<3,5,16,32>"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - Player player = (Player) sender; - - double radius = args.length > 0 ? Double.parseDouble(args[0]) : 5.0; - player.sendMessage(GOLD + "Causing a " + GRAY + "sphere" + GOLD + - " shaped explosion with a radius of " + GRAY + radius); - - explode(new SphericalExplosion(radius), player, player.getLocation()); - } - } - - @CommandPermission(permission = "weaponmechanics.commands.test.explosion.cube") - private class CubeExplosionCommand extends SubCommand { - - CubeExplosionCommand() { - super("wm test explosion", "cube", "Cubical Explosion Test", INTEGERS + " " + INTEGERS); - } - - @Override - public void execute(CommandSender sender, String[] args) { - Player player = (Player) sender; - - int width = (int) (args.length > 0 ? Double.parseDouble(args[0]) : 5.0); - int height = (int) (args.length > 1 ? Double.parseDouble(args[1]) : 5.0); - player.sendMessage(GOLD + "Causing a " + GRAY + "cube" + GOLD + " shaped explosion with a width of " - + GRAY + width + GOLD + " and a height of " + GRAY + height); - - explode(new CuboidExplosion(width, height), player, player.getLocation()); - } - } - - @CommandPermission(permission = "weaponmechanics.commands.test.explosion.parabola") - private class ParabolaExplosionCommand extends SubCommand { - - ParabolaExplosionCommand() { - super("wm test explosion", "parabola", "Parabolic Explosion Test", " "); - } - - @Override - public void execute(CommandSender sender, String[] args) { - Player player = (Player) sender; - - double angle = args.length > 0 ? Double.parseDouble(args[0]) : 0.5; - double depth = args.length > 1 ? Double.parseDouble(args[1]) : -3.0; - player.sendMessage(GOLD + "Causing a " + GRAY + "parabola" + GOLD + " shaped explosion with an angle of " - + GRAY + angle + GOLD + " and a depth of " + GRAY + depth); - - explode(new ParabolicExplosion(depth, angle), player, player.getLocation()); - } - } - - @CommandPermission(permission = "weaponmechanics.commands.test.explosion.default") - private class DefaultExplosionCommand extends SubCommand { - - DefaultExplosionCommand() { - super("wm test explosion", "default", "Parabolic Explosion Test", "<3,5,10>"); - } - - @Override - public void execute(CommandSender sender, String[] args) { - Player player = (Player) sender; - - double yield = args.length > 0 ? Double.parseDouble(args[0]) : 5; - player.sendMessage(GOLD + "Causing a " + GRAY + "Minecraft" + GOLD + " shaped explosion with an yield of " + GRAY + yield); - - explode(new DefaultExplosion(yield), player, player.getLocation()); - } - } -} \ No newline at end of file diff --git a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/FakeEntityCommand.java b/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/FakeEntityCommand.java deleted file mode 100644 index 76d385ba6..000000000 --- a/WeaponMechanics/src/main/java/me/deecaad/weaponmechanics/commands/testcommands/FakeEntityCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package me.deecaad.weaponmechanics.commands.testcommands; - -import me.deecaad.core.commands.SubCommand; -import me.deecaad.core.utils.EnumUtil; -import me.deecaad.core.utils.StringUtil; -import me.deecaad.weaponmechanics.commands.WeaponMechanicsCommand; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class FakeEntityCommand extends SubCommand { - - public FakeEntityCommand() { - super("wm test", "fakeentity", "Spawns a fake entity", "