From 3bc35058ac04b1ca7324a43d2bde130ca7f0937e Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Mon, 5 Jul 2021 11:48:10 +0200 Subject: [PATCH 1/8] CompatibleMaterial: Add missing BLACKSTONE_SLAB --- .../com/songoda/core/compatibility/CompatibleMaterial.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java b/Compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java index f95ad8a1..0d46ac8e 100644 --- a/Compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java @@ -23,9 +23,9 @@ import java.util.Set; public enum CompatibleMaterial { /* TODO: add another handler for getBlockItem() for materials and fallback materials - + Legacy has some values not used in modern, eg: - + DIODE_BLOCK_OFF(93, Diode.class), DIODE_BLOCK_ON(94, Diode.class), SPRUCE_DOOR_ITEM(427), @@ -193,6 +193,7 @@ public enum CompatibleMaterial { BLACKSTONE(), BLACKSTONE_STAIRS(), BLACKSTONE_WALL(), + BLACKSTONE_SLAB(), BLASTSTONE_SLAB(), CHAIN(), CHISELED_NETHER_BRICKS(), From f5bf5903c70087967177c002c70ebb71ea2650d7 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Tue, 6 Jul 2021 13:15:17 +0200 Subject: [PATCH 2/8] Dependency: Update mcMMO from v2.1.50 to v2.1.200 This fixes failing maven builds reporting a http repo being used and blocked - As only the patch version has been increased, there should be no problem related to this update (Core's only getting compiled against it's API anyway) --- Core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/pom.xml b/Core/pom.xml index 6be4f74e..b08ec7a8 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -312,7 +312,7 @@ com.gmail.nossr50.mcMMO mcMMO - 2.1.50 + 2.1.200 provided From a73ed7908e38176c7bc380e3fd407f6439fe8260 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 8 Jul 2021 15:35:34 +0200 Subject: [PATCH 3/8] Update pom.xml files and project structure * Should fix IntelliJ sometimes not finding classes * Should make things easier to understand and maintain * Rename `LICENSE.md` to `LICENSE` --- .gitignore | 226 ++---------------- .idea/encodings.xml | 24 -- .idea/jarRepositories.xml | 40 ---- Compatibility/pom.xml | 20 +- .../core/compatibility/ClassMapping.java | 0 .../core/compatibility/ClientVersion.java | 0 .../core/compatibility/CompatibleBiome.java | 0 .../core/compatibility/CompatibleHand.java | 0 .../compatibility/CompatibleMaterial.java | 0 .../CompatibleParticleHandler.java | 0 .../core/compatibility/CompatibleSound.java | 0 .../core/compatibility/EntityNamespace.java | 0 .../compatibility/LegacyMaterialAnalouge.java | 0 .../LegacyMaterialBlockType.java | 0 .../compatibility/LegacyParticleEffects.java | 0 .../compatibility/LegacyPotionEffects.java | 0 .../core/compatibility/ServerProject.java | 0 .../core/compatibility/ServerVersion.java | 0 Core/pom.xml | 101 ++++---- LICENSE.md => LICENSE | 11 +- NMS/NMS-API/pom.xml | 20 +- .../com/songoda/core/nms/ReflectionUtils.java | 0 .../com/songoda/core/nms/anvil/AnvilCore.java | 0 .../songoda/core/nms/anvil/CustomAnvil.java | 0 .../nms/anvil/methods/AnvilTextChange.java | 0 .../com/songoda/core/nms/nbt/NBTCompound.java | 0 .../com/songoda/core/nms/nbt/NBTCore.java | 0 .../com/songoda/core/nms/nbt/NBTEntity.java | 0 .../com/songoda/core/nms/nbt/NBTItem.java | 0 .../com/songoda/core/nms/nbt/NBTObject.java | 0 .../songoda/core/nms/world/BBaseSpawner.java | 0 .../songoda/core/nms/world/SItemStack.java | 0 .../com/songoda/core/nms/world/SSpawner.java | 0 .../com/songoda/core/nms/world/SWorld.java | 0 .../songoda/core/nms/world/SpawnedEntity.java | 0 .../com/songoda/core/nms/world/WorldCore.java | 0 NMS/NMS-v1_10_R1/pom.xml | 19 +- .../core/nms/v1_10_R1/anvil/AnvilCore.java | 0 .../v1_10_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_10_R1/anvil/AnvilView.java | 0 .../nms/v1_10_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_10_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_10_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_10_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_10_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_10_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_10_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_10_R1/world/SWorldImpl.java | 0 .../nms/v1_10_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_11_R1/pom.xml | 19 +- .../core/nms/v1_11_R1/anvil/AnvilCore.java | 0 .../v1_11_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_11_R1/anvil/AnvilView.java | 0 .../nms/v1_11_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_11_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_11_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_11_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_11_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_11_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_11_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_11_R1/world/SWorldImpl.java | 0 .../nms/v1_11_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_12_R1/pom.xml | 19 +- .../core/nms/v1_12_R1/anvil/AnvilCore.java | 0 .../v1_12_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_12_R1/anvil/AnvilView.java | 0 .../nms/v1_12_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_12_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_12_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_12_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_12_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_12_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_12_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_12_R1/world/SWorldImpl.java | 0 .../nms/v1_12_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_13_R1/pom.xml | 19 +- .../core/nms/v1_13_R1/anvil/AnvilCore.java | 0 .../v1_13_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_13_R1/anvil/AnvilView.java | 0 .../nms/v1_13_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_13_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_13_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_13_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_13_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_13_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_13_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_13_R1/world/SWorldImpl.java | 0 .../nms/v1_13_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_13_R2/pom.xml | 19 +- .../core/nms/v1_13_R2/anvil/AnvilCore.java | 0 .../v1_13_R2/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_13_R2/anvil/AnvilView.java | 0 .../nms/v1_13_R2/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_13_R2/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_13_R2/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_13_R2/nbt/NBTItemImpl.java | 0 .../core/nms/v1_13_R2/nbt/NBTObjectImpl.java | 0 .../nms/v1_13_R2/world/SItemStackImpl.java | 0 .../core/nms/v1_13_R2/world/SSpawnerImpl.java | 0 .../core/nms/v1_13_R2/world/SWorldImpl.java | 0 .../nms/v1_13_R2/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_14_R1/pom.xml | 19 +- .../core/nms/v1_14_R1/anvil/AnvilCore.java | 0 .../v1_14_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_14_R1/anvil/AnvilView.java | 0 .../nms/v1_14_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_14_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_14_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_14_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_14_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_14_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_14_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_14_R1/world/SWorldImpl.java | 0 .../nms/v1_14_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_15_R1/pom.xml | 19 +- .../core/nms/v1_15_R1/anvil/AnvilCore.java | 0 .../v1_15_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_15_R1/anvil/AnvilView.java | 0 .../nms/v1_15_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_15_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_15_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_15_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_15_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_15_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_15_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_15_R1/world/SWorldImpl.java | 0 .../nms/v1_15_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_16_R1/pom.xml | 19 +- .../core/nms/v1_16_R1/anvil/AnvilCore.java | 0 .../v1_16_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_16_R1/anvil/AnvilView.java | 0 .../nms/v1_16_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_16_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_16_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_16_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_16_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_16_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_16_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_16_R1/world/SWorldImpl.java | 0 .../nms/v1_16_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_16_R2/pom.xml | 19 +- .../core/nms/v1_16_R2/anvil/AnvilCore.java | 0 .../v1_16_R2/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_16_R2/anvil/AnvilView.java | 0 .../nms/v1_16_R2/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_16_R2/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_16_R2/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_16_R2/nbt/NBTItemImpl.java | 0 .../core/nms/v1_16_R2/nbt/NBTObjectImpl.java | 0 .../nms/v1_16_R2/world/SItemStackImpl.java | 0 .../core/nms/v1_16_R2/world/SSpawnerImpl.java | 0 .../core/nms/v1_16_R2/world/SWorldImpl.java | 0 .../nms/v1_16_R2/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_16_R3/pom.xml | 19 +- .../core/nms/v1_16_R3/anvil/AnvilCore.java | 0 .../v1_16_R3/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_16_R3/anvil/AnvilView.java | 0 .../nms/v1_16_R3/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_16_R3/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_16_R3/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_16_R3/nbt/NBTItemImpl.java | 0 .../core/nms/v1_16_R3/nbt/NBTObjectImpl.java | 0 .../nms/v1_16_R3/world/SItemStackImpl.java | 0 .../core/nms/v1_16_R3/world/SSpawnerImpl.java | 0 .../core/nms/v1_16_R3/world/SWorldImpl.java | 0 .../nms/v1_16_R3/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_17_R1/pom.xml | 19 +- .../core/nms/v1_17_R1/anvil/AnvilCore.java | 0 .../v1_17_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_17_R1/anvil/AnvilView.java | 0 .../nms/v1_17_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_17_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_17_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_17_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_17_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_17_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_17_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_17_R1/world/SWorldImpl.java | 0 .../nms/v1_17_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_8_R1/pom.xml | 19 +- .../core/nms/v1_8_R1/anvil/AnvilCore.java | 0 .../v1_8_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_8_R1/anvil/AnvilView.java | 0 .../core/nms/v1_8_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_8_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_8_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_8_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_8_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_8_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_8_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_8_R1/world/SWorldImpl.java | 0 .../core/nms/v1_8_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_8_R2/pom.xml | 19 +- .../core/nms/v1_8_R2/anvil/AnvilCore.java | 0 .../v1_8_R2/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_8_R2/anvil/AnvilView.java | 0 .../core/nms/v1_8_R2/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_8_R2/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_8_R2/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_8_R2/nbt/NBTItemImpl.java | 0 .../core/nms/v1_8_R2/nbt/NBTObjectImpl.java | 0 .../nms/v1_8_R2/world/SItemStackImpl.java | 0 .../core/nms/v1_8_R2/world/SSpawnerImpl.java | 0 .../core/nms/v1_8_R2/world/SWorldImpl.java | 0 .../core/nms/v1_8_R2/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_8_R3/pom.xml | 19 +- .../core/nms/v1_8_R3/anvil/AnvilCore.java | 0 .../v1_8_R3/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_8_R3/anvil/AnvilView.java | 0 .../core/nms/v1_8_R3/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_8_R3/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_8_R3/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_8_R3/nbt/NBTItemImpl.java | 0 .../core/nms/v1_8_R3/nbt/NBTObjectImpl.java | 0 .../nms/v1_8_R3/world/SItemStackImpl.java | 0 .../core/nms/v1_8_R3/world/SSpawnerImpl.java | 0 .../core/nms/v1_8_R3/world/SWorldImpl.java | 0 .../core/nms/v1_8_R3/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_9_R1/pom.xml | 19 +- .../core/nms/v1_9_R1/anvil/AnvilCore.java | 0 .../v1_9_R1/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_9_R1/anvil/AnvilView.java | 0 .../core/nms/v1_9_R1/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_9_R1/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_9_R1/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_9_R1/nbt/NBTItemImpl.java | 0 .../core/nms/v1_9_R1/nbt/NBTObjectImpl.java | 0 .../nms/v1_9_R1/world/SItemStackImpl.java | 0 .../core/nms/v1_9_R1/world/SSpawnerImpl.java | 0 .../core/nms/v1_9_R1/world/SWorldImpl.java | 0 .../core/nms/v1_9_R1/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 NMS/NMS-v1_9_R2/pom.xml | 19 +- .../core/nms/v1_9_R2/anvil/AnvilCore.java | 0 .../v1_9_R2/anvil/AnvilInventoryCustom.java | 0 .../core/nms/v1_9_R2/anvil/AnvilView.java | 0 .../core/nms/v1_9_R2/nbt/NBTCompoundImpl.java | 0 .../core/nms/v1_9_R2/nbt/NBTCoreImpl.java | 0 .../core/nms/v1_9_R2/nbt/NBTEntityImpl.java | 0 .../core/nms/v1_9_R2/nbt/NBTItemImpl.java | 0 .../core/nms/v1_9_R2/nbt/NBTObjectImpl.java | 0 .../nms/v1_9_R2/world/SItemStackImpl.java | 0 .../core/nms/v1_9_R2/world/SSpawnerImpl.java | 0 .../core/nms/v1_9_R2/world/SWorldImpl.java | 0 .../core/nms/v1_9_R2/world/WorldCoreImpl.java | 0 .../world/spawner/BBaseSpawnerImpl.java | 0 assembly.xml | 20 -- pom.xml | 51 ++-- 262 files changed, 290 insertions(+), 527 deletions(-) delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/jarRepositories.xml rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/ClassMapping.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/ClientVersion.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/CompatibleBiome.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/CompatibleHand.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/CompatibleMaterial.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/CompatibleParticleHandler.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/CompatibleSound.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/EntityNamespace.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/LegacyMaterialAnalouge.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/LegacyMaterialBlockType.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/LegacyParticleEffects.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/LegacyPotionEffects.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/ServerProject.java (100%) rename Compatibility/src/{ => main/java}/com/songoda/core/compatibility/ServerVersion.java (100%) rename LICENSE.md => LICENSE (99%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/ReflectionUtils.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/anvil/AnvilCore.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/anvil/CustomAnvil.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/anvil/methods/AnvilTextChange.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/nbt/NBTCompound.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/nbt/NBTCore.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/nbt/NBTEntity.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/nbt/NBTItem.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/nbt/NBTObject.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/world/BBaseSpawner.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/world/SItemStack.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/world/SSpawner.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/world/SWorld.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/world/SpawnedEntity.java (100%) rename NMS/NMS-API/src/{ => main/java}/com/songoda/core/nms/world/WorldCore.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_10_R1/src/{ => main/java}/com/songoda/core/nms/v1_10_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_11_R1/src/{ => main/java}/com/songoda/core/nms/v1_11_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_12_R1/src/{ => main/java}/com/songoda/core/nms/v1_12_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_13_R1/src/{ => main/java}/com/songoda/core/nms/v1_13_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/world/SWorldImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_13_R2/src/{ => main/java}/com/songoda/core/nms/v1_13_R2/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_14_R1/src/{ => main/java}/com/songoda/core/nms/v1_14_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_15_R1/src/{ => main/java}/com/songoda/core/nms/v1_15_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_16_R1/src/{ => main/java}/com/songoda/core/nms/v1_16_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/world/SWorldImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_16_R2/src/{ => main/java}/com/songoda/core/nms/v1_16_R2/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/world/SWorldImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_16_R3/src/{ => main/java}/com/songoda/core/nms/v1_16_R3/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_17_R1/src/{ => main/java}/com/songoda/core/nms/v1_17_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_8_R1/src/{ => main/java}/com/songoda/core/nms/v1_8_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/world/SWorldImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_8_R2/src/{ => main/java}/com/songoda/core/nms/v1_8_R2/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/world/SWorldImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_8_R3/src/{ => main/java}/com/songoda/core/nms/v1_8_R3/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/world/SWorldImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_9_R1/src/{ => main/java}/com/songoda/core/nms/v1_9_R1/world/spawner/BBaseSpawnerImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/anvil/AnvilInventoryCustom.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/anvil/AnvilView.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/nbt/NBTCompoundImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/nbt/NBTItemImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/nbt/NBTObjectImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/world/SWorldImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java (100%) rename NMS/NMS-v1_9_R2/src/{ => main/java}/com/songoda/core/nms/v1_9_R2/world/spawner/BBaseSpawnerImpl.java (100%) delete mode 100644 assembly.xml diff --git a/.gitignore b/.gitignore index 8e8fe60c..e075f419 100644 --- a/.gitignore +++ b/.gitignore @@ -1,214 +1,24 @@ -### Eclipse ### -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.recommenders +## +# JetBrains IDEs +## +/.idea/ -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT- autotools -.autotools - -# Java annotation processor (APT) -.factorypath - -# PDT-specific (PHP Development Tools) -.buildpath - -# sbteclipse plugin -.target - -# Tern plugin -.tern-project - -# TeXlipse plugin -.texlipse - -# STS (Spring Tool Suite) -.springBeans - -# Code Recommenders -.recommenders/ - -# Annotation Processing -.apt_generated/ - -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - -### Eclipse Patch ### -# Eclipse Core -.project - -# JDT-specific (Eclipse Java Development Tools) -.classpath - -# Annotation Processing -.apt_generated - -.sts4-cache/ - -### Intellij ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf - -# Generated files -.idea/**/contentModel.xml - -# Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml - -# Gradle -.idea/**/gradle.xml -.idea/**/libraries - -# Gradle and Maven with auto-import -auto-import. -.idea/modules.xml -.idea/*.iml -.idea/modules +# Don't exclude files that might not be related to the IDE *.iml -*.ipr +/*/*.iml +/NMS/*/*.iml -# Mongo Explorer plugin -.idea/**/mongoSettings.xml +## +# Maven +## +# Don't exclude a 'target' package by accident +/target/ +/*/target/ +/NMS/*/target/ -# File-based project format -*.iws - -# IntelliJ -out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Cursive Clojure plugin -.idea/replstate.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -# Editor-based Rest Client -.idea/httpRequests - -# Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser - -### Intellij Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -*.iml -modules.xml -.idea/misc.xml -*.ipr -.idea/compiler.xml - -# Sonarlint plugin -.idea/**/sonarlint/ - -# SonarQube Plugin -.idea/**/sonarIssues.xml - -# Markdown Navigator plugin -.idea/**/markdown-navigator.xml -.idea/**/markdown-navigator/ - -### Java ### -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -### Maven ### -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties dependency-reduced-pom.xml -buildNumber.properties -.mvn/timing.properties -.mvn/wrapper/maven-wrapper.jar -.flattened-pom.xml -### NetBeans ### -**/nbproject/private/ -**/nbproject/Makefile-*.mk -**/nbproject/Package-*.bash -build/ -nbbuild/ -dist/ -nbdist/ -.nb-gradle/ - -### Gradle ### -.gradle - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Cache of project -.gradletasknamecache - -# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 -# gradle/wrapper/gradle-wrapper.properties - -### Gradle Patch ### -**/build/ - -.DS_Store \ No newline at end of file +## +# Misc. +## +.DS_Store diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index ffc27ba0..00000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index d61d2ab7..00000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Compatibility/pom.xml b/Compatibility/pom.xml index 0b41ee47..f0157783 100644 --- a/Compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -1,29 +1,33 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../ + ../pom.xml SongodaCore-Compatibility - - 4.0.0 jar - org.jetbrains - annotations - 13.0 + org.spigotmc + spigot-api + 1.17-R0.1-SNAPSHOT + us.myles.viaversion-bukkit ViaVersion 2.1.3 provided + protocolsupport ProtocolSupport @@ -31,4 +35,4 @@ provided - \ No newline at end of file + diff --git a/Compatibility/src/com/songoda/core/compatibility/ClassMapping.java b/Compatibility/src/main/java/com/songoda/core/compatibility/ClassMapping.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/ClassMapping.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/ClassMapping.java diff --git a/Compatibility/src/com/songoda/core/compatibility/ClientVersion.java b/Compatibility/src/main/java/com/songoda/core/compatibility/ClientVersion.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/ClientVersion.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/ClientVersion.java diff --git a/Compatibility/src/com/songoda/core/compatibility/CompatibleBiome.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleBiome.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/CompatibleBiome.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleBiome.java diff --git a/Compatibility/src/com/songoda/core/compatibility/CompatibleHand.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleHand.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/CompatibleHand.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleHand.java diff --git a/Compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java diff --git a/Compatibility/src/com/songoda/core/compatibility/CompatibleParticleHandler.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/CompatibleParticleHandler.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleParticleHandler.java diff --git a/Compatibility/src/com/songoda/core/compatibility/CompatibleSound.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleSound.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/CompatibleSound.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleSound.java diff --git a/Compatibility/src/com/songoda/core/compatibility/EntityNamespace.java b/Compatibility/src/main/java/com/songoda/core/compatibility/EntityNamespace.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/EntityNamespace.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/EntityNamespace.java diff --git a/Compatibility/src/com/songoda/core/compatibility/LegacyMaterialAnalouge.java b/Compatibility/src/main/java/com/songoda/core/compatibility/LegacyMaterialAnalouge.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/LegacyMaterialAnalouge.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/LegacyMaterialAnalouge.java diff --git a/Compatibility/src/com/songoda/core/compatibility/LegacyMaterialBlockType.java b/Compatibility/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/LegacyMaterialBlockType.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java diff --git a/Compatibility/src/com/songoda/core/compatibility/LegacyParticleEffects.java b/Compatibility/src/main/java/com/songoda/core/compatibility/LegacyParticleEffects.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/LegacyParticleEffects.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/LegacyParticleEffects.java diff --git a/Compatibility/src/com/songoda/core/compatibility/LegacyPotionEffects.java b/Compatibility/src/main/java/com/songoda/core/compatibility/LegacyPotionEffects.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/LegacyPotionEffects.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/LegacyPotionEffects.java diff --git a/Compatibility/src/com/songoda/core/compatibility/ServerProject.java b/Compatibility/src/main/java/com/songoda/core/compatibility/ServerProject.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/ServerProject.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/ServerProject.java diff --git a/Compatibility/src/com/songoda/core/compatibility/ServerVersion.java b/Compatibility/src/main/java/com/songoda/core/compatibility/ServerVersion.java similarity index 100% rename from Compatibility/src/com/songoda/core/compatibility/ServerVersion.java rename to Compatibility/src/main/java/com/songoda/core/compatibility/ServerVersion.java diff --git a/Core/pom.xml b/Core/pom.xml index b08ec7a8..a486e184 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -1,27 +1,28 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../ + ../pom.xml - com.songoda SongodaCore - - 4.0.0 jar - src/main/java - clean install SongodaCore-${project.version} + org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 + ${java.version} ${java.version} @@ -29,42 +30,52 @@ ${java.release} + org.apache.maven.plugins maven-source-plugin 3.2.1 + attach-sources + jar + org.apache.maven.plugins maven-shade-plugin 3.1.0 + shaded package + shade + false - true + false + com.songoda:* com.zaxxer:HikariCP + *:* + com/ META-INF/MANIFEST.MF @@ -76,30 +87,9 @@ - + org.spigotmc @@ -107,135 +97,121 @@ 1.17 provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar compile + ${project.groupId} SongodaCore-NMS-API ${project.version} - jar compile + ${project.groupId} SongodaCore-NMS-v1_8_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_8_R2 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_8_R3 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_9_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_9_R2 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_10_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_11_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_12_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_13_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_13_R2 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_14_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_15_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_16_R1 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_16_R2 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_16_R3 ${project.version} - jar compile ${project.groupId} SongodaCore-NMS-v1_17_R1 ${project.version} - jar compile + com.gmail.filoghost.holographicdisplays @@ -243,152 +219,177 @@ 2.3.2 provided + com.sainttx Holograms 2.13 provided + com.github.Zrips CMI-API 7.6.2.0 provided + net.tnemc Reserve 0.1.3.0 provided + org.black_ixx PlayerPoints 2.1.4 provided + net.milkbowl VaultAPI 1.7.2 provided + com.sk89q worldguard-bukkit 7.0.4 provided + com.sk89q worldedit-bukkit 7.1.0 provided + com.songoda UltimateStacker 2.1.1 provided + com.bgsoftware wildstacker 3.5.1 provided + uk.antiperson stackmob 4-0-2 provided + com.github.Zrips Jobs LATEST provided + com.gmail.nossr50.mcMMO mcMMO 2.1.200 provided + net coreprotect 2.17.5 provided + me.ryanhamshire GriefPrevention 16.16.0 provided + me.angeschossen LandsAPI 4.12.20 provided + br.net.fabiozumbi12 RedProtect 7.7.2 provided + com.songoda UltimateClaims 1.3.2 provided + com.palmergames Towny 0.96.5.0 provided + world.bentobox bentobox 1.15.5 provided - + com.googlecode.json-simple json-simple 1.1 + org.jetbrains annotations 13.0 + org.yaml snakeyaml 1.26 + org.slf4j slf4j-api 1.7.25 + org.slf4j slf4j-nop 1.7.25 + com.zaxxer HikariCP 3.2.0 + org.xerial sqlite-jdbc diff --git a/LICENSE.md b/LICENSE similarity index 99% rename from LICENSE.md rename to LICENSE index 5dc6b429..f288702d 100644 --- a/LICENSE.md +++ b/LICENSE @@ -1,8 +1,7 @@ - GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -646,14 +645,14 @@ the "copyright" line and a pointer to where the full notice is found. GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - {project} Copyright (C) {year} {fullname} + Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. @@ -665,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -. +. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. +. diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index d54e7690..c6945aa0 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-API - - 4.0.0 jar @@ -19,17 +21,11 @@ 1.17 provided - - org.jetbrains - annotations - 13.0 - + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-API/src/com/songoda/core/nms/ReflectionUtils.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/ReflectionUtils.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/ReflectionUtils.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/ReflectionUtils.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/anvil/AnvilCore.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/anvil/AnvilCore.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/anvil/AnvilCore.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/anvil/CustomAnvil.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/anvil/CustomAnvil.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/anvil/CustomAnvil.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/anvil/CustomAnvil.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/anvil/methods/AnvilTextChange.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/anvil/methods/AnvilTextChange.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/anvil/methods/AnvilTextChange.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/anvil/methods/AnvilTextChange.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTCompound.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCompound.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTCompound.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCompound.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTCore.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCore.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTCore.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCore.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTEntity.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTEntity.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTEntity.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTEntity.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTItem.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTItem.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTItem.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTItem.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTObject.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTObject.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/nbt/NBTObject.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTObject.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/world/BBaseSpawner.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/BBaseSpawner.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/world/BBaseSpawner.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/world/BBaseSpawner.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/world/SItemStack.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SItemStack.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/world/SItemStack.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SItemStack.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/world/SSpawner.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SSpawner.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/world/SSpawner.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SSpawner.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/world/SWorld.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SWorld.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/world/SWorld.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SWorld.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/world/SpawnedEntity.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SpawnedEntity.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/world/SpawnedEntity.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SpawnedEntity.java diff --git a/NMS/NMS-API/src/com/songoda/core/nms/world/WorldCore.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/WorldCore.java similarity index 100% rename from NMS/NMS-API/src/com/songoda/core/nms/world/WorldCore.java rename to NMS/NMS-API/src/main/java/com/songoda/core/nms/world/WorldCore.java diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index d0a5dfe8..6dce3d93 100644 --- a/NMS/NMS-v1_10_R1/pom.xml +++ b/NMS/NMS-v1_10_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_10_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.10.2 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/SWorldImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/SWorldImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_10_R1/src/com/songoda/core/nms/v1_10_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index af59b7af..1376f61f 100644 --- a/NMS/NMS-v1_11_R1/pom.xml +++ b/NMS/NMS-v1_11_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_11_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.11.2 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/SWorldImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/SWorldImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_11_R1/src/com/songoda/core/nms/v1_11_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index c0f93231..02f1f4a0 100644 --- a/NMS/NMS-v1_12_R1/pom.xml +++ b/NMS/NMS-v1_12_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_12_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.12.2 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/SWorldImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/SWorldImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_12_R1/src/com/songoda/core/nms/v1_12_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index ac385ff4..988ad55c 100644 --- a/NMS/NMS-v1_13_R1/pom.xml +++ b/NMS/NMS-v1_13_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_13_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.13 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/SWorldImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/SWorldImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_13_R1/src/com/songoda/core/nms/v1_13_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index a277a9a9..01f13c86 100644 --- a/NMS/NMS-v1_13_R2/pom.xml +++ b/NMS/NMS-v1_13_R2/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_13_R2 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.13.2 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTItemImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTItemImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTObjectImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/SWorldImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/SWorldImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SWorldImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_13_R2/src/com/songoda/core/nms/v1_13_R2/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 8237c89f..0759baed 100644 --- a/NMS/NMS-v1_14_R1/pom.xml +++ b/NMS/NMS-v1_14_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_14_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.14.4 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/SWorldImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/SWorldImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_14_R1/src/com/songoda/core/nms/v1_14_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index df009de6..d80c95bb 100644 --- a/NMS/NMS-v1_15_R1/pom.xml +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_15_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.15 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/SItemStackImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/SWorldImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/SWorldImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_15_R1/src/com/songoda/core/nms/v1_15_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index e1c50845..6f533560 100644 --- a/NMS/NMS-v1_16_R1/pom.xml +++ b/NMS/NMS-v1_16_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_16_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.16.1 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/SItemStackImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/SWorldImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/SWorldImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_16_R1/src/com/songoda/core/nms/v1_16_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index e0882c5f..0b2603e0 100644 --- a/NMS/NMS-v1_16_R2/pom.xml +++ b/NMS/NMS-v1_16_R2/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_16_R2 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.16.2 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTItemImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTItemImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTObjectImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/SItemStackImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/SItemStackImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/SSpawnerImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/SSpawnerImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/SWorldImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/SWorldImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/SWorldImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_16_R2/src/com/songoda/core/nms/v1_16_R2/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index 3b6a853d..a81966cb 100644 --- a/NMS/NMS-v1_16_R3/pom.xml +++ b/NMS/NMS-v1_16_R3/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_16_R3 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.16.5 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTObjectImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/SItemStackImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/SItemStackImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/SSpawnerImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/SSpawnerImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/SWorldImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/SWorldImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/SWorldImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_16_R3/src/com/songoda/core/nms/v1_16_R3/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_17_R1/pom.xml b/NMS/NMS-v1_17_R1/pom.xml index 8c8247e0..d3b29046 100644 --- a/NMS/NMS-v1_17_R1/pom.xml +++ b/NMS/NMS-v1_17_R1/pom.xml @@ -1,22 +1,22 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml 16 16 - - UTF-8 SongodaCore-NMS-v1_17_R1 - - 4.0.0 jar @@ -26,18 +26,17 @@ 1.17 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/SItemStackImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_17_R1/src/com/songoda/core/nms/v1_17_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index 86617edf..51dc12d0 100644 --- a/NMS/NMS-v1_8_R1/pom.xml +++ b/NMS/NMS-v1_8_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_8_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.8 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/SWorldImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/SWorldImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_8_R1/src/com/songoda/core/nms/v1_8_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index b8577259..89430def 100644 --- a/NMS/NMS-v1_8_R2/pom.xml +++ b/NMS/NMS-v1_8_R2/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_8_R2 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.8.3 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTItemImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTItemImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTObjectImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/SSpawnerImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/SSpawnerImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/SWorldImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/SWorldImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SWorldImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_8_R2/src/com/songoda/core/nms/v1_8_R2/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index 415d9789..c266e2ca 100644 --- a/NMS/NMS-v1_8_R3/pom.xml +++ b/NMS/NMS-v1_8_R3/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_8_R3 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.8.8 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTItemImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTItemImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTObjectImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/SSpawnerImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/SSpawnerImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/SWorldImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/SWorldImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SWorldImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_8_R3/src/com/songoda/core/nms/v1_8_R3/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index daf5f3a0..26ed3c80 100644 --- a/NMS/NMS-v1_9_R1/pom.xml +++ b/NMS/NMS-v1_9_R1/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_9_R1 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.9.2 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTItemImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTItemImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTObjectImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/SWorldImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/SWorldImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SWorldImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_9_R1/src/com/songoda/core/nms/v1_9_R1/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/spawner/BBaseSpawnerImpl.java diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index 1e786f42..0422c690 100644 --- a/NMS/NMS-v1_9_R2/pom.xml +++ b/NMS/NMS-v1_9_R2/pom.xml @@ -1,15 +1,17 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - ../../ + ../../pom.xml SongodaCore-NMS-v1_9_R2 - - 4.0.0 jar @@ -19,18 +21,17 @@ 1.9.4 provided + - com.songoda + ${project.groupId} SongodaCore-NMS-API ${project.version} - provided + ${project.groupId} SongodaCore-Compatibility ${project.version} - jar - compile - \ No newline at end of file + diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/anvil/AnvilInventoryCustom.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilInventoryCustom.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/anvil/AnvilInventoryCustom.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilInventoryCustom.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/anvil/AnvilView.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilView.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/anvil/AnvilView.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilView.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTCompoundImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTCompoundImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTCompoundImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTEntityImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTItemImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTItemImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTItemImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTItemImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTObjectImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTObjectImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/nbt/NBTObjectImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTObjectImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/SWorldImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SWorldImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/SWorldImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SWorldImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java diff --git a/NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/spawner/BBaseSpawnerImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/spawner/BBaseSpawnerImpl.java similarity index 100% rename from NMS/NMS-v1_9_R2/src/com/songoda/core/nms/v1_9_R2/world/spawner/BBaseSpawnerImpl.java rename to NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/spawner/BBaseSpawnerImpl.java diff --git a/assembly.xml b/assembly.xml deleted file mode 100644 index 0028b5d6..00000000 --- a/assembly.xml +++ /dev/null @@ -1,20 +0,0 @@ - - dist - - jar - - false - - - - true - false - - ${project.groupId}:* - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2d050ef1..aae6c9f9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,12 @@ - + + + 4.0.0 com.songoda SongodaCore-Modules 2.5.7 - 4.0.0 pom @@ -35,15 +38,25 @@ NMS/NMS-v1_17_R1 + + https://support.songoda.com/servicedesk/customer/portal/3 + Jira Service Desk + + + + https://github.com/songoda/SongodaCore + scm:git:git:github.com/songoda/SongodaCore.git + + - src - clean install ${project.artifactId}-${project.version} + org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 + ${java.version} ${java.version} @@ -53,31 +66,41 @@ + + + + apache.snapshots + https://repository.apache.org/snapshots/ + + + - public + songoda-public https://repo.songoda.com/repository/public/ + - spigot-repo + spigotmc-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + jitpack.io - https://jitpack.io + https://jitpack.io/ + CodeMC - https://repo.codemc.org/repository/maven-public + https://repo.codemc.org/repository/maven-public/ - + - org.spigotmc - spigot - 1.17 - provided + org.jetbrains + annotations + 13.0 From 685aa4bc8a4dabd2a1100a0ecabf3c898b23d1d2 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Wed, 7 Jul 2021 18:40:17 +0200 Subject: [PATCH 4/8] Dependabot, FUNDING, README --- .github/FUNDING.yml | 12 ++++++++++ .github/dependabot.yml | 11 +++++++++ README.md | 52 +++++++++++++++++++++++++++--------------- 3 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/dependabot.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..c4daa16d --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: songoda +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..2bdcc460 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "maven" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "monthly" diff --git a/README.md b/README.md index 6b8fe9b4..07f9214e 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,47 @@ -SongodaCore ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/Songoda/SongodaCore/Build%20SongodaCore/master) ![GitHub Workflow Status (branch)](https://img.shields.io/discord/293212540723396608) -=========== + +
-An elaborate multi functional general Spigot plugin compatibility core and general use API. +# SongodaCore -Maven Information ------- +**An elaborate multi functional general Spigot plugin compatibility core and general use API.** -* Repository + +[![Discord](https://img.shields.io/discord/293212540723396608?color=7289DA&label=Discord&logo=discord&logoColor=7289DA)](https://discord.gg/songoda) +[![Patreon](https://img.shields.io/badge/-Support_on_Patreon-F96854.svg?logo=patreon&style=flat&logoColor=white)](https://www.patreon.com/join/songoda) +
+[![Build](https://github.com/songoda/SongodaCore/actions/workflows/maven.yml/badge.svg)](https://github.com/songoda/SongodaCore/actions/workflows/maven.yml) +[![Latest version](https://img.shields.io/nexus/public/com.songoda/SongodaCore?label=Latest%20version&server=https%3A%2F%2Frepo.songoda.com%2F)](https://repo.songoda.com/#browse/browse:public:com%2Fsongoda%2FSongodaCore) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=songoda_SongodaCore&metric=alert_status)](https://sonarcloud.io/dashboard?id=songoda_SongodaCore) +[![GitHub last commit](https://img.shields.io/github/last-commit/songoda/SongodaCore?label=Last+commit)](https://github.com/songoda/SongodaCore/commits) +
+ + + +## Maven +**Repository** ```xml - Songoda + songoda-public https://repo.songoda.com/repository/public/ ``` - * Artifact Information: + +**Artifact** ```xml - com.songoda - SongodaCore - 2.4.59 - provided + com.songoda + SongodaCore + VERSION ``` -Gradle Information ------- - * Repository: +## Gradle +**Repository** ```groovy repositories { maven { @@ -34,9 +49,10 @@ repositories { } } ``` - * Artifact: + +**Artifact** ```groovy dependencies { - compileOnly 'com.songoda:SongodaCore:2.4.59' + compileOnly 'com.songoda:SongodaCore:VERSION' } -``` \ No newline at end of file +``` From 6dbf806e7d4198e483398b0e84d694e2656d8b06 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 8 Jul 2021 15:33:44 +0200 Subject: [PATCH 5/8] EditorConfig --- .editorconfig | 311 + .github/workflows/maven.yml | 17 +- .../core/compatibility/ClientVersion.java | 229 +- .../core/compatibility/CompatibleBiome.java | 14 +- .../core/compatibility/CompatibleHand.java | 1 + .../compatibility/CompatibleMaterial.java | 6114 +++++++++-------- .../core/compatibility/CompatibleSound.java | 2832 ++++---- .../LegacyMaterialBlockType.java | 257 +- .../core/compatibility/ServerProject.java | 107 +- .../java/com/songoda/core/SongodaCore.java | 7 +- .../java/com/songoda/core/SongodaPlugin.java | 355 +- .../com/songoda/core/chat/ChatMessage.java | 547 +- .../java/com/songoda/core/chat/ColorCode.java | 3 +- .../com/songoda/core/chat/ColorContainer.java | 4 +- .../songoda/core/commands/CommandManager.java | 2 - .../songoda/core/commands/MainCommand.java | 239 +- .../core/commands/SelectorArguments.java | 387 +- .../core/commands/SimpleNestedCommand.java | 49 +- .../songoda/core/configuration/Config.java | 1465 ++-- .../configuration/ConfigFormattingRules.java | 187 +- .../core/configuration/ConfigSetting.java | 1 - .../core/configuration/SimpleDataStore.java | 535 +- .../configuration/editor/ConfigEditorGui.java | 614 +- .../editor/ConfigEditorListEditorGui.java | 169 +- .../configuration/editor/PluginConfigGui.java | 197 +- .../songoda/core/core/PluginInfoModule.java | 1 - .../songoda/core/core/SongodaCoreCommand.java | 103 +- .../core/core/SongodaCoreDiagCommand.java | 2 +- .../core/core/SongodaCoreOverviewGUI.java | 28 +- .../songoda/core/database/DataMigration.java | 1 - .../core/database/DataMigrationManager.java | 1 - .../core/database/DatabaseConnector.java | 1 - .../songoda/core/database/MySQLConnector.java | 1 - .../core/database/SQLiteConnector.java | 1 - .../com/songoda/core/gui/BackgroundType.java | 1 - .../com/songoda/core/gui/CustomizableGui.java | 1516 ++-- .../main/java/com/songoda/core/gui/Gui.java | 1751 +++-- .../java/com/songoda/core/gui/GuiType.java | 41 +- .../java/com/songoda/core/gui/GuiUtils.java | 825 +-- .../com/songoda/core/gui/PopupMessage.java | 373 +- .../core/gui/events/GuiClickEvent.java | 57 +- .../core/gui/events/GuiCloseEvent.java | 25 +- .../core/gui/events/GuiDropItemEvent.java | 43 +- .../com/songoda/core/gui/events/GuiEvent.java | 37 +- .../songoda/core/gui/events/GuiOpenEvent.java | 25 +- .../songoda/core/gui/events/GuiPageEvent.java | 39 +- .../songoda/core/hooks/EconomyManager.java | 8 +- .../com/songoda/core/hooks/HookManager.java | 373 +- .../com/songoda/core/hooks/LogManager.java | 1 - .../com/songoda/core/hooks/McMMOHook.java | 461 +- .../com/songoda/core/hooks/PluginHook.java | 332 +- .../songoda/core/hooks/WorldGuardHook.java | 314 +- .../songoda/core/hooks/economies/Economy.java | 6 +- .../hooks/economies/PlayerPointsEconomy.java | 2 - .../core/hooks/holograms/Holograms.java | 1 + .../HolographicDisplaysHolograms.java | 1 - .../core/hooks/mcmmo/McMMOHandler.java | 1028 ++- .../core/hooks/protection/Protection.java | 1 - .../songoda/core/hooks/stackers/StackMob.java | 1 - .../songoda/core/hooks/stackers/Stacker.java | 1 - .../core/hooks/stackers/UltimateStacker.java | 1 - .../core/hooks/stackers/WildStacker.java | 1 - .../worldguard/WorldGuardFlagHandler.java | 827 ++- .../worldguard/WorldGuardRegionHandler.java | 497 +- .../com/songoda/core/input/ChatPrompt.java | 1 - .../java/com/songoda/core/locale/Locale.java | 20 +- .../java/com/songoda/core/locale/Message.java | 3 +- .../lootables/gui/AbstractGuiListEditor.java | 12 +- .../core/lootables/gui/GuiEnchantEditor.java | 11 +- .../core/lootables/gui/GuiLootEditor.java | 66 +- .../core/lootables/gui/GuiLootableEditor.java | 2 +- .../core/lootables/loot/DropUtils.java | 3 +- .../com/songoda/core/lootables/loot/Loot.java | 1 - .../core/lootables/loot/LootBuilder.java | 7 +- .../core/lootables/loot/LootManager.java | 2 - .../main/java/com/songoda/core/math/Eval.java | 12 +- .../com/songoda/core/utils/BlockUtils.java | 2133 +++--- .../songoda/core/utils/BlockUtilsModern.java | 681 +- .../com/songoda/core/utils/ColorUtils.java | 4 +- .../com/songoda/core/utils/EntityUtils.java | 2 +- .../songoda/core/utils/ItemSerializer.java | 6 + .../com/songoda/core/utils/ItemUtils.java | 2243 +++--- .../com/songoda/core/utils/LocationUtils.java | 1 - .../java/com/songoda/core/utils/Metrics.java | 14 +- .../com/songoda/core/utils/NumberUtils.java | 3 +- .../com/songoda/core/utils/PlayerUtils.java | 466 +- .../songoda/core/utils/ReflectionUtils.java | 676 +- .../com/songoda/core/utils/RotationUtils.java | 79 +- .../com/songoda/core/utils/TextUtils.java | 5 +- .../com/songoda/core/utils/TimeUtils.java | 1 - .../java/com/songoda/core/world/SSpawner.java | 5 +- .../com/songoda/core/world/SWorldBorder.java | 2 - .../com/songoda/core/nms/nbt/NBTCompound.java | 1 - .../com/songoda/core/nms/nbt/NBTCore.java | 1 - .../com/songoda/core/nms/nbt/NBTEntity.java | 1 - .../com/songoda/core/nms/nbt/NBTItem.java | 1 - .../songoda/core/nms/world/SItemStack.java | 1 - .../songoda/core/nms/world/SpawnedEntity.java | 1 - .../core/nms/v1_10_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_10_R1/anvil/AnvilView.java | 1 - .../core/nms/v1_10_R1/nbt/NBTCoreImpl.java | 1 - .../nms/v1_10_R1/world/SItemStackImpl.java | 2 +- .../core/nms/v1_10_R1/world/SSpawnerImpl.java | 2 +- .../nms/v1_10_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_11_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_11_R1/anvil/AnvilView.java | 1 - .../core/nms/v1_11_R1/nbt/NBTCoreImpl.java | 1 - .../nms/v1_11_R1/world/SItemStackImpl.java | 2 +- .../core/nms/v1_11_R1/world/SSpawnerImpl.java | 2 +- .../nms/v1_11_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_12_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_12_R1/anvil/AnvilView.java | 1 - .../nms/v1_12_R1/nbt/NBTCompoundImpl.java | 1 - .../core/nms/v1_12_R1/nbt/NBTCoreImpl.java | 1 - .../nms/v1_12_R1/world/SItemStackImpl.java | 2 +- .../core/nms/v1_12_R1/world/SSpawnerImpl.java | 2 +- .../nms/v1_12_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_13_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_13_R1/anvil/AnvilView.java | 1 - .../nms/v1_13_R1/nbt/NBTCompoundImpl.java | 1 - .../core/nms/v1_13_R1/nbt/NBTCoreImpl.java | 1 - .../nms/v1_13_R1/world/SItemStackImpl.java | 2 +- .../core/nms/v1_13_R1/world/SSpawnerImpl.java | 2 +- .../nms/v1_13_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_13_R2/anvil/AnvilCore.java | 1 - .../core/nms/v1_13_R2/anvil/AnvilView.java | 1 - .../nms/v1_13_R2/nbt/NBTCompoundImpl.java | 2 +- .../core/nms/v1_13_R2/nbt/NBTCoreImpl.java | 1 - .../nms/v1_13_R2/world/SItemStackImpl.java | 2 +- .../core/nms/v1_13_R2/world/SSpawnerImpl.java | 2 +- .../nms/v1_13_R2/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_14_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_14_R1/anvil/AnvilView.java | 13 +- .../core/nms/v1_14_R1/nbt/NBTCoreImpl.java | 1 - .../nms/v1_14_R1/world/SItemStackImpl.java | 2 +- .../nms/v1_14_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_15_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_15_R1/anvil/AnvilView.java | 14 +- .../core/nms/v1_15_R1/nbt/NBTCoreImpl.java | 1 - .../nms/v1_15_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_16_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_16_R1/anvil/AnvilView.java | 15 +- .../core/nms/v1_16_R1/nbt/NBTCoreImpl.java | 1 - .../nms/v1_16_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_16_R2/anvil/AnvilCore.java | 1 - .../core/nms/v1_16_R2/anvil/AnvilView.java | 15 +- .../core/nms/v1_16_R2/nbt/NBTCoreImpl.java | 1 - .../nms/v1_16_R2/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_16_R3/anvil/AnvilCore.java | 1 - .../core/nms/v1_16_R3/anvil/AnvilView.java | 15 +- .../core/nms/v1_16_R3/nbt/NBTCoreImpl.java | 1 - .../core/nms/v1_16_R3/nbt/NBTItemImpl.java | 6 - .../nms/v1_16_R3/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_17_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_17_R1/anvil/AnvilView.java | 3 +- .../core/nms/v1_17_R1/nbt/NBTCoreImpl.java | 1 - .../core/nms/v1_17_R1/world/SWorldImpl.java | 1 - .../core/nms/v1_8_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_8_R1/anvil/AnvilView.java | 1 - .../core/nms/v1_8_R1/nbt/NBTCompoundImpl.java | 1 - .../core/nms/v1_8_R1/nbt/NBTCoreImpl.java | 1 - .../core/nms/v1_8_R1/nbt/NBTEntityImpl.java | 1 - .../nms/v1_8_R1/world/SItemStackImpl.java | 2 +- .../core/nms/v1_8_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_8_R2/anvil/AnvilCore.java | 1 - .../core/nms/v1_8_R2/anvil/AnvilView.java | 1 - .../core/nms/v1_8_R2/nbt/NBTCoreImpl.java | 1 - .../core/nms/v1_8_R2/nbt/NBTEntityImpl.java | 1 - .../nms/v1_8_R2/world/SItemStackImpl.java | 2 +- .../core/nms/v1_8_R2/world/WorldCoreImpl.java | 6 +- .../core/nms/v1_8_R3/anvil/AnvilCore.java | 1 - .../core/nms/v1_8_R3/anvil/AnvilView.java | 1 - .../core/nms/v1_8_R3/nbt/NBTCoreImpl.java | 1 - .../core/nms/v1_8_R3/nbt/NBTEntityImpl.java | 1 - .../nms/v1_8_R3/world/SItemStackImpl.java | 2 +- .../core/nms/v1_8_R3/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_9_R1/anvil/AnvilCore.java | 1 - .../core/nms/v1_9_R1/anvil/AnvilView.java | 1 - .../core/nms/v1_9_R1/nbt/NBTCoreImpl.java | 1 - .../nms/v1_9_R1/world/SItemStackImpl.java | 2 +- .../core/nms/v1_9_R1/world/SSpawnerImpl.java | 2 +- .../core/nms/v1_9_R1/world/WorldCoreImpl.java | 4 +- .../core/nms/v1_9_R2/anvil/AnvilCore.java | 1 - .../core/nms/v1_9_R2/nbt/NBTCoreImpl.java | 1 - .../nms/v1_9_R2/world/SItemStackImpl.java | 2 +- .../core/nms/v1_9_R2/world/SSpawnerImpl.java | 2 +- .../core/nms/v1_9_R2/world/WorldCoreImpl.java | 4 +- 187 files changed, 15198 insertions(+), 14869 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..9737e6fa --- /dev/null +++ b/.editorconfig @@ -0,0 +1,311 @@ +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +# max_line_length = 120 +tab_width = 4 +trim_trailing_whitespace = true +ij_continuation_indent_size = 8 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = false +ij_smart_tabs = false +ij_visual_guides = none +ij_wrap_on_typing = false + +[*.java] +ij_smart_tabs = true +ij_java_align_consecutive_assignments = false +ij_java_align_consecutive_variable_declarations = false +ij_java_align_group_field_declarations = false +ij_java_align_multiline_annotation_parameters = false +ij_java_align_multiline_array_initializer_expression = false +ij_java_align_multiline_assignment = false +ij_java_align_multiline_binary_operation = false +ij_java_align_multiline_chained_methods = false +ij_java_align_multiline_extends_list = false +ij_java_align_multiline_for = true +ij_java_align_multiline_method_parentheses = false +ij_java_align_multiline_parameters = true +ij_java_align_multiline_parameters_in_calls = false +ij_java_align_multiline_parenthesized_expression = false +ij_java_align_multiline_records = true +ij_java_align_multiline_resources = true +ij_java_align_multiline_ternary_operation = false +ij_java_align_multiline_text_blocks = false +ij_java_align_multiline_throws_list = false +ij_java_align_subsequent_simple_methods = false +ij_java_align_throws_keyword = false +ij_java_annotation_parameter_wrap = off +ij_java_array_initializer_new_line_after_left_brace = false +ij_java_array_initializer_right_brace_on_new_line = false +ij_java_array_initializer_wrap = off +ij_java_assert_statement_colon_on_next_line = false +ij_java_assert_statement_wrap = off +ij_java_assignment_wrap = off +ij_java_binary_operation_sign_on_next_line = false +ij_java_binary_operation_wrap = off +ij_java_blank_lines_after_anonymous_class_header = 0 +ij_java_blank_lines_after_class_header = 0 +ij_java_blank_lines_after_imports = 1 +ij_java_blank_lines_after_package = 1 +ij_java_blank_lines_around_class = 1 +ij_java_blank_lines_around_field = 0 +ij_java_blank_lines_around_field_in_interface = 0 +ij_java_blank_lines_around_initializer = 1 +ij_java_blank_lines_around_method = 1 +ij_java_blank_lines_around_method_in_interface = 1 +ij_java_blank_lines_before_class_end = 0 +ij_java_blank_lines_before_imports = 1 +ij_java_blank_lines_before_method_body = 0 +ij_java_blank_lines_before_package = 0 +ij_java_block_brace_style = end_of_line +ij_java_block_comment_at_first_column = true +ij_java_builder_methods = none +ij_java_call_parameters_new_line_after_left_paren = false +ij_java_call_parameters_right_paren_on_new_line = false +ij_java_call_parameters_wrap = off +ij_java_case_statement_on_separate_line = true +ij_java_catch_on_new_line = false +ij_java_class_annotation_wrap = split_into_lines +ij_java_class_brace_style = end_of_line +ij_java_class_count_to_use_import_on_demand = 15 +ij_java_class_names_in_javadoc = 1 +ij_java_do_not_indent_top_level_class_members = false +ij_java_do_not_wrap_after_single_annotation = false +ij_java_do_while_brace_force = never +ij_java_doc_add_blank_line_after_description = true +ij_java_doc_add_blank_line_after_param_comments = true +ij_java_doc_add_blank_line_after_return = true +ij_java_doc_add_p_tag_on_empty_lines = true +ij_java_doc_align_exception_comments = true +ij_java_doc_align_param_comments = true +ij_java_doc_do_not_wrap_if_one_line = true +ij_java_doc_enable_formatting = true +ij_java_doc_enable_leading_asterisks = true +ij_java_doc_indent_on_continuation = true +ij_java_doc_keep_empty_lines = true +ij_java_doc_keep_empty_parameter_tag = true +ij_java_doc_keep_empty_return_tag = true +ij_java_doc_keep_empty_throws_tag = true +ij_java_doc_keep_invalid_tags = true +ij_java_doc_param_description_on_new_line = false +ij_java_doc_preserve_line_breaks = false +ij_java_doc_use_throws_not_exception_tag = true +ij_java_else_on_new_line = false +ij_java_enum_constants_wrap = off +ij_java_extends_keyword_wrap = off +ij_java_extends_list_wrap = off +ij_java_field_annotation_wrap = split_into_lines +ij_java_finally_on_new_line = false +ij_java_for_brace_force = never +ij_java_for_statement_new_line_after_left_paren = false +ij_java_for_statement_right_paren_on_new_line = false +ij_java_for_statement_wrap = off +ij_java_generate_final_locals = false +ij_java_generate_final_parameters = false +ij_java_if_brace_force = never +ij_java_imports_layout = *, |, javax.**, java.**, |, $* +ij_java_indent_case_from_switch = true +ij_java_insert_inner_class_imports = false +ij_java_insert_override_annotation = true +ij_java_keep_blank_lines_before_right_brace = 0 +ij_java_keep_blank_lines_between_package_declaration_and_header = 0 +ij_java_keep_blank_lines_in_code = 1 +ij_java_keep_blank_lines_in_declarations = 1 +ij_java_keep_builder_methods_indents = false +ij_java_keep_control_statement_in_one_line = true +ij_java_keep_first_column_comment = true +ij_java_keep_indents_on_empty_lines = false +ij_java_keep_line_breaks = true +ij_java_keep_multiple_expressions_in_one_line = false +ij_java_keep_simple_blocks_in_one_line = false +ij_java_keep_simple_classes_in_one_line = true +ij_java_keep_simple_lambdas_in_one_line = true +ij_java_keep_simple_methods_in_one_line = true +ij_java_label_indent_absolute = false +ij_java_label_indent_size = 0 +ij_java_lambda_brace_style = end_of_line +ij_java_layout_static_imports_separately = true +ij_java_line_comment_add_space = false +ij_java_line_comment_at_first_column = true +ij_java_method_annotation_wrap = split_into_lines +ij_java_method_brace_style = end_of_line +ij_java_method_call_chain_wrap = off +ij_java_method_parameters_new_line_after_left_paren = false +ij_java_method_parameters_right_paren_on_new_line = false +ij_java_method_parameters_wrap = off +ij_java_modifier_list_wrap = false +ij_java_names_count_to_use_import_on_demand = 9 +ij_java_new_line_after_lparen_in_record_header = false +ij_java_packages_to_use_import_on_demand = _java.awt.*, _javax.swing.* +ij_java_parameter_annotation_wrap = off +ij_java_parentheses_expression_new_line_after_left_paren = false +ij_java_parentheses_expression_right_paren_on_new_line = false +ij_java_place_assignment_sign_on_next_line = false +ij_java_prefer_longer_names = true +ij_java_prefer_parameters_wrap = false +ij_java_record_components_wrap = normal +ij_java_repeat_synchronized = true +ij_java_replace_instanceof_and_cast = true +ij_java_replace_null_check = true +ij_java_replace_sum_lambda_with_method_ref = true +ij_java_resource_list_new_line_after_left_paren = false +ij_java_resource_list_right_paren_on_new_line = false +ij_java_resource_list_wrap = off +ij_java_rparen_on_new_line_in_record_header = false +ij_java_space_after_closing_angle_bracket_in_type_argument = false +ij_java_space_after_colon = true +ij_java_space_after_comma = true +ij_java_space_after_comma_in_type_arguments = true +ij_java_space_after_for_semicolon = true +ij_java_space_after_quest = true +ij_java_space_after_type_cast = true +ij_java_space_before_annotation_array_initializer_left_brace = false +ij_java_space_before_annotation_parameter_list = false +ij_java_space_before_array_initializer_left_brace = true +ij_java_space_before_catch_keyword = true +ij_java_space_before_catch_left_brace = true +ij_java_space_before_catch_parentheses = true +ij_java_space_before_class_left_brace = true +ij_java_space_before_colon = true +ij_java_space_before_colon_in_foreach = true +ij_java_space_before_comma = false +ij_java_space_before_do_left_brace = true +ij_java_space_before_else_keyword = true +ij_java_space_before_else_left_brace = true +ij_java_space_before_finally_keyword = true +ij_java_space_before_finally_left_brace = true +ij_java_space_before_for_left_brace = true +ij_java_space_before_for_parentheses = true +ij_java_space_before_for_semicolon = false +ij_java_space_before_if_left_brace = true +ij_java_space_before_if_parentheses = true +ij_java_space_before_method_call_parentheses = false +ij_java_space_before_method_left_brace = true +ij_java_space_before_method_parentheses = false +ij_java_space_before_opening_angle_bracket_in_type_parameter = false +ij_java_space_before_quest = true +ij_java_space_before_switch_left_brace = true +ij_java_space_before_switch_parentheses = true +ij_java_space_before_synchronized_left_brace = true +ij_java_space_before_synchronized_parentheses = true +ij_java_space_before_try_left_brace = true +ij_java_space_before_try_parentheses = true +ij_java_space_before_type_parameter_list = false +ij_java_space_before_while_keyword = true +ij_java_space_before_while_left_brace = true +ij_java_space_before_while_parentheses = true +ij_java_space_inside_one_line_enum_braces = false +ij_java_space_within_empty_array_initializer_braces = true +ij_java_space_within_empty_method_call_parentheses = false +ij_java_space_within_empty_method_parentheses = false +ij_java_spaces_around_additive_operators = true +ij_java_spaces_around_assignment_operators = true +ij_java_spaces_around_bitwise_operators = true +ij_java_spaces_around_equality_operators = true +ij_java_spaces_around_lambda_arrow = true +ij_java_spaces_around_logical_operators = true +ij_java_spaces_around_method_ref_dbl_colon = false +ij_java_spaces_around_multiplicative_operators = true +ij_java_spaces_around_relational_operators = true +ij_java_spaces_around_shift_operators = true +ij_java_spaces_around_type_bounds_in_type_parameters = true +ij_java_spaces_around_unary_operator = false +ij_java_spaces_within_angle_brackets = false +ij_java_spaces_within_annotation_parentheses = false +ij_java_spaces_within_array_initializer_braces = false +ij_java_spaces_within_braces = true +ij_java_spaces_within_brackets = false +ij_java_spaces_within_cast_parentheses = false +ij_java_spaces_within_catch_parentheses = false +ij_java_spaces_within_for_parentheses = false +ij_java_spaces_within_if_parentheses = false +ij_java_spaces_within_method_call_parentheses = false +ij_java_spaces_within_method_parentheses = false +ij_java_spaces_within_parentheses = false +ij_java_spaces_within_record_header = false +ij_java_spaces_within_switch_parentheses = false +ij_java_spaces_within_synchronized_parentheses = false +ij_java_spaces_within_try_parentheses = false +ij_java_spaces_within_while_parentheses = false +ij_java_special_else_if_treatment = true +ij_java_subclass_name_suffix = Impl +ij_java_ternary_operation_signs_on_next_line = false +ij_java_ternary_operation_wrap = off +ij_java_test_name_suffix = Test +ij_java_throws_keyword_wrap = off +ij_java_throws_list_wrap = off +ij_java_use_external_annotations = false +ij_java_use_fq_class_names = false +ij_java_use_relative_indents = false +ij_java_use_single_class_imports = true +ij_java_variable_annotation_wrap = off +ij_java_visibility = public +ij_java_while_brace_force = never +ij_java_while_on_new_line = false +ij_java_wrap_comments = false +ij_java_wrap_first_method_in_call_chain = false +ij_java_wrap_long_lines = false + +[*.properties] +ij_properties_align_group_field_declarations = false +ij_properties_keep_blank_lines = false +ij_properties_key_value_delimiter = equals +ij_properties_spaces_around_key_value_delimiter = false + +[.editorconfig] +ij_editorconfig_align_group_field_declarations = false +ij_editorconfig_space_after_colon = false +ij_editorconfig_space_after_comma = true +ij_editorconfig_space_before_colon = false +ij_editorconfig_space_before_comma = false +ij_editorconfig_spaces_around_assignment_operators = true + +[{*.ant, *.fxml, *.jhm, *.jnlp, *.jrxml, *.pom, *.rng, *.tld, *.wsdl, *.xml, *.xsd, *.xsl, *.xslt, *.xul}] +ij_xml_align_attributes = true +ij_xml_align_text = false +ij_xml_attribute_wrap = normal +ij_xml_block_comment_at_first_column = true +ij_xml_keep_blank_lines = 2 +ij_xml_keep_indents_on_empty_lines = false +ij_xml_keep_line_breaks = true +ij_xml_keep_line_breaks_in_text = true +ij_xml_keep_whitespaces = false +ij_xml_keep_whitespaces_around_cdata = preserve +ij_xml_keep_whitespaces_inside_cdata = false +ij_xml_line_comment_at_first_column = true +ij_xml_space_after_tag_name = false +ij_xml_space_around_equals_in_attribute = false +ij_xml_space_inside_empty_tag = false +ij_xml_text_wrap = normal + +[{*.markdown, *.md}] +indent_size = 2 +tab_width = 2 +ij_markdown_force_one_space_after_blockquote_symbol = true +ij_markdown_force_one_space_after_header_symbol = true +ij_markdown_force_one_space_after_list_bullet = true +ij_markdown_force_one_space_between_words = true +ij_markdown_keep_indents_on_empty_lines = false +ij_markdown_max_lines_around_block_elements = 1 +ij_markdown_max_lines_around_header = 1 +ij_markdown_max_lines_between_paragraphs = 1 +ij_markdown_min_lines_around_block_elements = 1 +ij_markdown_min_lines_around_header = 1 +ij_markdown_min_lines_between_paragraphs = 1 + +[{*.yaml, *.yml, *.lang}] +indent_size = 2 +ij_yaml_align_values_properties = do_not_align +ij_yaml_autoinsert_sequence_marker = true +ij_yaml_block_mapping_on_new_line = false +ij_yaml_indent_sequence_value = true +ij_yaml_keep_indents_on_empty_lines = false +ij_yaml_keep_line_breaks = true +ij_yaml_sequence_on_new_line = false +ij_yaml_space_before_colon = false +ij_yaml_spaces_within_braces = true +ij_yaml_spaces_within_brackets = true diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 3d438a77..a461e4da 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -7,18 +7,17 @@ on: push: branches: [ master ] pull_request: - branches: [ master ] + types: [ opened, synchronize, reopened ] jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 16 - uses: actions/setup-java@v1 - with: - java-version: 16 - - name: Build with Maven - run: mvn -B package --file pom.xml + - uses: actions/checkout@v2 + - name: Set up JDK 16 + uses: actions/setup-java@v1 + with: + java-version: 16 + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/ClientVersion.java b/Compatibility/src/main/java/com/songoda/core/compatibility/ClientVersion.java index 02fd1add..2964b473 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/ClientVersion.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/ClientVersion.java @@ -1,114 +1,115 @@ -package com.songoda.core.compatibility; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.HashMap; -import java.util.UUID; - -/** - * Handy reference for checking a connected client's Minecraft version
- * NOTE: this is automatically initialized through SongodaCore - */ -public class ClientVersion { - - static HashMap players = new HashMap(); - - /** - * Check to see what client version this player is connected to the server - * with. Note that if a player is connecting with a newer client than the server, - * this value will simply be the server version. - * - * @param player Player to check - * @return ServerVersion that matches this player's Minecraft version - */ - public static ServerVersion getClientVersion(Player player) { - if (player == null || !players.containsKey(player.getUniqueId())) { - return ServerVersion.getServerVersion(); - } - return players.get(player.getUniqueId()); - } - - /** - * Do Not Use: This is handled by SongodaCore. - */ - @Deprecated - public static void onLoginProtocol(Player p, JavaPlugin plugin) { - Bukkit.getScheduler().runTaskLater(plugin, () -> { - if (p.isOnline()) { - final int version = protocolsupport.api.ProtocolSupportAPI.getProtocolVersion(p).getId(); - players.put(p.getUniqueId(), protocolToVersion(version)); - } - }, 20); - } - - /** - * Do Not Use: This is handled by SongodaCore. - */ - @Deprecated - public static void onLoginVia(Player p, JavaPlugin plugin) { - Bukkit.getScheduler().runTaskLater(plugin, () -> { - if (p.isOnline()) { - final int version = us.myles.ViaVersion.api.Via.getAPI().getPlayerVersion(p.getUniqueId()); - players.put(p.getUniqueId(), protocolToVersion(version)); - } - }, 20); - } - - private static ServerVersion protocolToVersion(int version) { - // https://github.com/ViaVersion/ViaVersion/blob/master/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java - // https://github.com/ProtocolSupport/ProtocolSupport/blob/master/src/protocolsupport/api/ProtocolVersion.java - switch (version) { - case 4: - case 5: - return ServerVersion.V1_7; - case 47: - return ServerVersion.V1_8; - case 107: - case 108: - case 109: - case 110: - return ServerVersion.V1_9; - case 210: - return ServerVersion.V1_10; - case 315: - case 316: - return ServerVersion.V1_11; - case 335: - case 338: - case 340: - return ServerVersion.V1_12; - case 393: - case 401: - case 404: - return ServerVersion.V1_13; - case 477: - case 485: - case 490: - case 498: - return ServerVersion.V1_14; - case 573: - case 575: - case 578: - return ServerVersion.V1_15; - case 735: - case 736: - case 751: - case 753: - case 754: - return ServerVersion.V1_16; - case 755: - return ServerVersion.V1_17; - } - return version > 498 ? ServerVersion.getServerVersion() : ServerVersion.UNKNOWN; - } - - /** - * Do Not Use: This is handled by SongodaCore. - */ - @Deprecated - public static void onLogout(Player p) { - players.remove(p.getUniqueId()); - } -} +package com.songoda.core.compatibility; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashMap; +import java.util.UUID; + +/** + * Handy reference for checking a connected client's Minecraft version
+ * NOTE: this is automatically initialized through SongodaCore + */ +public class ClientVersion { + + static HashMap players = new HashMap(); + + /** + * Check to see what client version this player is connected to the server + * with. Note that if a player is connecting with a newer client than the server, + * this value will simply be the server version. + * + * @param player Player to check + * + * @return ServerVersion that matches this player's Minecraft version + */ + public static ServerVersion getClientVersion(Player player) { + if (player == null || !players.containsKey(player.getUniqueId())) { + return ServerVersion.getServerVersion(); + } + return players.get(player.getUniqueId()); + } + + /** + * Do Not Use: This is handled by SongodaCore. + */ + @Deprecated + public static void onLoginProtocol(Player p, JavaPlugin plugin) { + Bukkit.getScheduler().runTaskLater(plugin, () -> { + if (p.isOnline()) { + final int version = protocolsupport.api.ProtocolSupportAPI.getProtocolVersion(p).getId(); + players.put(p.getUniqueId(), protocolToVersion(version)); + } + }, 20); + } + + /** + * Do Not Use: This is handled by SongodaCore. + */ + @Deprecated + public static void onLoginVia(Player p, JavaPlugin plugin) { + Bukkit.getScheduler().runTaskLater(plugin, () -> { + if (p.isOnline()) { + final int version = us.myles.ViaVersion.api.Via.getAPI().getPlayerVersion(p.getUniqueId()); + players.put(p.getUniqueId(), protocolToVersion(version)); + } + }, 20); + } + + private static ServerVersion protocolToVersion(int version) { + // https://github.com/ViaVersion/ViaVersion/blob/master/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java + // https://github.com/ProtocolSupport/ProtocolSupport/blob/master/src/protocolsupport/api/ProtocolVersion.java + switch (version) { + case 4: + case 5: + return ServerVersion.V1_7; + case 47: + return ServerVersion.V1_8; + case 107: + case 108: + case 109: + case 110: + return ServerVersion.V1_9; + case 210: + return ServerVersion.V1_10; + case 315: + case 316: + return ServerVersion.V1_11; + case 335: + case 338: + case 340: + return ServerVersion.V1_12; + case 393: + case 401: + case 404: + return ServerVersion.V1_13; + case 477: + case 485: + case 490: + case 498: + return ServerVersion.V1_14; + case 573: + case 575: + case 578: + return ServerVersion.V1_15; + case 735: + case 736: + case 751: + case 753: + case 754: + return ServerVersion.V1_16; + case 755: + return ServerVersion.V1_17; + } + return version > 498 ? ServerVersion.getServerVersion() : ServerVersion.UNKNOWN; + } + + /** + * Do Not Use: This is handled by SongodaCore. + */ + @Deprecated + public static void onLogout(Player p) { + players.remove(p.getUniqueId()); + } +} diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleBiome.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleBiome.java index 45701b96..c1cce071 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleBiome.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleBiome.java @@ -131,12 +131,12 @@ public enum CompatibleBiome { if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_15)) { try { - Class classBiomeBase = ClassMapping.BIOME_BASE.getClazz(), - classCraftChunk = ClassMapping.CRAFT_CHUNK.getClazz(), - classCraftBlock = ClassMapping.CRAFT_BLOCK.getClazz(), - classChunk = ClassMapping.CHUNK.getClazz(), - classBiomeStorage = ClassMapping.BIOME_STORAGE.getClazz(), - classIRegistry = ClassMapping.I_REGISTRY.getClazz(); + Class classBiomeBase = ClassMapping.BIOME_BASE.getClazz(), + classCraftChunk = ClassMapping.CRAFT_CHUNK.getClazz(), + classCraftBlock = ClassMapping.CRAFT_BLOCK.getClazz(), + classChunk = ClassMapping.CHUNK.getClazz(), + classBiomeStorage = ClassMapping.BIOME_STORAGE.getClazz(), + classIRegistry = ClassMapping.I_REGISTRY.getClazz(); methodBiomeToBiomeBase = isAbove1_16_R1 ? classCraftBlock.getMethod("biomeToBiomeBase", classIRegistry, Biome.class) : classCraftBlock.getMethod("biomeToBiomeBase", Biome.class); @@ -189,7 +189,6 @@ public enum CompatibleBiome { return compatibleBiomes; } - public static CompatibleBiome getBiome(Biome biome) { return biome == null ? null : lookupMap.get(biome.name()); } @@ -252,6 +251,5 @@ public enum CompatibleBiome { this.version = version; this.biome = biome; } - } } diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleHand.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleHand.java index 7b56c0e0..882cf601 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleHand.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleHand.java @@ -75,6 +75,7 @@ public enum CompatibleHand { * Get item in the selected hand * * @param player the player to get the item from + * * @return the item */ public ItemStack getItem(Player player) { diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java index 0d46ac8e..1e3baae5 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleMaterial.java @@ -1,3050 +1,3064 @@ -package com.songoda.core.compatibility; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.FallingBlock; -import org.bukkit.inventory.ItemStack; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -/** - * Items that are compatible with server versions 1.7+ - * - * @author jascotty2 - * @since 2019-08-23 - */ -public enum CompatibleMaterial { - /* - TODO: add another handler for getBlockItem() for materials and fallback materials - - Legacy has some values not used in modern, eg: - - DIODE_BLOCK_OFF(93, Diode.class), - DIODE_BLOCK_ON(94, Diode.class), - SPRUCE_DOOR_ITEM(427), - BIRCH_DOOR_ITEM(428), - JUNGLE_DOOR_ITEM(429), - ACACIA_DOOR_ITEM(430), - DARK_OAK_DOOR_ITEM(431), - */ - - /* 1.17 */ - AMETHYST_BLOCK(), - AMETHYST_CLUSTER(), - AMETHYST_SHARD(), - AXOLOTL_BUCKET(), - AXOLOTL_SPAWN_EGG(), - AZALEA(), - AZALEA_LEAVES(), - BIG_DRIPLEAF(), - BIG_DRIPLEAF_STEM(), - BLACK_CANDLE(), - BLACK_CANDLE_CAKE(), - BLUE_CANDLE(), - BLUE_CANDLE_CAKE(), - BROWN_CANDLE(), - BROWN_CANDLE_CAKE(), - BUDDING_AMETHYST(), - BUNDLE(), - CALCITE(), - CANDLE(), - CANDLE_CAKE(), - CAVE_VINES(), - CAVE_VINES_PLANT(), - CHISELED_DEEPSLATE(), - COBBLED_DEEPSLATE(), - COBBLED_DEEPSLATE_SLAB(), - COBBLED_DEEPSLATE_STAIRS(), - COBBLED_DEEPSLATE_WALL(), - COPPER_BLOCK(), - COPPER_INGOT(), - COPPER_ORE(), - CRACKED_DEEPSLATE_BRICKS(), - CRACKED_DEEPSLATE_TILES(), - CUT_COPPER(), - CUT_COPPER_SLAB(), - CUT_COPPER_STAIRS(), - CYAN_CANDLE(), - CYAN_CANDLE_CAKE(), - DEEPSLATE(), - DEEPSLATE_BRICKS(), - DEEPSLATE_BRICK_SLAB(), - DEEPSLATE_BRICK_STAIRS(), - DEEPSLATE_BRICK_WALL(), - DEEPSLATE_COAL_ORE(), - DEEPSLATE_COPPER_ORE(), - DEEPSLATE_DIAMOND_ORE(), - DEEPSLATE_EMERALD_ORE(), - DEEPSLATE_GOLD_ORE(), - DEEPSLATE_IRON_ORE(), - DEEPSLATE_LAPIS_ORE(), - DEEPSLATE_REDSTONE_ORE(), - DEEPSLATE_TILES(), - DEEPSLATE_TILE_SLAB(), - DEEPSLATE_TILE_STAIRS(), - DEEPSLATE_TILE_WALL(), - DRIPSTONE_BLOCK(), - EXPOSED_COPPER(), - EXPOSED_CUT_COPPER(), - EXPOSED_CUT_COPPER_SLAB(), - EXPOSED_CUT_COPPER_STAIRS(), - FLOWERING_AZALEA(), - FLOWERING_AZALEA_LEAVES(), - GLOW_BERRIES(), - GLOW_INK_SAC(), - GLOW_ITEM_FRAME(), - GLOW_LICHEN(), - GLOW_SQUID_SPAWN_EGG(), - GOAT_SPAWN_EGG(), - GRAY_CANDLE(), - GRAY_CANDLE_CAKE(), - GREEN_CANDLE(), - GREEN_CANDLE_CAKE(), - HANGING_ROOTS(), - INFESTED_DEEPSLATE(), - LARGE_AMETHYST_BUD(), - LAVA_CAULDRON(), - LIGHT(), - LIGHTNING_ROD(), - LIGHT_BLUE_CANDLE(), - LIGHT_BLUE_CANDLE_CAKE(), - LIGHT_GRAY_CANDLE(), - LIGHT_GRAY_CANDLE_CAKE(), - LIME_CANDLE(), - LIME_CANDLE_CAKE(), - MAGENTA_CANDLE(), - MAGENTA_CANDLE_CAKE(), - MEDIUM_AMETHYST_BUD(), - MOSS_BLOCK(), - MOSS_CARPET(), - ORANGE_CANDLE(), - ORANGE_CANDLE_CAKE(), - OXIDIZED_COPPER(), - OXIDIZED_CUT_COPPER(), - OXIDIZED_CUT_COPPER_SLAB(), - OXIDIZED_CUT_COPPER_STAIRS(), - PINK_CANDLE(), - PINK_CANDLE_CAKE(), - POINTED_DRIPSTONE(), - POLISHED_DEEPSLATE(), - POLISHED_DEEPSLATE_SLAB(), - POLISHED_DEEPSLATE_STAIRS(), - POLISHED_DEEPSLATE_WALL(), - POTTED_AZALEA_BUSH(), - POTTED_FLOWERING_AZALEA_BUSH(), - POWDER_SNOW(), - POWDER_SNOW_BUCKET(), - POWDER_SNOW_CAULDRON(), - PURPLE_CANDLE(), - PURPLE_CANDLE_CAKE(), - RAW_COPPER(), - RAW_COPPER_BLOCK(), - RAW_GOLD(), - RAW_GOLD_BLOCK(), - RAW_IRON(), - RAW_IRON_BLOCK(), - RED_CANDLE(), - RED_CANDLE_CAKE(), - ROOTED_DIRT(), - SCULK_SENSOR(), - SMALL_AMETHYST_BUD(), - SMALL_DRIPLEAF(), - SMOOTH_BASALT(), - SPORE_BLOSSOM(), - SPYGLASS(), - TINTED_GLASS(), - TUFF(), - WATER_CAULDRON(), - WAXED_COPPER_BLOCK(), - WAXED_CUT_COPPER(), - WAXED_CUT_COPPER_SLAB(), - WAXED_CUT_COPPER_STAIRS(), - WAXED_EXPOSED_COPPER(), - WAXED_EXPOSED_CUT_COPPER(), - WAXED_EXPOSED_CUT_COPPER_SLAB(), - WAXED_EXPOSED_CUT_COPPER_STAIRS(), - WAXED_OXIDIZED_COPPER(), - WAXED_OXIDIZED_CUT_COPPER(), - WAXED_OXIDIZED_CUT_COPPER_SLAB(), - WAXED_OXIDIZED_CUT_COPPER_STAIRS(), - WAXED_WEATHERED_COPPER(), - WAXED_WEATHERED_CUT_COPPER(), - WAXED_WEATHERED_CUT_COPPER_SLAB(), - WAXED_WEATHERED_CUT_COPPER_STAIRS(), - WEATHERED_COPPER(), - WEATHERED_CUT_COPPER(), - WEATHERED_CUT_COPPER_SLAB(), - WEATHERED_CUT_COPPER_STAIRS(), - WHITE_CANDLE(), - WHITE_CANDLE_CAKE(), - YELLOW_CANDLE(), - YELLOW_CANDLE_CAKE(), - - /* 1.16 */ - ANCIENT_DEBRIS(), - BASALT(), - BLACKSTONE(), - BLACKSTONE_STAIRS(), - BLACKSTONE_WALL(), - BLACKSTONE_SLAB(), - BLASTSTONE_SLAB(), - CHAIN(), - CHISELED_NETHER_BRICKS(), - CHISELED_POLISHED_BLACKSTONE(), - CRACKED_NETHER_BRICKS(), - CRACKED_POLISHED_BLACKSTONE_BRICKS(), - CRIMSON_BUTTON(), - CRIMSON_DOOR(), - CRIMSON_FENCE(), - CRIMSON_FENCE_GATE(), - CRIMSON_FUNGUS(), - CRIMSON_HYPHAE(), - CRIMSON_NYLIUM(), - CRIMSON_PLANKS(), - CRIMSON_PRESSURE_PLATE(), - CRIMSON_ROOTS(), - CRIMSON_SIGN(), - CRIMSON_SLAB(), - CRIMSON_STAIRS(), - CRIMSON_STEM(), - CRIMSON_TRAPDOOR(), - CRIMSON_WALL_SIGN(), - CRYING_OBSIDIAN(), - GILDED_BLACKSTONE(), - HOGLIN_SPAWN_EGG(), - LODESTONE(), - MUSIC_DISC_PIGSTEP(), - NETHERITE_AXE(), - NETHERITE_BLOCK(), - NETHERITE_BOOTS(), - NETHERITE_CHESTPLATE(), - NETHERITE_HELMET(), - NETHERITE_HOE(), - NETHERITE_INGOT(), - NETHERITE_LEGGINGS(), - NETHERITE_PICKAXE(), - NETHERITE_SCRAP(), - NETHERITE_SHOVEL(), - NETHERITE_SWORD(), - NETHER_GOLD_ORE(), - NETHER_SPROUTS(), - PIGLIN_BANNER_PATTERN(), - PIGLIN_SPAWN_EGG(), - POLISHED_BASALT(), - POLISHED_BLACKSTONE(), - POLISHED_BLACKSTONE_BRICKS(), - POLISHED_BLACKSTONE_BRICK_SLAB(), - POLISHED_BLACKSTONE_BRICK_STAIRS(), - POLISHED_BLACKSTONE_BRICK_WALL(), - POLISHED_BLACKSTONE_BUTTON(), - POLISHED_BLACKSTONE_PRESSURE_PLATE(), - POLISHED_BLACKSTONE_SLAB(), - POLISHED_BLACKSTONE_STAIRS(), - POLISHED_BLACKSTONE_WALL(), - POTTED_CRIMSON_FUNGUS(), - POTTED_CRIMSON_ROOTS(), - POTTED_WARPED_FUNGUS(), - POTTED_WARPED_ROOTS(), - QUARTZ_BRICKS(), - RESPAWN_ANCHOR(), - SHROOMLIGHT(), - SOUL_CAMPFIRE(), - SOUL_FIRE(), - SOUL_LANTERN(), - SOUL_SOIL(), - SOUL_TORCH(), - SOUL_WALL_TORCH(), - STRIDER_SPAWN_EGG(), - STRIPPED_CRIMSON_HYPHAE(), - STRIPPED_CRIMSON_STEM(), - STRIPPED_WARPED_HYPHAE(), - STRIPPED_WARPED_STEM(), - TARGET(), - TWISTING_VINES(), - TWISTING_VINES_PLANT(), - WARPED_BUTTON(), - WARPED_DOOR(), - WARPED_FENCE(), - WARPED_FENCE_GATE(), - WARPED_FUNGUS(), - WARPED_FUNGUS_ON_A_STICK(), - WARPED_HYPHAE(), - WARPED_NYLIUM(), - WARPED_PLANKS(), - WARPED_PRESSURE_PLATE(), - WARPED_ROOTS(), - WARPED_SIGN(), - WARPED_SLAB(), - WARPED_STAIRS(), - WARPED_STEM(), - WARPED_TRAPDOOR(), - WARPED_WALL_SIGN(), - WARPED_WART_BLOCK(), - WEEPING_VINES(), - WEEPING_VINES_PLANT(), - ZOGLIN_SPAWN_EGG(), - ZOMBIFIED_PIGLIN_SPAWN_EGG(), - - /* 1.15 */ - BEE_SPAWN_EGG(), - BEE_NEST(), - BEEHIVE(), - HONEY_BLOCK(), - HONEY_BOTTLE(), - HONEYCOMB(), - HONEYCOMB_BLOCK(), - - ACACIA_BOAT("BOAT_ACACIA"), - ACACIA_BUTTON(), - ACACIA_DOOR("ACACIA_DOOR_ITEM"), - ACACIA_FENCE(), - ACACIA_FENCE_GATE(), - ACACIA_LEAVES("LEAVES_2", (byte) 0), - ACACIA_LOG("LOG_2", (byte) 0), - ACACIA_PLANKS("WOOD", (byte) 4), - ACACIA_PRESSURE_PLATE(), - ACACIA_SAPLING("SAPLING", (byte) 4), - ACACIA_SIGN(ServerVersion.V1_14, null), - ACACIA_SLAB("WOOD_STEP", (byte) 4), - ACACIA_STAIRS, - ACACIA_TRAPDOOR(), - ACACIA_WALL_SIGN(), - ACACIA_WOOD("LOG_2", (byte) 12), - ACTIVATOR_RAIL, - AIR, - ALLIUM("RED_ROSE", (byte) 2), - ANDESITE("STONE", (byte) 5), - ANDESITE_SLAB(), - ANDESITE_STAIRS(), - ANDESITE_WALL(), - ANVIL("ANVIL", (byte) 0), - APPLE, - ARMOR_STAND(ServerVersion.V1_8, null), - ARROW, - ATTACHED_MELON_STEM("MELON_STEM"), - ATTACHED_PUMPKIN_STEM("PUMPKIN_STEM"), - AZURE_BLUET("RED_ROSE", (byte) 3), - BAKED_POTATO("BAKED_POTATO"), - BAMBOO(), - BAMBOO_SAPLING(), - BARREL(), - BARRIER(), - BAT_SPAWN_EGG("MONSTER_EGG", (byte) 65), - BEACON, - BEDROCK, - BEEF("RAW_BEEF"), - BEETROOT(), // the item - BEETROOTS("BEETROOT_BLOCK"), // the crop - BEETROOT_SEEDS(), - BEETROOT_SOUP(), - BELL(), - BIRCH_BOAT("BOAT_BIRCH"), - BIRCH_BUTTON(), - BIRCH_DOOR("BIRCH_DOOR_ITEM"), - BIRCH_FENCE(), - BIRCH_FENCE_GATE(), - BIRCH_LEAVES("LEAVES", (byte) 2), - BIRCH_LOG("LOG", (byte) 2), - BIRCH_PLANKS("WOOD", (byte) 2), - BIRCH_PRESSURE_PLATE(), - BIRCH_SAPLING("SAPLING", (byte) 2), - BIRCH_SIGN(), - BIRCH_SLAB("WOOD_STEP", (byte) 2), - BIRCH_STAIRS(), - BIRCH_TRAPDOOR(), - BIRCH_WALL_SIGN(), - BIRCH_WOOD("LOG", (byte) 14), - BLACK_BANNER("BANNER", (byte) 0), - BLACK_BED("BED", (byte) 15), - BLACK_CARPET("CARPET", (byte) 15), - BLACK_CONCRETE("CONCRETE", (byte) 15), - BLACK_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 15), - BLACK_DYE(), - BLACK_GLAZED_TERRACOTTA(), - BLACK_SHULKER_BOX(), - BLACK_STAINED_GLASS("STAINED_GLASS", (byte) 15), - BLACK_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 15), - BLACK_TERRACOTTA("STAINED_CLAY", (byte) 15), - BLACK_WALL_BANNER("WALL_BANNER", (byte) 0), - BLACK_WOOL("WOOL", (byte) 15), - BLAST_FURNACE, - BLAZE_POWDER, - BLAZE_ROD, - BLAZE_SPAWN_EGG("MONSTER_EGG", (byte) 61), - BLUE_BANNER("BANNER", (byte) 4), - BLUE_BED("BED", (byte) 11), - BLUE_CARPET("CARPET", (byte) 11), - BLUE_CONCRETE("CONCRETE", (byte) 11), - BLUE_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 11), - BLUE_DYE(), - BLUE_GLAZED_TERRACOTTA(), - BLUE_ICE, - BLUE_ORCHID("RED_ROSE", (byte) 1), - BLUE_SHULKER_BOX(), - BLUE_STAINED_GLASS("STAINED_GLASS", (byte) 11), - BLUE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 11), - BLUE_TERRACOTTA("STAINED_CLAY", (byte) 11), - BLUE_WALL_BANNER("WALL_BANNER", (byte) 4), - BLUE_WOOL("WOOL", (byte) 11), - BONE, - BONE_BLOCK, - BONE_MEAL("INK_SACK", (byte) 15), - BOOK, - BOOKSHELF, - BOW, - BOWL, - BRAIN_CORAL, - BRAIN_CORAL_BLOCK, - BRAIN_CORAL_FAN, - BRAIN_CORAL_WALL_FAN, - BREAD, - BREWING_STAND("BREWING_STAND_ITEM"), - /** - * minecraft:brick (item) - */ - BRICK("CLAY_BRICK"), - /** - * minecraft:brick_block (block) - */ - BRICKS("BRICK"), - BRICK_SLAB("STEP", (byte) 4), - BRICK_STAIRS, - BRICK_WALL, - BROWN_BANNER("BANNER", (byte) 3), - BROWN_BED("BED", (byte) 12), - BROWN_CARPET("CARPET", (byte) 12), - BROWN_CONCRETE("CONCRETE", (byte) 12), - BROWN_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 12), - BROWN_DYE(), - BROWN_GLAZED_TERRACOTTA(), - BROWN_MUSHROOM, - BROWN_MUSHROOM_BLOCK("HUGE_MUSHROOM_1"), - BROWN_SHULKER_BOX(), - BROWN_STAINED_GLASS("STAINED_GLASS", (byte) 12), - BROWN_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 12), - BROWN_TERRACOTTA("STAINED_CLAY", (byte) 12), - BROWN_WALL_BANNER("WALL_BANNER", (byte) 3), - BROWN_WOOL("WOOL", (byte) 12), - BUBBLE_COLUMN, - BUBBLE_CORAL, - BUBBLE_CORAL_BLOCK, - BUBBLE_CORAL_FAN, - BUBBLE_CORAL_WALL_FAN, - BUCKET, - CACTUS, - CAKE, - CAMPFIRE, - CARROT("CARROT_ITEM"), - CARROTS("CARROT"), // totally makes sense, lol - CARROT_ON_A_STICK("CARROT_STICK"), - CARTOGRAPHY_TABLE, - CARVED_PUMPKIN("JACK_O_LANTERN"), - CAT_SPAWN_EGG(), - CAULDRON("CAULDRON_ITEM"), - CAVE_AIR(), - CAVE_SPIDER_SPAWN_EGG("MONSTER_EGG", (byte) 59), - CHAINMAIL_BOOTS, - CHAINMAIL_CHESTPLATE, - CHAINMAIL_HELMET, - CHAINMAIL_LEGGINGS, - CHAIN_COMMAND_BLOCK("COMMAND_CHAIN"), - CHARCOAL("COAL", (byte) 1), - CHEST, - CHEST_MINECART("STORAGE_MINECART"), - CHICKEN("RAW_CHICKEN"), - CHICKEN_SPAWN_EGG("MONSTER_EGG", (byte) 93), - CHIPPED_ANVIL("ANVIL", (byte) 1), - CHISELED_QUARTZ_BLOCK("QUARTZ_BLOCK", (byte) 1), - CHISELED_RED_SANDSTONE("RED_SANDSTONE", (byte) 1), - CHISELED_SANDSTONE("SANDSTONE", (byte) 1), - CHISELED_STONE_BRICKS("SMOOTH_BRICK", (byte) 3), - CHORUS_FLOWER, - CHORUS_FRUIT, - CHORUS_PLANT, - CLAY, - CLAY_BALL, - CLOCK("WATCH"), - COAL, - COAL_BLOCK, - COAL_ORE, - COARSE_DIRT("DIRT", (byte) 1), - COBBLESTONE, - COBBLESTONE_SLAB("STEP", (byte) 3), - COBBLESTONE_STAIRS, - COBBLESTONE_WALL("COBBLE_WALL"), - COBWEB("WEB"), - COCOA, - COCOA_BEANS("INK_SACK", (byte) 3), - COD("RAW_FISH", (byte) 0), - COD_BUCKET, - COD_SPAWN_EGG(), - COMMAND_BLOCK("COMMAND"), - COMMAND_BLOCK_MINECART("COMMAND_MINECART"), - COMPARATOR("REDSTONE_COMPARATOR"), - COMPASS, - COMPOSTER, - CONDUIT, - COOKED_BEEF, - COOKED_CHICKEN, - COOKED_COD("COOKED_FISH", (byte) 0), - COOKED_MUTTON, - COOKED_PORKCHOP("GRILLED_PORK"), - COOKED_RABBIT, - COOKED_SALMON("COOKED_FISH", (byte) 1), - COOKIE, - CORNFLOWER, - COW_SPAWN_EGG("MONSTER_EGG", (byte) 92), - CRACKED_STONE_BRICKS("SMOOTH_BRICK", (byte) 2), - CRAFTING_TABLE("WORKBENCH"), - CREEPER_BANNER_PATTERN, - CREEPER_HEAD("SKULL_ITEM", (byte) 4), - CREEPER_SPAWN_EGG("MONSTER_EGG", (byte) 50), - CREEPER_WALL_HEAD("SKULL", (byte) 4), - CROSSBOW, - CUT_RED_SANDSTONE, - CUT_RED_SANDSTONE_SLAB(), - CUT_SANDSTONE, - CUT_SANDSTONE_SLAB(), - CYAN_BANNER("BANNER", (byte) 6), - CYAN_BED("BED", (byte) 9), - CYAN_CARPET("CARPET", (byte) 9), - CYAN_CONCRETE("CONCRETE", (byte) 9), - CYAN_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 9), - CYAN_DYE("INK_SACK", (byte) 6), - CYAN_GLAZED_TERRACOTTA(), - CYAN_SHULKER_BOX(), - CYAN_STAINED_GLASS("STAINED_GLASS", (byte) 9), - CYAN_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 9), - CYAN_TERRACOTTA("STAINED_CLAY", (byte) 9), - CYAN_WALL_BANNER("WALL_BANNER", (byte) 6), - CYAN_WOOL("WOOL", (byte) 9), - DAMAGED_ANVIL("ANVIL", (byte) 2), - DANDELION("YELLOW_FLOWER"), - DARK_OAK_BOAT("BOAT_DARK_OAK"), - DARK_OAK_BUTTON(), - DARK_OAK_DOOR("DARK_OAK_DOOR_ITEM"), - DARK_OAK_FENCE(), - DARK_OAK_FENCE_GATE(), - DARK_OAK_LEAVES("LEAVES_2", (byte) 1), - DARK_OAK_LOG("LOG_2", (byte) 1), - DARK_OAK_PLANKS("WOOD", (byte) 5), - DARK_OAK_PRESSURE_PLATE(), - DARK_OAK_SAPLING("SAPLING", (byte) 5), - DARK_OAK_SIGN(), - DARK_OAK_SLAB("WOOD_STEP", (byte) 5), - DARK_OAK_STAIRS, - DARK_OAK_TRAPDOOR(), - DARK_OAK_WALL_SIGN(), - DARK_OAK_WOOD("LOG_2", (byte) 13), - DARK_PRISMARINE("PRISMARINE", (byte) 2), - DARK_PRISMARINE_SLAB(), - DARK_PRISMARINE_STAIRS, - DAYLIGHT_DETECTOR, - DEAD_BRAIN_CORAL, - DEAD_BRAIN_CORAL_BLOCK, - DEAD_BRAIN_CORAL_FAN, - DEAD_BRAIN_CORAL_WALL_FAN, - DEAD_BUBBLE_CORAL, - DEAD_BUBBLE_CORAL_BLOCK, - DEAD_BUBBLE_CORAL_FAN, - DEAD_BUBBLE_CORAL_WALL_FAN, - DEAD_BUSH("LONG_GRASS", (byte) 0), - DEAD_FIRE_CORAL, - DEAD_FIRE_CORAL_BLOCK, - DEAD_FIRE_CORAL_FAN, - DEAD_FIRE_CORAL_WALL_FAN, - DEAD_HORN_CORAL, - DEAD_HORN_CORAL_BLOCK, - DEAD_HORN_CORAL_FAN, - DEAD_HORN_CORAL_WALL_FAN, - DEAD_TUBE_CORAL, - DEAD_TUBE_CORAL_BLOCK, - DEAD_TUBE_CORAL_FAN, - DEAD_TUBE_CORAL_WALL_FAN, - DEBUG_STICK, - DETECTOR_RAIL, - DIAMOND, - DIAMOND_AXE, - DIAMOND_BLOCK, - DIAMOND_BOOTS, - DIAMOND_CHESTPLATE, - DIAMOND_HELMET, - DIAMOND_HOE, - DIAMOND_HORSE_ARMOR("DIAMOND_BARDING"), - DIAMOND_LEGGINGS, - DIAMOND_ORE, - DIAMOND_PICKAXE, - DIAMOND_SHOVEL("DIAMOND_SPADE"), - DIAMOND_SWORD, - DIORITE("STONE", (byte) 3), - DIORITE_SLAB(), - DIORITE_STAIRS, - DIORITE_WALL, - DIRT("DIRT", (byte) 0), - DISPENSER, - DOLPHIN_SPAWN_EGG(), - DONKEY_SPAWN_EGG(), - DRAGON_BREATH, - DRAGON_EGG, - DRAGON_HEAD("SKULL_ITEM", (byte) 5), - DRAGON_WALL_HEAD("SKULL", (byte) 5), - DRIED_KELP(), - DRIED_KELP_BLOCK(), - DROPPER, - DROWNED_SPAWN_EGG(), - EGG, - ELDER_GUARDIAN_SPAWN_EGG("MONSTER_EGG", (byte) 4), - ELYTRA, - EMERALD, - EMERALD_BLOCK, - EMERALD_ORE, - ENCHANTED_BOOK, - ENCHANTED_GOLDEN_APPLE("GOLDEN_APPLE", (byte) 1), - ENCHANTING_TABLE("ENCHANTMENT_TABLE"), - ENDERMAN_SPAWN_EGG("MONSTER_EGG", (byte) 58), - ENDERMITE_SPAWN_EGG("MONSTER_EGG", (byte) 67), - ENDER_CHEST, - ENDER_EYE("EYE_OF_ENDER"), - ENDER_PEARL, - END_CRYSTAL, - END_GATEWAY, - END_PORTAL("ENDER_PORTAL"), - END_PORTAL_FRAME("ENDER_PORTAL_FRAME"), - END_ROD, - END_STONE("ENDER_STONE"), - END_STONE_BRICKS("END_BRICKS"), - END_STONE_BRICK_SLAB(), - END_STONE_BRICK_STAIRS, - END_STONE_BRICK_WALL, - EVOKER_SPAWN_EGG("MONSTER_EGG", (byte) 34), - EXPERIENCE_BOTTLE("EXP_BOTTLE"), - FARMLAND("SOIL"), - FEATHER, - FERMENTED_SPIDER_EYE, - FERN("LONG_GRASS", (byte) 2), - FILLED_MAP, - FIRE, - FIREWORK_ROCKET("FIREWORK"), - FIREWORK_STAR("FIREWORK_CHARGE"), - FIRE_CHARGE("FIREBALL"), - FIRE_CORAL, - FIRE_CORAL_BLOCK, - FIRE_CORAL_FAN, - FIRE_CORAL_WALL_FAN, - FISHING_ROD, - FLETCHING_TABLE, - FLINT, - FLINT_AND_STEEL, - FLOWER_BANNER_PATTERN, - FLOWER_POT("FLOWER_POT_ITEM"), - FOX_SPAWN_EGG(), - FROSTED_ICE, - FURNACE, - FURNACE_MINECART("POWERED_MINECART"), - GHAST_SPAWN_EGG("MONSTER_EGG", (byte) 56), - GHAST_TEAR, - GLASS, - GLASS_BOTTLE, - GLASS_PANE("THIN_GLASS"), - GLISTERING_MELON_SLICE("SPECKLED_MELON"), - GLOBE_BANNER_PATTERN, - GLOWSTONE, - GLOWSTONE_DUST, - GOLDEN_APPLE, - GOLDEN_AXE("GOLD_AXE"), - GOLDEN_BOOTS("GOLD_BOOTS"), - GOLDEN_CARROT, - GOLDEN_CHESTPLATE("GOLD_CHESTPLATE"), - GOLDEN_HELMET("GOLD_HELMET"), - GOLDEN_HOE("GOLD_HOE"), - GOLDEN_HORSE_ARMOR("GOLD_BARDING"), - GOLDEN_LEGGINGS("GOLD_LEGGINGS"), - GOLDEN_PICKAXE("GOLD_PICKAXE"), - GOLDEN_SHOVEL("GOLD_SPADE"), - GOLDEN_SWORD("GOLD_SWORD"), - GOLD_BLOCK, - GOLD_INGOT, - GOLD_NUGGET, - GOLD_ORE, - GRANITE("STONE", (byte) 1), - GRANITE_SLAB(), - GRANITE_STAIRS, - GRANITE_WALL, - GRASS("LONG_GRASS", (byte) 1), - GRASS_BLOCK("GRASS"), - DIRT_PATH("GRASS_PATH"), - GRAVEL, - GRAY_BANNER("BANNER", (byte) 8), - GRAY_BED("BED", (byte) 7), - GRAY_CARPET("CARPET", (byte) 7), - GRAY_CONCRETE("CONCRETE", (byte) 7), - GRAY_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 7), - GRAY_DYE("INK_SACK", (byte) 8), - GRAY_GLAZED_TERRACOTTA(), - GRAY_SHULKER_BOX(), - GRAY_STAINED_GLASS("STAINED_GLASS", (byte) 7), - GRAY_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 7), - GRAY_TERRACOTTA("STAINED_CLAY", (byte) 7), - GRAY_WALL_BANNER("WALL_BANNER", (byte) 8), - GRAY_WOOL("WOOL", (byte) 7), - GREEN_BANNER("BANNER", (byte) 2), - GREEN_BED("BED", (byte) 13), - GREEN_CARPET("CARPET", (byte) 13), - GREEN_CONCRETE(ServerVersion.V1_13, "CONCRETE", (byte) 13), - GREEN_CONCRETE_POWDER(ServerVersion.V1_13, "CONCRETE_POWDER", (byte) 13), - GREEN_DYE(ServerVersion.V1_14, "CACTUS_GREEN", ServerVersion.V1_13, "INK_SACK", (byte) 2), - GREEN_GLAZED_TERRACOTTA(), - GREEN_SHULKER_BOX(), - GREEN_STAINED_GLASS("STAINED_GLASS", (byte) 13), - GREEN_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 13), - GREEN_TERRACOTTA("STAINED_CLAY", (byte) 13), - GREEN_WALL_BANNER(ServerVersion.V1_13, "WALL_BANNER", (byte) 2), - GREEN_WOOL("WOOL", (byte) 13), - GRINDSTONE, - GUARDIAN_SPAWN_EGG("MONSTER_EGG", (byte) 68), - GUNPOWDER("SULPHUR"), - HAY_BLOCK, - HEART_OF_THE_SEA, - HEAVY_WEIGHTED_PRESSURE_PLATE("IRON_PLATE"), - HOPPER, - HOPPER_MINECART("HOPPER_MINECART"), - HORN_CORAL, - HORN_CORAL_BLOCK, - HORN_CORAL_FAN, - HORN_CORAL_WALL_FAN, - HORSE_SPAWN_EGG("MONSTER_EGG", (byte) 100), - HUSK_SPAWN_EGG("MONSTER_EGG", (byte) 23), - ICE, - INFESTED_CHISELED_STONE_BRICKS("MONSTER_EGGS", (byte) 5), - INFESTED_COBBLESTONE("MONSTER_EGGS", (byte) 1), - INFESTED_CRACKED_STONE_BRICKS("MONSTER_EGGS", (byte) 4), - INFESTED_MOSSY_STONE_BRICKS("MONSTER_EGGS", (byte) 3), - INFESTED_STONE("MONSTER_EGGS", (byte) 0), - INFESTED_STONE_BRICKS("MONSTER_EGGS", (byte) 2), - INK_SAC("INK_SACK", (byte) 0), - IRON_AXE, - IRON_BARS("IRON_FENCE"), - IRON_BLOCK, - IRON_BOOTS, - IRON_CHESTPLATE, - IRON_DOOR, - IRON_HELMET, - IRON_HOE, - IRON_HORSE_ARMOR("IRON_BARDING"), - IRON_INGOT, - IRON_LEGGINGS, - IRON_NUGGET, - IRON_ORE, - IRON_PICKAXE, - IRON_SHOVEL("IRON_SPADE"), - IRON_SWORD, - IRON_TRAPDOOR(), - ITEM_FRAME, - JACK_O_LANTERN, - JIGSAW, - JUKEBOX, - JUNGLE_BOAT("BOAT_JUNGLE"), - JUNGLE_BUTTON(), - JUNGLE_DOOR("JUNGLE_DOOR_ITEM"), - JUNGLE_FENCE(), - JUNGLE_FENCE_GATE(), - JUNGLE_LEAVES("LEAVES", (byte) 3), - JUNGLE_LOG("LOG", (byte) 3), - JUNGLE_PLANKS("WOOD", (byte) 3), - JUNGLE_PRESSURE_PLATE(), - JUNGLE_SAPLING("SAPLING", (byte) 3), - JUNGLE_SIGN(), - JUNGLE_SLAB("WOOD_STEP", (byte) 3), - JUNGLE_STAIRS("JUNGLE_WOOD_STAIRS"), - JUNGLE_TRAPDOOR(), - JUNGLE_WALL_SIGN(), - JUNGLE_WOOD("LOG", (byte) 15), - KELP, - KELP_PLANT, - KNOWLEDGE_BOOK, - LADDER, - LANTERN, - LAPIS_BLOCK, - LAPIS_LAZULI("INK_SACK", (byte) 4), - LAPIS_ORE, - LARGE_FERN("DOUBLE_PLANT", (byte) 3), - LAVA, - LAVA_BUCKET, - LEAD("LEASH"), - LEATHER, - LEATHER_BOOTS, - LEATHER_CHESTPLATE, - LEATHER_HELMET, - LEATHER_HORSE_ARMOR(), - LEATHER_LEGGINGS, - LECTERN, - LEVER, - LIGHT_BLUE_BANNER("BANNER", (byte) 12), - LIGHT_BLUE_BED("BED", (byte) 3), - LIGHT_BLUE_CARPET("CARPET", (byte) 3), - LIGHT_BLUE_CONCRETE("CONCRETE", (byte) 3), - LIGHT_BLUE_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 3), - LIGHT_BLUE_DYE("INK_SACK", (byte) 12), - LIGHT_BLUE_GLAZED_TERRACOTTA(), - LIGHT_BLUE_SHULKER_BOX(), - LIGHT_BLUE_STAINED_GLASS("STAINED_GLASS", (byte) 3), - LIGHT_BLUE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 3), - LIGHT_BLUE_TERRACOTTA("STAINED_CLAY", (byte) 3), - LIGHT_BLUE_WALL_BANNER("WALL_BANNER", (byte) 12), - LIGHT_BLUE_WOOL("WOOL", (byte) 3), - LIGHT_GRAY_BANNER("BANNER", (byte) 7), - LIGHT_GRAY_BED("BED", (byte) 8), - LIGHT_GRAY_CARPET("CARPET", (byte) 8), - LIGHT_GRAY_CONCRETE("CONCRETE", (byte) 8), - LIGHT_GRAY_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 8), - LIGHT_GRAY_DYE("INK_SACK", (byte) 7), - LIGHT_GRAY_GLAZED_TERRACOTTA("SILVER_GLAZED_TERRACOTTA"), - LIGHT_GRAY_SHULKER_BOX(ServerVersion.V1_11, "SILVER_SHULKER_BOX"), - LIGHT_GRAY_STAINED_GLASS("STAINED_GLASS", (byte) 8), - LIGHT_GRAY_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 8), // this is nearly invisible in a chest, lol - LIGHT_GRAY_TERRACOTTA("STAINED_CLAY", (byte) 8), - LIGHT_GRAY_WALL_BANNER("WALL_BANNER", (byte) 7), - LIGHT_GRAY_WOOL("WOOL", (byte) 8), - LIGHT_WEIGHTED_PRESSURE_PLATE("GOLD_PLATE"), - LILAC("LONG_GRASS", (byte) 1), - LILY_OF_THE_VALLEY, - LILY_PAD("WATER_LILY"), - LIME_BANNER("BANNER", (byte) 10), - LIME_BED("BED", (byte) 5), - LIME_CARPET("CARPET", (byte) 5), - LIME_CONCRETE("CONCRETE", (byte) 5), - LIME_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 5), - LIME_DYE("INK_SACK", (byte) 10), - LIME_GLAZED_TERRACOTTA(), - LIME_SHULKER_BOX(), - LIME_STAINED_GLASS("STAINED_GLASS", (byte) 5), - LIME_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 5), - LIME_TERRACOTTA("STAINED_CLAY", (byte) 5), - LIME_WALL_BANNER("WALL_BANNER", (byte) 10), - LIME_WOOL("WOOL", (byte) 5), - LINGERING_POTION, - LLAMA_SPAWN_EGG("MONSTER_EGG", (byte) 103), - LOOM, - MAGENTA_BANNER("BANNER", (byte) 13), - MAGENTA_BED("BED", (byte) 2), - MAGENTA_CARPET("CARPET", (byte) 2), - MAGENTA_CONCRETE("CONCRETE", (byte) 2), - MAGENTA_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 2), - MAGENTA_DYE("INK_SACK", (byte) 13), - MAGENTA_GLAZED_TERRACOTTA(), - MAGENTA_SHULKER_BOX(), - MAGENTA_STAINED_GLASS("STAINED_GLASS", (byte) 2), - MAGENTA_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 2), - MAGENTA_TERRACOTTA("STAINED_CLAY", (byte) 2), - MAGENTA_WALL_BANNER("WALL_BANNER", (byte) 13), - MAGENTA_WOOL("WOOL", (byte) 2), - MAGMA_BLOCK("MAGMA"), - MAGMA_CREAM, - MAGMA_CUBE_SPAWN_EGG("MONSTER_EGG", (byte) 62), - MAP, - MELON("MELON_BLOCK"), - MELON_SEEDS, - MELON_SLICE("MELON"), - MELON_STEM, - MILK_BUCKET, - MINECART, - MOJANG_BANNER_PATTERN, - MOOSHROOM_SPAWN_EGG("MONSTER_EGG", (byte) 96), - MOSSY_COBBLESTONE, - MOSSY_COBBLESTONE_SLAB(), - MOSSY_COBBLESTONE_STAIRS, - MOSSY_COBBLESTONE_WALL, - MOSSY_STONE_BRICKS("SMOOTH_BRICK", (byte) 1), - MOSSY_STONE_BRICK_SLAB(), - MOSSY_STONE_BRICK_STAIRS, - MOSSY_STONE_BRICK_WALL, - MOVING_PISTON("PISTON_MOVING_PIECE"), - MULE_SPAWN_EGG("MONSTER_EGG", (byte) 32), - MUSHROOM_STEM("HUGE_MUSHROOM_1", (byte) 10), // also ("HUGE_MUSHROOM_2", (byte) 10) - MUSHROOM_STEW("MUSHROOM_SOUP"), - MUSIC_DISC_11("RECORD_11"), - MUSIC_DISC_13("GOLD_RECORD"), - MUSIC_DISC_BLOCKS("RECORD_3"), - MUSIC_DISC_CAT("GREEN_RECORD"), - MUSIC_DISC_CHIRP("RECORD_4"), - MUSIC_DISC_FAR("RECORD_5"), - MUSIC_DISC_MALL("RECORD_6"), - MUSIC_DISC_MELLOHI("RECORD_7"), - MUSIC_DISC_STAL("RECORD_8"), - MUSIC_DISC_STRAD("RECORD_9"), - MUSIC_DISC_WAIT("RECORD_12"), - MUSIC_DISC_WARD("RECORD_10"), - MUTTON, - MYCELIUM("MYCEL"), - NAME_TAG, - NAUTILUS_SHELL, - NETHERRACK, - NETHER_BRICK("NETHER_BRICK_ITEM"), - NETHER_BRICKS("NETHER_BRICK"), - NETHER_BRICK_FENCE("NETHER_FENCE"), - NETHER_BRICK_SLAB("STEP", (byte) 6), - NETHER_BRICK_STAIRS, - NETHER_BRICK_WALL, - NETHER_PORTAL("PORTAL"), - NETHER_QUARTZ_ORE("QUARTZ_ORE"), - NETHER_STAR, - NETHER_WART("NETHER_STALK"), - NETHER_WART_BLOCK, - NOTE_BLOCK, - OAK_BOAT("BOAT"), - OAK_BUTTON("WOOD_BUTTON"), - OAK_DOOR("WOOD_DOOR"), // TODO: legacy block id is WOODEN_DOOR - OAK_FENCE("FENCE"), - OAK_FENCE_GATE("FENCE_GATE"), - OAK_LEAVES("LEAVES", (byte) 0), - OAK_LOG("LOG", (byte) 0), - OAK_PLANKS("WOOD", (byte) 0), - OAK_PRESSURE_PLATE("WOOD_PLATE"), - OAK_SAPLING("SAPLING", (byte) 0), - OAK_SIGN(ServerVersion.V1_14, "SIGN"), - OAK_SLAB("WOOD_STEP", (byte) 0), - OAK_STAIRS("WOOD_STAIRS"), - OAK_TRAPDOOR("TRAP_DOOR"), - OAK_WALL_SIGN(ServerVersion.V1_14, "WALL_SIGN"), - OAK_WOOD("LOG", (byte) 12), - OBSERVER, - OBSIDIAN, - OCELOT_SPAWN_EGG("MONSTER_EGG", (byte) 98), - ORANGE_BANNER("BANNER", (byte) 14), - ORANGE_BED("BED", (byte) 1), - ORANGE_CARPET("CARPET", (byte) 1), - ORANGE_CONCRETE("CONCRETE", (byte) 1), - ORANGE_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 1), - ORANGE_DYE("INK_SACK", (byte) 14), - ORANGE_GLAZED_TERRACOTTA(), - ORANGE_SHULKER_BOX(), - ORANGE_STAINED_GLASS("STAINED_GLASS", (byte) 1), - ORANGE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 1), - ORANGE_TERRACOTTA("STAINED_CLAY", (byte) 1), - ORANGE_TULIP("RED_ROSE", (byte) 5), - ORANGE_WALL_BANNER("WALL_BANNER", (byte) 14), - ORANGE_WOOL("WOOL", (byte) 1), - OXEYE_DAISY("RED_ROSE", (byte) 8), - PACKED_ICE, - PAINTING, - PANDA_SPAWN_EGG(), - PAPER, - PARROT_SPAWN_EGG("MONSTER_EGG", (byte) 105), - PEONY("DOUBLE_PLANT", (byte) 5), - PETRIFIED_OAK_SLAB("WOOD_STEP", (byte) 0), - PHANTOM_MEMBRANE(), - PHANTOM_SPAWN_EGG(), - PIG_SPAWN_EGG("MONSTER_EGG", (byte) 90), - PILLAGER_SPAWN_EGG(), - PINK_BANNER("BANNER", (byte) 9), - PINK_BED("BED", (byte) 6), - PINK_CARPET("CARPET", (byte) 6), - PINK_CONCRETE("CONCRETE", (byte) 6), - PINK_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 6), - PINK_DYE("INK_SACK", (byte) 9), - PINK_GLAZED_TERRACOTTA(), - PINK_SHULKER_BOX(), - PINK_STAINED_GLASS("STAINED_GLASS", (byte) 6), - PINK_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 6), - PINK_TERRACOTTA("STAINED_CLAY", (byte) 6), - PINK_TULIP("RED_ROSE", (byte) 7), - PINK_WALL_BANNER("WALL_BANNER", (byte) 9), - PINK_WOOL("WOOL", (byte) 6), - PISTON("PISTON_BASE"), - PISTON_HEAD("PISTON_EXTENSION"), - PLAYER_HEAD("SKULL_ITEM", (byte) 3), - PLAYER_WALL_HEAD("SKULL", (byte) 3), - PODZOL("DIRT", (byte) 2), - POISONOUS_POTATO, - POLAR_BEAR_SPAWN_EGG("MONSTER_EGG", (byte) 102), - POLISHED_ANDESITE("STONE", (byte) 6), - POLISHED_ANDESITE_SLAB(), - POLISHED_ANDESITE_STAIRS, - POLISHED_DIORITE("STONE", (byte) 4), - POLISHED_DIORITE_SLAB(), - POLISHED_DIORITE_STAIRS, - POLISHED_GRANITE("STONE", (byte) 2), - POLISHED_GRANITE_SLAB(), - POLISHED_GRANITE_STAIRS, - POPPED_CHORUS_FRUIT, - POPPY("RED_ROSE", (byte) 0), - PORKCHOP("PORK"), - POTATO("POTATO_ITEM"), - POTATOES("POTATO"), - POTION, - POTTED_ACACIA_SAPLING, - POTTED_ALLIUM, - POTTED_AZURE_BLUET, - POTTED_BAMBOO, - POTTED_BIRCH_SAPLING, - POTTED_BLUE_ORCHID, - POTTED_BROWN_MUSHROOM, - POTTED_CACTUS, - POTTED_CORNFLOWER, - POTTED_DANDELION, - POTTED_DARK_OAK_SAPLING, - POTTED_DEAD_BUSH, - POTTED_FERN, - POTTED_JUNGLE_SAPLING, - POTTED_LILY_OF_THE_VALLEY, - POTTED_OAK_SAPLING, - POTTED_ORANGE_TULIP, - POTTED_OXEYE_DAISY, - POTTED_PINK_TULIP, - POTTED_POPPY, - POTTED_RED_MUSHROOM, - POTTED_RED_TULIP, - POTTED_SPRUCE_SAPLING, - POTTED_WHITE_TULIP, - POTTED_WITHER_ROSE, - POWERED_RAIL, - PRISMARINE("PRISMARINE", (byte) 0), - PRISMARINE_BRICKS("PRISMARINE", (byte) 1), - PRISMARINE_BRICK_SLAB(), - PRISMARINE_BRICK_STAIRS, - PRISMARINE_CRYSTALS, - PRISMARINE_SHARD, - PRISMARINE_SLAB(), - PRISMARINE_STAIRS, - PRISMARINE_WALL, - PUFFERFISH("RAW_FISH", (byte) 3), - PUFFERFISH_BUCKET, - PUFFERFISH_SPAWN_EGG(), - PUMPKIN, - PUMPKIN_PIE, - PUMPKIN_SEEDS, - PUMPKIN_STEM, - PURPLE_BANNER("BANNER", (byte) 5), - PURPLE_BED("BED", (byte) 10), - PURPLE_CARPET("CARPET", (byte) 10), - PURPLE_CONCRETE("CONCRETE", (byte) 10), - PURPLE_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 10), - PURPLE_DYE("INK_SACK", (byte) 5), - PURPLE_GLAZED_TERRACOTTA(), - PURPLE_SHULKER_BOX(), - PURPLE_STAINED_GLASS("STAINED_GLASS", (byte) 10), - PURPLE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 10), - PURPLE_TERRACOTTA("STAINED_CLAY", (byte) 10), - PURPLE_WALL_BANNER("WALL_BANNER", (byte) 5), - PURPLE_WOOL("WOOL", (byte) 10), - PURPUR_BLOCK, - PURPUR_PILLAR, - PURPUR_SLAB(), - PURPUR_STAIRS, - QUARTZ, - QUARTZ_BLOCK("QUARTZ_BLOCK", (byte) 0), - QUARTZ_PILLAR("QUARTZ_BLOCK", (byte) 2), - QUARTZ_SLAB("STEP", (byte) 7), - QUARTZ_STAIRS, - RABBIT, - RABBIT_FOOT, - RABBIT_HIDE, - RABBIT_SPAWN_EGG("MONSTER_EGG", (byte) 101), - RABBIT_STEW, - RAIL("RAILS"), - RAVAGER_SPAWN_EGG(), - REDSTONE, - REDSTONE_BLOCK, - REDSTONE_LAMP("REDSTONE_LAMP_OFF"), - REDSTONE_ORE, - REDSTONE_TORCH("REDSTONE_TORCH_ON"), - REDSTONE_WALL_TORCH, - REDSTONE_WIRE, - RED_BANNER("BANNER", (byte) 1), - RED_BED("BED", (byte) 14), - RED_CARPET("CARPET", (byte) 14), - RED_CONCRETE("CONCRETE", (byte) 14), - RED_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 14), - RED_DYE(ServerVersion.V1_14, "ROSE_RED", ServerVersion.V1_13, "INK_SACK", (byte) 1), - RED_GLAZED_TERRACOTTA(), - RED_MUSHROOM, - RED_MUSHROOM_BLOCK("HUGE_MUSHROOM_2"), - RED_NETHER_BRICKS("RED_NETHER_BRICK"), - RED_NETHER_BRICK_SLAB(), - RED_NETHER_BRICK_STAIRS, - RED_NETHER_BRICK_WALL, - RED_SAND("SAND", (byte) 1), - RED_SANDSTONE("RED_SANDSTONE", (byte) 0), - RED_SANDSTONE_SLAB("STONE_SLAB2", (byte) 0), - RED_SANDSTONE_STAIRS, - RED_SANDSTONE_WALL, - RED_SHULKER_BOX(), - RED_STAINED_GLASS("STAINED_GLASS", (byte) 14), - RED_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 14), - RED_TERRACOTTA("STAINED_CLAY", (byte) 14), - RED_TULIP("RED_ROSE", (byte) 4), - RED_WALL_BANNER("WALL_BANNER", (byte) 1), - RED_WOOL("WOOL", (byte) 14), - REPEATER("DIODE"), - REPEATING_COMMAND_BLOCK("COMMAND_REPEATING"), - ROSE_BUSH("DOUBLE_PLANT", (byte) 4), - ROTTEN_FLESH, - SADDLE, - SALMON("RAW_FISH", (byte) 1), - SALMON_BUCKET, - SALMON_SPAWN_EGG(), - SAND("SAND", (byte) 0), - SANDSTONE("SANDSTONE", (byte) 0), - SANDSTONE_SLAB("STEP", (byte) 1), - SANDSTONE_STAIRS, - SANDSTONE_WALL, - SCAFFOLDING, - SCUTE, - SEAGRASS, - SEA_LANTERN, - SEA_PICKLE, - SHEARS, - SHEEP_SPAWN_EGG("MONSTER_EGG", (byte) 91), - SHIELD, - SHULKER_BOX(), - SHULKER_SHELL(), - SHULKER_SPAWN_EGG("MONSTER_EGG", (byte) 69), - SILVERFISH_SPAWN_EGG("MONSTER_EGG", (byte) 60), - SKELETON_HORSE_SPAWN_EGG("MONSTER_EGG", (byte) 28), - SKELETON_SKULL("SKULL_ITEM", (byte) 0), - SKELETON_SPAWN_EGG("MONSTER_EGG", (byte) 51), - SKELETON_WALL_SKULL("SKULL", (byte) 0), - SKULL_BANNER_PATTERN, - SLIME_BALL, - SLIME_BLOCK, - SLIME_SPAWN_EGG("MONSTER_EGG", (byte) 55), - SMITHING_TABLE, - SMOKER, - SMOOTH_QUARTZ, - SMOOTH_QUARTZ_SLAB(), - SMOOTH_QUARTZ_STAIRS, - SMOOTH_RED_SANDSTONE("RED_SANDSTONE", (byte) 2), - SMOOTH_RED_SANDSTONE_SLAB("STONE_SLAB2", (byte) 0), - SMOOTH_RED_SANDSTONE_STAIRS, - SMOOTH_SANDSTONE("SANDSTONE", (byte) 2), - SMOOTH_SANDSTONE_SLAB(), - SMOOTH_SANDSTONE_STAIRS, - SMOOTH_STONE, - SMOOTH_STONE_SLAB(), - SNOW, - SNOWBALL("SNOW_BALL"), - SNOW_BLOCK, - SOUL_SAND, - SPAWNER("MOB_SPAWNER"), - SPECTRAL_ARROW, - SPIDER_EYE, - SPIDER_SPAWN_EGG("MONSTER_EGG", (byte) 52), - SPLASH_POTION("POTION"), // legacy uses data to make the specific potions and splash variants - SPONGE("SPONGE", (byte) 0), - SPRUCE_BOAT("BOAT_SPRUCE"), - SPRUCE_BUTTON(), - SPRUCE_DOOR("SPRUCE_DOOR_ITEM"), - SPRUCE_FENCE(), - SPRUCE_FENCE_GATE(), - SPRUCE_LEAVES("LEAVES", (byte) 1), - SPRUCE_LOG("LOG", (byte) 1), - SPRUCE_PLANKS("WOOD", (byte) 1), - SPRUCE_PRESSURE_PLATE(), - SPRUCE_SAPLING("SAPLING", (byte) 1), - SPRUCE_SIGN(), - SPRUCE_SLAB("WOOD_STEP", (byte) 1), - SPRUCE_STAIRS("SPRUCE_WOOD_STAIRS"), - SPRUCE_TRAPDOOR(), - SPRUCE_WALL_SIGN(), - SPRUCE_WOOD("LOG", (byte) 13), - SQUID_SPAWN_EGG("MONSTER_EGG", (byte) 94), - STICK, - STICKY_PISTON("PISTON_STICKY_BASE"), - STONE(), - STONECUTTER, - STONE_AXE, - /** - * minecraft:stonebrick - */ - STONE_BRICKS("SMOOTH_BRICK", (byte) 0), - STONE_BRICK_SLAB("STEP", (byte) 5), - STONE_BRICK_STAIRS("SMOOTH_STAIRS"), - STONE_BRICK_WALL(), - STONE_BUTTON, - STONE_HOE, - STONE_PICKAXE, - STONE_PRESSURE_PLATE("STONE_PLATE"), - STONE_SHOVEL("STONE_SPADE"), - STONE_SLAB("STEP", (byte) 0), - STONE_STAIRS(), - STONE_SWORD, - STRAY_SPAWN_EGG("MONSTER_EGG", (byte) 6), - STRING, - STRIPPED_ACACIA_LOG, - STRIPPED_ACACIA_WOOD, - STRIPPED_BIRCH_LOG, - STRIPPED_BIRCH_WOOD, - STRIPPED_DARK_OAK_LOG, - STRIPPED_DARK_OAK_WOOD, - STRIPPED_JUNGLE_LOG, - STRIPPED_JUNGLE_WOOD, - STRIPPED_OAK_LOG, - STRIPPED_OAK_WOOD, - STRIPPED_SPRUCE_LOG, - STRIPPED_SPRUCE_WOOD, - STRUCTURE_BLOCK, - STRUCTURE_VOID, - SUGAR, - SUGAR_CANE, - SUNFLOWER("DOUBLE_PLANT", (byte) 0), - SUSPICIOUS_STEW, - SWEET_BERRIES, - SWEET_BERRY_BUSH, - TALL_GRASS("DOUBLE_PLANT", (byte) 2), - TALL_SEAGRASS, - TERRACOTTA("HARD_CLAY"), - TIPPED_ARROW, - TNT, - TNT_MINECART("EXPLOSIVE_MINECART"), - TORCH, - TOTEM_OF_UNDYING("TOTEM"), - TRADER_LLAMA_SPAWN_EGG(), - TRAPPED_CHEST, - TRIDENT, - TRIPWIRE, - TRIPWIRE_HOOK, - TROPICAL_FISH("RAW_FISH", (byte) 2), // (aka clownfish) - TROPICAL_FISH_BUCKET, - TROPICAL_FISH_SPAWN_EGG(), - TUBE_CORAL, - TUBE_CORAL_BLOCK, - TUBE_CORAL_FAN, - TUBE_CORAL_WALL_FAN, - TURTLE_EGG, - TURTLE_HELMET, - TURTLE_SPAWN_EGG(), - VEX_SPAWN_EGG("MONSTER_EGG", (byte) 35), - VILLAGER_SPAWN_EGG("MONSTER_EGG", (byte) 120), - VINDICATOR_SPAWN_EGG("MONSTER_EGG", (byte) 36), - VINE, - VOID_AIR, - WALL_TORCH, - WANDERING_TRADER_SPAWN_EGG(), - WATER, - WATER_BUCKET, - WET_SPONGE("SPONGE", (byte) 1), - WHEAT, - WHEAT_SEEDS("SEEDS"), - WHITE_BANNER("BANNER", (byte) 15), - WHITE_BED("BED", (byte) 0), - WHITE_CARPET("CARPET", (byte) 0), - WHITE_CONCRETE("CONCRETE", (byte) 0), - WHITE_CONCRETE_POWDER("CONCRETE", (byte) 0), - WHITE_DYE("INK_SACK", (byte) 15), - WHITE_GLAZED_TERRACOTTA(), - WHITE_SHULKER_BOX(), - WHITE_STAINED_GLASS("STAINED_GLASS", (byte) 0), - WHITE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 0), - WHITE_TERRACOTTA("STAINED_CLAY", (byte) 0), - WHITE_TULIP("RED_ROSE", (byte) 6), - WHITE_WALL_BANNER("WALL_BANNER", (byte) 15), - WHITE_WOOL("WOOL", (byte) 0), - WITCH_SPAWN_EGG("MONSTER_EGG", (byte) 66), - WITHER_ROSE, - WITHER_SKELETON_SKULL("SKULL_ITEM", (byte) 1), - WITHER_SKELETON_SPAWN_EGG("MONSTER_EGG", (byte) 5), - WITHER_SKELETON_WALL_SKULL("SKULL", (byte) 1), - WOLF_SPAWN_EGG("MONSTER_EGG", (byte) 95), - WOODEN_AXE("WOOD_AXE"), - WOODEN_HOE("WOOD_HOE"), - WOODEN_PICKAXE("WOOD_PICKAXE"), - WOODEN_SHOVEL("WOOD_SPADE"), - WOODEN_SWORD("WOOD_SWORD"), - WRITABLE_BOOK("BOOK_AND_QUILL"), - WRITTEN_BOOK, - YELLOW_BANNER("BANNER", (byte) 11), - YELLOW_BED("BED", (byte) 4), - YELLOW_CARPET("CARPET", (byte) 4), - YELLOW_CONCRETE("CONCRETE", (byte) 4), - YELLOW_CONCRETE_POWDER("CONCRETE", (byte) 4), - YELLOW_DYE(ServerVersion.V1_14, "DANDELION_YELLOW", ServerVersion.V1_13, "INK_SACK", (byte) 11), - YELLOW_GLAZED_TERRACOTTA(), - YELLOW_SHULKER_BOX(), - YELLOW_STAINED_GLASS("STAINED_GLASS", (byte) 4), - YELLOW_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 4), - YELLOW_TERRACOTTA("STAINED_CLAY", (byte) 4), - YELLOW_WALL_BANNER("WALL_BANNER", (byte) 11), - YELLOW_WOOL("WOOL", (byte) 4), - ZOMBIE_HEAD("SKULL_ITEM", (byte) 2), - ZOMBIE_HORSE_SPAWN_EGG("MONSTER_EGG", (byte) 29), - ZOMBIE_PIGMAN_SPAWN_EGG("MONSTER_EGG", (byte) 57), - ZOMBIE_SPAWN_EGG("MONSTER_EGG", (byte) 54), - ZOMBIE_VILLAGER_SPAWN_EGG("MONSTER_EGG", (byte) 27), - ZOMBIE_WALL_HEAD("SKULL", (byte) 2), - ; - - private final String modern, modern2, legacy; - private final LegacyMaterialAnalouge compatibleMaterial; - private final LegacyMaterialBlockType legacyBlockMaterial; - private final boolean legacyRequiresData; - // some materials (I'm looking at you, GREEN_DYE) have changed ID more than once - // minVersion is the min for modern, and minVersion2 is min to use legacyCompat1 - private final ServerVersion minVersion, minVersion2; - private final byte legacyData; - private final Material material; - private final Byte data; - // quick test to see if our version is < 1.13 - protected static final boolean useLegacy = ServerVersion.isServerVersionBelow(ServerVersion.V1_13); - // map to speed up name->material lookups - private static final Map lookupMap = new HashMap(); - - static { - for (CompatibleMaterial m : values()) { - if (m.isRecycled()) { - lookupMap.put(m.legacy, m); - continue; - } - lookupMap.put(m.name(), m); - if (!m.usesCompatibility()) { - lookupMap.put(m.material + ":" + (m.data == null ? "" : m.data), m); - } - } - for (CompatibleMaterial m : values()) { - if (!m.usesCompatibility()) { - if (m.legacy != null && !lookupMap.containsKey(m.legacy)) { - lookupMap.put(m.legacy, m); - } - if (m.modern2 != null && !lookupMap.containsKey(m.modern2)) { - lookupMap.put(m.modern2, m); - } - if (m.legacyBlockMaterial != null && !lookupMap.containsKey(m.legacyBlockMaterial.blockMaterialName)) { - lookupMap.put(m.legacyBlockMaterial.blockMaterialName, m); - } - if (m.legacyBlockMaterial != null && !lookupMap.containsKey(m.legacyBlockMaterial.alternateBlockMaterialName)) { - lookupMap.put(m.legacyBlockMaterial.alternateBlockMaterialName, m); - } - } - } - } - - CompatibleMaterial() { - this(ServerVersion.UNKNOWN, null, null); - } - - CompatibleMaterial(String legacy) { - this(ServerVersion.V1_13, null, null, legacy, null); - } - - CompatibleMaterial(String legacy, byte legacyData) { - this(ServerVersion.V1_13, null, null, legacy, legacyData); - } - - CompatibleMaterial(ServerVersion modernMinimum, String legacy) { - this(modernMinimum, null, null, legacy, null); - } - - CompatibleMaterial(ServerVersion modernMinimum, String legacy, Byte legacyData) { - this(modernMinimum, null, null, legacy, legacyData); - } - - CompatibleMaterial(ServerVersion modernMinimum, String modern2, ServerVersion modern2Minimum, String legacyMaterial, Byte legacyData) { - this.modern = name(); - this.modern2 = modern2; - this.minVersion = modernMinimum; - this.minVersion2 = modern2Minimum; - this.legacy = legacyMaterial; - this.legacyData = legacyData == null ? 0 : legacyData; - this.legacyRequiresData = legacyData != null; - this.compatibleMaterial = LegacyMaterialAnalouge.lookupAnalouge(modern); - - if (compatibleMaterial != null && ServerVersion.isServerVersionBelow(compatibleMaterial.versionLessThan)) { - // server older than this item: use a proxy - material = compatibleMaterial.material; - data = compatibleMaterial.data; - } else if (ServerVersion.isServerVersionAtLeast(minVersion)) { - material = Material.getMaterial(modern); - data = null; - } else if (modern2 != null && ServerVersion.isServerVersionAtLeast(minVersion2)) { - material = Material.getMaterial(modern2); - data = null; - } else if (legacyMaterial != null && (compatibleMaterial == null || ServerVersion.isServerVersionAtLeast(compatibleMaterial.versionLessThan))) { - // we're using a server that has the legacy value available - material = Material.getMaterial(legacyMaterial); - data = legacyRequiresData ? this.legacyData : null; - } else if (compatibleMaterial != null) { - // no match: use a proxy - material = compatibleMaterial.material; - data = compatibleMaterial.data; - } else { - material = null; - data = null; - } - - if (material != null && ServerVersion.isServerVersionBelow(ServerVersion.V1_13) && (compatibleMaterial == null || material != compatibleMaterial.material)) { - legacyBlockMaterial = LegacyMaterialBlockType.getMaterial(this.modern); - } else { - legacyBlockMaterial = null; - } - } - - /** - * @return the Bukkit Material for this material - */ - public Material getMaterial() { - return material; - } - - /** - * @return the Bukkit Material required to create a block - */ - public Material getBlockMaterial() { - return legacyBlockMaterial != null ? legacyBlockMaterial.getBlockMaterial() : (isBlock() ? material : AIR.material); - } - - /** - * @return an item that resembles this material for the current server version - */ - public ItemStack getItem() { - return getItem(1); - } - - /** - * @param amount the amount to return - * @return an item that resembles this material for the current server version - */ - public ItemStack getItem(int amount) { - if (usesCompatibility()) { - return compatibleMaterial.getItem(); - } - return data != null ? new ItemStack(material, amount, data) : new ItemStack(material); - } - - /** - * Does this material need to use a legacy fallback? - * - * @return - */ - public boolean usesLegacy() { - return legacy != null && ServerVersion.isServerVersionBelow(minVersion); - } - - /** - * Does this material need to use a fallback item on this server? - * - * @return - */ - public boolean usesCompatibility() { - return compatibleMaterial != null && material == compatibleMaterial.material; - //return compatibleMaterial != null && ServerVersion.isServerVersionBelow(compatibleMaterial.versionLessThan); - } - - /** - * Is this item reused in later versions of Minecraft? - * - * @return - */ - public boolean isRecycled() { - return usesLegacy() && this == CompatibleMaterial.GRASS; - } - - /** - * Get the legacy data value for this material if there is one, or -1 if - * none - * - * @return - */ - public byte getData() { - return data != null ? data : -1; - } - - /** - * Check if current material requires a data value. - * - * @return true if server is legacy and this item requires data to be defined. - */ - public boolean usesData() { - return data != null; - } - - /** - * Lookup a Material by its modern id name.
- * This also can grab materials by their legacy, but only if there is no - * modern material by that name. - * - * @param name item to lookup - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getMaterial(String name) { - return name == null ? null : lookupMap.get(name.toUpperCase()); - } - - /** - * Lookup a Material by its modern id name.
- * This also can grab materials by their legacy, but only if there is no - * modern material by that name. - * - * @param name item to lookup - * @param def default item if this is not a valid material - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getMaterial(String name, CompatibleMaterial def) { - return name == null ? def : lookupMap.getOrDefault(name.toUpperCase(), def); - } - - /** - * Lookup a Material by bukkit material. - * - * @param mat item to lookup - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getMaterial(Material mat) { - if (mat == null) - return null; - if (useLegacy) { - CompatibleMaterial compatibleMaterial = lookupMap.get(mat.name() + ":0"); - if (compatibleMaterial != null) - return compatibleMaterial; - } - return lookupMap.get(mat.name()); - } - - /** - * Lookup a Material by Itemstack. - * - * @param item item to lookup - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getMaterial(ItemStack item) { - if (item == null) { - return null; - } - String key = item.getType() + ":"; - CompatibleMaterial m = lookupMap.get(key); - return m != null ? m : lookupMap.get(key + item.getDurability()); - } - - /** - * Lookup a Material by Block, corrected for legacy - * - * @param block block to check - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getMaterial(Block block) { - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { // Flattening - return CompatibleMaterial.getMaterialFromNewBlock(block); - } else { // Pre-Flattening - if (block != null) { - if (block.getData() != 0) { - for (CompatibleMaterial cm : CompatibleMaterial.values()) { - if (cm.isValidItem() && !cm.usesCompatibility() && cm.getMaterial() != null && cm.getMaterial().equals(block.getType())) { - if (cm.getData() == block.getData()) { - return cm; - } - } - } - } - return CompatibleMaterial.getMaterialFromNewBlock(block); - } - } - return null; - } - - private static Method methodGetBlockData; - - static { - if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { - try { - methodGetBlockData = FallingBlock.class.getDeclaredMethod("getBlockData"); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } - } - } - - /** - * Lookup a Material by FallingBlock, corrected for legacy - * - * @param block falling block to check - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getMaterial(FallingBlock block) { - if (block == null) return null; - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - return getMaterial(block.getBlockData().getMaterial()); - } else { - try { - return getMaterial(block.getMaterial(), (byte) methodGetBlockData.invoke(block)); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - return null; - } - - /** - * Lookup a Material by Material and data, corrected for legacy - * - * @param mat material to check - * @param data data of the block - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getMaterial(Material mat, byte data) { - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { // Flattening - return CompatibleMaterial.getMaterial(mat); - } else { // Pre-Flattening - if (mat != null) { - if (data != 0) { - for (CompatibleMaterial cm : CompatibleMaterial.values()) { - if (cm.getMaterial() != null - && cm.getMaterial().equals(mat)) { - if (cm.getData() == data) { - return cm; - } - } - } - } - return CompatibleMaterial.getMaterial(mat); - } - } - return null; - } - - private static CompatibleMaterial getMaterialFromNewBlock(Block block) { - if (block == null) { - return null; - } - Material mat = block.getType(); - if (useLegacy) { - LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name(), block.getData()); - if (legacyBlock != null) { - return lookupMap.get(legacyBlock.name()); - } - CompatibleMaterial withData = lookupMap.get(mat.name() + ":" + block.getData()); - return withData == null ? lookupMap.get(mat.name()) : withData; - } - return lookupMap.get(mat.name()); - } - - /** - * Lookup a Block Material by its modern id name.
- * This also can grab materials by their legacy, but only if there is no - * modern material by that name. - * - * @param name item to lookup - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getBlockMaterial(String name) { - if (name == null) { - return null; - } else if (useLegacy) { - LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(name.toUpperCase()); - if (legacyBlock != null) { - return lookupMap.get(legacyBlock.name()); - } - } - return lookupMap.get(name.toUpperCase()); - } - - /** - * Lookup a Block Material by its modern id name.
- * This also can grab materials by their legacy, but only if there is no - * modern material by that name. - * - * @param name item to lookup - * @param def default item if this is not a valid material - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getBlockMaterial(String name, CompatibleMaterial def) { - if (name == null) { - return def; - } else if (useLegacy) { - LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(name.toUpperCase()); - if (legacyBlock != null) { - return lookupMap.get(legacyBlock.name()); - } - } - return lookupMap.getOrDefault(name.toUpperCase(), def); - } - - /** - * Lookup a Block Material by bukkit material. - * - * @param mat item to lookup - * @return LegacyMaterial or null if none found - */ - public static CompatibleMaterial getBlockMaterial(Material mat) { - if (mat == null) { - return null; - } else if (useLegacy) { - LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name()); - if (legacyBlock != null) { - return lookupMap.get(legacyBlock.name()); - } - } - return lookupMap.get(mat.name()); - } - - static LinkedHashSet all = null; - - public static Set getAllValidItemMaterials() { - if (all == null) { - all = new LinkedHashSet(); - for (CompatibleMaterial mat : values()) { - if (mat.isValidItem() && !mat.usesCompatibility()) { - all.add(mat); - } - } - } - return Collections.unmodifiableSet(all); - } - - /** - * Lookup a Legacy Material by its modern id name and return its associated - * Item.
- * This also can grab materials by their legacy, but only if there is no - * modern material by that name. - * - * @param name item to lookup - * @return ItemStack for this material, or null if none found - */ - public static ItemStack getItem(String name) { - if (name == null) { - return null; - } - CompatibleMaterial m = lookupMap.get(name.toUpperCase()); - if (m != null) { - return m.getItem(); - } - Material mat = Material.getMaterial(name); - return mat != null ? new ItemStack(mat) : null; - } - - private static Method methodSetData; - static { - if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { - try { - methodSetData = Block.class.getDeclaredMethod("setData", byte.class); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } - } - } - - /** - * Apply the current material to a block. - * - * @param block the block to apply the material to. - */ - public void applyToBlock(Block block) { - if (block == null) return; - block.setType(material); - if (data != null && data != -1 && ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { - try { - methodSetData.invoke(block, data); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - } - } - - /** - * Check to see if an item matches this specific material type - * - * @param item Item to check - * @return true if material of the ItemStack matches this item, corrected for legacy data - */ - public boolean matches(ItemStack item) { - return item != null && !usesCompatibility() && item.getType() == material && (data == null || item.getDurability() == data); // eons ago, ItemStack.getData() would return a byte. 1.7 doesn't, though. - } - - /** - * Some blocks change to other materials when placed down. This checks to - * see if this one is one of those. - * - * @return - */ - public boolean hasDifferentBlockItem() { - switch (this) { - case STRING: - return true; - case ACACIA_DOOR: - case BIRCH_DOOR: - case DARK_OAK_DOOR: - case JUNGLE_DOOR: - case SPRUCE_DOOR: - case IRON_DOOR: - case OAK_DOOR: - case ACACIA_SIGN: - case BIRCH_SIGN: - case DARK_OAK_SIGN: - case JUNGLE_SIGN: - case OAK_SIGN: - case SPRUCE_SIGN: - case BLACK_BANNER: - case BLUE_BANNER: - case BROWN_BANNER: - case CYAN_BANNER: - case GRAY_BANNER: - case GREEN_BANNER: - case LIGHT_BLUE_BANNER: - case LIGHT_GRAY_BANNER: - case LIME_BANNER: - case MAGENTA_BANNER: - case ORANGE_BANNER: - case PINK_BANNER: - case PURPLE_BANNER: - case RED_BANNER: - case WHITE_BANNER: - case YELLOW_BANNER: - case BLACK_BED: - case BLUE_BED: - case BROWN_BED: - case CYAN_BED: - case GRAY_BED: - case GREEN_BED: - case LIGHT_BLUE_BED: - case LIGHT_GRAY_BED: - case LIME_BED: - case MAGENTA_BED: - case ORANGE_BED: - case PINK_BED: - case PURPLE_BED: - case RED_BED: - case WHITE_BED: - case YELLOW_BED: - case REDSTONE: - case REPEATER: - case SUGAR_CANE: - case CAKE: - case COMPARATOR: - return usesLegacy(); - } - return false; - } - - /** - * Check to see if this is a material that can exist as a block - * - * @return - */ - public boolean isBlock() { - return material != null && material.isBlock(); - } - - /** - * Check to see if this is an item that can be consumed to restore hunger - * - * @return - */ - public boolean isEdible() { - return material != null && material.isEdible(); - } - - /** - * Check if the material is a block and can be built on - * - * @return - */ - public boolean isSolid() { - return material != null && material.isSolid(); - } - - /** - * Check if the material is a block and does not block any light - * - * @return - */ - public boolean isTransparent() { - return material != null && material.isTransparent(); - } - - /** - * Check if the material is a block and can catch fire - * - * @return - */ - public boolean isFlammable() { - return material != null && material.isFlammable(); - } - - /** - * Check if the material is a block and can be destroyed by burning - * - * @return - */ - public boolean isBurnable() { - return material != null && material.isBurnable(); - } - - /** - * Checks if this Material can be used as fuel in a Furnace - * - * @return - */ - public boolean isFuel() { - // this function is not implemented in some older versions, so we need this here.. - switch (this) { - case ACACIA_BOAT: - case ACACIA_BUTTON: - case ACACIA_DOOR: - case ACACIA_FENCE: - case ACACIA_FENCE_GATE: - case ACACIA_LOG: - case ACACIA_PLANKS: - case ACACIA_PRESSURE_PLATE: - case ACACIA_SAPLING: - case ACACIA_SIGN: - case ACACIA_SLAB: - case ACACIA_STAIRS: - case ACACIA_TRAPDOOR: - case ACACIA_WOOD: - case BAMBOO: - case BARREL: - case BIRCH_BOAT: - case BIRCH_BUTTON: - case BIRCH_DOOR: - case BIRCH_FENCE: - case BIRCH_FENCE_GATE: - case BIRCH_LOG: - case BIRCH_PLANKS: - case BIRCH_PRESSURE_PLATE: - case BIRCH_SAPLING: - case BIRCH_SIGN: - case BIRCH_SLAB: - case BIRCH_STAIRS: - case BIRCH_TRAPDOOR: - case BIRCH_WOOD: - case BLACK_BANNER: - case BLACK_CARPET: - case BLACK_WOOL: - case BLAZE_ROD: - case BLUE_BANNER: - case BLUE_CARPET: - case BLUE_WOOL: - case BOOKSHELF: - case BOW: - case BOWL: - case BROWN_BANNER: - case BROWN_CARPET: - case BROWN_WOOL: - case CARTOGRAPHY_TABLE: - case CHARCOAL: - case CHEST: - case COAL: - case COAL_BLOCK: - case COMPOSTER: - case CRAFTING_TABLE: - case CROSSBOW: - case CYAN_BANNER: - case CYAN_CARPET: - case CYAN_WOOL: - case DARK_OAK_BOAT: - case DARK_OAK_BUTTON: - case DARK_OAK_DOOR: - case DARK_OAK_FENCE: - case DARK_OAK_FENCE_GATE: - case DARK_OAK_LOG: - case DARK_OAK_PLANKS: - case DARK_OAK_PRESSURE_PLATE: - case DARK_OAK_SAPLING: - case DARK_OAK_SIGN: - case DARK_OAK_SLAB: - case DARK_OAK_STAIRS: - case DARK_OAK_TRAPDOOR: - case DARK_OAK_WOOD: - case DAYLIGHT_DETECTOR: - case DEAD_BUSH: - case DRIED_KELP_BLOCK: - case FISHING_ROD: - case FLETCHING_TABLE: - case GRAY_BANNER: - case GRAY_CARPET: - case GRAY_WOOL: - case GREEN_BANNER: - case GREEN_CARPET: - case GREEN_WOOL: - case JUKEBOX: - case JUNGLE_BOAT: - case JUNGLE_BUTTON: - case JUNGLE_DOOR: - case JUNGLE_FENCE: - case JUNGLE_FENCE_GATE: - case JUNGLE_LOG: - case JUNGLE_PLANKS: - case JUNGLE_PRESSURE_PLATE: - case JUNGLE_SAPLING: - case JUNGLE_SIGN: - case JUNGLE_SLAB: - case JUNGLE_STAIRS: - case JUNGLE_TRAPDOOR: - case JUNGLE_WOOD: - case LADDER: - case LAVA_BUCKET: - case LECTERN: - case LIGHT_BLUE_BANNER: - case LIGHT_BLUE_CARPET: - case LIGHT_BLUE_WOOL: - case LIGHT_GRAY_BANNER: - case LIGHT_GRAY_CARPET: - case LIGHT_GRAY_WOOL: - case LIME_BANNER: - case LIME_CARPET: - case LIME_WOOL: - case LOOM: - case MAGENTA_BANNER: - case MAGENTA_CARPET: - case MAGENTA_WOOL: - case NOTE_BLOCK: - case OAK_BOAT: - case OAK_BUTTON: - case OAK_DOOR: - case OAK_FENCE: - case OAK_FENCE_GATE: - case OAK_LOG: - case OAK_PLANKS: - case OAK_PRESSURE_PLATE: - case OAK_SAPLING: - case OAK_SIGN: - case OAK_SLAB: - case OAK_STAIRS: - case OAK_TRAPDOOR: - case OAK_WOOD: - case ORANGE_BANNER: - case ORANGE_CARPET: - case ORANGE_WOOL: - case PINK_BANNER: - case PINK_CARPET: - case PINK_WOOL: - case PURPLE_BANNER: - case PURPLE_CARPET: - case PURPLE_WOOL: - case RED_BANNER: - case RED_CARPET: - case RED_WOOL: - case SCAFFOLDING: - case SMITHING_TABLE: - case SPRUCE_BOAT: - case SPRUCE_BUTTON: - case SPRUCE_DOOR: - case SPRUCE_FENCE: - case SPRUCE_FENCE_GATE: - case SPRUCE_LOG: - case SPRUCE_PLANKS: - case SPRUCE_PRESSURE_PLATE: - case SPRUCE_SAPLING: - case SPRUCE_SIGN: - case SPRUCE_SLAB: - case SPRUCE_STAIRS: - case SPRUCE_TRAPDOOR: - case SPRUCE_WOOD: - case STICK: - case STRIPPED_ACACIA_LOG: - case STRIPPED_ACACIA_WOOD: - case STRIPPED_BIRCH_LOG: - case STRIPPED_BIRCH_WOOD: - case STRIPPED_DARK_OAK_LOG: - case STRIPPED_DARK_OAK_WOOD: - case STRIPPED_JUNGLE_LOG: - case STRIPPED_JUNGLE_WOOD: - case STRIPPED_OAK_LOG: - case STRIPPED_OAK_WOOD: - case STRIPPED_SPRUCE_LOG: - case STRIPPED_SPRUCE_WOOD: - case TRAPPED_CHEST: - case WHITE_BANNER: - case WHITE_CARPET: - case WHITE_WOOL: - case WOODEN_AXE: - case WOODEN_HOE: - case WOODEN_PICKAXE: - case WOODEN_SHOVEL: - case WOODEN_SWORD: - case YELLOW_BANNER: - case YELLOW_CARPET: - case YELLOW_WOOL: - return true; - default: - return false; - } - } - - /** - * Get the result of putting this item - * into a furnace. - *

- * return - */ - public CompatibleMaterial getBurnResult() { - switch (this) { - case PORKCHOP: - return COOKED_PORKCHOP; - case BEEF: - return COOKED_BEEF; - case CHICKEN: - return COOKED_CHICKEN; - case COD: - return COOKED_COD; - case SALMON: - return COOKED_SALMON; - case POTATO: - return BAKED_POTATO; - case MUTTON: - return COOKED_MUTTON; - case RABBIT: - return COOKED_RABBIT; - case KELP: - return DRIED_KELP; - case IRON_ORE: - case DEEPSLATE_IRON_ORE: - return IRON_INGOT; - case GOLD_ORE: - case DEEPSLATE_GOLD_ORE: - return GOLD_INGOT; - case DIAMOND_ORE: - case DEEPSLATE_DIAMOND_ORE: - return DIAMOND; - case LAPIS_ORE: - case DEEPSLATE_LAPIS_ORE: - return LAPIS_LAZULI; - case REDSTONE_ORE: - case DEEPSLATE_REDSTONE_ORE: - return REDSTONE; - case COAL_ORE: - case DEEPSLATE_COAL_ORE: - return COAL; - case EMERALD_ORE: - case DEEPSLATE_EMERALD_ORE: - return EMERALD; - case NETHER_QUARTZ_ORE: - return QUARTZ; - case COPPER_ORE: - case DEEPSLATE_COPPER_ORE: - return COPPER_INGOT; - case SAND: - case RED_SAND: - return GLASS; - case COBBLESTONE: - return STONE; - case SANDSTONE: - return SMOOTH_SANDSTONE; - case RED_SANDSTONE: - return SMOOTH_RED_SANDSTONE; - case STONE: - return SMOOTH_STONE; - case QUARTZ_BLOCK: - return SMOOTH_QUARTZ; - case CLAY_BALL: - return BRICK; - case NETHERRACK: - return NETHER_BRICK; - case CLAY: - return BRICKS; - case STONE_BRICKS: - return CRACKED_STONE_BRICKS; - case WHITE_TERRACOTTA: - return WHITE_GLAZED_TERRACOTTA; - case ORANGE_TERRACOTTA: - return ORANGE_GLAZED_TERRACOTTA; - case MAGENTA_TERRACOTTA: - return MAGENTA_GLAZED_TERRACOTTA; - case LIGHT_BLUE_TERRACOTTA: - return LIGHT_BLUE_GLAZED_TERRACOTTA; - case YELLOW_TERRACOTTA: - return YELLOW_GLAZED_TERRACOTTA; - case LIME_TERRACOTTA: - return LIME_GLAZED_TERRACOTTA; - case PINK_TERRACOTTA: - return PINK_GLAZED_TERRACOTTA; - case GRAY_TERRACOTTA: - return GRAY_GLAZED_TERRACOTTA; - case LIGHT_GRAY_TERRACOTTA: - return LIGHT_GRAY_GLAZED_TERRACOTTA; - case CYAN_TERRACOTTA: - return CYAN_GLAZED_TERRACOTTA; - case PURPLE_TERRACOTTA: - return PURPLE_GLAZED_TERRACOTTA; - case BLUE_TERRACOTTA: - return BLUE_GLAZED_TERRACOTTA; - case BROWN_TERRACOTTA: - return BROWN_GLAZED_TERRACOTTA; - case GREEN_TERRACOTTA: - return GREEN_GLAZED_TERRACOTTA; - case RED_TERRACOTTA: - return RED_GLAZED_TERRACOTTA; - case BLACK_TERRACOTTA: - return BLACK_GLAZED_TERRACOTTA; - case IRON_SWORD: - case IRON_PICKAXE: - case IRON_AXE: - case IRON_SHOVEL: - case IRON_HOE: - case IRON_HELMET: - case IRON_CHESTPLATE: - case IRON_LEGGINGS: - case IRON_BOOTS: - case IRON_HORSE_ARMOR: - case CHAINMAIL_HELMET: - case CHAINMAIL_CHESTPLATE: - case CHAINMAIL_LEGGINGS: - case CHAINMAIL_BOOTS: - return IRON_NUGGET; - case GOLDEN_SWORD: - case GOLDEN_PICKAXE: - case GOLDEN_AXE: - case GOLDEN_SHOVEL: - case GOLDEN_HOE: - case GOLDEN_HELMET: - case GOLDEN_CHESTPLATE: - case GOLDEN_LEGGINGS: - case GOLDEN_BOOTS: - case GOLDEN_HORSE_ARMOR: - return GOLD_NUGGET; - case CACTUS: - return GREEN_DYE; - case SEA_PICKLE: - return LIME_DYE; - case OAK_LOG: - case BIRCH_LOG: - case ACACIA_LOG: - case DARK_OAK_LOG: - case JUNGLE_LOG: - case SPRUCE_LOG: - case STRIPPED_ACACIA_LOG: - case STRIPPED_BIRCH_LOG: - case STRIPPED_DARK_OAK_LOG: - case STRIPPED_JUNGLE_LOG: - case STRIPPED_OAK_LOG: - case STRIPPED_SPRUCE_LOG: - case ACACIA_WOOD: - case BIRCH_WOOD: - case JUNGLE_WOOD: - case OAK_WOOD: - case SPRUCE_WOOD: - case STRIPPED_ACACIA_WOOD: - case STRIPPED_BIRCH_WOOD: - case STRIPPED_DARK_OAK_WOOD: - case STRIPPED_JUNGLE_WOOD: - case STRIPPED_OAK_WOOD: - case STRIPPED_SPRUCE_WOOD: - return CHARCOAL; - case CHORUS_FRUIT: - return POPPED_CHORUS_FRUIT; - default: - return null; - } - } - - /** - * Check if the material is air - * - * @return - */ - public boolean isAir() { - switch (this) { - case AIR: - case CAVE_AIR: - case VOID_AIR: - return true; - default: - return false; - } - } - - /** - * Check if the material is water - * - * @return - */ - public boolean isWater() { - return this == CompatibleMaterial.WATER; - } - - /** - * Get the EntityType of the monster spawn egg. - * - * @return - */ - public EntityType getEggType() { - String entityName = this.name().replace("_SPAWN_EGG", ""); - if (entityName.equals("MOOSHROOM")) - entityName = "MUSHROOM_COW"; - else if (entityName.equals("ZOMBIE_PIGMAN")) - entityName = "PIG_ZOMBIE"; - try { - return EntityType.valueOf(entityName); - } catch (IllegalArgumentException e) { - return null; - } - } - - /** - * Check if the material is a block and completely blocks vision - * - * @return - */ - public boolean isOccluding() { - return material != null && material.isOccluding(); - } - - /** - * @return True if this material is affected by gravity. - */ - public boolean hasGravity() { - return material != null && material.hasGravity(); - } - - /** - * Checks if this Material is an obtainable item. - * - * @return - */ - public boolean isItem() { - // this function is not implemented in some older versions, so we need this here.. - switch (this) { - case CAVE_AIR: - case VOID_AIR: - case ACACIA_WALL_SIGN: - case ATTACHED_MELON_STEM: - case ATTACHED_PUMPKIN_STEM: - case BAMBOO_SAPLING: - case BEETROOTS: - case BIRCH_WALL_SIGN: - case BLACK_WALL_BANNER: - case BLUE_WALL_BANNER: - case BRAIN_CORAL_WALL_FAN: - case BROWN_WALL_BANNER: - case BUBBLE_COLUMN: - case BUBBLE_CORAL_WALL_FAN: - case CARROTS: - case COCOA: - case CREEPER_WALL_HEAD: - case CYAN_WALL_BANNER: - case DARK_OAK_WALL_SIGN: - case DEAD_BRAIN_CORAL_WALL_FAN: - case DEAD_BUBBLE_CORAL_WALL_FAN: - case DEAD_FIRE_CORAL_WALL_FAN: - case DEAD_HORN_CORAL_WALL_FAN: - case DEAD_TUBE_CORAL_WALL_FAN: - case DRAGON_WALL_HEAD: - case END_GATEWAY: - case END_PORTAL: - case FIRE: - case FIRE_CORAL_WALL_FAN: - case FROSTED_ICE: - case GRAY_WALL_BANNER: - case GREEN_WALL_BANNER: - case HORN_CORAL_WALL_FAN: - case JUNGLE_WALL_SIGN: - case KELP_PLANT: - case LAVA: - case LIGHT_BLUE_WALL_BANNER: - case LIGHT_GRAY_WALL_BANNER: - case LIME_WALL_BANNER: - case MAGENTA_WALL_BANNER: - case MELON_STEM: - case MOVING_PISTON: - case NETHER_PORTAL: - case OAK_WALL_SIGN: - case ORANGE_WALL_BANNER: - case PINK_WALL_BANNER: - case PISTON_HEAD: - case PLAYER_WALL_HEAD: - case POTATOES: - case POTTED_ACACIA_SAPLING: - case POTTED_ALLIUM: - case POTTED_AZURE_BLUET: - case POTTED_BAMBOO: - case POTTED_BIRCH_SAPLING: - case POTTED_BLUE_ORCHID: - case POTTED_BROWN_MUSHROOM: - case POTTED_CACTUS: - case POTTED_CORNFLOWER: - case POTTED_DANDELION: - case POTTED_DARK_OAK_SAPLING: - case POTTED_DEAD_BUSH: - case POTTED_FERN: - case POTTED_JUNGLE_SAPLING: - case POTTED_LILY_OF_THE_VALLEY: - case POTTED_OAK_SAPLING: - case POTTED_ORANGE_TULIP: - case POTTED_OXEYE_DAISY: - case POTTED_PINK_TULIP: - case POTTED_POPPY: - case POTTED_RED_MUSHROOM: - case POTTED_RED_TULIP: - case POTTED_SPRUCE_SAPLING: - case POTTED_WHITE_TULIP: - case POTTED_WITHER_ROSE: - case PUMPKIN_STEM: - case PURPLE_WALL_BANNER: - case REDSTONE_WALL_TORCH: - case REDSTONE_WIRE: - case RED_WALL_BANNER: - case SKELETON_WALL_SKULL: - case SPRUCE_WALL_SIGN: - case SWEET_BERRY_BUSH: - case TALL_SEAGRASS: - case TRIPWIRE: - case TUBE_CORAL_WALL_FAN: - case WALL_TORCH: - case WATER: - case WHITE_WALL_BANNER: - case WITHER_SKELETON_WALL_SKULL: - case YELLOW_WALL_BANNER: - case ZOMBIE_WALL_HEAD: - return false; - } - return true; - } - - /** - * Checks if this Material can be interacted with.
- * This method will return true if there is at least one state in which - * additional interact handling is performed for the material. - * - * @return - */ - public boolean isInteractable() { - // this function is not implemented in some older versions, so we need this here.. - switch (this) { - case ACACIA_BUTTON: - case ACACIA_DOOR: - case ACACIA_FENCE: - case ACACIA_FENCE_GATE: - case ACACIA_SIGN: - case ACACIA_STAIRS: - case ACACIA_TRAPDOOR: - case ACACIA_WALL_SIGN: - case ANDESITE_STAIRS: - case ANVIL: - case BARREL: - case BEACON: - case BEEHIVE: - case BEE_NEST: - case BELL: - case BIRCH_BUTTON: - case BIRCH_DOOR: - case BIRCH_FENCE: - case BIRCH_FENCE_GATE: - case BIRCH_SIGN: - case BIRCH_STAIRS: - case BIRCH_TRAPDOOR: - case BIRCH_WALL_SIGN: - case BLACKSTONE_STAIRS: - case BLACK_BED: - case BLACK_SHULKER_BOX: - case BLAST_FURNACE: - case BLUE_BED: - case BLUE_SHULKER_BOX: - case BREWING_STAND: - case BRICK_STAIRS: - case BROWN_BED: - case BROWN_SHULKER_BOX: - case CAKE: - case CAMPFIRE: - case CARTOGRAPHY_TABLE: - case CAULDRON: - case CHAIN_COMMAND_BLOCK: - case CHEST: - case CHIPPED_ANVIL: - case COBBLESTONE_STAIRS: - case COMMAND_BLOCK: - case COMPARATOR: - case COMPOSTER: - case CRAFTING_TABLE: - case CRIMSON_BUTTON: - case CRIMSON_DOOR: - case CRIMSON_FENCE: - case CRIMSON_FENCE_GATE: - case CRIMSON_SIGN: - case CRIMSON_STAIRS: - case CRIMSON_TRAPDOOR: - case CRIMSON_WALL_SIGN: - case CYAN_BED: - case CYAN_SHULKER_BOX: - case DAMAGED_ANVIL: - case DARK_OAK_BUTTON: - case DARK_OAK_DOOR: - case DARK_OAK_FENCE: - case DARK_OAK_FENCE_GATE: - case DARK_OAK_SIGN: - case DARK_OAK_STAIRS: - case DARK_OAK_TRAPDOOR: - case DARK_OAK_WALL_SIGN: - case DARK_PRISMARINE_STAIRS: - case DAYLIGHT_DETECTOR: - case DIORITE_STAIRS: - case DISPENSER: - case DRAGON_EGG: - case DROPPER: - case ENCHANTING_TABLE: - case ENDER_CHEST: - case END_STONE_BRICK_STAIRS: - case FLETCHING_TABLE: - case FLOWER_POT: - case FURNACE: - case GRANITE_STAIRS: - case GRAY_BED: - case GRAY_SHULKER_BOX: - case GREEN_BED: - case GREEN_SHULKER_BOX: - case GRINDSTONE: - case HOPPER: - case IRON_DOOR: - case IRON_TRAPDOOR: - case JIGSAW: - case JUKEBOX: - case JUNGLE_BUTTON: - case JUNGLE_DOOR: - case JUNGLE_FENCE: - case JUNGLE_FENCE_GATE: - case JUNGLE_SIGN: - case JUNGLE_STAIRS: - case JUNGLE_TRAPDOOR: - case JUNGLE_WALL_SIGN: - case LECTERN: - case LEVER: - case LIGHT_BLUE_BED: - case LIGHT_BLUE_SHULKER_BOX: - case LIGHT_GRAY_BED: - case LIGHT_GRAY_SHULKER_BOX: - case LIME_BED: - case LIME_SHULKER_BOX: - case LOOM: - case MAGENTA_BED: - case MAGENTA_SHULKER_BOX: - case MOSSY_COBBLESTONE_STAIRS: - case MOSSY_STONE_BRICK_STAIRS: - case MOVING_PISTON: - case NETHER_BRICK_FENCE: - case NETHER_BRICK_STAIRS: - case NOTE_BLOCK: - case OAK_BUTTON: - case OAK_DOOR: - case OAK_FENCE: - case OAK_FENCE_GATE: - case OAK_SIGN: - case OAK_STAIRS: - case OAK_TRAPDOOR: - case OAK_WALL_SIGN: - case ORANGE_BED: - case ORANGE_SHULKER_BOX: - case PINK_BED: - case PINK_SHULKER_BOX: - case POLISHED_ANDESITE_STAIRS: - case POLISHED_BLACKSTONE_BRICK_STAIRS: - case POLISHED_BLACKSTONE_BUTTON: - case POLISHED_BLACKSTONE_STAIRS: - case POLISHED_DIORITE_STAIRS: - case POLISHED_GRANITE_STAIRS: - case POTTED_ACACIA_SAPLING: - case POTTED_ALLIUM: - case POTTED_AZURE_BLUET: - case POTTED_BAMBOO: - case POTTED_BIRCH_SAPLING: - case POTTED_BLUE_ORCHID: - case POTTED_BROWN_MUSHROOM: - case POTTED_CACTUS: - case POTTED_CORNFLOWER: - case POTTED_CRIMSON_FUNGUS: - case POTTED_CRIMSON_ROOTS: - case POTTED_DANDELION: - case POTTED_DARK_OAK_SAPLING: - case POTTED_DEAD_BUSH: - case POTTED_FERN: - case POTTED_JUNGLE_SAPLING: - case POTTED_LILY_OF_THE_VALLEY: - case POTTED_OAK_SAPLING: - case POTTED_ORANGE_TULIP: - case POTTED_OXEYE_DAISY: - case POTTED_PINK_TULIP: - case POTTED_POPPY: - case POTTED_RED_MUSHROOM: - case POTTED_RED_TULIP: - case POTTED_SPRUCE_SAPLING: - case POTTED_WARPED_FUNGUS: - case POTTED_WARPED_ROOTS: - case POTTED_WHITE_TULIP: - case POTTED_WITHER_ROSE: - case PRISMARINE_BRICK_STAIRS: - case PRISMARINE_STAIRS: - case PUMPKIN: - case PURPLE_BED: - case PURPLE_SHULKER_BOX: - case PURPUR_STAIRS: - case QUARTZ_STAIRS: - case REDSTONE_ORE: - case REDSTONE_WIRE: - case RED_BED: - case RED_NETHER_BRICK_STAIRS: - case RED_SANDSTONE_STAIRS: - case RED_SHULKER_BOX: - case REPEATER: - case REPEATING_COMMAND_BLOCK: - case RESPAWN_ANCHOR: - case SANDSTONE_STAIRS: - case SHULKER_BOX: - case SMITHING_TABLE: - case SMOKER: - case SMOOTH_QUARTZ_STAIRS: - case SMOOTH_RED_SANDSTONE_STAIRS: - case SMOOTH_SANDSTONE_STAIRS: - case SOUL_CAMPFIRE: - case SPRUCE_BUTTON: - case SPRUCE_DOOR: - case SPRUCE_FENCE: - case SPRUCE_FENCE_GATE: - case SPRUCE_SIGN: - case SPRUCE_STAIRS: - case SPRUCE_TRAPDOOR: - case SPRUCE_WALL_SIGN: - case STONECUTTER: - case STONE_BRICK_STAIRS: - case STONE_BUTTON: - case STONE_STAIRS: - case STRUCTURE_BLOCK: - case SWEET_BERRY_BUSH: - case TNT: - case TRAPPED_CHEST: - case WARPED_BUTTON: - case WARPED_DOOR: - case WARPED_FENCE: - case WARPED_FENCE_GATE: - case WARPED_SIGN: - case WARPED_STAIRS: - case WARPED_TRAPDOOR: - case WARPED_WALL_SIGN: - case WHITE_BED: - case WHITE_SHULKER_BOX: - case YELLOW_BED: - case YELLOW_SHULKER_BOX: { - return true; - } - } - return false; - } - - /** - * @return true if this material is valid as an item - */ - public boolean isValidItem() { - switch (this) { - case ACACIA_WALL_SIGN: - case AIR: - case ATTACHED_MELON_STEM: - case ATTACHED_PUMPKIN_STEM: - case BAMBOO_SAPLING: - case BEETROOTS: - case BIRCH_WALL_SIGN: - case BLACK_WALL_BANNER: - case BLUE_WALL_BANNER: - case BRAIN_CORAL_WALL_FAN: - case BROWN_WALL_BANNER: - case BUBBLE_COLUMN: - case BUBBLE_CORAL_WALL_FAN: - case CARROTS: - case CAVE_AIR: - case COCOA: - case CREEPER_WALL_HEAD: - case CYAN_WALL_BANNER: - case DARK_OAK_WALL_SIGN: - case DEAD_BRAIN_CORAL_WALL_FAN: - case DEAD_BUBBLE_CORAL_WALL_FAN: - case DEAD_FIRE_CORAL_WALL_FAN: - case DEAD_HORN_CORAL_WALL_FAN: - case DEAD_TUBE_CORAL_WALL_FAN: - case DRAGON_WALL_HEAD: - case END_GATEWAY: - case END_PORTAL: - case FARMLAND: - case FIRE: // used to be able to in older versions - case FIRE_CORAL_WALL_FAN: - case FROSTED_ICE: - case GRAY_WALL_BANNER: - case GREEN_WALL_BANNER: - case HORN_CORAL_WALL_FAN: - case JUNGLE_WALL_SIGN: - case KELP_PLANT: - case LAVA: - case LIGHT_BLUE_WALL_BANNER: - case LIGHT_GRAY_WALL_BANNER: - case LIME_WALL_BANNER: - case MAGENTA_WALL_BANNER: - case MELON_STEM: - case MOVING_PISTON: - case NETHER_PORTAL: - case OAK_WALL_SIGN: - case ORANGE_WALL_BANNER: - case PINK_WALL_BANNER: - case PISTON_HEAD: - case PLAYER_WALL_HEAD: - case POTATOES: - case POTTED_ACACIA_SAPLING: - case POTTED_ALLIUM: - case POTTED_AZURE_BLUET: - case POTTED_BAMBOO: - case POTTED_BIRCH_SAPLING: - case POTTED_BLUE_ORCHID: - case POTTED_BROWN_MUSHROOM: - case POTTED_CACTUS: - case POTTED_CORNFLOWER: - case POTTED_DANDELION: - case POTTED_DARK_OAK_SAPLING: - case POTTED_DEAD_BUSH: - case POTTED_FERN: - case POTTED_JUNGLE_SAPLING: - case POTTED_LILY_OF_THE_VALLEY: - case POTTED_OAK_SAPLING: - case POTTED_ORANGE_TULIP: - case POTTED_OXEYE_DAISY: - case POTTED_PINK_TULIP: - case POTTED_POPPY: - case POTTED_RED_MUSHROOM: - case POTTED_RED_TULIP: - case POTTED_SPRUCE_SAPLING: - case POTTED_WHITE_TULIP: - case POTTED_WITHER_ROSE: - case PUMPKIN_STEM: - case PURPLE_WALL_BANNER: - case REDSTONE_WALL_TORCH: - case REDSTONE_WIRE: - case RED_WALL_BANNER: - case SKELETON_WALL_SKULL: - case SPRUCE_WALL_SIGN: - case SWEET_BERRY_BUSH: - case TALL_SEAGRASS: - case TRIPWIRE: - case TUBE_CORAL_WALL_FAN: - case VOID_AIR: - case WALL_TORCH: - case WATER: - case WHITE_WALL_BANNER: - case WITHER_SKELETON_WALL_SKULL: - return false; - } - if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { - switch (this) { - case ACACIA_WOOD: - case BIRCH_WOOD: - case DARK_OAK_WOOD: - case JUNGLE_WOOD: - case OAK_WOOD: - case SPRUCE_WOOD: - case STRIPPED_ACACIA_WOOD: - case STRIPPED_BIRCH_WOOD: - case STRIPPED_DARK_OAK_WOOD: - case STRIPPED_JUNGLE_WOOD: - case STRIPPED_OAK_WOOD: - case STRIPPED_SPRUCE_WOOD: - return false; - } - } - return true; - } - - /** - * @return true if this material is a food that can be cooked and is in its cooked state - */ - public boolean isCooked() { - switch (this) { - case BAKED_POTATO: - case COOKED_BEEF: - case COOKED_CHICKEN: - case COOKED_COD: - case COOKED_MUTTON: - case COOKED_PORKCHOP: - case COOKED_RABBIT: - case COOKED_SALMON: - case DRIED_KELP: - return true; - } - return false; - } - - /** - * @return true if this material is a food that can be cooked and is in its raw state - */ - public boolean isRaw() { - switch (this) { - case BEEF: - case CHICKEN: - case COD: - case KELP: // not edible, but is the raw state of DRIED_KELP - case MUTTON: - case PORKCHOP: - case POTATO: - case RABBIT: - case SALMON: - return true; - } - return false; - } - - /** - * @return true if this material is two blocks tall - */ - public boolean isTall() { - switch (this) { - case SUNFLOWER: - case LILAC: - case LARGE_FERN: - case ROSE_BUSH: - case PEONY: - case TALL_GRASS: - return true; - } - return false; - } - - /** - * Note: If using this on a legacy server without #getBlockMaterial - * you may run into issues. - * - * @return true if this is a block that has a growth state - */ - public boolean isCrop() { - switch (this) { - case BEETROOTS: - case CACTUS: - case CARROTS: - case CHORUS_FLOWER: - // FROSTED_ICE is Ageable, but not a crop - case KELP: - case MELON_STEM: - case NETHER_WART: - case POTATOES: - case PUMPKIN_STEM: - case SUGAR_CANE: - case WHEAT: - return true; - default: - return false; - } - } - - /** - * @return the yield of this crop. - */ - public CompatibleMaterial getCropYield() { - switch (this) { - case BEETROOTS: - return BEETROOT; - case CACTUS: - return CACTUS; - case CARROTS: - return CARROT; - case CHORUS_FLOWER: - return CHORUS_PLANT; - case KELP: - return KELP; - case MELON_STEM: - return MELON; - case NETHER_WART: - return NETHER_WART; - case POTATOES: - return POTATO; - case PUMPKIN_STEM: - return PUMPKIN; - case SUGAR_CANE: - return SUGAR_CANE; - case WHEAT: - return WHEAT; - default: - return null; - } - } - - /** - * @return the seed of this crop. - */ - public CompatibleMaterial getCropSeed() { - switch (this) { - case BEETROOTS: - return BEETROOT_SEEDS; - case CACTUS: - return CACTUS; - case CARROTS: - return CARROT; - case CHORUS_PLANT: - return CHORUS_FLOWER; - case KELP: - return KELP; - case MELON_STEM: - return MELON_SEEDS; - case NETHER_WART: - return NETHER_WART; - case POTATOES: - return POTATO; - case PUMPKIN_STEM: - return PUMPKIN_SEEDS; - case SUGAR_CANE: - return SUGAR_CANE; - case WHEAT: - return WHEAT_SEEDS; - default: - return null; - } - } - - public static CompatibleMaterial getSpawnEgg(EntityType type) { - if (type == EntityType.MUSHROOM_COW) { - return MOOSHROOM_SPAWN_EGG; - } - - if (ServerVersion.isServerVersionBelow(ServerVersion.V1_16) - && type == EntityType.valueOf("PIG_ZOMBIE")) { - return ZOMBIE_PIGMAN_SPAWN_EGG; - } - - return lookupMap.get(type.name() + "_SPAWN_EGG"); - } - - public static CompatibleMaterial getGlassPaneColor(int color) { - switch (color) { - case 0: - return WHITE_STAINED_GLASS_PANE; - case 1: - return ORANGE_STAINED_GLASS_PANE; - case 2: - return MAGENTA_STAINED_GLASS_PANE; - case 3: - return LIGHT_BLUE_STAINED_GLASS_PANE; - case 4: - return YELLOW_STAINED_GLASS_PANE; - case 5: - return LIME_STAINED_GLASS_PANE; - case 6: - return PINK_STAINED_GLASS_PANE; - case 7: - return GRAY_STAINED_GLASS_PANE; - case 8: - return LIGHT_GRAY_STAINED_GLASS_PANE; - case 9: - return CYAN_STAINED_GLASS_PANE; - case 10: - return PURPLE_STAINED_GLASS_PANE; - case 11: - return BLUE_STAINED_GLASS_PANE; - case 12: - return BROWN_STAINED_GLASS_PANE; - case 13: - return GREEN_STAINED_GLASS_PANE; - case 14: - return RED_STAINED_GLASS_PANE; - case 15: - return BLACK_STAINED_GLASS_PANE; - } - return WHITE_STAINED_GLASS_PANE; - } - - public static CompatibleMaterial getGlassColor(int color) { - switch (color) { - case 0: - return WHITE_STAINED_GLASS; - case 1: - return ORANGE_STAINED_GLASS; - case 2: - return MAGENTA_STAINED_GLASS; - case 3: - return LIGHT_BLUE_STAINED_GLASS; - case 4: - return YELLOW_STAINED_GLASS; - case 5: - return LIME_STAINED_GLASS; - case 6: - return PINK_STAINED_GLASS; - case 7: - return GRAY_STAINED_GLASS; - case 8: - return LIGHT_GRAY_STAINED_GLASS; - case 9: - return CYAN_STAINED_GLASS; - case 10: - return PURPLE_STAINED_GLASS; - case 11: - return BLUE_STAINED_GLASS; - case 12: - return BROWN_STAINED_GLASS; - case 13: - return GREEN_STAINED_GLASS; - case 14: - return RED_STAINED_GLASS; - case 15: - return BLACK_STAINED_GLASS; - } - return WHITE_STAINED_GLASS; - } - - public static CompatibleMaterial getWoolColor(int color) { - switch (color) { - case 0: - return WHITE_WOOL; - case 1: - return ORANGE_WOOL; - case 2: - return MAGENTA_WOOL; - case 3: - return LIGHT_BLUE_WOOL; - case 4: - return YELLOW_WOOL; - case 5: - return LIME_WOOL; - case 6: - return PINK_WOOL; - case 7: - return GRAY_WOOL; - case 8: - return LIGHT_GRAY_WOOL; - case 9: - return CYAN_WOOL; - case 10: - return PURPLE_WOOL; - case 11: - return BLUE_WOOL; - case 12: - return BROWN_WOOL; - case 13: - return GREEN_WOOL; - case 14: - return RED_WOOL; - case 15: - return BLACK_WOOL; - } - return WHITE_WOOL; - } - - public static CompatibleMaterial getDyeColor(int color) { - switch (color) { - case 0: - return BLACK_DYE; - case 1: - return RED_DYE; - case 2: - return GREEN_DYE; - case 3: - return BROWN_DYE; - case 4: - return BLUE_DYE; - case 5: - return PURPLE_DYE; - case 6: - return CYAN_DYE; - case 7: - return LIGHT_GRAY_DYE; - case 8: - return GRAY_DYE; - case 9: - return PINK_DYE; - case 10: - return LIME_DYE; - case 11: - return YELLOW_DYE; - case 12: - return LIGHT_BLUE_DYE; - case 13: - return MAGENTA_DYE; - case 14: - return ORANGE_DYE; - case 15: - return WHITE_DYE; - } - return WHITE_DYE; - } -} +package com.songoda.core.compatibility; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.FallingBlock; +import org.bukkit.inventory.ItemStack; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +/** + * Items that are compatible with server versions 1.7+ + * + * @author jascotty2 + * @since 2019-08-23 + */ +public enum CompatibleMaterial { + /* + TODO: add another handler for getBlockItem() for materials and fallback materials + + Legacy has some values not used in modern, eg: + + DIODE_BLOCK_OFF(93, Diode.class), + DIODE_BLOCK_ON(94, Diode.class), + SPRUCE_DOOR_ITEM(427), + BIRCH_DOOR_ITEM(428), + JUNGLE_DOOR_ITEM(429), + ACACIA_DOOR_ITEM(430), + DARK_OAK_DOOR_ITEM(431), + */ + + /* 1.17 */ + AMETHYST_BLOCK(), + AMETHYST_CLUSTER(), + AMETHYST_SHARD(), + AXOLOTL_BUCKET(), + AXOLOTL_SPAWN_EGG(), + AZALEA(), + AZALEA_LEAVES(), + BIG_DRIPLEAF(), + BIG_DRIPLEAF_STEM(), + BLACK_CANDLE(), + BLACK_CANDLE_CAKE(), + BLUE_CANDLE(), + BLUE_CANDLE_CAKE(), + BROWN_CANDLE(), + BROWN_CANDLE_CAKE(), + BUDDING_AMETHYST(), + BUNDLE(), + CALCITE(), + CANDLE(), + CANDLE_CAKE(), + CAVE_VINES(), + CAVE_VINES_PLANT(), + CHISELED_DEEPSLATE(), + COBBLED_DEEPSLATE(), + COBBLED_DEEPSLATE_SLAB(), + COBBLED_DEEPSLATE_STAIRS(), + COBBLED_DEEPSLATE_WALL(), + COPPER_BLOCK(), + COPPER_INGOT(), + COPPER_ORE(), + CRACKED_DEEPSLATE_BRICKS(), + CRACKED_DEEPSLATE_TILES(), + CUT_COPPER(), + CUT_COPPER_SLAB(), + CUT_COPPER_STAIRS(), + CYAN_CANDLE(), + CYAN_CANDLE_CAKE(), + DEEPSLATE(), + DEEPSLATE_BRICKS(), + DEEPSLATE_BRICK_SLAB(), + DEEPSLATE_BRICK_STAIRS(), + DEEPSLATE_BRICK_WALL(), + DEEPSLATE_COAL_ORE(), + DEEPSLATE_COPPER_ORE(), + DEEPSLATE_DIAMOND_ORE(), + DEEPSLATE_EMERALD_ORE(), + DEEPSLATE_GOLD_ORE(), + DEEPSLATE_IRON_ORE(), + DEEPSLATE_LAPIS_ORE(), + DEEPSLATE_REDSTONE_ORE(), + DEEPSLATE_TILES(), + DEEPSLATE_TILE_SLAB(), + DEEPSLATE_TILE_STAIRS(), + DEEPSLATE_TILE_WALL(), + DRIPSTONE_BLOCK(), + EXPOSED_COPPER(), + EXPOSED_CUT_COPPER(), + EXPOSED_CUT_COPPER_SLAB(), + EXPOSED_CUT_COPPER_STAIRS(), + FLOWERING_AZALEA(), + FLOWERING_AZALEA_LEAVES(), + GLOW_BERRIES(), + GLOW_INK_SAC(), + GLOW_ITEM_FRAME(), + GLOW_LICHEN(), + GLOW_SQUID_SPAWN_EGG(), + GOAT_SPAWN_EGG(), + GRAY_CANDLE(), + GRAY_CANDLE_CAKE(), + GREEN_CANDLE(), + GREEN_CANDLE_CAKE(), + HANGING_ROOTS(), + INFESTED_DEEPSLATE(), + LARGE_AMETHYST_BUD(), + LAVA_CAULDRON(), + LIGHT(), + LIGHTNING_ROD(), + LIGHT_BLUE_CANDLE(), + LIGHT_BLUE_CANDLE_CAKE(), + LIGHT_GRAY_CANDLE(), + LIGHT_GRAY_CANDLE_CAKE(), + LIME_CANDLE(), + LIME_CANDLE_CAKE(), + MAGENTA_CANDLE(), + MAGENTA_CANDLE_CAKE(), + MEDIUM_AMETHYST_BUD(), + MOSS_BLOCK(), + MOSS_CARPET(), + ORANGE_CANDLE(), + ORANGE_CANDLE_CAKE(), + OXIDIZED_COPPER(), + OXIDIZED_CUT_COPPER(), + OXIDIZED_CUT_COPPER_SLAB(), + OXIDIZED_CUT_COPPER_STAIRS(), + PINK_CANDLE(), + PINK_CANDLE_CAKE(), + POINTED_DRIPSTONE(), + POLISHED_DEEPSLATE(), + POLISHED_DEEPSLATE_SLAB(), + POLISHED_DEEPSLATE_STAIRS(), + POLISHED_DEEPSLATE_WALL(), + POTTED_AZALEA_BUSH(), + POTTED_FLOWERING_AZALEA_BUSH(), + POWDER_SNOW(), + POWDER_SNOW_BUCKET(), + POWDER_SNOW_CAULDRON(), + PURPLE_CANDLE(), + PURPLE_CANDLE_CAKE(), + RAW_COPPER(), + RAW_COPPER_BLOCK(), + RAW_GOLD(), + RAW_GOLD_BLOCK(), + RAW_IRON(), + RAW_IRON_BLOCK(), + RED_CANDLE(), + RED_CANDLE_CAKE(), + ROOTED_DIRT(), + SCULK_SENSOR(), + SMALL_AMETHYST_BUD(), + SMALL_DRIPLEAF(), + SMOOTH_BASALT(), + SPORE_BLOSSOM(), + SPYGLASS(), + TINTED_GLASS(), + TUFF(), + WATER_CAULDRON(), + WAXED_COPPER_BLOCK(), + WAXED_CUT_COPPER(), + WAXED_CUT_COPPER_SLAB(), + WAXED_CUT_COPPER_STAIRS(), + WAXED_EXPOSED_COPPER(), + WAXED_EXPOSED_CUT_COPPER(), + WAXED_EXPOSED_CUT_COPPER_SLAB(), + WAXED_EXPOSED_CUT_COPPER_STAIRS(), + WAXED_OXIDIZED_COPPER(), + WAXED_OXIDIZED_CUT_COPPER(), + WAXED_OXIDIZED_CUT_COPPER_SLAB(), + WAXED_OXIDIZED_CUT_COPPER_STAIRS(), + WAXED_WEATHERED_COPPER(), + WAXED_WEATHERED_CUT_COPPER(), + WAXED_WEATHERED_CUT_COPPER_SLAB(), + WAXED_WEATHERED_CUT_COPPER_STAIRS(), + WEATHERED_COPPER(), + WEATHERED_CUT_COPPER(), + WEATHERED_CUT_COPPER_SLAB(), + WEATHERED_CUT_COPPER_STAIRS(), + WHITE_CANDLE(), + WHITE_CANDLE_CAKE(), + YELLOW_CANDLE(), + YELLOW_CANDLE_CAKE(), + + /* 1.16 */ + ANCIENT_DEBRIS(), + BASALT(), + BLACKSTONE(), + BLACKSTONE_STAIRS(), + BLACKSTONE_WALL(), + BLACKSTONE_SLAB(), + BLASTSTONE_SLAB(), + CHAIN(), + CHISELED_NETHER_BRICKS(), + CHISELED_POLISHED_BLACKSTONE(), + CRACKED_NETHER_BRICKS(), + CRACKED_POLISHED_BLACKSTONE_BRICKS(), + CRIMSON_BUTTON(), + CRIMSON_DOOR(), + CRIMSON_FENCE(), + CRIMSON_FENCE_GATE(), + CRIMSON_FUNGUS(), + CRIMSON_HYPHAE(), + CRIMSON_NYLIUM(), + CRIMSON_PLANKS(), + CRIMSON_PRESSURE_PLATE(), + CRIMSON_ROOTS(), + CRIMSON_SIGN(), + CRIMSON_SLAB(), + CRIMSON_STAIRS(), + CRIMSON_STEM(), + CRIMSON_TRAPDOOR(), + CRIMSON_WALL_SIGN(), + CRYING_OBSIDIAN(), + GILDED_BLACKSTONE(), + HOGLIN_SPAWN_EGG(), + LODESTONE(), + MUSIC_DISC_PIGSTEP(), + NETHERITE_AXE(), + NETHERITE_BLOCK(), + NETHERITE_BOOTS(), + NETHERITE_CHESTPLATE(), + NETHERITE_HELMET(), + NETHERITE_HOE(), + NETHERITE_INGOT(), + NETHERITE_LEGGINGS(), + NETHERITE_PICKAXE(), + NETHERITE_SCRAP(), + NETHERITE_SHOVEL(), + NETHERITE_SWORD(), + NETHER_GOLD_ORE(), + NETHER_SPROUTS(), + PIGLIN_BANNER_PATTERN(), + PIGLIN_SPAWN_EGG(), + POLISHED_BASALT(), + POLISHED_BLACKSTONE(), + POLISHED_BLACKSTONE_BRICKS(), + POLISHED_BLACKSTONE_BRICK_SLAB(), + POLISHED_BLACKSTONE_BRICK_STAIRS(), + POLISHED_BLACKSTONE_BRICK_WALL(), + POLISHED_BLACKSTONE_BUTTON(), + POLISHED_BLACKSTONE_PRESSURE_PLATE(), + POLISHED_BLACKSTONE_SLAB(), + POLISHED_BLACKSTONE_STAIRS(), + POLISHED_BLACKSTONE_WALL(), + POTTED_CRIMSON_FUNGUS(), + POTTED_CRIMSON_ROOTS(), + POTTED_WARPED_FUNGUS(), + POTTED_WARPED_ROOTS(), + QUARTZ_BRICKS(), + RESPAWN_ANCHOR(), + SHROOMLIGHT(), + SOUL_CAMPFIRE(), + SOUL_FIRE(), + SOUL_LANTERN(), + SOUL_SOIL(), + SOUL_TORCH(), + SOUL_WALL_TORCH(), + STRIDER_SPAWN_EGG(), + STRIPPED_CRIMSON_HYPHAE(), + STRIPPED_CRIMSON_STEM(), + STRIPPED_WARPED_HYPHAE(), + STRIPPED_WARPED_STEM(), + TARGET(), + TWISTING_VINES(), + TWISTING_VINES_PLANT(), + WARPED_BUTTON(), + WARPED_DOOR(), + WARPED_FENCE(), + WARPED_FENCE_GATE(), + WARPED_FUNGUS(), + WARPED_FUNGUS_ON_A_STICK(), + WARPED_HYPHAE(), + WARPED_NYLIUM(), + WARPED_PLANKS(), + WARPED_PRESSURE_PLATE(), + WARPED_ROOTS(), + WARPED_SIGN(), + WARPED_SLAB(), + WARPED_STAIRS(), + WARPED_STEM(), + WARPED_TRAPDOOR(), + WARPED_WALL_SIGN(), + WARPED_WART_BLOCK(), + WEEPING_VINES(), + WEEPING_VINES_PLANT(), + ZOGLIN_SPAWN_EGG(), + ZOMBIFIED_PIGLIN_SPAWN_EGG(), + + /* 1.15 */ + BEE_SPAWN_EGG(), + BEE_NEST(), + BEEHIVE(), + HONEY_BLOCK(), + HONEY_BOTTLE(), + HONEYCOMB(), + HONEYCOMB_BLOCK(), + + ACACIA_BOAT("BOAT_ACACIA"), + ACACIA_BUTTON(), + ACACIA_DOOR("ACACIA_DOOR_ITEM"), + ACACIA_FENCE(), + ACACIA_FENCE_GATE(), + ACACIA_LEAVES("LEAVES_2", (byte) 0), + ACACIA_LOG("LOG_2", (byte) 0), + ACACIA_PLANKS("WOOD", (byte) 4), + ACACIA_PRESSURE_PLATE(), + ACACIA_SAPLING("SAPLING", (byte) 4), + ACACIA_SIGN(ServerVersion.V1_14, null), + ACACIA_SLAB("WOOD_STEP", (byte) 4), + ACACIA_STAIRS, + ACACIA_TRAPDOOR(), + ACACIA_WALL_SIGN(), + ACACIA_WOOD("LOG_2", (byte) 12), + ACTIVATOR_RAIL, + AIR, + ALLIUM("RED_ROSE", (byte) 2), + ANDESITE("STONE", (byte) 5), + ANDESITE_SLAB(), + ANDESITE_STAIRS(), + ANDESITE_WALL(), + ANVIL("ANVIL", (byte) 0), + APPLE, + ARMOR_STAND(ServerVersion.V1_8, null), + ARROW, + ATTACHED_MELON_STEM("MELON_STEM"), + ATTACHED_PUMPKIN_STEM("PUMPKIN_STEM"), + AZURE_BLUET("RED_ROSE", (byte) 3), + BAKED_POTATO("BAKED_POTATO"), + BAMBOO(), + BAMBOO_SAPLING(), + BARREL(), + BARRIER(), + BAT_SPAWN_EGG("MONSTER_EGG", (byte) 65), + BEACON, + BEDROCK, + BEEF("RAW_BEEF"), + BEETROOT(), // the item + BEETROOTS("BEETROOT_BLOCK"), // the crop + BEETROOT_SEEDS(), + BEETROOT_SOUP(), + BELL(), + BIRCH_BOAT("BOAT_BIRCH"), + BIRCH_BUTTON(), + BIRCH_DOOR("BIRCH_DOOR_ITEM"), + BIRCH_FENCE(), + BIRCH_FENCE_GATE(), + BIRCH_LEAVES("LEAVES", (byte) 2), + BIRCH_LOG("LOG", (byte) 2), + BIRCH_PLANKS("WOOD", (byte) 2), + BIRCH_PRESSURE_PLATE(), + BIRCH_SAPLING("SAPLING", (byte) 2), + BIRCH_SIGN(), + BIRCH_SLAB("WOOD_STEP", (byte) 2), + BIRCH_STAIRS(), + BIRCH_TRAPDOOR(), + BIRCH_WALL_SIGN(), + BIRCH_WOOD("LOG", (byte) 14), + BLACK_BANNER("BANNER", (byte) 0), + BLACK_BED("BED", (byte) 15), + BLACK_CARPET("CARPET", (byte) 15), + BLACK_CONCRETE("CONCRETE", (byte) 15), + BLACK_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 15), + BLACK_DYE(), + BLACK_GLAZED_TERRACOTTA(), + BLACK_SHULKER_BOX(), + BLACK_STAINED_GLASS("STAINED_GLASS", (byte) 15), + BLACK_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 15), + BLACK_TERRACOTTA("STAINED_CLAY", (byte) 15), + BLACK_WALL_BANNER("WALL_BANNER", (byte) 0), + BLACK_WOOL("WOOL", (byte) 15), + BLAST_FURNACE, + BLAZE_POWDER, + BLAZE_ROD, + BLAZE_SPAWN_EGG("MONSTER_EGG", (byte) 61), + BLUE_BANNER("BANNER", (byte) 4), + BLUE_BED("BED", (byte) 11), + BLUE_CARPET("CARPET", (byte) 11), + BLUE_CONCRETE("CONCRETE", (byte) 11), + BLUE_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 11), + BLUE_DYE(), + BLUE_GLAZED_TERRACOTTA(), + BLUE_ICE, + BLUE_ORCHID("RED_ROSE", (byte) 1), + BLUE_SHULKER_BOX(), + BLUE_STAINED_GLASS("STAINED_GLASS", (byte) 11), + BLUE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 11), + BLUE_TERRACOTTA("STAINED_CLAY", (byte) 11), + BLUE_WALL_BANNER("WALL_BANNER", (byte) 4), + BLUE_WOOL("WOOL", (byte) 11), + BONE, + BONE_BLOCK, + BONE_MEAL("INK_SACK", (byte) 15), + BOOK, + BOOKSHELF, + BOW, + BOWL, + BRAIN_CORAL, + BRAIN_CORAL_BLOCK, + BRAIN_CORAL_FAN, + BRAIN_CORAL_WALL_FAN, + BREAD, + BREWING_STAND("BREWING_STAND_ITEM"), + /** + * minecraft:brick (item) + */ + BRICK("CLAY_BRICK"), + /** + * minecraft:brick_block (block) + */ + BRICKS("BRICK"), + BRICK_SLAB("STEP", (byte) 4), + BRICK_STAIRS, + BRICK_WALL, + BROWN_BANNER("BANNER", (byte) 3), + BROWN_BED("BED", (byte) 12), + BROWN_CARPET("CARPET", (byte) 12), + BROWN_CONCRETE("CONCRETE", (byte) 12), + BROWN_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 12), + BROWN_DYE(), + BROWN_GLAZED_TERRACOTTA(), + BROWN_MUSHROOM, + BROWN_MUSHROOM_BLOCK("HUGE_MUSHROOM_1"), + BROWN_SHULKER_BOX(), + BROWN_STAINED_GLASS("STAINED_GLASS", (byte) 12), + BROWN_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 12), + BROWN_TERRACOTTA("STAINED_CLAY", (byte) 12), + BROWN_WALL_BANNER("WALL_BANNER", (byte) 3), + BROWN_WOOL("WOOL", (byte) 12), + BUBBLE_COLUMN, + BUBBLE_CORAL, + BUBBLE_CORAL_BLOCK, + BUBBLE_CORAL_FAN, + BUBBLE_CORAL_WALL_FAN, + BUCKET, + CACTUS, + CAKE, + CAMPFIRE, + CARROT("CARROT_ITEM"), + CARROTS("CARROT"), // totally makes sense, lol + CARROT_ON_A_STICK("CARROT_STICK"), + CARTOGRAPHY_TABLE, + CARVED_PUMPKIN("JACK_O_LANTERN"), + CAT_SPAWN_EGG(), + CAULDRON("CAULDRON_ITEM"), + CAVE_AIR(), + CAVE_SPIDER_SPAWN_EGG("MONSTER_EGG", (byte) 59), + CHAINMAIL_BOOTS, + CHAINMAIL_CHESTPLATE, + CHAINMAIL_HELMET, + CHAINMAIL_LEGGINGS, + CHAIN_COMMAND_BLOCK("COMMAND_CHAIN"), + CHARCOAL("COAL", (byte) 1), + CHEST, + CHEST_MINECART("STORAGE_MINECART"), + CHICKEN("RAW_CHICKEN"), + CHICKEN_SPAWN_EGG("MONSTER_EGG", (byte) 93), + CHIPPED_ANVIL("ANVIL", (byte) 1), + CHISELED_QUARTZ_BLOCK("QUARTZ_BLOCK", (byte) 1), + CHISELED_RED_SANDSTONE("RED_SANDSTONE", (byte) 1), + CHISELED_SANDSTONE("SANDSTONE", (byte) 1), + CHISELED_STONE_BRICKS("SMOOTH_BRICK", (byte) 3), + CHORUS_FLOWER, + CHORUS_FRUIT, + CHORUS_PLANT, + CLAY, + CLAY_BALL, + CLOCK("WATCH"), + COAL, + COAL_BLOCK, + COAL_ORE, + COARSE_DIRT("DIRT", (byte) 1), + COBBLESTONE, + COBBLESTONE_SLAB("STEP", (byte) 3), + COBBLESTONE_STAIRS, + COBBLESTONE_WALL("COBBLE_WALL"), + COBWEB("WEB"), + COCOA, + COCOA_BEANS("INK_SACK", (byte) 3), + COD("RAW_FISH", (byte) 0), + COD_BUCKET, + COD_SPAWN_EGG(), + COMMAND_BLOCK("COMMAND"), + COMMAND_BLOCK_MINECART("COMMAND_MINECART"), + COMPARATOR("REDSTONE_COMPARATOR"), + COMPASS, + COMPOSTER, + CONDUIT, + COOKED_BEEF, + COOKED_CHICKEN, + COOKED_COD("COOKED_FISH", (byte) 0), + COOKED_MUTTON, + COOKED_PORKCHOP("GRILLED_PORK"), + COOKED_RABBIT, + COOKED_SALMON("COOKED_FISH", (byte) 1), + COOKIE, + CORNFLOWER, + COW_SPAWN_EGG("MONSTER_EGG", (byte) 92), + CRACKED_STONE_BRICKS("SMOOTH_BRICK", (byte) 2), + CRAFTING_TABLE("WORKBENCH"), + CREEPER_BANNER_PATTERN, + CREEPER_HEAD("SKULL_ITEM", (byte) 4), + CREEPER_SPAWN_EGG("MONSTER_EGG", (byte) 50), + CREEPER_WALL_HEAD("SKULL", (byte) 4), + CROSSBOW, + CUT_RED_SANDSTONE, + CUT_RED_SANDSTONE_SLAB(), + CUT_SANDSTONE, + CUT_SANDSTONE_SLAB(), + CYAN_BANNER("BANNER", (byte) 6), + CYAN_BED("BED", (byte) 9), + CYAN_CARPET("CARPET", (byte) 9), + CYAN_CONCRETE("CONCRETE", (byte) 9), + CYAN_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 9), + CYAN_DYE("INK_SACK", (byte) 6), + CYAN_GLAZED_TERRACOTTA(), + CYAN_SHULKER_BOX(), + CYAN_STAINED_GLASS("STAINED_GLASS", (byte) 9), + CYAN_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 9), + CYAN_TERRACOTTA("STAINED_CLAY", (byte) 9), + CYAN_WALL_BANNER("WALL_BANNER", (byte) 6), + CYAN_WOOL("WOOL", (byte) 9), + DAMAGED_ANVIL("ANVIL", (byte) 2), + DANDELION("YELLOW_FLOWER"), + DARK_OAK_BOAT("BOAT_DARK_OAK"), + DARK_OAK_BUTTON(), + DARK_OAK_DOOR("DARK_OAK_DOOR_ITEM"), + DARK_OAK_FENCE(), + DARK_OAK_FENCE_GATE(), + DARK_OAK_LEAVES("LEAVES_2", (byte) 1), + DARK_OAK_LOG("LOG_2", (byte) 1), + DARK_OAK_PLANKS("WOOD", (byte) 5), + DARK_OAK_PRESSURE_PLATE(), + DARK_OAK_SAPLING("SAPLING", (byte) 5), + DARK_OAK_SIGN(), + DARK_OAK_SLAB("WOOD_STEP", (byte) 5), + DARK_OAK_STAIRS, + DARK_OAK_TRAPDOOR(), + DARK_OAK_WALL_SIGN(), + DARK_OAK_WOOD("LOG_2", (byte) 13), + DARK_PRISMARINE("PRISMARINE", (byte) 2), + DARK_PRISMARINE_SLAB(), + DARK_PRISMARINE_STAIRS, + DAYLIGHT_DETECTOR, + DEAD_BRAIN_CORAL, + DEAD_BRAIN_CORAL_BLOCK, + DEAD_BRAIN_CORAL_FAN, + DEAD_BRAIN_CORAL_WALL_FAN, + DEAD_BUBBLE_CORAL, + DEAD_BUBBLE_CORAL_BLOCK, + DEAD_BUBBLE_CORAL_FAN, + DEAD_BUBBLE_CORAL_WALL_FAN, + DEAD_BUSH("LONG_GRASS", (byte) 0), + DEAD_FIRE_CORAL, + DEAD_FIRE_CORAL_BLOCK, + DEAD_FIRE_CORAL_FAN, + DEAD_FIRE_CORAL_WALL_FAN, + DEAD_HORN_CORAL, + DEAD_HORN_CORAL_BLOCK, + DEAD_HORN_CORAL_FAN, + DEAD_HORN_CORAL_WALL_FAN, + DEAD_TUBE_CORAL, + DEAD_TUBE_CORAL_BLOCK, + DEAD_TUBE_CORAL_FAN, + DEAD_TUBE_CORAL_WALL_FAN, + DEBUG_STICK, + DETECTOR_RAIL, + DIAMOND, + DIAMOND_AXE, + DIAMOND_BLOCK, + DIAMOND_BOOTS, + DIAMOND_CHESTPLATE, + DIAMOND_HELMET, + DIAMOND_HOE, + DIAMOND_HORSE_ARMOR("DIAMOND_BARDING"), + DIAMOND_LEGGINGS, + DIAMOND_ORE, + DIAMOND_PICKAXE, + DIAMOND_SHOVEL("DIAMOND_SPADE"), + DIAMOND_SWORD, + DIORITE("STONE", (byte) 3), + DIORITE_SLAB(), + DIORITE_STAIRS, + DIORITE_WALL, + DIRT("DIRT", (byte) 0), + DISPENSER, + DOLPHIN_SPAWN_EGG(), + DONKEY_SPAWN_EGG(), + DRAGON_BREATH, + DRAGON_EGG, + DRAGON_HEAD("SKULL_ITEM", (byte) 5), + DRAGON_WALL_HEAD("SKULL", (byte) 5), + DRIED_KELP(), + DRIED_KELP_BLOCK(), + DROPPER, + DROWNED_SPAWN_EGG(), + EGG, + ELDER_GUARDIAN_SPAWN_EGG("MONSTER_EGG", (byte) 4), + ELYTRA, + EMERALD, + EMERALD_BLOCK, + EMERALD_ORE, + ENCHANTED_BOOK, + ENCHANTED_GOLDEN_APPLE("GOLDEN_APPLE", (byte) 1), + ENCHANTING_TABLE("ENCHANTMENT_TABLE"), + ENDERMAN_SPAWN_EGG("MONSTER_EGG", (byte) 58), + ENDERMITE_SPAWN_EGG("MONSTER_EGG", (byte) 67), + ENDER_CHEST, + ENDER_EYE("EYE_OF_ENDER"), + ENDER_PEARL, + END_CRYSTAL, + END_GATEWAY, + END_PORTAL("ENDER_PORTAL"), + END_PORTAL_FRAME("ENDER_PORTAL_FRAME"), + END_ROD, + END_STONE("ENDER_STONE"), + END_STONE_BRICKS("END_BRICKS"), + END_STONE_BRICK_SLAB(), + END_STONE_BRICK_STAIRS, + END_STONE_BRICK_WALL, + EVOKER_SPAWN_EGG("MONSTER_EGG", (byte) 34), + EXPERIENCE_BOTTLE("EXP_BOTTLE"), + FARMLAND("SOIL"), + FEATHER, + FERMENTED_SPIDER_EYE, + FERN("LONG_GRASS", (byte) 2), + FILLED_MAP, + FIRE, + FIREWORK_ROCKET("FIREWORK"), + FIREWORK_STAR("FIREWORK_CHARGE"), + FIRE_CHARGE("FIREBALL"), + FIRE_CORAL, + FIRE_CORAL_BLOCK, + FIRE_CORAL_FAN, + FIRE_CORAL_WALL_FAN, + FISHING_ROD, + FLETCHING_TABLE, + FLINT, + FLINT_AND_STEEL, + FLOWER_BANNER_PATTERN, + FLOWER_POT("FLOWER_POT_ITEM"), + FOX_SPAWN_EGG(), + FROSTED_ICE, + FURNACE, + FURNACE_MINECART("POWERED_MINECART"), + GHAST_SPAWN_EGG("MONSTER_EGG", (byte) 56), + GHAST_TEAR, + GLASS, + GLASS_BOTTLE, + GLASS_PANE("THIN_GLASS"), + GLISTERING_MELON_SLICE("SPECKLED_MELON"), + GLOBE_BANNER_PATTERN, + GLOWSTONE, + GLOWSTONE_DUST, + GOLDEN_APPLE, + GOLDEN_AXE("GOLD_AXE"), + GOLDEN_BOOTS("GOLD_BOOTS"), + GOLDEN_CARROT, + GOLDEN_CHESTPLATE("GOLD_CHESTPLATE"), + GOLDEN_HELMET("GOLD_HELMET"), + GOLDEN_HOE("GOLD_HOE"), + GOLDEN_HORSE_ARMOR("GOLD_BARDING"), + GOLDEN_LEGGINGS("GOLD_LEGGINGS"), + GOLDEN_PICKAXE("GOLD_PICKAXE"), + GOLDEN_SHOVEL("GOLD_SPADE"), + GOLDEN_SWORD("GOLD_SWORD"), + GOLD_BLOCK, + GOLD_INGOT, + GOLD_NUGGET, + GOLD_ORE, + GRANITE("STONE", (byte) 1), + GRANITE_SLAB(), + GRANITE_STAIRS, + GRANITE_WALL, + GRASS("LONG_GRASS", (byte) 1), + GRASS_BLOCK("GRASS"), + DIRT_PATH("GRASS_PATH"), + GRAVEL, + GRAY_BANNER("BANNER", (byte) 8), + GRAY_BED("BED", (byte) 7), + GRAY_CARPET("CARPET", (byte) 7), + GRAY_CONCRETE("CONCRETE", (byte) 7), + GRAY_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 7), + GRAY_DYE("INK_SACK", (byte) 8), + GRAY_GLAZED_TERRACOTTA(), + GRAY_SHULKER_BOX(), + GRAY_STAINED_GLASS("STAINED_GLASS", (byte) 7), + GRAY_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 7), + GRAY_TERRACOTTA("STAINED_CLAY", (byte) 7), + GRAY_WALL_BANNER("WALL_BANNER", (byte) 8), + GRAY_WOOL("WOOL", (byte) 7), + GREEN_BANNER("BANNER", (byte) 2), + GREEN_BED("BED", (byte) 13), + GREEN_CARPET("CARPET", (byte) 13), + GREEN_CONCRETE(ServerVersion.V1_13, "CONCRETE", (byte) 13), + GREEN_CONCRETE_POWDER(ServerVersion.V1_13, "CONCRETE_POWDER", (byte) 13), + GREEN_DYE(ServerVersion.V1_14, "CACTUS_GREEN", ServerVersion.V1_13, "INK_SACK", (byte) 2), + GREEN_GLAZED_TERRACOTTA(), + GREEN_SHULKER_BOX(), + GREEN_STAINED_GLASS("STAINED_GLASS", (byte) 13), + GREEN_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 13), + GREEN_TERRACOTTA("STAINED_CLAY", (byte) 13), + GREEN_WALL_BANNER(ServerVersion.V1_13, "WALL_BANNER", (byte) 2), + GREEN_WOOL("WOOL", (byte) 13), + GRINDSTONE, + GUARDIAN_SPAWN_EGG("MONSTER_EGG", (byte) 68), + GUNPOWDER("SULPHUR"), + HAY_BLOCK, + HEART_OF_THE_SEA, + HEAVY_WEIGHTED_PRESSURE_PLATE("IRON_PLATE"), + HOPPER, + HOPPER_MINECART("HOPPER_MINECART"), + HORN_CORAL, + HORN_CORAL_BLOCK, + HORN_CORAL_FAN, + HORN_CORAL_WALL_FAN, + HORSE_SPAWN_EGG("MONSTER_EGG", (byte) 100), + HUSK_SPAWN_EGG("MONSTER_EGG", (byte) 23), + ICE, + INFESTED_CHISELED_STONE_BRICKS("MONSTER_EGGS", (byte) 5), + INFESTED_COBBLESTONE("MONSTER_EGGS", (byte) 1), + INFESTED_CRACKED_STONE_BRICKS("MONSTER_EGGS", (byte) 4), + INFESTED_MOSSY_STONE_BRICKS("MONSTER_EGGS", (byte) 3), + INFESTED_STONE("MONSTER_EGGS", (byte) 0), + INFESTED_STONE_BRICKS("MONSTER_EGGS", (byte) 2), + INK_SAC("INK_SACK", (byte) 0), + IRON_AXE, + IRON_BARS("IRON_FENCE"), + IRON_BLOCK, + IRON_BOOTS, + IRON_CHESTPLATE, + IRON_DOOR, + IRON_HELMET, + IRON_HOE, + IRON_HORSE_ARMOR("IRON_BARDING"), + IRON_INGOT, + IRON_LEGGINGS, + IRON_NUGGET, + IRON_ORE, + IRON_PICKAXE, + IRON_SHOVEL("IRON_SPADE"), + IRON_SWORD, + IRON_TRAPDOOR(), + ITEM_FRAME, + JACK_O_LANTERN, + JIGSAW, + JUKEBOX, + JUNGLE_BOAT("BOAT_JUNGLE"), + JUNGLE_BUTTON(), + JUNGLE_DOOR("JUNGLE_DOOR_ITEM"), + JUNGLE_FENCE(), + JUNGLE_FENCE_GATE(), + JUNGLE_LEAVES("LEAVES", (byte) 3), + JUNGLE_LOG("LOG", (byte) 3), + JUNGLE_PLANKS("WOOD", (byte) 3), + JUNGLE_PRESSURE_PLATE(), + JUNGLE_SAPLING("SAPLING", (byte) 3), + JUNGLE_SIGN(), + JUNGLE_SLAB("WOOD_STEP", (byte) 3), + JUNGLE_STAIRS("JUNGLE_WOOD_STAIRS"), + JUNGLE_TRAPDOOR(), + JUNGLE_WALL_SIGN(), + JUNGLE_WOOD("LOG", (byte) 15), + KELP, + KELP_PLANT, + KNOWLEDGE_BOOK, + LADDER, + LANTERN, + LAPIS_BLOCK, + LAPIS_LAZULI("INK_SACK", (byte) 4), + LAPIS_ORE, + LARGE_FERN("DOUBLE_PLANT", (byte) 3), + LAVA, + LAVA_BUCKET, + LEAD("LEASH"), + LEATHER, + LEATHER_BOOTS, + LEATHER_CHESTPLATE, + LEATHER_HELMET, + LEATHER_HORSE_ARMOR(), + LEATHER_LEGGINGS, + LECTERN, + LEVER, + LIGHT_BLUE_BANNER("BANNER", (byte) 12), + LIGHT_BLUE_BED("BED", (byte) 3), + LIGHT_BLUE_CARPET("CARPET", (byte) 3), + LIGHT_BLUE_CONCRETE("CONCRETE", (byte) 3), + LIGHT_BLUE_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 3), + LIGHT_BLUE_DYE("INK_SACK", (byte) 12), + LIGHT_BLUE_GLAZED_TERRACOTTA(), + LIGHT_BLUE_SHULKER_BOX(), + LIGHT_BLUE_STAINED_GLASS("STAINED_GLASS", (byte) 3), + LIGHT_BLUE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 3), + LIGHT_BLUE_TERRACOTTA("STAINED_CLAY", (byte) 3), + LIGHT_BLUE_WALL_BANNER("WALL_BANNER", (byte) 12), + LIGHT_BLUE_WOOL("WOOL", (byte) 3), + LIGHT_GRAY_BANNER("BANNER", (byte) 7), + LIGHT_GRAY_BED("BED", (byte) 8), + LIGHT_GRAY_CARPET("CARPET", (byte) 8), + LIGHT_GRAY_CONCRETE("CONCRETE", (byte) 8), + LIGHT_GRAY_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 8), + LIGHT_GRAY_DYE("INK_SACK", (byte) 7), + LIGHT_GRAY_GLAZED_TERRACOTTA("SILVER_GLAZED_TERRACOTTA"), + LIGHT_GRAY_SHULKER_BOX(ServerVersion.V1_11, "SILVER_SHULKER_BOX"), + LIGHT_GRAY_STAINED_GLASS("STAINED_GLASS", (byte) 8), + LIGHT_GRAY_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 8), // this is nearly invisible in a chest, lol + LIGHT_GRAY_TERRACOTTA("STAINED_CLAY", (byte) 8), + LIGHT_GRAY_WALL_BANNER("WALL_BANNER", (byte) 7), + LIGHT_GRAY_WOOL("WOOL", (byte) 8), + LIGHT_WEIGHTED_PRESSURE_PLATE("GOLD_PLATE"), + LILAC("LONG_GRASS", (byte) 1), + LILY_OF_THE_VALLEY, + LILY_PAD("WATER_LILY"), + LIME_BANNER("BANNER", (byte) 10), + LIME_BED("BED", (byte) 5), + LIME_CARPET("CARPET", (byte) 5), + LIME_CONCRETE("CONCRETE", (byte) 5), + LIME_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 5), + LIME_DYE("INK_SACK", (byte) 10), + LIME_GLAZED_TERRACOTTA(), + LIME_SHULKER_BOX(), + LIME_STAINED_GLASS("STAINED_GLASS", (byte) 5), + LIME_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 5), + LIME_TERRACOTTA("STAINED_CLAY", (byte) 5), + LIME_WALL_BANNER("WALL_BANNER", (byte) 10), + LIME_WOOL("WOOL", (byte) 5), + LINGERING_POTION, + LLAMA_SPAWN_EGG("MONSTER_EGG", (byte) 103), + LOOM, + MAGENTA_BANNER("BANNER", (byte) 13), + MAGENTA_BED("BED", (byte) 2), + MAGENTA_CARPET("CARPET", (byte) 2), + MAGENTA_CONCRETE("CONCRETE", (byte) 2), + MAGENTA_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 2), + MAGENTA_DYE("INK_SACK", (byte) 13), + MAGENTA_GLAZED_TERRACOTTA(), + MAGENTA_SHULKER_BOX(), + MAGENTA_STAINED_GLASS("STAINED_GLASS", (byte) 2), + MAGENTA_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 2), + MAGENTA_TERRACOTTA("STAINED_CLAY", (byte) 2), + MAGENTA_WALL_BANNER("WALL_BANNER", (byte) 13), + MAGENTA_WOOL("WOOL", (byte) 2), + MAGMA_BLOCK("MAGMA"), + MAGMA_CREAM, + MAGMA_CUBE_SPAWN_EGG("MONSTER_EGG", (byte) 62), + MAP, + MELON("MELON_BLOCK"), + MELON_SEEDS, + MELON_SLICE("MELON"), + MELON_STEM, + MILK_BUCKET, + MINECART, + MOJANG_BANNER_PATTERN, + MOOSHROOM_SPAWN_EGG("MONSTER_EGG", (byte) 96), + MOSSY_COBBLESTONE, + MOSSY_COBBLESTONE_SLAB(), + MOSSY_COBBLESTONE_STAIRS, + MOSSY_COBBLESTONE_WALL, + MOSSY_STONE_BRICKS("SMOOTH_BRICK", (byte) 1), + MOSSY_STONE_BRICK_SLAB(), + MOSSY_STONE_BRICK_STAIRS, + MOSSY_STONE_BRICK_WALL, + MOVING_PISTON("PISTON_MOVING_PIECE"), + MULE_SPAWN_EGG("MONSTER_EGG", (byte) 32), + MUSHROOM_STEM("HUGE_MUSHROOM_1", (byte) 10), // also ("HUGE_MUSHROOM_2", (byte) 10) + MUSHROOM_STEW("MUSHROOM_SOUP"), + MUSIC_DISC_11("RECORD_11"), + MUSIC_DISC_13("GOLD_RECORD"), + MUSIC_DISC_BLOCKS("RECORD_3"), + MUSIC_DISC_CAT("GREEN_RECORD"), + MUSIC_DISC_CHIRP("RECORD_4"), + MUSIC_DISC_FAR("RECORD_5"), + MUSIC_DISC_MALL("RECORD_6"), + MUSIC_DISC_MELLOHI("RECORD_7"), + MUSIC_DISC_STAL("RECORD_8"), + MUSIC_DISC_STRAD("RECORD_9"), + MUSIC_DISC_WAIT("RECORD_12"), + MUSIC_DISC_WARD("RECORD_10"), + MUTTON, + MYCELIUM("MYCEL"), + NAME_TAG, + NAUTILUS_SHELL, + NETHERRACK, + NETHER_BRICK("NETHER_BRICK_ITEM"), + NETHER_BRICKS("NETHER_BRICK"), + NETHER_BRICK_FENCE("NETHER_FENCE"), + NETHER_BRICK_SLAB("STEP", (byte) 6), + NETHER_BRICK_STAIRS, + NETHER_BRICK_WALL, + NETHER_PORTAL("PORTAL"), + NETHER_QUARTZ_ORE("QUARTZ_ORE"), + NETHER_STAR, + NETHER_WART("NETHER_STALK"), + NETHER_WART_BLOCK, + NOTE_BLOCK, + OAK_BOAT("BOAT"), + OAK_BUTTON("WOOD_BUTTON"), + OAK_DOOR("WOOD_DOOR"), // TODO: legacy block id is WOODEN_DOOR + OAK_FENCE("FENCE"), + OAK_FENCE_GATE("FENCE_GATE"), + OAK_LEAVES("LEAVES", (byte) 0), + OAK_LOG("LOG", (byte) 0), + OAK_PLANKS("WOOD", (byte) 0), + OAK_PRESSURE_PLATE("WOOD_PLATE"), + OAK_SAPLING("SAPLING", (byte) 0), + OAK_SIGN(ServerVersion.V1_14, "SIGN"), + OAK_SLAB("WOOD_STEP", (byte) 0), + OAK_STAIRS("WOOD_STAIRS"), + OAK_TRAPDOOR("TRAP_DOOR"), + OAK_WALL_SIGN(ServerVersion.V1_14, "WALL_SIGN"), + OAK_WOOD("LOG", (byte) 12), + OBSERVER, + OBSIDIAN, + OCELOT_SPAWN_EGG("MONSTER_EGG", (byte) 98), + ORANGE_BANNER("BANNER", (byte) 14), + ORANGE_BED("BED", (byte) 1), + ORANGE_CARPET("CARPET", (byte) 1), + ORANGE_CONCRETE("CONCRETE", (byte) 1), + ORANGE_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 1), + ORANGE_DYE("INK_SACK", (byte) 14), + ORANGE_GLAZED_TERRACOTTA(), + ORANGE_SHULKER_BOX(), + ORANGE_STAINED_GLASS("STAINED_GLASS", (byte) 1), + ORANGE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 1), + ORANGE_TERRACOTTA("STAINED_CLAY", (byte) 1), + ORANGE_TULIP("RED_ROSE", (byte) 5), + ORANGE_WALL_BANNER("WALL_BANNER", (byte) 14), + ORANGE_WOOL("WOOL", (byte) 1), + OXEYE_DAISY("RED_ROSE", (byte) 8), + PACKED_ICE, + PAINTING, + PANDA_SPAWN_EGG(), + PAPER, + PARROT_SPAWN_EGG("MONSTER_EGG", (byte) 105), + PEONY("DOUBLE_PLANT", (byte) 5), + PETRIFIED_OAK_SLAB("WOOD_STEP", (byte) 0), + PHANTOM_MEMBRANE(), + PHANTOM_SPAWN_EGG(), + PIG_SPAWN_EGG("MONSTER_EGG", (byte) 90), + PILLAGER_SPAWN_EGG(), + PINK_BANNER("BANNER", (byte) 9), + PINK_BED("BED", (byte) 6), + PINK_CARPET("CARPET", (byte) 6), + PINK_CONCRETE("CONCRETE", (byte) 6), + PINK_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 6), + PINK_DYE("INK_SACK", (byte) 9), + PINK_GLAZED_TERRACOTTA(), + PINK_SHULKER_BOX(), + PINK_STAINED_GLASS("STAINED_GLASS", (byte) 6), + PINK_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 6), + PINK_TERRACOTTA("STAINED_CLAY", (byte) 6), + PINK_TULIP("RED_ROSE", (byte) 7), + PINK_WALL_BANNER("WALL_BANNER", (byte) 9), + PINK_WOOL("WOOL", (byte) 6), + PISTON("PISTON_BASE"), + PISTON_HEAD("PISTON_EXTENSION"), + PLAYER_HEAD("SKULL_ITEM", (byte) 3), + PLAYER_WALL_HEAD("SKULL", (byte) 3), + PODZOL("DIRT", (byte) 2), + POISONOUS_POTATO, + POLAR_BEAR_SPAWN_EGG("MONSTER_EGG", (byte) 102), + POLISHED_ANDESITE("STONE", (byte) 6), + POLISHED_ANDESITE_SLAB(), + POLISHED_ANDESITE_STAIRS, + POLISHED_DIORITE("STONE", (byte) 4), + POLISHED_DIORITE_SLAB(), + POLISHED_DIORITE_STAIRS, + POLISHED_GRANITE("STONE", (byte) 2), + POLISHED_GRANITE_SLAB(), + POLISHED_GRANITE_STAIRS, + POPPED_CHORUS_FRUIT, + POPPY("RED_ROSE", (byte) 0), + PORKCHOP("PORK"), + POTATO("POTATO_ITEM"), + POTATOES("POTATO"), + POTION, + POTTED_ACACIA_SAPLING, + POTTED_ALLIUM, + POTTED_AZURE_BLUET, + POTTED_BAMBOO, + POTTED_BIRCH_SAPLING, + POTTED_BLUE_ORCHID, + POTTED_BROWN_MUSHROOM, + POTTED_CACTUS, + POTTED_CORNFLOWER, + POTTED_DANDELION, + POTTED_DARK_OAK_SAPLING, + POTTED_DEAD_BUSH, + POTTED_FERN, + POTTED_JUNGLE_SAPLING, + POTTED_LILY_OF_THE_VALLEY, + POTTED_OAK_SAPLING, + POTTED_ORANGE_TULIP, + POTTED_OXEYE_DAISY, + POTTED_PINK_TULIP, + POTTED_POPPY, + POTTED_RED_MUSHROOM, + POTTED_RED_TULIP, + POTTED_SPRUCE_SAPLING, + POTTED_WHITE_TULIP, + POTTED_WITHER_ROSE, + POWERED_RAIL, + PRISMARINE("PRISMARINE", (byte) 0), + PRISMARINE_BRICKS("PRISMARINE", (byte) 1), + PRISMARINE_BRICK_SLAB(), + PRISMARINE_BRICK_STAIRS, + PRISMARINE_CRYSTALS, + PRISMARINE_SHARD, + PRISMARINE_SLAB(), + PRISMARINE_STAIRS, + PRISMARINE_WALL, + PUFFERFISH("RAW_FISH", (byte) 3), + PUFFERFISH_BUCKET, + PUFFERFISH_SPAWN_EGG(), + PUMPKIN, + PUMPKIN_PIE, + PUMPKIN_SEEDS, + PUMPKIN_STEM, + PURPLE_BANNER("BANNER", (byte) 5), + PURPLE_BED("BED", (byte) 10), + PURPLE_CARPET("CARPET", (byte) 10), + PURPLE_CONCRETE("CONCRETE", (byte) 10), + PURPLE_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 10), + PURPLE_DYE("INK_SACK", (byte) 5), + PURPLE_GLAZED_TERRACOTTA(), + PURPLE_SHULKER_BOX(), + PURPLE_STAINED_GLASS("STAINED_GLASS", (byte) 10), + PURPLE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 10), + PURPLE_TERRACOTTA("STAINED_CLAY", (byte) 10), + PURPLE_WALL_BANNER("WALL_BANNER", (byte) 5), + PURPLE_WOOL("WOOL", (byte) 10), + PURPUR_BLOCK, + PURPUR_PILLAR, + PURPUR_SLAB(), + PURPUR_STAIRS, + QUARTZ, + QUARTZ_BLOCK("QUARTZ_BLOCK", (byte) 0), + QUARTZ_PILLAR("QUARTZ_BLOCK", (byte) 2), + QUARTZ_SLAB("STEP", (byte) 7), + QUARTZ_STAIRS, + RABBIT, + RABBIT_FOOT, + RABBIT_HIDE, + RABBIT_SPAWN_EGG("MONSTER_EGG", (byte) 101), + RABBIT_STEW, + RAIL("RAILS"), + RAVAGER_SPAWN_EGG(), + REDSTONE, + REDSTONE_BLOCK, + REDSTONE_LAMP("REDSTONE_LAMP_OFF"), + REDSTONE_ORE, + REDSTONE_TORCH("REDSTONE_TORCH_ON"), + REDSTONE_WALL_TORCH, + REDSTONE_WIRE, + RED_BANNER("BANNER", (byte) 1), + RED_BED("BED", (byte) 14), + RED_CARPET("CARPET", (byte) 14), + RED_CONCRETE("CONCRETE", (byte) 14), + RED_CONCRETE_POWDER("CONCRETE_POWDER", (byte) 14), + RED_DYE(ServerVersion.V1_14, "ROSE_RED", ServerVersion.V1_13, "INK_SACK", (byte) 1), + RED_GLAZED_TERRACOTTA(), + RED_MUSHROOM, + RED_MUSHROOM_BLOCK("HUGE_MUSHROOM_2"), + RED_NETHER_BRICKS("RED_NETHER_BRICK"), + RED_NETHER_BRICK_SLAB(), + RED_NETHER_BRICK_STAIRS, + RED_NETHER_BRICK_WALL, + RED_SAND("SAND", (byte) 1), + RED_SANDSTONE("RED_SANDSTONE", (byte) 0), + RED_SANDSTONE_SLAB("STONE_SLAB2", (byte) 0), + RED_SANDSTONE_STAIRS, + RED_SANDSTONE_WALL, + RED_SHULKER_BOX(), + RED_STAINED_GLASS("STAINED_GLASS", (byte) 14), + RED_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 14), + RED_TERRACOTTA("STAINED_CLAY", (byte) 14), + RED_TULIP("RED_ROSE", (byte) 4), + RED_WALL_BANNER("WALL_BANNER", (byte) 1), + RED_WOOL("WOOL", (byte) 14), + REPEATER("DIODE"), + REPEATING_COMMAND_BLOCK("COMMAND_REPEATING"), + ROSE_BUSH("DOUBLE_PLANT", (byte) 4), + ROTTEN_FLESH, + SADDLE, + SALMON("RAW_FISH", (byte) 1), + SALMON_BUCKET, + SALMON_SPAWN_EGG(), + SAND("SAND", (byte) 0), + SANDSTONE("SANDSTONE", (byte) 0), + SANDSTONE_SLAB("STEP", (byte) 1), + SANDSTONE_STAIRS, + SANDSTONE_WALL, + SCAFFOLDING, + SCUTE, + SEAGRASS, + SEA_LANTERN, + SEA_PICKLE, + SHEARS, + SHEEP_SPAWN_EGG("MONSTER_EGG", (byte) 91), + SHIELD, + SHULKER_BOX(), + SHULKER_SHELL(), + SHULKER_SPAWN_EGG("MONSTER_EGG", (byte) 69), + SILVERFISH_SPAWN_EGG("MONSTER_EGG", (byte) 60), + SKELETON_HORSE_SPAWN_EGG("MONSTER_EGG", (byte) 28), + SKELETON_SKULL("SKULL_ITEM", (byte) 0), + SKELETON_SPAWN_EGG("MONSTER_EGG", (byte) 51), + SKELETON_WALL_SKULL("SKULL", (byte) 0), + SKULL_BANNER_PATTERN, + SLIME_BALL, + SLIME_BLOCK, + SLIME_SPAWN_EGG("MONSTER_EGG", (byte) 55), + SMITHING_TABLE, + SMOKER, + SMOOTH_QUARTZ, + SMOOTH_QUARTZ_SLAB(), + SMOOTH_QUARTZ_STAIRS, + SMOOTH_RED_SANDSTONE("RED_SANDSTONE", (byte) 2), + SMOOTH_RED_SANDSTONE_SLAB("STONE_SLAB2", (byte) 0), + SMOOTH_RED_SANDSTONE_STAIRS, + SMOOTH_SANDSTONE("SANDSTONE", (byte) 2), + SMOOTH_SANDSTONE_SLAB(), + SMOOTH_SANDSTONE_STAIRS, + SMOOTH_STONE, + SMOOTH_STONE_SLAB(), + SNOW, + SNOWBALL("SNOW_BALL"), + SNOW_BLOCK, + SOUL_SAND, + SPAWNER("MOB_SPAWNER"), + SPECTRAL_ARROW, + SPIDER_EYE, + SPIDER_SPAWN_EGG("MONSTER_EGG", (byte) 52), + SPLASH_POTION("POTION"), // legacy uses data to make the specific potions and splash variants + SPONGE("SPONGE", (byte) 0), + SPRUCE_BOAT("BOAT_SPRUCE"), + SPRUCE_BUTTON(), + SPRUCE_DOOR("SPRUCE_DOOR_ITEM"), + SPRUCE_FENCE(), + SPRUCE_FENCE_GATE(), + SPRUCE_LEAVES("LEAVES", (byte) 1), + SPRUCE_LOG("LOG", (byte) 1), + SPRUCE_PLANKS("WOOD", (byte) 1), + SPRUCE_PRESSURE_PLATE(), + SPRUCE_SAPLING("SAPLING", (byte) 1), + SPRUCE_SIGN(), + SPRUCE_SLAB("WOOD_STEP", (byte) 1), + SPRUCE_STAIRS("SPRUCE_WOOD_STAIRS"), + SPRUCE_TRAPDOOR(), + SPRUCE_WALL_SIGN(), + SPRUCE_WOOD("LOG", (byte) 13), + SQUID_SPAWN_EGG("MONSTER_EGG", (byte) 94), + STICK, + STICKY_PISTON("PISTON_STICKY_BASE"), + STONE(), + STONECUTTER, + STONE_AXE, + /** + * minecraft:stonebrick + */ + STONE_BRICKS("SMOOTH_BRICK", (byte) 0), + STONE_BRICK_SLAB("STEP", (byte) 5), + STONE_BRICK_STAIRS("SMOOTH_STAIRS"), + STONE_BRICK_WALL(), + STONE_BUTTON, + STONE_HOE, + STONE_PICKAXE, + STONE_PRESSURE_PLATE("STONE_PLATE"), + STONE_SHOVEL("STONE_SPADE"), + STONE_SLAB("STEP", (byte) 0), + STONE_STAIRS(), + STONE_SWORD, + STRAY_SPAWN_EGG("MONSTER_EGG", (byte) 6), + STRING, + STRIPPED_ACACIA_LOG, + STRIPPED_ACACIA_WOOD, + STRIPPED_BIRCH_LOG, + STRIPPED_BIRCH_WOOD, + STRIPPED_DARK_OAK_LOG, + STRIPPED_DARK_OAK_WOOD, + STRIPPED_JUNGLE_LOG, + STRIPPED_JUNGLE_WOOD, + STRIPPED_OAK_LOG, + STRIPPED_OAK_WOOD, + STRIPPED_SPRUCE_LOG, + STRIPPED_SPRUCE_WOOD, + STRUCTURE_BLOCK, + STRUCTURE_VOID, + SUGAR, + SUGAR_CANE, + SUNFLOWER("DOUBLE_PLANT", (byte) 0), + SUSPICIOUS_STEW, + SWEET_BERRIES, + SWEET_BERRY_BUSH, + TALL_GRASS("DOUBLE_PLANT", (byte) 2), + TALL_SEAGRASS, + TERRACOTTA("HARD_CLAY"), + TIPPED_ARROW, + TNT, + TNT_MINECART("EXPLOSIVE_MINECART"), + TORCH, + TOTEM_OF_UNDYING("TOTEM"), + TRADER_LLAMA_SPAWN_EGG(), + TRAPPED_CHEST, + TRIDENT, + TRIPWIRE, + TRIPWIRE_HOOK, + TROPICAL_FISH("RAW_FISH", (byte) 2), // (aka clownfish) + TROPICAL_FISH_BUCKET, + TROPICAL_FISH_SPAWN_EGG(), + TUBE_CORAL, + TUBE_CORAL_BLOCK, + TUBE_CORAL_FAN, + TUBE_CORAL_WALL_FAN, + TURTLE_EGG, + TURTLE_HELMET, + TURTLE_SPAWN_EGG(), + VEX_SPAWN_EGG("MONSTER_EGG", (byte) 35), + VILLAGER_SPAWN_EGG("MONSTER_EGG", (byte) 120), + VINDICATOR_SPAWN_EGG("MONSTER_EGG", (byte) 36), + VINE, + VOID_AIR, + WALL_TORCH, + WANDERING_TRADER_SPAWN_EGG(), + WATER, + WATER_BUCKET, + WET_SPONGE("SPONGE", (byte) 1), + WHEAT, + WHEAT_SEEDS("SEEDS"), + WHITE_BANNER("BANNER", (byte) 15), + WHITE_BED("BED", (byte) 0), + WHITE_CARPET("CARPET", (byte) 0), + WHITE_CONCRETE("CONCRETE", (byte) 0), + WHITE_CONCRETE_POWDER("CONCRETE", (byte) 0), + WHITE_DYE("INK_SACK", (byte) 15), + WHITE_GLAZED_TERRACOTTA(), + WHITE_SHULKER_BOX(), + WHITE_STAINED_GLASS("STAINED_GLASS", (byte) 0), + WHITE_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 0), + WHITE_TERRACOTTA("STAINED_CLAY", (byte) 0), + WHITE_TULIP("RED_ROSE", (byte) 6), + WHITE_WALL_BANNER("WALL_BANNER", (byte) 15), + WHITE_WOOL("WOOL", (byte) 0), + WITCH_SPAWN_EGG("MONSTER_EGG", (byte) 66), + WITHER_ROSE, + WITHER_SKELETON_SKULL("SKULL_ITEM", (byte) 1), + WITHER_SKELETON_SPAWN_EGG("MONSTER_EGG", (byte) 5), + WITHER_SKELETON_WALL_SKULL("SKULL", (byte) 1), + WOLF_SPAWN_EGG("MONSTER_EGG", (byte) 95), + WOODEN_AXE("WOOD_AXE"), + WOODEN_HOE("WOOD_HOE"), + WOODEN_PICKAXE("WOOD_PICKAXE"), + WOODEN_SHOVEL("WOOD_SPADE"), + WOODEN_SWORD("WOOD_SWORD"), + WRITABLE_BOOK("BOOK_AND_QUILL"), + WRITTEN_BOOK, + YELLOW_BANNER("BANNER", (byte) 11), + YELLOW_BED("BED", (byte) 4), + YELLOW_CARPET("CARPET", (byte) 4), + YELLOW_CONCRETE("CONCRETE", (byte) 4), + YELLOW_CONCRETE_POWDER("CONCRETE", (byte) 4), + YELLOW_DYE(ServerVersion.V1_14, "DANDELION_YELLOW", ServerVersion.V1_13, "INK_SACK", (byte) 11), + YELLOW_GLAZED_TERRACOTTA(), + YELLOW_SHULKER_BOX(), + YELLOW_STAINED_GLASS("STAINED_GLASS", (byte) 4), + YELLOW_STAINED_GLASS_PANE("STAINED_GLASS_PANE", (byte) 4), + YELLOW_TERRACOTTA("STAINED_CLAY", (byte) 4), + YELLOW_WALL_BANNER("WALL_BANNER", (byte) 11), + YELLOW_WOOL("WOOL", (byte) 4), + ZOMBIE_HEAD("SKULL_ITEM", (byte) 2), + ZOMBIE_HORSE_SPAWN_EGG("MONSTER_EGG", (byte) 29), + ZOMBIE_PIGMAN_SPAWN_EGG("MONSTER_EGG", (byte) 57), + ZOMBIE_SPAWN_EGG("MONSTER_EGG", (byte) 54), + ZOMBIE_VILLAGER_SPAWN_EGG("MONSTER_EGG", (byte) 27), + ZOMBIE_WALL_HEAD("SKULL", (byte) 2), + ; + + private final String modern, modern2, legacy; + private final LegacyMaterialAnalouge compatibleMaterial; + private final LegacyMaterialBlockType legacyBlockMaterial; + private final boolean legacyRequiresData; + // some materials (I'm looking at you, GREEN_DYE) have changed ID more than once + // minVersion is the min for modern, and minVersion2 is min to use legacyCompat1 + private final ServerVersion minVersion, minVersion2; + private final byte legacyData; + private final Material material; + private final Byte data; + // quick test to see if our version is < 1.13 + protected static final boolean useLegacy = ServerVersion.isServerVersionBelow(ServerVersion.V1_13); + // map to speed up name->material lookups + private static final Map lookupMap = new HashMap(); + + static { + for (CompatibleMaterial m : values()) { + if (m.isRecycled()) { + lookupMap.put(m.legacy, m); + continue; + } + lookupMap.put(m.name(), m); + if (!m.usesCompatibility()) { + lookupMap.put(m.material + ":" + (m.data == null ? "" : m.data), m); + } + } + for (CompatibleMaterial m : values()) { + if (!m.usesCompatibility()) { + if (m.legacy != null && !lookupMap.containsKey(m.legacy)) { + lookupMap.put(m.legacy, m); + } + if (m.modern2 != null && !lookupMap.containsKey(m.modern2)) { + lookupMap.put(m.modern2, m); + } + if (m.legacyBlockMaterial != null && !lookupMap.containsKey(m.legacyBlockMaterial.blockMaterialName)) { + lookupMap.put(m.legacyBlockMaterial.blockMaterialName, m); + } + if (m.legacyBlockMaterial != null && !lookupMap.containsKey(m.legacyBlockMaterial.alternateBlockMaterialName)) { + lookupMap.put(m.legacyBlockMaterial.alternateBlockMaterialName, m); + } + } + } + } + + CompatibleMaterial() { + this(ServerVersion.UNKNOWN, null, null); + } + + CompatibleMaterial(String legacy) { + this(ServerVersion.V1_13, null, null, legacy, null); + } + + CompatibleMaterial(String legacy, byte legacyData) { + this(ServerVersion.V1_13, null, null, legacy, legacyData); + } + + CompatibleMaterial(ServerVersion modernMinimum, String legacy) { + this(modernMinimum, null, null, legacy, null); + } + + CompatibleMaterial(ServerVersion modernMinimum, String legacy, Byte legacyData) { + this(modernMinimum, null, null, legacy, legacyData); + } + + CompatibleMaterial(ServerVersion modernMinimum, String modern2, ServerVersion modern2Minimum, String legacyMaterial, Byte legacyData) { + this.modern = name(); + this.modern2 = modern2; + this.minVersion = modernMinimum; + this.minVersion2 = modern2Minimum; + this.legacy = legacyMaterial; + this.legacyData = legacyData == null ? 0 : legacyData; + this.legacyRequiresData = legacyData != null; + this.compatibleMaterial = LegacyMaterialAnalouge.lookupAnalouge(modern); + + if (compatibleMaterial != null && ServerVersion.isServerVersionBelow(compatibleMaterial.versionLessThan)) { + // server older than this item: use a proxy + material = compatibleMaterial.material; + data = compatibleMaterial.data; + } else if (ServerVersion.isServerVersionAtLeast(minVersion)) { + material = Material.getMaterial(modern); + data = null; + } else if (modern2 != null && ServerVersion.isServerVersionAtLeast(minVersion2)) { + material = Material.getMaterial(modern2); + data = null; + } else if (legacyMaterial != null && (compatibleMaterial == null || ServerVersion.isServerVersionAtLeast(compatibleMaterial.versionLessThan))) { + // we're using a server that has the legacy value available + material = Material.getMaterial(legacyMaterial); + data = legacyRequiresData ? this.legacyData : null; + } else if (compatibleMaterial != null) { + // no match: use a proxy + material = compatibleMaterial.material; + data = compatibleMaterial.data; + } else { + material = null; + data = null; + } + + if (material != null && ServerVersion.isServerVersionBelow(ServerVersion.V1_13) && (compatibleMaterial == null || material != compatibleMaterial.material)) { + legacyBlockMaterial = LegacyMaterialBlockType.getMaterial(this.modern); + } else { + legacyBlockMaterial = null; + } + } + + /** + * @return the Bukkit Material for this material + */ + public Material getMaterial() { + return material; + } + + /** + * @return the Bukkit Material required to create a block + */ + public Material getBlockMaterial() { + return legacyBlockMaterial != null ? legacyBlockMaterial.getBlockMaterial() : (isBlock() ? material : AIR.material); + } + + /** + * @return an item that resembles this material for the current server version + */ + public ItemStack getItem() { + return getItem(1); + } + + /** + * @param amount the amount to return + * + * @return an item that resembles this material for the current server version + */ + public ItemStack getItem(int amount) { + if (usesCompatibility()) { + return compatibleMaterial.getItem(); + } + return data != null ? new ItemStack(material, amount, data) : new ItemStack(material); + } + + /** + * Does this material need to use a legacy fallback? + * + * @return + */ + public boolean usesLegacy() { + return legacy != null && ServerVersion.isServerVersionBelow(minVersion); + } + + /** + * Does this material need to use a fallback item on this server? + * + * @return + */ + public boolean usesCompatibility() { + return compatibleMaterial != null && material == compatibleMaterial.material; + //return compatibleMaterial != null && ServerVersion.isServerVersionBelow(compatibleMaterial.versionLessThan); + } + + /** + * Is this item reused in later versions of Minecraft? + * + * @return + */ + public boolean isRecycled() { + return usesLegacy() && this == CompatibleMaterial.GRASS; + } + + /** + * Get the legacy data value for this material if there is one, or -1 if + * none + * + * @return + */ + public byte getData() { + return data != null ? data : -1; + } + + /** + * Check if current material requires a data value. + * + * @return true if server is legacy and this item requires data to be defined. + */ + public boolean usesData() { + return data != null; + } + + /** + * Lookup a Material by its modern id name.
+ * This also can grab materials by their legacy, but only if there is no + * modern material by that name. + * + * @param name item to lookup + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(String name) { + return name == null ? null : lookupMap.get(name.toUpperCase()); + } + + /** + * Lookup a Material by its modern id name.
+ * This also can grab materials by their legacy, but only if there is no + * modern material by that name. + * + * @param name item to lookup + * @param def default item if this is not a valid material + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(String name, CompatibleMaterial def) { + return name == null ? def : lookupMap.getOrDefault(name.toUpperCase(), def); + } + + /** + * Lookup a Material by bukkit material. + * + * @param mat item to lookup + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(Material mat) { + if (mat == null) + return null; + if (useLegacy) { + CompatibleMaterial compatibleMaterial = lookupMap.get(mat.name() + ":0"); + if (compatibleMaterial != null) + return compatibleMaterial; + } + return lookupMap.get(mat.name()); + } + + /** + * Lookup a Material by Itemstack. + * + * @param item item to lookup + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(ItemStack item) { + if (item == null) { + return null; + } + String key = item.getType() + ":"; + CompatibleMaterial m = lookupMap.get(key); + return m != null ? m : lookupMap.get(key + item.getDurability()); + } + + /** + * Lookup a Material by Block, corrected for legacy + * + * @param block block to check + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(Block block) { + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { // Flattening + return CompatibleMaterial.getMaterialFromNewBlock(block); + } else { // Pre-Flattening + if (block != null) { + if (block.getData() != 0) { + for (CompatibleMaterial cm : CompatibleMaterial.values()) { + if (cm.isValidItem() && !cm.usesCompatibility() && cm.getMaterial() != null && cm.getMaterial().equals(block.getType())) { + if (cm.getData() == block.getData()) { + return cm; + } + } + } + } + return CompatibleMaterial.getMaterialFromNewBlock(block); + } + } + return null; + } + + private static Method methodGetBlockData; + + static { + if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { + try { + methodGetBlockData = FallingBlock.class.getDeclaredMethod("getBlockData"); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + } + + /** + * Lookup a Material by FallingBlock, corrected for legacy + * + * @param block falling block to check + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(FallingBlock block) { + if (block == null) return null; + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { + return getMaterial(block.getBlockData().getMaterial()); + } else { + try { + return getMaterial(block.getMaterial(), (byte) methodGetBlockData.invoke(block)); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * Lookup a Material by Material and data, corrected for legacy + * + * @param mat material to check + * @param data data of the block + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getMaterial(Material mat, byte data) { + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { // Flattening + return CompatibleMaterial.getMaterial(mat); + } else { // Pre-Flattening + if (mat != null) { + if (data != 0) { + for (CompatibleMaterial cm : CompatibleMaterial.values()) { + if (cm.getMaterial() != null + && cm.getMaterial().equals(mat)) { + if (cm.getData() == data) { + return cm; + } + } + } + } + return CompatibleMaterial.getMaterial(mat); + } + } + return null; + } + + private static CompatibleMaterial getMaterialFromNewBlock(Block block) { + if (block == null) { + return null; + } + Material mat = block.getType(); + if (useLegacy) { + LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name(), block.getData()); + if (legacyBlock != null) { + return lookupMap.get(legacyBlock.name()); + } + CompatibleMaterial withData = lookupMap.get(mat.name() + ":" + block.getData()); + return withData == null ? lookupMap.get(mat.name()) : withData; + } + return lookupMap.get(mat.name()); + } + + /** + * Lookup a Block Material by its modern id name.
+ * This also can grab materials by their legacy, but only if there is no + * modern material by that name. + * + * @param name item to lookup + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getBlockMaterial(String name) { + if (name == null) { + return null; + } else if (useLegacy) { + LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(name.toUpperCase()); + if (legacyBlock != null) { + return lookupMap.get(legacyBlock.name()); + } + } + return lookupMap.get(name.toUpperCase()); + } + + /** + * Lookup a Block Material by its modern id name.
+ * This also can grab materials by their legacy, but only if there is no + * modern material by that name. + * + * @param name item to lookup + * @param def default item if this is not a valid material + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getBlockMaterial(String name, CompatibleMaterial def) { + if (name == null) { + return def; + } else if (useLegacy) { + LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(name.toUpperCase()); + if (legacyBlock != null) { + return lookupMap.get(legacyBlock.name()); + } + } + return lookupMap.getOrDefault(name.toUpperCase(), def); + } + + /** + * Lookup a Block Material by bukkit material. + * + * @param mat item to lookup + * + * @return LegacyMaterial or null if none found + */ + public static CompatibleMaterial getBlockMaterial(Material mat) { + if (mat == null) { + return null; + } else if (useLegacy) { + LegacyMaterialBlockType legacyBlock = LegacyMaterialBlockType.getFromLegacy(mat.name()); + if (legacyBlock != null) { + return lookupMap.get(legacyBlock.name()); + } + } + return lookupMap.get(mat.name()); + } + + static LinkedHashSet all = null; + + public static Set getAllValidItemMaterials() { + if (all == null) { + all = new LinkedHashSet(); + for (CompatibleMaterial mat : values()) { + if (mat.isValidItem() && !mat.usesCompatibility()) { + all.add(mat); + } + } + } + return Collections.unmodifiableSet(all); + } + + /** + * Lookup a Legacy Material by its modern id name and return its associated + * Item.
+ * This also can grab materials by their legacy, but only if there is no + * modern material by that name. + * + * @param name item to lookup + * + * @return ItemStack for this material, or null if none found + */ + public static ItemStack getItem(String name) { + if (name == null) { + return null; + } + CompatibleMaterial m = lookupMap.get(name.toUpperCase()); + if (m != null) { + return m.getItem(); + } + Material mat = Material.getMaterial(name); + return mat != null ? new ItemStack(mat) : null; + } + + private static Method methodSetData; + + static { + if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { + try { + methodSetData = Block.class.getDeclaredMethod("setData", byte.class); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + } + + /** + * Apply the current material to a block. + * + * @param block the block to apply the material to. + */ + public void applyToBlock(Block block) { + if (block == null) return; + block.setType(material); + if (data != null && data != -1 && ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { + try { + methodSetData.invoke(block, data); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + } + + /** + * Check to see if an item matches this specific material type + * + * @param item Item to check + * + * @return true if material of the ItemStack matches this item, corrected for legacy data + */ + public boolean matches(ItemStack item) { + return item != null && !usesCompatibility() && item.getType() == material && (data == null || item.getDurability() == data); // eons ago, ItemStack.getData() would return a byte. 1.7 doesn't, though. + } + + /** + * Some blocks change to other materials when placed down. This checks to + * see if this one is one of those. + * + * @return + */ + public boolean hasDifferentBlockItem() { + switch (this) { + case STRING: + return true; + case ACACIA_DOOR: + case BIRCH_DOOR: + case DARK_OAK_DOOR: + case JUNGLE_DOOR: + case SPRUCE_DOOR: + case IRON_DOOR: + case OAK_DOOR: + case ACACIA_SIGN: + case BIRCH_SIGN: + case DARK_OAK_SIGN: + case JUNGLE_SIGN: + case OAK_SIGN: + case SPRUCE_SIGN: + case BLACK_BANNER: + case BLUE_BANNER: + case BROWN_BANNER: + case CYAN_BANNER: + case GRAY_BANNER: + case GREEN_BANNER: + case LIGHT_BLUE_BANNER: + case LIGHT_GRAY_BANNER: + case LIME_BANNER: + case MAGENTA_BANNER: + case ORANGE_BANNER: + case PINK_BANNER: + case PURPLE_BANNER: + case RED_BANNER: + case WHITE_BANNER: + case YELLOW_BANNER: + case BLACK_BED: + case BLUE_BED: + case BROWN_BED: + case CYAN_BED: + case GRAY_BED: + case GREEN_BED: + case LIGHT_BLUE_BED: + case LIGHT_GRAY_BED: + case LIME_BED: + case MAGENTA_BED: + case ORANGE_BED: + case PINK_BED: + case PURPLE_BED: + case RED_BED: + case WHITE_BED: + case YELLOW_BED: + case REDSTONE: + case REPEATER: + case SUGAR_CANE: + case CAKE: + case COMPARATOR: + return usesLegacy(); + } + return false; + } + + /** + * Check to see if this is a material that can exist as a block + * + * @return + */ + public boolean isBlock() { + return material != null && material.isBlock(); + } + + /** + * Check to see if this is an item that can be consumed to restore hunger + * + * @return + */ + public boolean isEdible() { + return material != null && material.isEdible(); + } + + /** + * Check if the material is a block and can be built on + * + * @return + */ + public boolean isSolid() { + return material != null && material.isSolid(); + } + + /** + * Check if the material is a block and does not block any light + * + * @return + */ + public boolean isTransparent() { + return material != null && material.isTransparent(); + } + + /** + * Check if the material is a block and can catch fire + * + * @return + */ + public boolean isFlammable() { + return material != null && material.isFlammable(); + } + + /** + * Check if the material is a block and can be destroyed by burning + * + * @return + */ + public boolean isBurnable() { + return material != null && material.isBurnable(); + } + + /** + * Checks if this Material can be used as fuel in a Furnace + * + * @return + */ + public boolean isFuel() { + // this function is not implemented in some older versions, so we need this here.. + switch (this) { + case ACACIA_BOAT: + case ACACIA_BUTTON: + case ACACIA_DOOR: + case ACACIA_FENCE: + case ACACIA_FENCE_GATE: + case ACACIA_LOG: + case ACACIA_PLANKS: + case ACACIA_PRESSURE_PLATE: + case ACACIA_SAPLING: + case ACACIA_SIGN: + case ACACIA_SLAB: + case ACACIA_STAIRS: + case ACACIA_TRAPDOOR: + case ACACIA_WOOD: + case BAMBOO: + case BARREL: + case BIRCH_BOAT: + case BIRCH_BUTTON: + case BIRCH_DOOR: + case BIRCH_FENCE: + case BIRCH_FENCE_GATE: + case BIRCH_LOG: + case BIRCH_PLANKS: + case BIRCH_PRESSURE_PLATE: + case BIRCH_SAPLING: + case BIRCH_SIGN: + case BIRCH_SLAB: + case BIRCH_STAIRS: + case BIRCH_TRAPDOOR: + case BIRCH_WOOD: + case BLACK_BANNER: + case BLACK_CARPET: + case BLACK_WOOL: + case BLAZE_ROD: + case BLUE_BANNER: + case BLUE_CARPET: + case BLUE_WOOL: + case BOOKSHELF: + case BOW: + case BOWL: + case BROWN_BANNER: + case BROWN_CARPET: + case BROWN_WOOL: + case CARTOGRAPHY_TABLE: + case CHARCOAL: + case CHEST: + case COAL: + case COAL_BLOCK: + case COMPOSTER: + case CRAFTING_TABLE: + case CROSSBOW: + case CYAN_BANNER: + case CYAN_CARPET: + case CYAN_WOOL: + case DARK_OAK_BOAT: + case DARK_OAK_BUTTON: + case DARK_OAK_DOOR: + case DARK_OAK_FENCE: + case DARK_OAK_FENCE_GATE: + case DARK_OAK_LOG: + case DARK_OAK_PLANKS: + case DARK_OAK_PRESSURE_PLATE: + case DARK_OAK_SAPLING: + case DARK_OAK_SIGN: + case DARK_OAK_SLAB: + case DARK_OAK_STAIRS: + case DARK_OAK_TRAPDOOR: + case DARK_OAK_WOOD: + case DAYLIGHT_DETECTOR: + case DEAD_BUSH: + case DRIED_KELP_BLOCK: + case FISHING_ROD: + case FLETCHING_TABLE: + case GRAY_BANNER: + case GRAY_CARPET: + case GRAY_WOOL: + case GREEN_BANNER: + case GREEN_CARPET: + case GREEN_WOOL: + case JUKEBOX: + case JUNGLE_BOAT: + case JUNGLE_BUTTON: + case JUNGLE_DOOR: + case JUNGLE_FENCE: + case JUNGLE_FENCE_GATE: + case JUNGLE_LOG: + case JUNGLE_PLANKS: + case JUNGLE_PRESSURE_PLATE: + case JUNGLE_SAPLING: + case JUNGLE_SIGN: + case JUNGLE_SLAB: + case JUNGLE_STAIRS: + case JUNGLE_TRAPDOOR: + case JUNGLE_WOOD: + case LADDER: + case LAVA_BUCKET: + case LECTERN: + case LIGHT_BLUE_BANNER: + case LIGHT_BLUE_CARPET: + case LIGHT_BLUE_WOOL: + case LIGHT_GRAY_BANNER: + case LIGHT_GRAY_CARPET: + case LIGHT_GRAY_WOOL: + case LIME_BANNER: + case LIME_CARPET: + case LIME_WOOL: + case LOOM: + case MAGENTA_BANNER: + case MAGENTA_CARPET: + case MAGENTA_WOOL: + case NOTE_BLOCK: + case OAK_BOAT: + case OAK_BUTTON: + case OAK_DOOR: + case OAK_FENCE: + case OAK_FENCE_GATE: + case OAK_LOG: + case OAK_PLANKS: + case OAK_PRESSURE_PLATE: + case OAK_SAPLING: + case OAK_SIGN: + case OAK_SLAB: + case OAK_STAIRS: + case OAK_TRAPDOOR: + case OAK_WOOD: + case ORANGE_BANNER: + case ORANGE_CARPET: + case ORANGE_WOOL: + case PINK_BANNER: + case PINK_CARPET: + case PINK_WOOL: + case PURPLE_BANNER: + case PURPLE_CARPET: + case PURPLE_WOOL: + case RED_BANNER: + case RED_CARPET: + case RED_WOOL: + case SCAFFOLDING: + case SMITHING_TABLE: + case SPRUCE_BOAT: + case SPRUCE_BUTTON: + case SPRUCE_DOOR: + case SPRUCE_FENCE: + case SPRUCE_FENCE_GATE: + case SPRUCE_LOG: + case SPRUCE_PLANKS: + case SPRUCE_PRESSURE_PLATE: + case SPRUCE_SAPLING: + case SPRUCE_SIGN: + case SPRUCE_SLAB: + case SPRUCE_STAIRS: + case SPRUCE_TRAPDOOR: + case SPRUCE_WOOD: + case STICK: + case STRIPPED_ACACIA_LOG: + case STRIPPED_ACACIA_WOOD: + case STRIPPED_BIRCH_LOG: + case STRIPPED_BIRCH_WOOD: + case STRIPPED_DARK_OAK_LOG: + case STRIPPED_DARK_OAK_WOOD: + case STRIPPED_JUNGLE_LOG: + case STRIPPED_JUNGLE_WOOD: + case STRIPPED_OAK_LOG: + case STRIPPED_OAK_WOOD: + case STRIPPED_SPRUCE_LOG: + case STRIPPED_SPRUCE_WOOD: + case TRAPPED_CHEST: + case WHITE_BANNER: + case WHITE_CARPET: + case WHITE_WOOL: + case WOODEN_AXE: + case WOODEN_HOE: + case WOODEN_PICKAXE: + case WOODEN_SHOVEL: + case WOODEN_SWORD: + case YELLOW_BANNER: + case YELLOW_CARPET: + case YELLOW_WOOL: + return true; + default: + return false; + } + } + + /** + * Get the result of putting this item + * into a furnace. + *

+ * return + */ + public CompatibleMaterial getBurnResult() { + switch (this) { + case PORKCHOP: + return COOKED_PORKCHOP; + case BEEF: + return COOKED_BEEF; + case CHICKEN: + return COOKED_CHICKEN; + case COD: + return COOKED_COD; + case SALMON: + return COOKED_SALMON; + case POTATO: + return BAKED_POTATO; + case MUTTON: + return COOKED_MUTTON; + case RABBIT: + return COOKED_RABBIT; + case KELP: + return DRIED_KELP; + case IRON_ORE: + case DEEPSLATE_IRON_ORE: + return IRON_INGOT; + case GOLD_ORE: + case DEEPSLATE_GOLD_ORE: + return GOLD_INGOT; + case DIAMOND_ORE: + case DEEPSLATE_DIAMOND_ORE: + return DIAMOND; + case LAPIS_ORE: + case DEEPSLATE_LAPIS_ORE: + return LAPIS_LAZULI; + case REDSTONE_ORE: + case DEEPSLATE_REDSTONE_ORE: + return REDSTONE; + case COAL_ORE: + case DEEPSLATE_COAL_ORE: + return COAL; + case EMERALD_ORE: + case DEEPSLATE_EMERALD_ORE: + return EMERALD; + case NETHER_QUARTZ_ORE: + return QUARTZ; + case COPPER_ORE: + case DEEPSLATE_COPPER_ORE: + return COPPER_INGOT; + case SAND: + case RED_SAND: + return GLASS; + case COBBLESTONE: + return STONE; + case SANDSTONE: + return SMOOTH_SANDSTONE; + case RED_SANDSTONE: + return SMOOTH_RED_SANDSTONE; + case STONE: + return SMOOTH_STONE; + case QUARTZ_BLOCK: + return SMOOTH_QUARTZ; + case CLAY_BALL: + return BRICK; + case NETHERRACK: + return NETHER_BRICK; + case CLAY: + return BRICKS; + case STONE_BRICKS: + return CRACKED_STONE_BRICKS; + case WHITE_TERRACOTTA: + return WHITE_GLAZED_TERRACOTTA; + case ORANGE_TERRACOTTA: + return ORANGE_GLAZED_TERRACOTTA; + case MAGENTA_TERRACOTTA: + return MAGENTA_GLAZED_TERRACOTTA; + case LIGHT_BLUE_TERRACOTTA: + return LIGHT_BLUE_GLAZED_TERRACOTTA; + case YELLOW_TERRACOTTA: + return YELLOW_GLAZED_TERRACOTTA; + case LIME_TERRACOTTA: + return LIME_GLAZED_TERRACOTTA; + case PINK_TERRACOTTA: + return PINK_GLAZED_TERRACOTTA; + case GRAY_TERRACOTTA: + return GRAY_GLAZED_TERRACOTTA; + case LIGHT_GRAY_TERRACOTTA: + return LIGHT_GRAY_GLAZED_TERRACOTTA; + case CYAN_TERRACOTTA: + return CYAN_GLAZED_TERRACOTTA; + case PURPLE_TERRACOTTA: + return PURPLE_GLAZED_TERRACOTTA; + case BLUE_TERRACOTTA: + return BLUE_GLAZED_TERRACOTTA; + case BROWN_TERRACOTTA: + return BROWN_GLAZED_TERRACOTTA; + case GREEN_TERRACOTTA: + return GREEN_GLAZED_TERRACOTTA; + case RED_TERRACOTTA: + return RED_GLAZED_TERRACOTTA; + case BLACK_TERRACOTTA: + return BLACK_GLAZED_TERRACOTTA; + case IRON_SWORD: + case IRON_PICKAXE: + case IRON_AXE: + case IRON_SHOVEL: + case IRON_HOE: + case IRON_HELMET: + case IRON_CHESTPLATE: + case IRON_LEGGINGS: + case IRON_BOOTS: + case IRON_HORSE_ARMOR: + case CHAINMAIL_HELMET: + case CHAINMAIL_CHESTPLATE: + case CHAINMAIL_LEGGINGS: + case CHAINMAIL_BOOTS: + return IRON_NUGGET; + case GOLDEN_SWORD: + case GOLDEN_PICKAXE: + case GOLDEN_AXE: + case GOLDEN_SHOVEL: + case GOLDEN_HOE: + case GOLDEN_HELMET: + case GOLDEN_CHESTPLATE: + case GOLDEN_LEGGINGS: + case GOLDEN_BOOTS: + case GOLDEN_HORSE_ARMOR: + return GOLD_NUGGET; + case CACTUS: + return GREEN_DYE; + case SEA_PICKLE: + return LIME_DYE; + case OAK_LOG: + case BIRCH_LOG: + case ACACIA_LOG: + case DARK_OAK_LOG: + case JUNGLE_LOG: + case SPRUCE_LOG: + case STRIPPED_ACACIA_LOG: + case STRIPPED_BIRCH_LOG: + case STRIPPED_DARK_OAK_LOG: + case STRIPPED_JUNGLE_LOG: + case STRIPPED_OAK_LOG: + case STRIPPED_SPRUCE_LOG: + case ACACIA_WOOD: + case BIRCH_WOOD: + case JUNGLE_WOOD: + case OAK_WOOD: + case SPRUCE_WOOD: + case STRIPPED_ACACIA_WOOD: + case STRIPPED_BIRCH_WOOD: + case STRIPPED_DARK_OAK_WOOD: + case STRIPPED_JUNGLE_WOOD: + case STRIPPED_OAK_WOOD: + case STRIPPED_SPRUCE_WOOD: + return CHARCOAL; + case CHORUS_FRUIT: + return POPPED_CHORUS_FRUIT; + default: + return null; + } + } + + /** + * Check if the material is air + * + * @return + */ + public boolean isAir() { + switch (this) { + case AIR: + case CAVE_AIR: + case VOID_AIR: + return true; + default: + return false; + } + } + + /** + * Check if the material is water + * + * @return + */ + public boolean isWater() { + return this == CompatibleMaterial.WATER; + } + + /** + * Get the EntityType of the monster spawn egg. + * + * @return + */ + public EntityType getEggType() { + String entityName = this.name().replace("_SPAWN_EGG", ""); + if (entityName.equals("MOOSHROOM")) + entityName = "MUSHROOM_COW"; + else if (entityName.equals("ZOMBIE_PIGMAN")) + entityName = "PIG_ZOMBIE"; + try { + return EntityType.valueOf(entityName); + } catch (IllegalArgumentException e) { + return null; + } + } + + /** + * Check if the material is a block and completely blocks vision + * + * @return + */ + public boolean isOccluding() { + return material != null && material.isOccluding(); + } + + /** + * @return True if this material is affected by gravity. + */ + public boolean hasGravity() { + return material != null && material.hasGravity(); + } + + /** + * Checks if this Material is an obtainable item. + * + * @return + */ + public boolean isItem() { + // this function is not implemented in some older versions, so we need this here.. + switch (this) { + case CAVE_AIR: + case VOID_AIR: + case ACACIA_WALL_SIGN: + case ATTACHED_MELON_STEM: + case ATTACHED_PUMPKIN_STEM: + case BAMBOO_SAPLING: + case BEETROOTS: + case BIRCH_WALL_SIGN: + case BLACK_WALL_BANNER: + case BLUE_WALL_BANNER: + case BRAIN_CORAL_WALL_FAN: + case BROWN_WALL_BANNER: + case BUBBLE_COLUMN: + case BUBBLE_CORAL_WALL_FAN: + case CARROTS: + case COCOA: + case CREEPER_WALL_HEAD: + case CYAN_WALL_BANNER: + case DARK_OAK_WALL_SIGN: + case DEAD_BRAIN_CORAL_WALL_FAN: + case DEAD_BUBBLE_CORAL_WALL_FAN: + case DEAD_FIRE_CORAL_WALL_FAN: + case DEAD_HORN_CORAL_WALL_FAN: + case DEAD_TUBE_CORAL_WALL_FAN: + case DRAGON_WALL_HEAD: + case END_GATEWAY: + case END_PORTAL: + case FIRE: + case FIRE_CORAL_WALL_FAN: + case FROSTED_ICE: + case GRAY_WALL_BANNER: + case GREEN_WALL_BANNER: + case HORN_CORAL_WALL_FAN: + case JUNGLE_WALL_SIGN: + case KELP_PLANT: + case LAVA: + case LIGHT_BLUE_WALL_BANNER: + case LIGHT_GRAY_WALL_BANNER: + case LIME_WALL_BANNER: + case MAGENTA_WALL_BANNER: + case MELON_STEM: + case MOVING_PISTON: + case NETHER_PORTAL: + case OAK_WALL_SIGN: + case ORANGE_WALL_BANNER: + case PINK_WALL_BANNER: + case PISTON_HEAD: + case PLAYER_WALL_HEAD: + case POTATOES: + case POTTED_ACACIA_SAPLING: + case POTTED_ALLIUM: + case POTTED_AZURE_BLUET: + case POTTED_BAMBOO: + case POTTED_BIRCH_SAPLING: + case POTTED_BLUE_ORCHID: + case POTTED_BROWN_MUSHROOM: + case POTTED_CACTUS: + case POTTED_CORNFLOWER: + case POTTED_DANDELION: + case POTTED_DARK_OAK_SAPLING: + case POTTED_DEAD_BUSH: + case POTTED_FERN: + case POTTED_JUNGLE_SAPLING: + case POTTED_LILY_OF_THE_VALLEY: + case POTTED_OAK_SAPLING: + case POTTED_ORANGE_TULIP: + case POTTED_OXEYE_DAISY: + case POTTED_PINK_TULIP: + case POTTED_POPPY: + case POTTED_RED_MUSHROOM: + case POTTED_RED_TULIP: + case POTTED_SPRUCE_SAPLING: + case POTTED_WHITE_TULIP: + case POTTED_WITHER_ROSE: + case PUMPKIN_STEM: + case PURPLE_WALL_BANNER: + case REDSTONE_WALL_TORCH: + case REDSTONE_WIRE: + case RED_WALL_BANNER: + case SKELETON_WALL_SKULL: + case SPRUCE_WALL_SIGN: + case SWEET_BERRY_BUSH: + case TALL_SEAGRASS: + case TRIPWIRE: + case TUBE_CORAL_WALL_FAN: + case WALL_TORCH: + case WATER: + case WHITE_WALL_BANNER: + case WITHER_SKELETON_WALL_SKULL: + case YELLOW_WALL_BANNER: + case ZOMBIE_WALL_HEAD: + return false; + } + return true; + } + + /** + * Checks if this Material can be interacted with.
+ * This method will return true if there is at least one state in which + * additional interact handling is performed for the material. + * + * @return + */ + public boolean isInteractable() { + // this function is not implemented in some older versions, so we need this here.. + switch (this) { + case ACACIA_BUTTON: + case ACACIA_DOOR: + case ACACIA_FENCE: + case ACACIA_FENCE_GATE: + case ACACIA_SIGN: + case ACACIA_STAIRS: + case ACACIA_TRAPDOOR: + case ACACIA_WALL_SIGN: + case ANDESITE_STAIRS: + case ANVIL: + case BARREL: + case BEACON: + case BEEHIVE: + case BEE_NEST: + case BELL: + case BIRCH_BUTTON: + case BIRCH_DOOR: + case BIRCH_FENCE: + case BIRCH_FENCE_GATE: + case BIRCH_SIGN: + case BIRCH_STAIRS: + case BIRCH_TRAPDOOR: + case BIRCH_WALL_SIGN: + case BLACKSTONE_STAIRS: + case BLACK_BED: + case BLACK_SHULKER_BOX: + case BLAST_FURNACE: + case BLUE_BED: + case BLUE_SHULKER_BOX: + case BREWING_STAND: + case BRICK_STAIRS: + case BROWN_BED: + case BROWN_SHULKER_BOX: + case CAKE: + case CAMPFIRE: + case CARTOGRAPHY_TABLE: + case CAULDRON: + case CHAIN_COMMAND_BLOCK: + case CHEST: + case CHIPPED_ANVIL: + case COBBLESTONE_STAIRS: + case COMMAND_BLOCK: + case COMPARATOR: + case COMPOSTER: + case CRAFTING_TABLE: + case CRIMSON_BUTTON: + case CRIMSON_DOOR: + case CRIMSON_FENCE: + case CRIMSON_FENCE_GATE: + case CRIMSON_SIGN: + case CRIMSON_STAIRS: + case CRIMSON_TRAPDOOR: + case CRIMSON_WALL_SIGN: + case CYAN_BED: + case CYAN_SHULKER_BOX: + case DAMAGED_ANVIL: + case DARK_OAK_BUTTON: + case DARK_OAK_DOOR: + case DARK_OAK_FENCE: + case DARK_OAK_FENCE_GATE: + case DARK_OAK_SIGN: + case DARK_OAK_STAIRS: + case DARK_OAK_TRAPDOOR: + case DARK_OAK_WALL_SIGN: + case DARK_PRISMARINE_STAIRS: + case DAYLIGHT_DETECTOR: + case DIORITE_STAIRS: + case DISPENSER: + case DRAGON_EGG: + case DROPPER: + case ENCHANTING_TABLE: + case ENDER_CHEST: + case END_STONE_BRICK_STAIRS: + case FLETCHING_TABLE: + case FLOWER_POT: + case FURNACE: + case GRANITE_STAIRS: + case GRAY_BED: + case GRAY_SHULKER_BOX: + case GREEN_BED: + case GREEN_SHULKER_BOX: + case GRINDSTONE: + case HOPPER: + case IRON_DOOR: + case IRON_TRAPDOOR: + case JIGSAW: + case JUKEBOX: + case JUNGLE_BUTTON: + case JUNGLE_DOOR: + case JUNGLE_FENCE: + case JUNGLE_FENCE_GATE: + case JUNGLE_SIGN: + case JUNGLE_STAIRS: + case JUNGLE_TRAPDOOR: + case JUNGLE_WALL_SIGN: + case LECTERN: + case LEVER: + case LIGHT_BLUE_BED: + case LIGHT_BLUE_SHULKER_BOX: + case LIGHT_GRAY_BED: + case LIGHT_GRAY_SHULKER_BOX: + case LIME_BED: + case LIME_SHULKER_BOX: + case LOOM: + case MAGENTA_BED: + case MAGENTA_SHULKER_BOX: + case MOSSY_COBBLESTONE_STAIRS: + case MOSSY_STONE_BRICK_STAIRS: + case MOVING_PISTON: + case NETHER_BRICK_FENCE: + case NETHER_BRICK_STAIRS: + case NOTE_BLOCK: + case OAK_BUTTON: + case OAK_DOOR: + case OAK_FENCE: + case OAK_FENCE_GATE: + case OAK_SIGN: + case OAK_STAIRS: + case OAK_TRAPDOOR: + case OAK_WALL_SIGN: + case ORANGE_BED: + case ORANGE_SHULKER_BOX: + case PINK_BED: + case PINK_SHULKER_BOX: + case POLISHED_ANDESITE_STAIRS: + case POLISHED_BLACKSTONE_BRICK_STAIRS: + case POLISHED_BLACKSTONE_BUTTON: + case POLISHED_BLACKSTONE_STAIRS: + case POLISHED_DIORITE_STAIRS: + case POLISHED_GRANITE_STAIRS: + case POTTED_ACACIA_SAPLING: + case POTTED_ALLIUM: + case POTTED_AZURE_BLUET: + case POTTED_BAMBOO: + case POTTED_BIRCH_SAPLING: + case POTTED_BLUE_ORCHID: + case POTTED_BROWN_MUSHROOM: + case POTTED_CACTUS: + case POTTED_CORNFLOWER: + case POTTED_CRIMSON_FUNGUS: + case POTTED_CRIMSON_ROOTS: + case POTTED_DANDELION: + case POTTED_DARK_OAK_SAPLING: + case POTTED_DEAD_BUSH: + case POTTED_FERN: + case POTTED_JUNGLE_SAPLING: + case POTTED_LILY_OF_THE_VALLEY: + case POTTED_OAK_SAPLING: + case POTTED_ORANGE_TULIP: + case POTTED_OXEYE_DAISY: + case POTTED_PINK_TULIP: + case POTTED_POPPY: + case POTTED_RED_MUSHROOM: + case POTTED_RED_TULIP: + case POTTED_SPRUCE_SAPLING: + case POTTED_WARPED_FUNGUS: + case POTTED_WARPED_ROOTS: + case POTTED_WHITE_TULIP: + case POTTED_WITHER_ROSE: + case PRISMARINE_BRICK_STAIRS: + case PRISMARINE_STAIRS: + case PUMPKIN: + case PURPLE_BED: + case PURPLE_SHULKER_BOX: + case PURPUR_STAIRS: + case QUARTZ_STAIRS: + case REDSTONE_ORE: + case REDSTONE_WIRE: + case RED_BED: + case RED_NETHER_BRICK_STAIRS: + case RED_SANDSTONE_STAIRS: + case RED_SHULKER_BOX: + case REPEATER: + case REPEATING_COMMAND_BLOCK: + case RESPAWN_ANCHOR: + case SANDSTONE_STAIRS: + case SHULKER_BOX: + case SMITHING_TABLE: + case SMOKER: + case SMOOTH_QUARTZ_STAIRS: + case SMOOTH_RED_SANDSTONE_STAIRS: + case SMOOTH_SANDSTONE_STAIRS: + case SOUL_CAMPFIRE: + case SPRUCE_BUTTON: + case SPRUCE_DOOR: + case SPRUCE_FENCE: + case SPRUCE_FENCE_GATE: + case SPRUCE_SIGN: + case SPRUCE_STAIRS: + case SPRUCE_TRAPDOOR: + case SPRUCE_WALL_SIGN: + case STONECUTTER: + case STONE_BRICK_STAIRS: + case STONE_BUTTON: + case STONE_STAIRS: + case STRUCTURE_BLOCK: + case SWEET_BERRY_BUSH: + case TNT: + case TRAPPED_CHEST: + case WARPED_BUTTON: + case WARPED_DOOR: + case WARPED_FENCE: + case WARPED_FENCE_GATE: + case WARPED_SIGN: + case WARPED_STAIRS: + case WARPED_TRAPDOOR: + case WARPED_WALL_SIGN: + case WHITE_BED: + case WHITE_SHULKER_BOX: + case YELLOW_BED: + case YELLOW_SHULKER_BOX: { + return true; + } + } + return false; + } + + /** + * @return true if this material is valid as an item + */ + public boolean isValidItem() { + switch (this) { + case ACACIA_WALL_SIGN: + case AIR: + case ATTACHED_MELON_STEM: + case ATTACHED_PUMPKIN_STEM: + case BAMBOO_SAPLING: + case BEETROOTS: + case BIRCH_WALL_SIGN: + case BLACK_WALL_BANNER: + case BLUE_WALL_BANNER: + case BRAIN_CORAL_WALL_FAN: + case BROWN_WALL_BANNER: + case BUBBLE_COLUMN: + case BUBBLE_CORAL_WALL_FAN: + case CARROTS: + case CAVE_AIR: + case COCOA: + case CREEPER_WALL_HEAD: + case CYAN_WALL_BANNER: + case DARK_OAK_WALL_SIGN: + case DEAD_BRAIN_CORAL_WALL_FAN: + case DEAD_BUBBLE_CORAL_WALL_FAN: + case DEAD_FIRE_CORAL_WALL_FAN: + case DEAD_HORN_CORAL_WALL_FAN: + case DEAD_TUBE_CORAL_WALL_FAN: + case DRAGON_WALL_HEAD: + case END_GATEWAY: + case END_PORTAL: + case FARMLAND: + case FIRE: // used to be able to in older versions + case FIRE_CORAL_WALL_FAN: + case FROSTED_ICE: + case GRAY_WALL_BANNER: + case GREEN_WALL_BANNER: + case HORN_CORAL_WALL_FAN: + case JUNGLE_WALL_SIGN: + case KELP_PLANT: + case LAVA: + case LIGHT_BLUE_WALL_BANNER: + case LIGHT_GRAY_WALL_BANNER: + case LIME_WALL_BANNER: + case MAGENTA_WALL_BANNER: + case MELON_STEM: + case MOVING_PISTON: + case NETHER_PORTAL: + case OAK_WALL_SIGN: + case ORANGE_WALL_BANNER: + case PINK_WALL_BANNER: + case PISTON_HEAD: + case PLAYER_WALL_HEAD: + case POTATOES: + case POTTED_ACACIA_SAPLING: + case POTTED_ALLIUM: + case POTTED_AZURE_BLUET: + case POTTED_BAMBOO: + case POTTED_BIRCH_SAPLING: + case POTTED_BLUE_ORCHID: + case POTTED_BROWN_MUSHROOM: + case POTTED_CACTUS: + case POTTED_CORNFLOWER: + case POTTED_DANDELION: + case POTTED_DARK_OAK_SAPLING: + case POTTED_DEAD_BUSH: + case POTTED_FERN: + case POTTED_JUNGLE_SAPLING: + case POTTED_LILY_OF_THE_VALLEY: + case POTTED_OAK_SAPLING: + case POTTED_ORANGE_TULIP: + case POTTED_OXEYE_DAISY: + case POTTED_PINK_TULIP: + case POTTED_POPPY: + case POTTED_RED_MUSHROOM: + case POTTED_RED_TULIP: + case POTTED_SPRUCE_SAPLING: + case POTTED_WHITE_TULIP: + case POTTED_WITHER_ROSE: + case PUMPKIN_STEM: + case PURPLE_WALL_BANNER: + case REDSTONE_WALL_TORCH: + case REDSTONE_WIRE: + case RED_WALL_BANNER: + case SKELETON_WALL_SKULL: + case SPRUCE_WALL_SIGN: + case SWEET_BERRY_BUSH: + case TALL_SEAGRASS: + case TRIPWIRE: + case TUBE_CORAL_WALL_FAN: + case VOID_AIR: + case WALL_TORCH: + case WATER: + case WHITE_WALL_BANNER: + case WITHER_SKELETON_WALL_SKULL: + return false; + } + if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12)) { + switch (this) { + case ACACIA_WOOD: + case BIRCH_WOOD: + case DARK_OAK_WOOD: + case JUNGLE_WOOD: + case OAK_WOOD: + case SPRUCE_WOOD: + case STRIPPED_ACACIA_WOOD: + case STRIPPED_BIRCH_WOOD: + case STRIPPED_DARK_OAK_WOOD: + case STRIPPED_JUNGLE_WOOD: + case STRIPPED_OAK_WOOD: + case STRIPPED_SPRUCE_WOOD: + return false; + } + } + return true; + } + + /** + * @return true if this material is a food that can be cooked and is in its cooked state + */ + public boolean isCooked() { + switch (this) { + case BAKED_POTATO: + case COOKED_BEEF: + case COOKED_CHICKEN: + case COOKED_COD: + case COOKED_MUTTON: + case COOKED_PORKCHOP: + case COOKED_RABBIT: + case COOKED_SALMON: + case DRIED_KELP: + return true; + } + return false; + } + + /** + * @return true if this material is a food that can be cooked and is in its raw state + */ + public boolean isRaw() { + switch (this) { + case BEEF: + case CHICKEN: + case COD: + case KELP: // not edible, but is the raw state of DRIED_KELP + case MUTTON: + case PORKCHOP: + case POTATO: + case RABBIT: + case SALMON: + return true; + } + return false; + } + + /** + * @return true if this material is two blocks tall + */ + public boolean isTall() { + switch (this) { + case SUNFLOWER: + case LILAC: + case LARGE_FERN: + case ROSE_BUSH: + case PEONY: + case TALL_GRASS: + return true; + } + return false; + } + + /** + * Note: If using this on a legacy server without #getBlockMaterial + * you may run into issues. + * + * @return true if this is a block that has a growth state + */ + public boolean isCrop() { + switch (this) { + case BEETROOTS: + case CACTUS: + case CARROTS: + case CHORUS_FLOWER: + // FROSTED_ICE is Ageable, but not a crop + case KELP: + case MELON_STEM: + case NETHER_WART: + case POTATOES: + case PUMPKIN_STEM: + case SUGAR_CANE: + case WHEAT: + return true; + default: + return false; + } + } + + /** + * @return the yield of this crop. + */ + public CompatibleMaterial getCropYield() { + switch (this) { + case BEETROOTS: + return BEETROOT; + case CACTUS: + return CACTUS; + case CARROTS: + return CARROT; + case CHORUS_FLOWER: + return CHORUS_PLANT; + case KELP: + return KELP; + case MELON_STEM: + return MELON; + case NETHER_WART: + return NETHER_WART; + case POTATOES: + return POTATO; + case PUMPKIN_STEM: + return PUMPKIN; + case SUGAR_CANE: + return SUGAR_CANE; + case WHEAT: + return WHEAT; + default: + return null; + } + } + + /** + * @return the seed of this crop. + */ + public CompatibleMaterial getCropSeed() { + switch (this) { + case BEETROOTS: + return BEETROOT_SEEDS; + case CACTUS: + return CACTUS; + case CARROTS: + return CARROT; + case CHORUS_PLANT: + return CHORUS_FLOWER; + case KELP: + return KELP; + case MELON_STEM: + return MELON_SEEDS; + case NETHER_WART: + return NETHER_WART; + case POTATOES: + return POTATO; + case PUMPKIN_STEM: + return PUMPKIN_SEEDS; + case SUGAR_CANE: + return SUGAR_CANE; + case WHEAT: + return WHEAT_SEEDS; + default: + return null; + } + } + + public static CompatibleMaterial getSpawnEgg(EntityType type) { + if (type == EntityType.MUSHROOM_COW) { + return MOOSHROOM_SPAWN_EGG; + } + + if (ServerVersion.isServerVersionBelow(ServerVersion.V1_16) + && type == EntityType.valueOf("PIG_ZOMBIE")) { + return ZOMBIE_PIGMAN_SPAWN_EGG; + } + + return lookupMap.get(type.name() + "_SPAWN_EGG"); + } + + public static CompatibleMaterial getGlassPaneColor(int color) { + switch (color) { + case 0: + return WHITE_STAINED_GLASS_PANE; + case 1: + return ORANGE_STAINED_GLASS_PANE; + case 2: + return MAGENTA_STAINED_GLASS_PANE; + case 3: + return LIGHT_BLUE_STAINED_GLASS_PANE; + case 4: + return YELLOW_STAINED_GLASS_PANE; + case 5: + return LIME_STAINED_GLASS_PANE; + case 6: + return PINK_STAINED_GLASS_PANE; + case 7: + return GRAY_STAINED_GLASS_PANE; + case 8: + return LIGHT_GRAY_STAINED_GLASS_PANE; + case 9: + return CYAN_STAINED_GLASS_PANE; + case 10: + return PURPLE_STAINED_GLASS_PANE; + case 11: + return BLUE_STAINED_GLASS_PANE; + case 12: + return BROWN_STAINED_GLASS_PANE; + case 13: + return GREEN_STAINED_GLASS_PANE; + case 14: + return RED_STAINED_GLASS_PANE; + case 15: + return BLACK_STAINED_GLASS_PANE; + } + return WHITE_STAINED_GLASS_PANE; + } + + public static CompatibleMaterial getGlassColor(int color) { + switch (color) { + case 0: + return WHITE_STAINED_GLASS; + case 1: + return ORANGE_STAINED_GLASS; + case 2: + return MAGENTA_STAINED_GLASS; + case 3: + return LIGHT_BLUE_STAINED_GLASS; + case 4: + return YELLOW_STAINED_GLASS; + case 5: + return LIME_STAINED_GLASS; + case 6: + return PINK_STAINED_GLASS; + case 7: + return GRAY_STAINED_GLASS; + case 8: + return LIGHT_GRAY_STAINED_GLASS; + case 9: + return CYAN_STAINED_GLASS; + case 10: + return PURPLE_STAINED_GLASS; + case 11: + return BLUE_STAINED_GLASS; + case 12: + return BROWN_STAINED_GLASS; + case 13: + return GREEN_STAINED_GLASS; + case 14: + return RED_STAINED_GLASS; + case 15: + return BLACK_STAINED_GLASS; + } + return WHITE_STAINED_GLASS; + } + + public static CompatibleMaterial getWoolColor(int color) { + switch (color) { + case 0: + return WHITE_WOOL; + case 1: + return ORANGE_WOOL; + case 2: + return MAGENTA_WOOL; + case 3: + return LIGHT_BLUE_WOOL; + case 4: + return YELLOW_WOOL; + case 5: + return LIME_WOOL; + case 6: + return PINK_WOOL; + case 7: + return GRAY_WOOL; + case 8: + return LIGHT_GRAY_WOOL; + case 9: + return CYAN_WOOL; + case 10: + return PURPLE_WOOL; + case 11: + return BLUE_WOOL; + case 12: + return BROWN_WOOL; + case 13: + return GREEN_WOOL; + case 14: + return RED_WOOL; + case 15: + return BLACK_WOOL; + } + return WHITE_WOOL; + } + + public static CompatibleMaterial getDyeColor(int color) { + switch (color) { + case 0: + return BLACK_DYE; + case 1: + return RED_DYE; + case 2: + return GREEN_DYE; + case 3: + return BROWN_DYE; + case 4: + return BLUE_DYE; + case 5: + return PURPLE_DYE; + case 6: + return CYAN_DYE; + case 7: + return LIGHT_GRAY_DYE; + case 8: + return GRAY_DYE; + case 9: + return PINK_DYE; + case 10: + return LIME_DYE; + case 11: + return YELLOW_DYE; + case 12: + return LIGHT_BLUE_DYE; + case 13: + return MAGENTA_DYE; + case 14: + return ORANGE_DYE; + case 15: + return WHITE_DYE; + } + return WHITE_DYE; + } +} diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleSound.java b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleSound.java index efc60521..370fedbb 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleSound.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/CompatibleSound.java @@ -1,1417 +1,1415 @@ -package com.songoda.core.compatibility; - -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.entity.Player; - -/** - * Sounds that are compatible with server versions 1.7+
- * TODO: This needs work. - * Finished 1.8, finished 1.9 blocks, resume with 1.9 entities
- * Between 1.8 and 1.9, all sounds were renamed, and between 1.12 and 1.13, some - * sounds were renamed. New sounds have been added by different versions, as - * well. The intent of this class is to provide either the correct sound or a - * near equivalent for the current server. - * - * @author jascotty2 - * @since 2019-08-25 - */ -public enum CompatibleSound { - - // some of these values are missing an API value.. - // would using the raw strings be better? - // 1.8 list: - // https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/mapping-and-modding-tutorials/2213619-1-8-all-playsound-sound-arguments - - /* 1.17 */ - // TODO: add similar sounds for older versions - BLOCK_AMETHYST_BLOCK_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_BLOCK_CHIME(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_BLOCK_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_BLOCK_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_BLOCK_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_BLOCK_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_CLUSTER_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_CLUSTER_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_CLUSTER_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_CLUSTER_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_AMETHYST_CLUSTER_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_LEAVES_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_LEAVES_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_LEAVES_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_LEAVES_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_LEAVES_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_AZALEA_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_BIG_DRIPLEAF_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_BIG_DRIPLEAF_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_BIG_DRIPLEAF_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_BIG_DRIPLEAF_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_BIG_DRIPLEAF_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_BIG_DRIPLEAF_TILT_DOWN(ServerVersion.V1_17, v(null, true)), - BLOCK_BIG_DRIPLEAF_TILT_UP(ServerVersion.V1_17, v(null, true)), - BLOCK_CAKE_ADD_CANDLE(ServerVersion.V1_17, v(null, true)), - BLOCK_CALCITE_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_CALCITE_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_CALCITE_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_CALCITE_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_CALCITE_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_CANDLE_AMBIENT(ServerVersion.V1_17, v(null, true)), - BLOCK_CANDLE_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_CANDLE_EXTINGUISH(ServerVersion.V1_17, v(null, true)), - BLOCK_CANDLE_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_CANDLE_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_CANDLE_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_CANDLE_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_CAVE_VINES_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_CAVE_VINES_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_CAVE_VINES_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_CAVE_VINES_PICK_BERRIES(ServerVersion.V1_17, v(null, true)), - BLOCK_CAVE_VINES_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_CAVE_VINES_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_COPPER_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_COPPER_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_COPPER_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_COPPER_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_COPPER_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_BRICKS_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_BRICKS_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_BRICKS_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_BRICKS_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_BRICKS_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_TILES_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_TILES_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_TILES_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_TILES_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_DEEPSLATE_TILES_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_DRIPSTONE_BLOCK_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_DRIPSTONE_BLOCK_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_DRIPSTONE_BLOCK_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_DRIPSTONE_BLOCK_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_DRIPSTONE_BLOCK_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_FLOWERING_AZALEA_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_FLOWERING_AZALEA_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_FLOWERING_AZALEA_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_FLOWERING_AZALEA_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_FLOWERING_AZALEA_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_HANGING_ROOTS_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_HANGING_ROOTS_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_HANGING_ROOTS_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_HANGING_ROOTS_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_HANGING_ROOTS_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_LARGE_AMETHYST_BUD_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_LARGE_AMETHYST_BUD_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_MEDIUM_AMETHYST_BUD_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_MEDIUM_AMETHYST_BUD_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_CARPET_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_CARPET_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_CARPET_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_CARPET_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_CARPET_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_MOSS_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_DRIP_LAVA(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_DRIP_LAVA_INTO_CAULDRON(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_DRIP_WATER(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_DRIP_WATER_INTO_CAULDRON(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_LAND(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_POINTED_DRIPSTONE_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_POLISHED_DEEPSLATE_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_POLISHED_DEEPSLATE_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_POLISHED_DEEPSLATE_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_POLISHED_DEEPSLATE_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_POLISHED_DEEPSLATE_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_POWDER_SNOW_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_POWDER_SNOW_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_POWDER_SNOW_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_POWDER_SNOW_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_POWDER_SNOW_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_ROOTED_DIRT_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_ROOTED_DIRT_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_ROOTED_DIRT_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_ROOTED_DIRT_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_ROOTED_DIRT_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_SCULK_SENSOR_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_SCULK_SENSOR_CLICKING(ServerVersion.V1_17, v(null, true)), - BLOCK_SCULK_SENSOR_CLICKING_STOP(ServerVersion.V1_17, v(null, true)), - BLOCK_SCULK_SENSOR_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_SCULK_SENSOR_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_SCULK_SENSOR_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_SCULK_SENSOR_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_SMALL_AMETHYST_BUD_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_SMALL_AMETHYST_BUD_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_SMALL_DRIPLEAF_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_SMALL_DRIPLEAF_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_SMALL_DRIPLEAF_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_SMALL_DRIPLEAF_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_SMALL_DRIPLEAF_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_SPORE_BLOSSOM_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_SPORE_BLOSSOM_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_SPORE_BLOSSOM_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_SPORE_BLOSSOM_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_SPORE_BLOSSOM_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES(ServerVersion.V1_17, v(null, true)), // "ITEM_SWEET_BERRIES_PICK_FROM_BUSH" - BLOCK_TUFF_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_TUFF_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_TUFF_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_TUFF_PLACE(ServerVersion.V1_17, v(null, true)), - BLOCK_TUFF_STEP(ServerVersion.V1_17, v(null, true)), - BLOCK_VINE_BREAK(ServerVersion.V1_17, v(null, true)), - BLOCK_VINE_FALL(ServerVersion.V1_17, v(null, true)), - BLOCK_VINE_HIT(ServerVersion.V1_17, v(null, true)), - BLOCK_VINE_PLACE(ServerVersion.V1_17, v(null, true)), - ENTITY_AXOLOTL_ATTACK(ServerVersion.V1_17, v(null, true)), - ENTITY_AXOLOTL_DEATH(ServerVersion.V1_17, v(null, true)), - ENTITY_AXOLOTL_HURT(ServerVersion.V1_17, v(null, true)), - ENTITY_AXOLOTL_IDLE_AIR(ServerVersion.V1_17, v(null, true)), - ENTITY_AXOLOTL_IDLE_WATER(ServerVersion.V1_17, v(null, true)), - ENTITY_AXOLOTL_SPLASH(ServerVersion.V1_17, v(null, true)), - ENTITY_AXOLOTL_SWIM(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_ITEM_FRAME_ADD_ITEM(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_ITEM_FRAME_BREAK(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_ITEM_FRAME_PLACE(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_ITEM_FRAME_REMOVE_ITEM(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_ITEM_FRAME_ROTATE_ITEM(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_SQUID_AMBIENT(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_SQUID_DEATH(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_SQUID_HURT(ServerVersion.V1_17, v(null, true)), - ENTITY_GLOW_SQUID_SQUIRT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_AMBIENT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_DEATH(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_EAT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_HURT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_LONG_JUMP(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_MILK(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_PREPARE_RAM(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_RAM_IMPACT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_SCREAMING_AMBIENT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_SCREAMING_DEATH(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_SCREAMING_EAT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_SCREAMING_HURT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_SCREAMING_LONG_JUMP(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_SCREAMING_MILK(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_SCREAMING_PREPARE_RAM(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_SCREAMING_RAM_IMPACT(ServerVersion.V1_17, v(null, true)), - ENTITY_GOAT_STEP(ServerVersion.V1_17, v(null, true)), - ENTITY_MINECART_INSIDE_UNDERWATER(ServerVersion.V1_17, v(null, true)), - ENTITY_PARROT_IMITATE_PIGLIN_BRUTE(ServerVersion.V1_17, v(null, true)), - ENTITY_PIGLIN_BRUTE_AMBIENT(ServerVersion.V1_17, v(null, true)), - ENTITY_PIGLIN_BRUTE_ANGRY(ServerVersion.V1_17, v(null, true)), - ENTITY_PIGLIN_BRUTE_CONVERTED_TO_ZOMBIFIED(ServerVersion.V1_17, v(null, true)), - ENTITY_PIGLIN_BRUTE_DEATH(ServerVersion.V1_17, v(null, true)), - ENTITY_PIGLIN_BRUTE_HURT(ServerVersion.V1_17, v(null, true)), - ENTITY_PIGLIN_BRUTE_STEP(ServerVersion.V1_17, v(null, true)), - ENTITY_PLAYER_HURT_FREEZE(ServerVersion.V1_17, v(null, true)), - ENTITY_SKELETON_CONVERTED_TO_STRAY(ServerVersion.V1_17, v(null, true)), - ITEM_AXE_SCRAPE(ServerVersion.V1_17, v(null, true)), - ITEM_AXE_WAX_OFF(ServerVersion.V1_17, v(null, true)), - ITEM_BONE_MEAL_USE(ServerVersion.V1_17, v(null, true)), - ITEM_BUCKET_EMPTY_AXOLOTL(ServerVersion.V1_17, v(null, true)), - ITEM_BUCKET_EMPTY_POWDER_SNOW(ServerVersion.V1_17, v(null, true)), - ITEM_BUCKET_FILL_AXOLOTL(ServerVersion.V1_17, v(null, true)), - ITEM_BUCKET_FILL_POWDER_SNOW(ServerVersion.V1_17, v(null, true)), - ITEM_GLOW_INK_SAC_USE(ServerVersion.V1_17, v(null, true)), - ITEM_HONEYCOMB_WAX_ON(ServerVersion.V1_17, v(null, true)), - ITEM_INK_SAC_USE(ServerVersion.V1_17, v(null, true)), - ITEM_SPYGLASS_STOP_USING(ServerVersion.V1_17, v(null, true)), - ITEM_SPYGLASS_USE(ServerVersion.V1_17, v(null, true)), - ITEM_DYE_USE(ServerVersion.V1_17, v(null, true)), - - /* 1.16 */ - // TODO: add similar sounds for older versions - AMBIENT_BASALT_DELTAS_ADDITIONS(ServerVersion.V1_16, v(null, true)), - AMBIENT_BASALT_DELTAS_LOOP(ServerVersion.V1_16, v(null, true)), - AMBIENT_BASALT_DELTAS_MOOD(ServerVersion.V1_16, v(null, true)), - AMBIENT_CRIMSON_FOREST_ADDITIONS(ServerVersion.V1_16, v(null, true)), - AMBIENT_CRIMSON_FOREST_LOOP(ServerVersion.V1_16, v(null, true)), - AMBIENT_CRIMSON_FOREST_MOOD(ServerVersion.V1_16, v(null, true)), - AMBIENT_NETHER_WASTES_ADDITIONS(ServerVersion.V1_16, v(null, true)), - AMBIENT_NETHER_WASTES_LOOP(ServerVersion.V1_16, v(null, true)), - AMBIENT_NETHER_WASTES_MOOD(ServerVersion.V1_16, v(null, true)), - AMBIENT_SOUL_SAND_VALLEY_ADDITIONS(ServerVersion.V1_16, v(null, true)), - AMBIENT_SOUL_SAND_VALLEY_LOOP(ServerVersion.V1_16, v(null, true)), - AMBIENT_SOUL_SAND_VALLEY_MOOD(ServerVersion.V1_16, v(null, true)), - AMBIENT_WARPED_FOREST_ADDITIONS(ServerVersion.V1_16, v(null, true)), - AMBIENT_WARPED_FOREST_LOOP(ServerVersion.V1_16, v(null, true)), - AMBIENT_WARPED_FOREST_MOOD(ServerVersion.V1_16, v(null, true)), - BLOCK_ANCIENT_DEBRIS_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_ANCIENT_DEBRIS_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_ANCIENT_DEBRIS_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_ANCIENT_DEBRIS_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_ANCIENT_DEBRIS_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_BASALT_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_BASALT_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_BASALT_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_BASALT_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_BASALT_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_BONE_BLOCK_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_BONE_BLOCK_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_BONE_BLOCK_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_BONE_BLOCK_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_BONE_BLOCK_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_CHAIN_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_CHAIN_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_CHAIN_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_CHAIN_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_CHAIN_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_FUNGUS_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_FUNGUS_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_FUNGUS_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_FUNGUS_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_FUNGUS_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_GILDED_BLACKSTONE_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_GILDED_BLACKSTONE_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_GILDED_BLACKSTONE_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_GILDED_BLACKSTONE_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_GILDED_BLACKSTONE_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_LODESTONE_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_LODESTONE_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_LODESTONE_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_LODESTONE_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_LODESTONE_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERITE_BLOCK_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERITE_BLOCK_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERITE_BLOCK_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERITE_BLOCK_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERITE_BLOCK_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERRACK_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERRACK_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERRACK_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERRACK_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHERRACK_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_BRICKS_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_BRICKS_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_BRICKS_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_BRICKS_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_BRICKS_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_GOLD_ORE_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_GOLD_ORE_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_GOLD_ORE_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_GOLD_ORE_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_GOLD_ORE_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_ORE_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_ORE_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_ORE_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_ORE_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_ORE_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_SPROUTS_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_SPROUTS_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_SPROUTS_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_SPROUTS_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_NETHER_SPROUTS_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_NYLIUM_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_NYLIUM_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_NYLIUM_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_NYLIUM_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_NYLIUM_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_RESPAWN_ANCHOR_AMBIENT(ServerVersion.V1_16, v(null, true)), - BLOCK_RESPAWN_ANCHOR_CHARGE(ServerVersion.V1_16, v(null, true)), - BLOCK_RESPAWN_ANCHOR_DEPLETE(ServerVersion.V1_16, v(null, true)), - BLOCK_RESPAWN_ANCHOR_SET_SPAWN(ServerVersion.V1_16, v(null, true)), - BLOCK_ROOTS_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_ROOTS_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_ROOTS_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_ROOTS_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_ROOTS_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_SHROOMLIGHT_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_SHROOMLIGHT_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_SHROOMLIGHT_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_SHROOMLIGHT_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_SHROOMLIGHT_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_SMITHING_TABLE_USE(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SAND_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SAND_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SAND_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SAND_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SAND_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SOIL_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SOIL_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SOIL_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SOIL_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_SOUL_SOIL_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_STEM_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_STEM_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_STEM_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_STEM_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_STEM_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_VINE_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_WART_BLOCK_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_WART_BLOCK_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_WART_BLOCK_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_WART_BLOCK_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_WART_BLOCK_STEP(ServerVersion.V1_16, v(null, true)), - BLOCK_WEEPING_VINES_BREAK(ServerVersion.V1_16, v(null, true)), - BLOCK_WEEPING_VINES_FALL(ServerVersion.V1_16, v(null, true)), - BLOCK_WEEPING_VINES_HIT(ServerVersion.V1_16, v(null, true)), - BLOCK_WEEPING_VINES_PLACE(ServerVersion.V1_16, v(null, true)), - BLOCK_WEEPING_VINES_STEP(ServerVersion.V1_16, v(null, true)), - ENTITY_DONKEY_EAT(ServerVersion.V1_16, v(null, true)), - ENTITY_FOX_TELEPORT(ServerVersion.V1_16, v(null, true)), - ENTITY_MULE_ANGRY(ServerVersion.V1_16, v(null, true)), - ENTITY_MULE_EAT(ServerVersion.V1_16, v(null, true)), - ENTITY_PARROT_IMITATE_HOGLIN(ServerVersion.V1_16, v(null, true)), - ENTITY_PARROT_IMITATE_PIGLIN(ServerVersion.V1_16, v(null, true)), - ENTITY_PARROT_IMITATE_ZOGLIN(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_ADMIRING_ITEM(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_AMBIENT(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_ANGRY(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_CELEBRATE(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_CONVERTED_TO_ZOMBIFIED(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_DEATH(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_HURT(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_JEALOUS(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_RETREAT(ServerVersion.V1_16, v(null, true)), - ENTITY_PIGLIN_STEP(ServerVersion.V1_16, v(null, true)), - ENTITY_SNOW_GOLEM_SHEAR(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_AMBIENT(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_DEATH(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_EAT(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_HAPPY(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_HURT(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_RETREAT(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_SADDLE(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_STEP(ServerVersion.V1_16, v(null, true)), - ENTITY_STRIDER_STEP_LAVA(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOGLIN_AMBIENT(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOGLIN_ANGRY(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOGLIN_ATTACK(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOGLIN_DEATH(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOGLIN_HURT(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOGLIN_STEP(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOMBIFIED_PIGLIN_AMBIENT(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOMBIFIED_PIGLIN_ANGRY(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOMBIFIED_PIGLIN_DEATH(ServerVersion.V1_16, v(null, true)), - ENTITY_ZOMBIFIED_PIGLIN_HURT(ServerVersion.V1_16, v(null, true)), - ITEM_ARMOR_EQUIP_NETHERITE(ServerVersion.V1_16, v(null, true)), - ITEM_LODESTONE_COMPASS_LOCK(ServerVersion.V1_16, v(null, true)), - MUSIC_DISC_PIGSTEP(ServerVersion.V1_16, v(null, true)), - MUSIC_NETHER_BASALT_DELTAS(ServerVersion.V1_16, v(null, true)), - MUSIC_NETHER_CRIMSON_FOREST(ServerVersion.V1_16, v(null, true)), - MUSIC_NETHER_NETHER_WASTES(ServerVersion.V1_16, v(null, true)), - MUSIC_NETHER_SOUL_SAND_VALLEY(ServerVersion.V1_16, v(null, true)), - MUSIC_NETHER_WARPED_FOREST(ServerVersion.V1_16, v(null, true)), - PARTICLE_SOUL_ESCAPE(ServerVersion.V1_16, v(null, true)), - - /* 1.15 */ - // TODO: add similar sounds for older versions - BLOCK_BEEHIVE_DRIP(ServerVersion.V1_15, v(null, true)), - BLOCK_BEEHIVE_ENTER(ServerVersion.V1_15, v(null, true)), - BLOCK_BEEHIVE_EXIT(ServerVersion.V1_15, v(null, true)), - BLOCK_BEEHIVE_SHEAR(ServerVersion.V1_15, v(null, true)), - BLOCK_BEEHIVE_WORK(ServerVersion.V1_15, v(null, true)), - BLOCK_HONEY_BLOCK_BREAK(ServerVersion.V1_15, v(null, true)), - BLOCK_HONEY_BLOCK_FALL(ServerVersion.V1_15, v(null, true)), - BLOCK_HONEY_BLOCK_HIT(ServerVersion.V1_15, v(null, true)), - BLOCK_HONEY_BLOCK_PLACE(ServerVersion.V1_15, v(null, true)), - BLOCK_HONEY_BLOCK_SLIDE(ServerVersion.V1_15, v(null, true)), - BLOCK_HONEY_BLOCK_STEP(ServerVersion.V1_15, v(null, true)), - ENTITY_BEE_DEATH(ServerVersion.V1_15, v(null, true)), - ENTITY_BEE_HURT(ServerVersion.V1_15, v(null, true)), - ENTITY_BEE_LOOP(ServerVersion.V1_15, v(null, true)), - ENTITY_BEE_LOOP_AGGRESSIVE(ServerVersion.V1_15, v(null, true)), - ENTITY_BEE_POLLINATE(ServerVersion.V1_15, v(null, true)), - ENTITY_BEE_STING(ServerVersion.V1_15, v(null, true)), - ENTITY_IRON_GOLEM_DAMAGE(ServerVersion.V1_15, v(null, true)), - ENTITY_IRON_GOLEM_REPAIR(ServerVersion.V1_15, v(null, true)), - ITEM_HONEY_BOTTLE_DRINK(ServerVersion.V1_15, v(null, true)), - - AMBIENT_CAVE(ServerVersion.V1_9, v("AMBIENCE_CAVE")), - AMBIENT_UNDERWATER_ENTER, - AMBIENT_UNDERWATER_EXIT, - AMBIENT_UNDERWATER_LOOP, - AMBIENT_UNDERWATER_LOOP_ADDITIONS, - AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE, - AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE, - BLOCK_ANVIL_BREAK(ServerVersion.V1_9, v("ANVIL_BREAK")), - BLOCK_ANVIL_DESTROY(ServerVersion.V1_9, v("ANVIL_BREAK", true)), - BLOCK_ANVIL_FALL(ServerVersion.V1_9, v("ANVIL_LAND", true)), - BLOCK_ANVIL_HIT(ServerVersion.V1_9, v("ANVIL_LAND", true)), - BLOCK_ANVIL_LAND(ServerVersion.V1_9, v("ANVIL_LAND")), - BLOCK_ANVIL_PLACE(ServerVersion.V1_9, v("ANVIL_LAND", true)), - BLOCK_ANVIL_STEP(ServerVersion.V1_9, v("ANVIL_LAND", true)), - BLOCK_ANVIL_USE("ANVIL_USE"), - BLOCK_BAMBOO_BREAK(ServerVersion.V1_14, v(ServerVersion.V1_9, "BLOCK_WOOD_BREAK"), v(ServerVersion.V1_8, "DIG_WOOD")), - BLOCK_BAMBOO_FALL, - BLOCK_BAMBOO_HIT, - BLOCK_BAMBOO_PLACE, - BLOCK_BAMBOO_SAPLING_BREAK, - BLOCK_BAMBOO_SAPLING_HIT, - BLOCK_BAMBOO_SAPLING_PLACE, - BLOCK_BAMBOO_STEP, - BLOCK_BARREL_CLOSE, - BLOCK_BARREL_OPEN, - BLOCK_BEACON_ACTIVATE, - BLOCK_BEACON_AMBIENT, - BLOCK_BEACON_DEACTIVATE, - BLOCK_BEACON_POWER_SELECT, - BLOCK_BELL_RESONATE, - BLOCK_BELL_USE, - BLOCK_BLASTFURNACE_FIRE_CRACKLE, - BLOCK_BREWING_STAND_BREW(ServerVersion.V1_9, v("LAVA_POP", true)), - BLOCK_BUBBLE_COLUMN_BUBBLE_POP, - BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT, - BLOCK_BUBBLE_COLUMN_UPWARDS_INSIDE, - BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT, - BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE, - BLOCK_CAMPFIRE_CRACKLE, - BLOCK_CHEST_CLOSE(ServerVersion.V1_9, v("CHEST_CLOSE")), - BLOCK_CHEST_LOCKED(ServerVersion.V1_9, v("CHEST_CLOSE", true)), - BLOCK_CHEST_OPEN(ServerVersion.V1_9, v("CHEST_OPEN")), - BLOCK_CHORUS_FLOWER_DEATH(ServerVersion.V1_9, v(null, true)), // I have no idea.. - BLOCK_CHORUS_FLOWER_GROW(ServerVersion.V1_9, v(null, true)), // I have no idea.. - BLOCK_COMPARATOR_CLICK(ServerVersion.V1_9, v("WOOD_CLICK", true)), - BLOCK_COMPOSTER_EMPTY, - BLOCK_COMPOSTER_FILL, - BLOCK_COMPOSTER_FILL_SUCCESS, - BLOCK_COMPOSTER_READY, - BLOCK_CONDUIT_ACTIVATE, - BLOCK_CONDUIT_AMBIENT, - BLOCK_CONDUIT_AMBIENT_SHORT, - BLOCK_CONDUIT_ATTACK_TARGET, - BLOCK_CONDUIT_DEACTIVATE, - BLOCK_CORAL_BLOCK_BREAK, - BLOCK_CORAL_BLOCK_FALL, - BLOCK_CORAL_BLOCK_HIT, - BLOCK_CORAL_BLOCK_PLACE, - BLOCK_CORAL_BLOCK_STEP, - BLOCK_CROP_BREAK, - BLOCK_DISPENSER_DISPENSE(ServerVersion.V1_9, v("SHOOT_ARROW", true)), - BLOCK_DISPENSER_FAIL(ServerVersion.V1_9, v("WOOD_CLICK", true)), - BLOCK_DISPENSER_LAUNCH(ServerVersion.V1_9, v("GHAST_FIREBALL", true)), - BLOCK_ENCHANTMENT_TABLE_USE, - BLOCK_ENDER_CHEST_CLOSE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_CLOSE"), v("CHEST_CLOSE", true)), - BLOCK_ENDER_CHEST_OPEN(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_OPEN"), v("CHEST_OPEN", true)), - BLOCK_END_GATEWAY_SPAWN(ServerVersion.V1_9, v("PORTAL_TRIGGER", true)), - BLOCK_END_PORTAL_FRAME_FILL, - BLOCK_END_PORTAL_SPAWN, - BLOCK_FENCE_GATE_CLOSE("DOOR_CLOSE"), - BLOCK_FENCE_GATE_OPEN("DOOR_OPEN"), - BLOCK_FIRE_AMBIENT("FIRE"), - BLOCK_FIRE_EXTINGUISH("FIZZ"), - BLOCK_FURNACE_FIRE_CRACKLE(ServerVersion.V1_9, v("FIRE", true)), - BLOCK_GLASS_BREAK("GLASS"), - BLOCK_GLASS_FALL(ServerVersion.V1_9, v("STEP_GRASS", true)), - BLOCK_GLASS_HIT(ServerVersion.V1_9, v("STEP_GRASS", true)), - BLOCK_GLASS_PLACE(ServerVersion.V1_9, v("STEP_GRASS", true)), - BLOCK_GLASS_STEP(ServerVersion.V1_9, v("STEP_STONE", true)), - BLOCK_GRASS_BREAK("DIG_GRASS"), - BLOCK_GRASS_FALL(ServerVersion.V1_9, v("STEP_GRASS", true)), - BLOCK_GRASS_HIT(ServerVersion.V1_9, v("STEP_GRASS", true)), - BLOCK_GRASS_PLACE(ServerVersion.V1_9, v("STEP_GRASS", true)), - BLOCK_GRASS_STEP("STEP_GRASS"), - BLOCK_GRAVEL_BREAK("DIG_GRAVEL"), - BLOCK_GRAVEL_FALL(ServerVersion.V1_9, v("STEP_GRAVEL", true)), - BLOCK_GRAVEL_HIT(ServerVersion.V1_9, v("STEP_GRAVEL", true)), - BLOCK_GRAVEL_PLACE(ServerVersion.V1_9, v("STEP_GRAVEL", true)), - BLOCK_GRAVEL_STEP("STEP_GRAVEL"), - BLOCK_GRINDSTONE_USE, - BLOCK_IRON_DOOR_CLOSE("DOOR_CLOSE"), - BLOCK_IRON_DOOR_OPEN("DOOR_OPEN"), - BLOCK_IRON_TRAPDOOR_CLOSE("DOOR_CLOSE"), - BLOCK_IRON_TRAPDOOR_OPEN("DOOR_OPEN"), - BLOCK_LADDER_BREAK(ServerVersion.V1_9, v(null, true)), - BLOCK_LADDER_FALL(ServerVersion.V1_9, v("STEP_LADDER", true)), - BLOCK_LADDER_HIT(ServerVersion.V1_9, v(null, true)), - BLOCK_LADDER_PLACE(ServerVersion.V1_9, v(null, true)), - BLOCK_LADDER_STEP("STEP_LADDER"), - BLOCK_LANTERN_BREAK, - BLOCK_LANTERN_FALL, - BLOCK_LANTERN_HIT, - BLOCK_LANTERN_PLACE, - BLOCK_LANTERN_STEP, - BLOCK_LAVA_AMBIENT("LAVA"), - BLOCK_LAVA_EXTINGUISH("FIZZ"), - BLOCK_LAVA_POP("LAVA_POP"), - BLOCK_LEVER_CLICK("WOOD_CLICK"), - BLOCK_LILY_PAD_PLACE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WATERLILY_PLACE"), v(null, true)), - BLOCK_METAL_BREAK(ServerVersion.V1_9, v(null, true)), - BLOCK_METAL_FALL(ServerVersion.V1_9, v(null, true)), - BLOCK_METAL_HIT(ServerVersion.V1_9, v(null, true)), - BLOCK_METAL_PLACE(ServerVersion.V1_9, v(null, true)), - BLOCK_METAL_PRESSURE_PLATE_CLICK_OFF(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_METAL_PRESSUREPLATE_CLICK_OFF"), v("WOOD_CLICK", true)), - BLOCK_METAL_PRESSURE_PLATE_CLICK_ON(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_METAL_PRESSUREPLATE_CLICK_ON"), v("WOOD_CLICK", true)), - BLOCK_METAL_STEP(ServerVersion.V1_9, v("STEP_STONE", true)), - BLOCK_NETHER_WART_BREAK, - BLOCK_NOTE_BLOCK_BANJO(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_GUITAR", true), v(ServerVersion.V1_12, "BLOCK_NOTE_GUITAR", true), v(ServerVersion.V1_9, "BLOCK_NOTE_BASS"), v("NOTE_BASS_GUITAR", true)), - BLOCK_NOTE_BLOCK_BASEDRUM(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_BASEDRUM"), v("NOTE_BASS_DRUM")), - BLOCK_NOTE_BLOCK_BASS(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_BASS"), v("NOTE_BASS")), - BLOCK_NOTE_BLOCK_BELL(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_BELL"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_PLING", true)), - BLOCK_NOTE_BLOCK_BIT(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_BELL", true), v(ServerVersion.V1_12, "BLOCK_NOTE_BELL", true), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_PLING", true)), - BLOCK_NOTE_BLOCK_CHIME(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_CHIME"), v(ServerVersion.V1_9, "BLOCK_NOTE_PLING", true), v("NOTE_PLING", true)), - BLOCK_NOTE_BLOCK_COW_BELL(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_BELL", true), v(ServerVersion.V1_12, "BLOCK_NOTE_BELL"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_PLING", true)), - BLOCK_NOTE_BLOCK_DIDGERIDOO(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_FLUTE", true), v(ServerVersion.V1_12, "BLOCK_NOTE_FLUTE", true), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_BASS_GUITAR", true)), - BLOCK_NOTE_BLOCK_FLUTE(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_FLUTE"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_BASS_GUITAR", true)), - BLOCK_NOTE_BLOCK_GUITAR(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_GUITAR"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_BASS_GUITAR")), // This value disappeared from the API from 1.9-1.11 (returned in 12) - BLOCK_NOTE_BLOCK_HARP(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_HARP"), v("NOTE_PIANO")), - BLOCK_NOTE_BLOCK_HAT(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_HAT"), v("NOTE_STICKS")), - BLOCK_NOTE_BLOCK_IRON_XYLOPHONE(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_XYLOPHONE", true), v(ServerVersion.V1_12, "BLOCK_NOTE_XYLOPHONE"), v(ServerVersion.V1_9, "BLOCK_NOTE_PLING", true), v("NOTE_PLING", true)), - BLOCK_NOTE_BLOCK_PLING(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_PLING"), v("NOTE_PLING")), - BLOCK_NOTE_BLOCK_SNARE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_SNARE"), v("NOTE_SNARE_DRUM")), - BLOCK_NOTE_BLOCK_XYLOPHONE(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_XYLOPHONE"), v(ServerVersion.V1_9, "BLOCK_NOTE_PLING", true), v("NOTE_PLING", true)), - BLOCK_PISTON_CONTRACT("PISTON_RETRACT"), - BLOCK_PISTON_EXTEND("PISTON_EXTEND"), - BLOCK_PORTAL_AMBIENT("PORTAL"), - BLOCK_PORTAL_TRAVEL("PORTAL_TRAVEL"), - BLOCK_PORTAL_TRIGGER("PORTAL_TRIGGER"), - BLOCK_PUMPKIN_CARVE, - BLOCK_REDSTONE_TORCH_BURNOUT("FIZZ"), - BLOCK_SAND_BREAK("DIG_SAND"), - BLOCK_SAND_FALL(ServerVersion.V1_9, v("STEP_SAND", true)), - BLOCK_SAND_HIT(ServerVersion.V1_9, v("STEP_SAND", true)), - BLOCK_SAND_PLACE(ServerVersion.V1_9, v("STEP_SAND", true)), - BLOCK_SAND_STEP("STEP_SAND"), - BLOCK_SCAFFOLDING_BREAK, - BLOCK_SCAFFOLDING_FALL, - BLOCK_SCAFFOLDING_HIT, - BLOCK_SCAFFOLDING_PLACE, - BLOCK_SCAFFOLDING_STEP, - BLOCK_SHULKER_BOX_CLOSE(ServerVersion.V1_11, v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_CLOSE", true), v("CHEST_CLOSE", true)), - BLOCK_SHULKER_BOX_OPEN(ServerVersion.V1_11, v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_OPEN", true), v("CHEST_OPEN", true)), - BLOCK_SLIME_BLOCK_BREAK(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_BREAK"), v(null, true)), - BLOCK_SLIME_BLOCK_FALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_FALL"), v(null, true)), - BLOCK_SLIME_BLOCK_HIT(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_HIT"), v(null, true)), - BLOCK_SLIME_BLOCK_PLACE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_PLACE"), v(null, true)), - BLOCK_SLIME_BLOCK_STEP(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_STEP"), v(null, true)), - BLOCK_SMOKER_SMOKE, - BLOCK_SNOW_BREAK("DIG_SNOW"), - BLOCK_SNOW_FALL(ServerVersion.V1_9, v("STEP_SNOW", true)), - BLOCK_SNOW_HIT(ServerVersion.V1_9, v("STEP_SNOW", true)), - BLOCK_SNOW_PLACE(ServerVersion.V1_9, v("STEP_SNOW", true)), - BLOCK_SNOW_STEP("STEP_SNOW"), - BLOCK_STONE_BREAK("DIG_STONE"), - BLOCK_STONE_BUTTON_CLICK_OFF(ServerVersion.V1_9, v("WOOD_CLICK", true)), - BLOCK_STONE_BUTTON_CLICK_ON(ServerVersion.V1_9, v("WOOD_CLICK", true)), - BLOCK_STONE_FALL, - BLOCK_STONE_HIT, - BLOCK_STONE_PLACE, - BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF, - BLOCK_STONE_PRESSURE_PLATE_CLICK_ON, - BLOCK_STONE_STEP("STEP_STONE"), - BLOCK_SWEET_BERRY_BUSH_BREAK, - BLOCK_SWEET_BERRY_BUSH_PLACE, - BLOCK_TRIPWIRE_ATTACH(ServerVersion.V1_9, v("WOOD_CLICK", true)), - BLOCK_TRIPWIRE_CLICK_OFF(ServerVersion.V1_9, v("WOOD_CLICK", true)), - BLOCK_TRIPWIRE_CLICK_ON(ServerVersion.V1_9, v("WOOD_CLICK", true)), - BLOCK_TRIPWIRE_DETACH(ServerVersion.V1_9, v("WOOD_CLICK", true)), - BLOCK_WATER_AMBIENT("WATER"), - BLOCK_WET_GRASS_BREAK, - BLOCK_WET_GRASS_FALL, - BLOCK_WET_GRASS_HIT, - BLOCK_WET_GRASS_PLACE, - BLOCK_WET_GRASS_STEP, - BLOCK_WOODEN_BUTTON_CLICK_OFF(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_BUTTON_CLICK_ON"), v("WOOD_CLICK")), - BLOCK_WOODEN_BUTTON_CLICK_ON(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_BUTTON_CLICK_ON"), v("WOOD_CLICK")), - BLOCK_WOODEN_DOOR_CLOSE("DOOR_CLOSE"), - BLOCK_WOODEN_DOOR_OPEN("DOOR_OPEN"), - BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_PRESSUREPLATE_CLICK_OFF"), v("WOOD_CLICK", true)), - BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_PRESSUREPLATE_CLICK_ON"), v("WOOD_CLICK", true)), - BLOCK_WOODEN_TRAPDOOR_CLOSE("DOOR_OPEN"), - BLOCK_WOODEN_TRAPDOOR_OPEN("DOOR_OPEN"), - BLOCK_WOOD_BREAK("DIG_WOOD"), - BLOCK_WOOD_FALL(ServerVersion.V1_9, v("STEP_WOOD", true)), - BLOCK_WOOD_HIT(ServerVersion.V1_9, v("STEP_WOOD", true)), - BLOCK_WOOD_PLACE(ServerVersion.V1_9, v("STEP_WOOD", true)), - BLOCK_WOOD_STEP("STEP_WOOD"), - BLOCK_WOOL_BREAK(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_BREAK"), v("DIG_WOOL")), - BLOCK_WOOL_FALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_STEP", true), v("STEP_WOOL", true)), - BLOCK_WOOL_HIT(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_STEP", true), v("STEP_WOOL", true)), - BLOCK_WOOL_PLACE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_STEP", true), v("STEP_WOOL", true)), - BLOCK_WOOL_STEP(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_STEP"), v("STEP_WOOL")), - ENCHANT_THORNS_HIT, - ENTITY_ARMOR_STAND_BREAK, - ENTITY_ARMOR_STAND_FALL, - ENTITY_ARMOR_STAND_HIT, - ENTITY_ARMOR_STAND_PLACE, - ENTITY_ARROW_HIT("SUCCESSFUL_HIT"), // these may be reversed.. - ENTITY_ARROW_HIT_PLAYER("ARROW_HIT"), - ENTITY_ARROW_SHOOT("SHOOT_ARROW"), - ENTITY_BAT_AMBIENT("BAT_IDLE"), - ENTITY_BAT_DEATH("BAT_DEATH"), - ENTITY_BAT_HURT("BAT_HURT"), - ENTITY_BAT_LOOP("BAT_LOOP"), - ENTITY_BAT_TAKEOFF("BAT_TAKEOFF"), - ENTITY_BLAZE_AMBIENT("BLAZE_BREATH"), - ENTITY_BLAZE_BURN("BLAZE_HIT"), - ENTITY_BLAZE_DEATH("BLAZE_DEATH"), - ENTITY_BLAZE_HURT("BLAZE_HIT"), - ENTITY_BLAZE_SHOOT, - ENTITY_BOAT_PADDLE_LAND, - ENTITY_BOAT_PADDLE_WATER, - ENTITY_CAT_AMBIENT(ServerVersion.V1_9, v("CAT_MEOW")), - ENTITY_CAT_BEG_FOR_FOOD(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_CAT_AMBIENT", true), v("CAT_MEOW", true)), - ENTITY_CAT_DEATH, - ENTITY_CAT_EAT(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT"), v("EAT")), - ENTITY_CAT_HISS("CAT_HISS"), - ENTITY_CAT_HURT("CAT_HIT"), - ENTITY_CAT_PURR("CAT_PURR"), - ENTITY_CAT_PURREOW("CAT_PURREOW"), - ENTITY_CAT_STRAY_AMBIENT, - ENTITY_CHICKEN_AMBIENT("CHICKEN_IDLE"), - ENTITY_CHICKEN_DEATH, - ENTITY_CHICKEN_EGG("CHICKEN_EGG_POP"), - ENTITY_CHICKEN_HURT("CHICKEN_HURT"), - ENTITY_CHICKEN_STEP("CHICKEN_WALK"), - ENTITY_COD_AMBIENT, - ENTITY_COD_DEATH, - ENTITY_COD_FLOP, - ENTITY_COD_HURT, - ENTITY_COW_AMBIENT("COW_IDLE"), - ENTITY_COW_DEATH("COW_HURT"), - ENTITY_COW_HURT("COW_HURT"), - ENTITY_COW_MILK, - ENTITY_COW_STEP("COW_WALK"), - ENTITY_CREEPER_DEATH("CREEPER_DEATH"), - ENTITY_CREEPER_HURT, - ENTITY_CREEPER_PRIMED("CREEPER_HISS"), - ENTITY_DOLPHIN_AMBIENT, - ENTITY_DOLPHIN_AMBIENT_WATER, - ENTITY_DOLPHIN_ATTACK, - ENTITY_DOLPHIN_DEATH, - ENTITY_DOLPHIN_EAT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), - ENTITY_DOLPHIN_HURT, - ENTITY_DOLPHIN_JUMP, - ENTITY_DOLPHIN_PLAY, - ENTITY_DOLPHIN_SPLASH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_GENERIC_SPLASH", true), v("SPLASH", true)), - ENTITY_DOLPHIN_SWIM, - ENTITY_DONKEY_AMBIENT("DONKEY_IDLE"), - ENTITY_DONKEY_ANGRY("DONKEY_ANGRY"), - ENTITY_DONKEY_CHEST, - ENTITY_DONKEY_DEATH("DONKEY_DEATH"), - ENTITY_DONKEY_HURT("DONKEY_HIT"), - ENTITY_DRAGON_FIREBALL_EXPLODE, - ENTITY_DROWNED_AMBIENT, - ENTITY_DROWNED_AMBIENT_WATER, - ENTITY_DROWNED_DEATH, - ENTITY_DROWNED_DEATH_WATER, - ENTITY_DROWNED_HURT, - ENTITY_DROWNED_HURT_WATER, - ENTITY_DROWNED_SHOOT, - ENTITY_DROWNED_STEP, - ENTITY_DROWNED_SWIM, - ENTITY_EGG_THROW(ServerVersion.V1_9, v("SHOOT_ARROW", true)), - ENTITY_ELDER_GUARDIAN_AMBIENT, - ENTITY_ELDER_GUARDIAN_AMBIENT_LAND, - ENTITY_ELDER_GUARDIAN_CURSE, - ENTITY_ELDER_GUARDIAN_DEATH, - ENTITY_ELDER_GUARDIAN_DEATH_LAND, - ENTITY_ELDER_GUARDIAN_FLOP, - ENTITY_ELDER_GUARDIAN_HURT, - ENTITY_ELDER_GUARDIAN_HURT_LAND, - ENTITY_ENDERMAN_AMBIENT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_AMBIENT"), v("ENDERMAN_IDLE")), - ENTITY_ENDERMAN_DEATH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_DEATH"), v("ENDERMAN_DEATH")), - ENTITY_ENDERMAN_HURT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_HURT"), v("ENDERMAN_HIT")), - ENTITY_ENDERMAN_SCREAM(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_SCREAM"), v("ENDERMAN_SCREAM")), - ENTITY_ENDERMAN_STARE(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_STARE"), v("ENDERMAN_STARE")), - ENTITY_ENDERMAN_TELEPORT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_TELEPORT"), v("ENDERMAN_TELEPORT")), - ENTITY_ENDERMITE_AMBIENT, - ENTITY_ENDERMITE_DEATH, - ENTITY_ENDERMITE_HURT, - ENTITY_ENDERMITE_STEP, - ENTITY_ENDER_DRAGON_AMBIENT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_AMBIENT"), v("ENDERDRAGON_GROWL", true)), - ENTITY_ENDER_DRAGON_DEATH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_DEATH"), v("ENDERDRAGON_DEATH")), - ENTITY_ENDER_DRAGON_FLAP(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_FLAP"), v("ENDERDRAGON_WINGS")), - ENTITY_ENDER_DRAGON_GROWL(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_GROWL"), v("ENDERDRAGON_GROWL")), - ENTITY_ENDER_DRAGON_HURT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_HURT"), v("ENDERDRAGON_HIT")), - ENTITY_ENDER_DRAGON_SHOOT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_SHOOT"), v("GHAST_FIREBALL", true)), - ENTITY_ENDER_EYE_DEATH(ServerVersion.V1_13, v(ServerVersion.V1_12, "ENTITY_ENDEREYE_DEATH"), v(ServerVersion.V1_9, "BLOCK_GLASS_BREAK", true), v("GLASS", true)), - ENTITY_ENDER_EYE_LAUNCH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDEREYE_LAUNCH"), v(ServerVersion.V1_9, "BLOCK_PORTAL_TRIGGER", true), v("PORTAL_TRIGGER", true)), - ENTITY_ENDER_PEARL_THROW, - ENTITY_EVOKER_AMBIENT, - ENTITY_EVOKER_CAST_SPELL, - ENTITY_EVOKER_CELEBRATE, - ENTITY_EVOKER_DEATH, - ENTITY_EVOKER_FANGS_ATTACK, - ENTITY_EVOKER_HURT, - ENTITY_EVOKER_PREPARE_ATTACK, - ENTITY_EVOKER_PREPARE_SUMMON, - ENTITY_EVOKER_PREPARE_WOLOLO, - ENTITY_EXPERIENCE_BOTTLE_THROW, - ENTITY_EXPERIENCE_ORB_PICKUP("ORB_PICKUP"), - ENTITY_FIREWORK_ROCKET_BLAST(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_BLAST"), v("FIREWORK_BLAST")), - ENTITY_FIREWORK_ROCKET_BLAST_FAR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_BLAST_FAR"), v("FIREWORK_BLAST2")), - ENTITY_FIREWORK_ROCKET_LARGE_BLAST(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_LARGE_BLAST"), v("FIREWORK_LARGE_BLAST")), - ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_LARGE_BLAST_FAR"), v("FIREWORK_LARGE_BLAST2")), - ENTITY_FIREWORK_ROCKET_LAUNCH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_LAUNCH"), v("FIREWORK_LAUNCH")), - ENTITY_FIREWORK_ROCKET_SHOOT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_SHOOT"), v("FIREWORK_LAUNCH", true)), - ENTITY_FIREWORK_ROCKET_TWINKLE(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_TWINKLE"), v("FIREWORK_TWINKLE")), - ENTITY_FIREWORK_ROCKET_TWINKLE_FAR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_TWINKLE_FAR"), v("FIREWORK_TWINKLE2")), - ENTITY_FISHING_BOBBER_RETRIEVE, - ENTITY_FISHING_BOBBER_SPLASH, - ENTITY_FISHING_BOBBER_THROW, - ENTITY_FISH_SWIM, - ENTITY_FOX_AGGRO, - ENTITY_FOX_AMBIENT, - ENTITY_FOX_BITE, - ENTITY_FOX_DEATH, - ENTITY_FOX_EAT(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), - ENTITY_FOX_HURT, - ENTITY_FOX_SCREECH, - ENTITY_FOX_SLEEP, - ENTITY_FOX_SNIFF, - ENTITY_FOX_SPIT, - ENTITY_GENERIC_BIG_FALL("FALL_BIG"), - ENTITY_GENERIC_BURN, - ENTITY_GENERIC_DEATH, - ENTITY_GENERIC_DRINK("DRINK"), - ENTITY_GENERIC_EAT("EAT"), - ENTITY_GENERIC_EXPLODE("EXPLODE"), - ENTITY_GENERIC_EXTINGUISH_FIRE("FIZZ"), - ENTITY_GENERIC_HURT("HURT_FLESH"), - ENTITY_GENERIC_SMALL_FALL("FALL_SMALL"), - ENTITY_GENERIC_SPLASH(ServerVersion.V1_9, v("SPLASH", true)), - ENTITY_GENERIC_SWIM, - ENTITY_GHAST_AMBIENT("GHAST_MOAN"), - ENTITY_GHAST_DEATH("GHAST_DEATH"), - ENTITY_GHAST_HURT("GHAST_SCREAM2"), - ENTITY_GHAST_SCREAM("GHAST_SCREAM"), - ENTITY_GHAST_SHOOT("GHAST_FIREBALL"), - ENTITY_GHAST_WARN("GHAST_CHARGE"), - ENTITY_GUARDIAN_AMBIENT, - ENTITY_GUARDIAN_AMBIENT_LAND, - ENTITY_GUARDIAN_ATTACK, - ENTITY_GUARDIAN_DEATH, - ENTITY_GUARDIAN_DEATH_LAND, - ENTITY_GUARDIAN_FLOP, - ENTITY_GUARDIAN_HURT, - ENTITY_GUARDIAN_HURT_LAND, - ENTITY_HORSE_AMBIENT("HORSE_IDLE"), - ENTITY_HORSE_ANGRY("HORSE_ANGRY"), - ENTITY_HORSE_ARMOR("HORSE_ARMOR"), - ENTITY_HORSE_BREATHE("HORSE_BREATHE"), - ENTITY_HORSE_DEATH("HORSE_DEATH"), - ENTITY_HORSE_EAT("EAT"), - ENTITY_HORSE_GALLOP("HORSE_GALLOP"), - ENTITY_HORSE_HURT("HORSE_HIT"), - ENTITY_HORSE_JUMP("HORSE_JUMP"), - ENTITY_HORSE_LAND("HORSE_LAND"), - ENTITY_HORSE_SADDLE("HORSE_SADDLE"), - ENTITY_HORSE_STEP("HORSE_SOFT"), - ENTITY_HORSE_STEP_WOOD("HORSE_WOOD"), - ENTITY_HOSTILE_BIG_FALL, - ENTITY_HOSTILE_DEATH, - ENTITY_HOSTILE_HURT, - ENTITY_HOSTILE_SMALL_FALL, - ENTITY_HOSTILE_SPLASH(ServerVersion.V1_9, v("SPLASH", true)), - ENTITY_HOSTILE_SWIM, - ENTITY_HUSK_AMBIENT, - ENTITY_HUSK_CONVERTED_TO_ZOMBIE, - ENTITY_HUSK_DEATH, - ENTITY_HUSK_HURT, - ENTITY_HUSK_STEP, - ENTITY_ILLUSIONER_AMBIENT, - ENTITY_ILLUSIONER_CAST_SPELL, - ENTITY_ILLUSIONER_DEATH, - ENTITY_ILLUSIONER_HURT, - ENTITY_ILLUSIONER_MIRROR_MOVE, - ENTITY_ILLUSIONER_PREPARE_BLINDNESS, - ENTITY_ILLUSIONER_PREPARE_MIRROR, - ENTITY_IRON_GOLEM_ATTACK(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_IRONGOLEM_ATTACK"), v("IRONGOLEM_THROW")), - ENTITY_IRON_GOLEM_DEATH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_IRONGOLEM_DEATH"), v("IRONGOLEM_DEATH")), - ENTITY_IRON_GOLEM_HURT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_IRONGOLEM_HURT"), v("IRONGOLEM_HIT")), - ENTITY_IRON_GOLEM_STEP(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_IRONGOLEM_STEP"), v("IRONGOLEM_WALK")), - ENTITY_ITEM_BREAK("ITEM_BREAK"), - ENTITY_ITEM_FRAME_ADD_ITEM, - ENTITY_ITEM_FRAME_BREAK, - ENTITY_ITEM_FRAME_PLACE, - ENTITY_ITEM_FRAME_REMOVE_ITEM, - ENTITY_ITEM_FRAME_ROTATE_ITEM, - ENTITY_ITEM_PICKUP("ITEM_PICKUP"), - ENTITY_LEASH_KNOT_BREAK, - ENTITY_LEASH_KNOT_PLACE, - ENTITY_LIGHTNING_BOLT_IMPACT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_LIGHTNING_IMPACT"), v("AMBIENCE_THUNDER", true)), - ENTITY_LIGHTNING_BOLT_THUNDER(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_LIGHTNING_THUNDER"), v("AMBIENCE_THUNDER")), - ENTITY_LINGERING_POTION_THROW, - ENTITY_LLAMA_AMBIENT, - ENTITY_LLAMA_ANGRY(v(ServerVersion.V1_11, "ENTITY_HORSE_ANGRY"), v("HORSE_ANGRY")), - ENTITY_LLAMA_CHEST, - ENTITY_LLAMA_DEATH(v(ServerVersion.V1_11, "ENTITY_HORSE_DEATH"), v("HORSE_DEATH")), - ENTITY_LLAMA_EAT(v(ServerVersion.V1_11, "ENTITY_HORSE_EAT"), v("EAT")), - ENTITY_LLAMA_HURT(v(ServerVersion.V1_11, "ENTITY_HORSE_HURT"), v("HORSE_HIT")), - ENTITY_LLAMA_SPIT, - ENTITY_LLAMA_STEP, - ENTITY_LLAMA_SWAG, - ENTITY_MAGMA_CUBE_DEATH, // ENTITY_MAGMACUBE_DEATH - ENTITY_MAGMA_CUBE_DEATH_SMALL, - ENTITY_MAGMA_CUBE_HURT, // ENTITY_MAGMACUBE_HURT - ENTITY_MAGMA_CUBE_HURT_SMALL, - ENTITY_MAGMA_CUBE_JUMP(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_MAGMACUBE_JUMP"), v("MAGMACUBE_JUMP")), - ENTITY_MAGMA_CUBE_SQUISH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_MAGMACUBE_SQUISH"), v("MAGMACUBE_WALK")), - ENTITY_MAGMA_CUBE_SQUISH_SMALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_MAGMACUBE_SQUISH", true), v("MAGMACUBE_WALK2")), - ENTITY_MINECART_INSIDE("MINECART_INSIDE"), - ENTITY_MINECART_RIDING("MINECART_BASE"), - ENTITY_MOOSHROOM_CONVERT, - ENTITY_MOOSHROOM_EAT(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), - ENTITY_MOOSHROOM_MILK, - ENTITY_MOOSHROOM_SHEAR, - ENTITY_MOOSHROOM_SUSPICIOUS_MILK, - ENTITY_MULE_AMBIENT, - ENTITY_MULE_CHEST, - ENTITY_MULE_DEATH, - ENTITY_MULE_HURT, - ENTITY_OCELOT_AMBIENT, - ENTITY_OCELOT_DEATH, - ENTITY_OCELOT_HURT, - ENTITY_PAINTING_BREAK, - ENTITY_PAINTING_PLACE, - ENTITY_PANDA_AGGRESSIVE_AMBIENT, - ENTITY_PANDA_AMBIENT, - ENTITY_PANDA_BITE, - ENTITY_PANDA_CANT_BREED, - ENTITY_PANDA_DEATH, - ENTITY_PANDA_EAT(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), - ENTITY_PANDA_HURT, - ENTITY_PANDA_PRE_SNEEZE, - ENTITY_PANDA_SNEEZE, - ENTITY_PANDA_STEP, - ENTITY_PANDA_WORRIED_AMBIENT, - ENTITY_PARROT_AMBIENT, - ENTITY_PARROT_DEATH, - ENTITY_PARROT_EAT(ServerVersion.V1_12, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), - ENTITY_PARROT_FLY, - ENTITY_PARROT_HURT, - ENTITY_PARROT_IMITATE_BLAZE, - ENTITY_PARROT_IMITATE_CREEPER, - ENTITY_PARROT_IMITATE_DROWNED, - ENTITY_PARROT_IMITATE_ELDER_GUARDIAN, - ENTITY_PARROT_IMITATE_ENDERMAN, - ENTITY_PARROT_IMITATE_ENDERMITE, - ENTITY_PARROT_IMITATE_ENDER_DRAGON, - ENTITY_PARROT_IMITATE_EVOKER, - ENTITY_PARROT_IMITATE_GHAST, - ENTITY_PARROT_IMITATE_GUARDIAN, - ENTITY_PARROT_IMITATE_HUSK, - ENTITY_PARROT_IMITATE_ILLUSIONER, - ENTITY_PARROT_IMITATE_MAGMA_CUBE, - ENTITY_PARROT_IMITATE_PANDA, - ENTITY_PARROT_IMITATE_PHANTOM, - ENTITY_PARROT_IMITATE_PILLAGER, - ENTITY_PARROT_IMITATE_POLAR_BEAR, - ENTITY_PARROT_IMITATE_RAVAGER, - ENTITY_PARROT_IMITATE_SHULKER, - ENTITY_PARROT_IMITATE_SILVERFISH, - ENTITY_PARROT_IMITATE_SKELETON, - ENTITY_PARROT_IMITATE_SLIME, - ENTITY_PARROT_IMITATE_SPIDER, - ENTITY_PARROT_IMITATE_STRAY, - ENTITY_PARROT_IMITATE_VEX, - ENTITY_PARROT_IMITATE_VINDICATOR, - ENTITY_PARROT_IMITATE_WITCH, - ENTITY_PARROT_IMITATE_WITHER, - ENTITY_PARROT_IMITATE_WITHER_SKELETON, - ENTITY_PARROT_IMITATE_WOLF, - ENTITY_PARROT_IMITATE_ZOMBIE, - ENTITY_PARROT_IMITATE_ZOMBIE_PIGMAN, - ENTITY_PARROT_IMITATE_ZOMBIE_VILLAGER, - ENTITY_PARROT_STEP, - ENTITY_PHANTOM_AMBIENT, - ENTITY_PHANTOM_BITE, - ENTITY_PHANTOM_DEATH, - ENTITY_PHANTOM_FLAP, - ENTITY_PHANTOM_HURT, - ENTITY_PHANTOM_SWOOP, - ENTITY_PIG_AMBIENT("PIG_IDLE"), - ENTITY_PIG_DEATH("PIG_DEATH"), - ENTITY_PIG_HURT, - ENTITY_PIG_SADDLE, - ENTITY_PIG_STEP("PIG_WALK"), - ENTITY_PILLAGER_AMBIENT, - ENTITY_PILLAGER_CELEBRATE, - ENTITY_PILLAGER_DEATH, - ENTITY_PILLAGER_HURT, - ENTITY_PLAYER_ATTACK_CRIT, - ENTITY_PLAYER_ATTACK_KNOCKBACK, - ENTITY_PLAYER_ATTACK_NODAMAGE, - ENTITY_PLAYER_ATTACK_STRONG, - ENTITY_PLAYER_ATTACK_SWEEP, - ENTITY_PLAYER_ATTACK_WEAK, - ENTITY_PLAYER_BIG_FALL, - ENTITY_PLAYER_BREATH, - ENTITY_PLAYER_BURP("BURP"), - ENTITY_PLAYER_DEATH, - ENTITY_PLAYER_HURT, - ENTITY_PLAYER_HURT_DROWN, - ENTITY_PLAYER_HURT_ON_FIRE, - ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH, - ENTITY_PLAYER_LEVELUP("LEVEL_UP"), - ENTITY_PLAYER_SMALL_FALL, - ENTITY_PLAYER_SPLASH("SPLASH"), - ENTITY_PLAYER_SPLASH_HIGH_SPEED(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_GENERIC_SPLASH"), v("SPLASH2", true)), - ENTITY_PLAYER_SWIM("SWIM"), - ENTITY_POLAR_BEAR_AMBIENT, - ENTITY_POLAR_BEAR_AMBIENT_BABY, - ENTITY_POLAR_BEAR_DEATH, - ENTITY_POLAR_BEAR_HURT, - ENTITY_POLAR_BEAR_STEP, - ENTITY_POLAR_BEAR_WARNING, - ENTITY_PUFFER_FISH_AMBIENT, - ENTITY_PUFFER_FISH_BLOW_OUT, - ENTITY_PUFFER_FISH_BLOW_UP, - ENTITY_PUFFER_FISH_DEATH, - ENTITY_PUFFER_FISH_FLOP, - ENTITY_PUFFER_FISH_HURT, - ENTITY_PUFFER_FISH_STING, - ENTITY_RABBIT_AMBIENT, - ENTITY_RABBIT_ATTACK, - ENTITY_RABBIT_DEATH, - ENTITY_RABBIT_HURT, - ENTITY_RABBIT_JUMP, - ENTITY_RAVAGER_AMBIENT, - ENTITY_RAVAGER_ATTACK, - ENTITY_RAVAGER_CELEBRATE, - ENTITY_RAVAGER_DEATH, - ENTITY_RAVAGER_HURT, - ENTITY_RAVAGER_ROAR, - ENTITY_RAVAGER_STEP, - ENTITY_RAVAGER_STUNNED, - ENTITY_SALMON_AMBIENT, - ENTITY_SALMON_DEATH, - ENTITY_SALMON_FLOP, - ENTITY_SALMON_HURT, - ENTITY_SHEEP_AMBIENT("SHEEP_IDLE"), - ENTITY_SHEEP_DEATH, - ENTITY_SHEEP_HURT, - ENTITY_SHEEP_SHEAR("SHEEP_SHEAR"), - ENTITY_SHEEP_STEP("SHEEP_WALK"), - ENTITY_SHULKER_AMBIENT, - ENTITY_SHULKER_BULLET_HIT, - ENTITY_SHULKER_BULLET_HURT, - ENTITY_SHULKER_CLOSE, - ENTITY_SHULKER_DEATH, - ENTITY_SHULKER_HURT, - ENTITY_SHULKER_HURT_CLOSED, - ENTITY_SHULKER_OPEN, - ENTITY_SHULKER_SHOOT, - ENTITY_SHULKER_TELEPORT, - ENTITY_SILVERFISH_AMBIENT("SILVERFISH_IDLE"), - ENTITY_SILVERFISH_DEATH("SILVERFISH_KILL"), - ENTITY_SILVERFISH_HURT("SILVERFISH_HIT"), - ENTITY_SILVERFISH_STEP("SILVERFISH_WALK"), - ENTITY_SKELETON_AMBIENT("SKELETON_IDLE"), - ENTITY_SKELETON_DEATH("SKELETON_DEATH"), - ENTITY_SKELETON_HORSE_AMBIENT("HORSE_SKELETON_IDLE"), - ENTITY_SKELETON_HORSE_AMBIENT_WATER, - ENTITY_SKELETON_HORSE_DEATH("HORSE_SKELETON_DEATH"), - ENTITY_SKELETON_HORSE_GALLOP_WATER, - ENTITY_SKELETON_HORSE_HURT("HORSE_SKELETON_HIT"), - ENTITY_SKELETON_HORSE_JUMP_WATER, - ENTITY_SKELETON_HORSE_STEP_WATER, - ENTITY_SKELETON_HORSE_SWIM, - ENTITY_SKELETON_HURT("SKELETON_HURT"), - ENTITY_SKELETON_SHOOT(ServerVersion.V1_9, v("SHOOT_ARROW", true)), - ENTITY_SKELETON_STEP("SKELETON_WALK"), - ENTITY_SLIME_ATTACK("SLIME_ATTACK"), - ENTITY_SLIME_DEATH, - ENTITY_SLIME_DEATH_SMALL, - ENTITY_SLIME_HURT, - ENTITY_SLIME_HURT_SMALL, - ENTITY_SLIME_JUMP("SLIME_WALK"), // Not sure which is 1 or 2 - ENTITY_SLIME_JUMP_SMALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_SLIME_JUMP", true), v("SLIME_WALK", true)), - ENTITY_SLIME_SQUISH("SLIME_WALK2"), - ENTITY_SLIME_SQUISH_SMALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_SLIME_JUMP", true), v("SLIME_WALK2", true)), - ENTITY_SNOWBALL_THROW, - ENTITY_SNOW_GOLEM_AMBIENT, - ENTITY_SNOW_GOLEM_DEATH, - ENTITY_SNOW_GOLEM_HURT, - ENTITY_SNOW_GOLEM_SHOOT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_SNOWMAN_SHOOT"), v("SHOOT_ARROW", true)), // this is missing from 1.8 API for some reason - ENTITY_SPIDER_AMBIENT("SPIDER_IDLE"), - ENTITY_SPIDER_DEATH("SPIDER_DEATH"), - ENTITY_SPIDER_HURT, - ENTITY_SPIDER_STEP("SPIDER_WALK"), - ENTITY_SPLASH_POTION_BREAK, - ENTITY_SPLASH_POTION_THROW, - ENTITY_SQUID_AMBIENT, - ENTITY_SQUID_DEATH, - ENTITY_SQUID_HURT, - ENTITY_SQUID_SQUIRT, - ENTITY_STRAY_AMBIENT, - ENTITY_STRAY_DEATH, - ENTITY_STRAY_HURT, - ENTITY_STRAY_STEP, - ENTITY_TNT_PRIMED("FUSE"), - ENTITY_TROPICAL_FISH_AMBIENT, - ENTITY_TROPICAL_FISH_DEATH, - ENTITY_TROPICAL_FISH_FLOP, - ENTITY_TROPICAL_FISH_HURT, - ENTITY_TURTLE_AMBIENT_LAND, - ENTITY_TURTLE_DEATH, - ENTITY_TURTLE_DEATH_BABY, - ENTITY_TURTLE_EGG_BREAK, - ENTITY_TURTLE_EGG_CRACK, - ENTITY_TURTLE_EGG_HATCH, - ENTITY_TURTLE_HURT, - ENTITY_TURTLE_HURT_BABY, - ENTITY_TURTLE_LAY_EGG, - ENTITY_TURTLE_SHAMBLE, - ENTITY_TURTLE_SHAMBLE_BABY, - ENTITY_TURTLE_SWIM, - ENTITY_VEX_AMBIENT, - ENTITY_VEX_CHARGE, - ENTITY_VEX_DEATH, - ENTITY_VEX_HURT, - ENTITY_VILLAGER_AMBIENT("VILLAGER_IDLE"), - ENTITY_VILLAGER_CELEBRATE, - ENTITY_VILLAGER_DEATH("VILLAGER_DEATH"), - ENTITY_VILLAGER_HURT("VILLAGER_HIT"), - ENTITY_VILLAGER_NO("VILLAGER_NO"), - ENTITY_VILLAGER_TRADE(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_VILLAGER_TRADING"), v("VILLAGER_HAGGLE")), - ENTITY_VILLAGER_WORK_ARMORER, - ENTITY_VILLAGER_WORK_BUTCHER, - ENTITY_VILLAGER_WORK_CARTOGRAPHER, - ENTITY_VILLAGER_WORK_CLERIC, - ENTITY_VILLAGER_WORK_FARMER, - ENTITY_VILLAGER_WORK_FISHERMAN, - ENTITY_VILLAGER_WORK_FLETCHER, - ENTITY_VILLAGER_WORK_LEATHERWORKER, - ENTITY_VILLAGER_WORK_LIBRARIAN, - ENTITY_VILLAGER_WORK_MASON, - ENTITY_VILLAGER_WORK_SHEPHERD, - ENTITY_VILLAGER_WORK_TOOLSMITH, - ENTITY_VILLAGER_WORK_WEAPONSMITH, - ENTITY_VILLAGER_YES("VILLAGER_YES"), - ENTITY_VINDICATOR_AMBIENT, - ENTITY_VINDICATOR_CELEBRATE, - ENTITY_VINDICATOR_DEATH, - ENTITY_VINDICATOR_HURT, - ENTITY_WANDERING_TRADER_AMBIENT, - ENTITY_WANDERING_TRADER_DEATH, - ENTITY_WANDERING_TRADER_DISAPPEARED, - ENTITY_WANDERING_TRADER_DRINK_MILK(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_DRINK", true), v("DRINK", true)), - ENTITY_WANDERING_TRADER_DRINK_POTION(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_DRINK", true), v("DRINK", true)), - ENTITY_WANDERING_TRADER_HURT, - ENTITY_WANDERING_TRADER_NO, - ENTITY_WANDERING_TRADER_REAPPEARED, - ENTITY_WANDERING_TRADER_TRADE, - ENTITY_WANDERING_TRADER_YES, - ENTITY_WITCH_AMBIENT, - ENTITY_WITCH_CELEBRATE, - ENTITY_WITCH_DEATH, - ENTITY_WITCH_DRINK("DRINK"), - ENTITY_WITCH_HURT, - ENTITY_WITCH_THROW, - ENTITY_WITHER_AMBIENT("WITHER_IDLE"), - ENTITY_WITHER_BREAK_BLOCK("WITHER_SPAWN"), - ENTITY_WITHER_DEATH("WITHER_DEATH"), - ENTITY_WITHER_HURT("WITHER_HURT"), - ENTITY_WITHER_SHOOT("WITHER_SHOOT"), - ENTITY_WITHER_SKELETON_AMBIENT, - ENTITY_WITHER_SKELETON_DEATH, - ENTITY_WITHER_SKELETON_HURT, - ENTITY_WITHER_SKELETON_STEP, - ENTITY_WITHER_SPAWN, - ENTITY_WOLF_AMBIENT("WOLF_BARK"), - ENTITY_WOLF_DEATH("WOLF_DEATH"), - ENTITY_WOLF_GROWL("WOLF_GROWL"), - ENTITY_WOLF_HOWL("WOLF_HOWL"), - ENTITY_WOLF_HURT("WOLF_HURT"), - ENTITY_WOLF_PANT("WOLF_PANT"), - ENTITY_WOLF_SHAKE("WOLF_SHAKE"), - ENTITY_WOLF_STEP("WOLF_WALK"), - ENTITY_WOLF_WHINE("WOLF_WHINE"), - ENTITY_ZOMBIE_AMBIENT("ZOMBIE_IDLE"), - ENTITY_ZOMBIE_ATTACK_IRON_DOOR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ZOMBIE_ATTACK_IRON_DOOR", true), v("ZOMBIE_METAL")), - ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ZOMBIE_ATTACK_DOOR_WOOD", true), v("ZOMBIE_WOOD")), - ENTITY_ZOMBIE_BREAK_WOODEN_DOOR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ZOMBIE_BREAK_DOOR_WOOD", true), v("ZOMBIE_WOODBREAK")), - ENTITY_ZOMBIE_CONVERTED_TO_DROWNED, - ENTITY_ZOMBIE_DEATH("ZOMBIE_DEATH"), - ENTITY_ZOMBIE_DESTROY_EGG, - ENTITY_ZOMBIE_HORSE_AMBIENT("HORSE_ZOMBIE_IDLE"), - ENTITY_ZOMBIE_HORSE_DEATH("HORSE_ZOMBIE_DEATH"), - ENTITY_ZOMBIE_HORSE_HURT("HORSE_ZOMBIE_HIT"), - ENTITY_ZOMBIE_HURT("ZOMBIE_HURT"), - ENTITY_ZOMBIE_INFECT("ZOMBIE_INFECT"), - ENTITY_ZOMBIE_STEP("ZOMBIE_WALK"), - ENTITY_ZOMBIE_VILLAGER_AMBIENT, - ENTITY_ZOMBIE_VILLAGER_CONVERTED("ZOMBIE_REMEDY"), - ENTITY_ZOMBIE_VILLAGER_CURE("ZOMBIE_UNFECT"), - ENTITY_ZOMBIE_VILLAGER_DEATH, - ENTITY_ZOMBIE_VILLAGER_HURT, - ENTITY_ZOMBIE_VILLAGER_STEP, - EVENT_RAID_HORN, - ITEM_ARMOR_EQUIP_CHAIN(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), - ITEM_ARMOR_EQUIP_DIAMOND(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), - ITEM_ARMOR_EQUIP_ELYTRA(ServerVersion.V1_11, v(ServerVersion.V1_9, "ITEM_ARMOR_EQUIP_GENERIC", true), v("SUCCESSFUL_HIT", true)), - ITEM_ARMOR_EQUIP_GENERIC(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), - ITEM_ARMOR_EQUIP_GOLD(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), - ITEM_ARMOR_EQUIP_IRON(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), - ITEM_ARMOR_EQUIP_LEATHER(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), - ITEM_ARMOR_EQUIP_TURTLE(ServerVersion.V1_13, v(ServerVersion.V1_9, "ITEM_ARMOR_EQUIP_GENERIC", true), v("SUCCESSFUL_HIT", true)), - ITEM_AXE_STRIP, - ITEM_BOOK_PAGE_TURN, - ITEM_BOOK_PUT, - ITEM_BOTTLE_EMPTY, - ITEM_BOTTLE_FILL, - ITEM_BOTTLE_FILL_DRAGONBREATH, - ITEM_BUCKET_EMPTY, - ITEM_BUCKET_EMPTY_FISH, - ITEM_BUCKET_EMPTY_LAVA, - ITEM_BUCKET_FILL, - ITEM_BUCKET_FILL_FISH, - ITEM_BUCKET_FILL_LAVA, - ITEM_CHORUS_FRUIT_TELEPORT, - ITEM_CROP_PLANT, - ITEM_CROSSBOW_HIT, - ITEM_CROSSBOW_LOADING_END, - ITEM_CROSSBOW_LOADING_MIDDLE, - ITEM_CROSSBOW_LOADING_START, - ITEM_CROSSBOW_QUICK_CHARGE_1, - ITEM_CROSSBOW_QUICK_CHARGE_2, - ITEM_CROSSBOW_QUICK_CHARGE_3, - ITEM_CROSSBOW_SHOOT, - ITEM_ELYTRA_FLYING, - ITEM_FIRECHARGE_USE(ServerVersion.V1_9, v("GHAST_FIREBALL", true)), - ITEM_FLINTANDSTEEL_USE("FIRE_IGNITE"), - ITEM_HOE_TILL, - ITEM_NETHER_WART_PLANT, - ITEM_SHIELD_BLOCK, - ITEM_SHIELD_BREAK, - ITEM_SHOVEL_FLATTEN, - ITEM_TOTEM_USE, - ITEM_TRIDENT_HIT, - ITEM_TRIDENT_HIT_GROUND, - ITEM_TRIDENT_RETURN, - ITEM_TRIDENT_RIPTIDE_1, - ITEM_TRIDENT_RIPTIDE_2, - ITEM_TRIDENT_RIPTIDE_3, - ITEM_TRIDENT_THROW, - ITEM_TRIDENT_THUNDER, - MUSIC_CREATIVE, - MUSIC_CREDITS, - MUSIC_DISC_11(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_11"), v("WOOD_CLICK", true)), - MUSIC_DISC_13(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_13"), v("WOOD_CLICK", true)), - MUSIC_DISC_BLOCKS(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_BLOCKS"), v("WOOD_CLICK", true)), - MUSIC_DISC_CAT(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_CAT"), v("WOOD_CLICK", true)), - MUSIC_DISC_CHIRP(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_CHIRP"), v("WOOD_CLICK", true)), - MUSIC_DISC_FAR(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_FAR"), v("WOOD_CLICK", true)), - MUSIC_DISC_MALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_MALL"), v("WOOD_CLICK", true)), - MUSIC_DISC_MELLOHI(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_MELLOHI"), v("WOOD_CLICK", true)), - MUSIC_DISC_STAL(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_STAL"), v("WOOD_CLICK", true)), - MUSIC_DISC_STRAD(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_STRAD"), v("WOOD_CLICK", true)), - MUSIC_DISC_WAIT(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_WAIT"), v("WOOD_CLICK", true)), - MUSIC_DISC_WARD(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_WARD"), v("WOOD_CLICK", true)), // records are missing from 1.8 API - MUSIC_DRAGON, - MUSIC_END, - MUSIC_GAME, - MUSIC_MENU, - MUSIC_NETHER, - MUSIC_UNDER_WATER, - UI_BUTTON_CLICK("CLICK"), - UI_CARTOGRAPHY_TABLE_TAKE_RESULT, - UI_LOOM_SELECT_PATTERN, - UI_LOOM_TAKE_RESULT, - UI_STONECUTTER_SELECT_RECIPE, - UI_STONECUTTER_TAKE_RESULT, - UI_TOAST_CHALLENGE_COMPLETE, - UI_TOAST_IN, - UI_TOAST_OUT, - WEATHER_RAIN("AMBIENCE_RAIN"), - WEATHER_RAIN_ABOVE; - - protected /*final*/ Sound sound; - protected /*final*/ boolean compatibilityMode; - protected static final boolean DEBUG = false; - - private CompatibleSound() { - // This could get risky, since we haven't finished this - //sound = Sound.valueOf(name()); - Sound find = null; - for (Sound s : Sound.values()) { - if (s.name().equals(name())) { - find = s; - break; - } - } - if (DEBUG && find == null) { - System.out.println("Sound for " + name() + " Not found!"); - } - sound = find; - compatibilityMode = find == null; - } - - // if the sound ony ever changed from 1.8 -> 1.9 - private CompatibleSound(String compatibility_18) { - try { - compatibilityMode = false; - if (ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) { - sound = Sound.valueOf(compatibility_18); - } else { - sound = Sound.valueOf(name()); - } - } catch (Exception e) { - System.out.println("ERROR loading " + name()); - e.printStackTrace(); - } - } - - private CompatibleSound(Version... versions) { - try { - for (Version v : versions) { - if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) { - sound = Sound.valueOf(v.sound); - compatibilityMode = v.compatibilityMode; - return; - } - } - - } catch (Exception e) { - System.out.println("ERROR loading " + name()); - for (Version v : versions) { - System.out.println(v.version + " - " + v.sound); - } - e.printStackTrace(); - } - Sound find = null; - for (Sound s : Sound.values()) { - if (s.name().equals(name())) { - find = s; - break; - } - } - sound = find; - compatibilityMode = find == null; - } - - private CompatibleSound(ServerVersion minVersion, Version... versions) { - try { - if (ServerVersion.isServerVersionAtLeast(minVersion)) { - // should be good to use this sound - sound = Sound.valueOf(name()); - compatibilityMode = false; - } else { - for (Version v : versions) { - if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) { - sound = Sound.valueOf(v.sound); - compatibilityMode = v.compatibilityMode; - return; - } - } - sound = null; - compatibilityMode = false; - } - } catch (Exception e) { - System.out.println("ERROR loading " + name() + " (" + minVersion); - for (Version v : versions) { - System.out.println(v.version + " - " + v.sound); - } - e.printStackTrace(); - } - } - - /** - * Get a Bukkit API sound that matches this sound - * - * @return Returns either the matching sound or a similar sound - */ - public Sound getSound() { - return sound != null ? sound : UI_BUTTON_CLICK.sound; - } - - /** - * Send a sound to a specific player - * - * @param sendTo player to send the sound to - */ - public void play(Player sendTo) { - sendTo.playSound(sendTo.getLocation(), getSound(), 1F, 1F); - } - - /** - * Send a sound to a specific player - * - * @param sendTo player to send the sound to - * @param volume the volume of the sound - * @param pitch the pitch of the sound - */ - public void play(Player sendTo, float volume, float pitch) { - sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch); - } - - /** - * Send a sound to a specific player - * - * @param sendTo player to send the sound to - * @param location where the sound should come from - * @param volume the volume of the sound - * @param pitch the pitch of the sound - */ - public void play(Player sendTo, Location location, float volume, float pitch) { - sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch); - } - - /** - * Play a sound in a world - * - * @param sendTo world to send the sound to - * @param location where the sound should come from - * @param volume the volume of the sound - * @param pitch the pitch of the sound - */ - public void play(World sendTo, Location location, float volume, float pitch) { - sendTo.playSound(location, getSound(), volume, pitch); - } - - /** - * Stop a currently active sound from playing for a player - * - * @param sendTo player to stop the sound for - */ - public void stop(Player sendTo) { - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10)) { - sendTo.stopSound(getSound()); - } - } - - /** - * Check to see if this sound is available on this server. - * - * @return Returns false if we are using a different sound. - */ - public boolean usesCompatibility() { - return !compatibilityMode; - } - - private static Version v(String sound) { - return new Version(ServerVersion.UNKNOWN, sound, false); - } - - private static Version v(ServerVersion version, String sound) { - return new Version(version, sound, false); - } - - private static Version v(ServerVersion version, String sound, boolean compatibility) { - return new Version(version, sound, compatibility); - } - - private static Version v(String sound, boolean compatibility) { - return new Version(ServerVersion.UNKNOWN, sound, compatibility); - } - - private static class Version { - - final ServerVersion version; - final String sound; - final boolean compatibilityMode; - - public Version(ServerVersion version, String sound, boolean compatibility) { - this.version = version; - this.sound = sound; - this.compatibilityMode = compatibility; - } - - } -} +package com.songoda.core.compatibility; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.entity.Player; + +/** + * Sounds that are compatible with server versions 1.7+
+ * TODO: This needs work. + * Finished 1.8, finished 1.9 blocks, resume with 1.9 entities
+ * Between 1.8 and 1.9, all sounds were renamed, and between 1.12 and 1.13, some + * sounds were renamed. New sounds have been added by different versions, as + * well. The intent of this class is to provide either the correct sound or a + * near equivalent for the current server. + * + * @author jascotty2 + * @since 2019-08-25 + */ +public enum CompatibleSound { + + // some of these values are missing an API value.. + // would using the raw strings be better? + // 1.8 list: + // https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/mapping-and-modding-tutorials/2213619-1-8-all-playsound-sound-arguments + + /* 1.17 */ + // TODO: add similar sounds for older versions + BLOCK_AMETHYST_BLOCK_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_BLOCK_CHIME(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_BLOCK_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_BLOCK_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_BLOCK_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_BLOCK_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_CLUSTER_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_CLUSTER_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_CLUSTER_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_CLUSTER_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_AMETHYST_CLUSTER_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_LEAVES_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_LEAVES_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_LEAVES_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_LEAVES_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_LEAVES_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_AZALEA_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_BIG_DRIPLEAF_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_BIG_DRIPLEAF_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_BIG_DRIPLEAF_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_BIG_DRIPLEAF_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_BIG_DRIPLEAF_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_BIG_DRIPLEAF_TILT_DOWN(ServerVersion.V1_17, v(null, true)), + BLOCK_BIG_DRIPLEAF_TILT_UP(ServerVersion.V1_17, v(null, true)), + BLOCK_CAKE_ADD_CANDLE(ServerVersion.V1_17, v(null, true)), + BLOCK_CALCITE_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_CALCITE_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_CALCITE_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_CALCITE_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_CALCITE_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_CANDLE_AMBIENT(ServerVersion.V1_17, v(null, true)), + BLOCK_CANDLE_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_CANDLE_EXTINGUISH(ServerVersion.V1_17, v(null, true)), + BLOCK_CANDLE_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_CANDLE_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_CANDLE_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_CANDLE_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_CAVE_VINES_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_CAVE_VINES_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_CAVE_VINES_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_CAVE_VINES_PICK_BERRIES(ServerVersion.V1_17, v(null, true)), + BLOCK_CAVE_VINES_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_CAVE_VINES_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_COPPER_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_COPPER_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_COPPER_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_COPPER_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_COPPER_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_BRICKS_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_BRICKS_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_BRICKS_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_BRICKS_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_BRICKS_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_TILES_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_TILES_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_TILES_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_TILES_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_DEEPSLATE_TILES_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_DRIPSTONE_BLOCK_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_DRIPSTONE_BLOCK_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_DRIPSTONE_BLOCK_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_DRIPSTONE_BLOCK_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_DRIPSTONE_BLOCK_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_FLOWERING_AZALEA_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_FLOWERING_AZALEA_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_FLOWERING_AZALEA_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_FLOWERING_AZALEA_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_FLOWERING_AZALEA_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_HANGING_ROOTS_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_HANGING_ROOTS_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_HANGING_ROOTS_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_HANGING_ROOTS_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_HANGING_ROOTS_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_LARGE_AMETHYST_BUD_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_LARGE_AMETHYST_BUD_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_MEDIUM_AMETHYST_BUD_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_MEDIUM_AMETHYST_BUD_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_CARPET_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_CARPET_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_CARPET_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_CARPET_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_CARPET_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_MOSS_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_DRIP_LAVA(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_DRIP_LAVA_INTO_CAULDRON(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_DRIP_WATER(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_DRIP_WATER_INTO_CAULDRON(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_LAND(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_POINTED_DRIPSTONE_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_POLISHED_DEEPSLATE_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_POLISHED_DEEPSLATE_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_POLISHED_DEEPSLATE_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_POLISHED_DEEPSLATE_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_POLISHED_DEEPSLATE_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_POWDER_SNOW_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_POWDER_SNOW_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_POWDER_SNOW_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_POWDER_SNOW_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_POWDER_SNOW_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_ROOTED_DIRT_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_ROOTED_DIRT_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_ROOTED_DIRT_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_ROOTED_DIRT_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_ROOTED_DIRT_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_SCULK_SENSOR_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_SCULK_SENSOR_CLICKING(ServerVersion.V1_17, v(null, true)), + BLOCK_SCULK_SENSOR_CLICKING_STOP(ServerVersion.V1_17, v(null, true)), + BLOCK_SCULK_SENSOR_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_SCULK_SENSOR_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_SCULK_SENSOR_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_SCULK_SENSOR_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_SMALL_AMETHYST_BUD_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_SMALL_AMETHYST_BUD_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_SMALL_DRIPLEAF_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_SMALL_DRIPLEAF_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_SMALL_DRIPLEAF_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_SMALL_DRIPLEAF_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_SMALL_DRIPLEAF_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_SPORE_BLOSSOM_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_SPORE_BLOSSOM_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_SPORE_BLOSSOM_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_SPORE_BLOSSOM_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_SPORE_BLOSSOM_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES(ServerVersion.V1_17, v(null, true)), // "ITEM_SWEET_BERRIES_PICK_FROM_BUSH" + BLOCK_TUFF_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_TUFF_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_TUFF_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_TUFF_PLACE(ServerVersion.V1_17, v(null, true)), + BLOCK_TUFF_STEP(ServerVersion.V1_17, v(null, true)), + BLOCK_VINE_BREAK(ServerVersion.V1_17, v(null, true)), + BLOCK_VINE_FALL(ServerVersion.V1_17, v(null, true)), + BLOCK_VINE_HIT(ServerVersion.V1_17, v(null, true)), + BLOCK_VINE_PLACE(ServerVersion.V1_17, v(null, true)), + ENTITY_AXOLOTL_ATTACK(ServerVersion.V1_17, v(null, true)), + ENTITY_AXOLOTL_DEATH(ServerVersion.V1_17, v(null, true)), + ENTITY_AXOLOTL_HURT(ServerVersion.V1_17, v(null, true)), + ENTITY_AXOLOTL_IDLE_AIR(ServerVersion.V1_17, v(null, true)), + ENTITY_AXOLOTL_IDLE_WATER(ServerVersion.V1_17, v(null, true)), + ENTITY_AXOLOTL_SPLASH(ServerVersion.V1_17, v(null, true)), + ENTITY_AXOLOTL_SWIM(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_ITEM_FRAME_ADD_ITEM(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_ITEM_FRAME_BREAK(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_ITEM_FRAME_PLACE(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_ITEM_FRAME_REMOVE_ITEM(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_ITEM_FRAME_ROTATE_ITEM(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_SQUID_AMBIENT(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_SQUID_DEATH(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_SQUID_HURT(ServerVersion.V1_17, v(null, true)), + ENTITY_GLOW_SQUID_SQUIRT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_AMBIENT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_DEATH(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_EAT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_HURT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_LONG_JUMP(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_MILK(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_PREPARE_RAM(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_RAM_IMPACT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_SCREAMING_AMBIENT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_SCREAMING_DEATH(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_SCREAMING_EAT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_SCREAMING_HURT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_SCREAMING_LONG_JUMP(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_SCREAMING_MILK(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_SCREAMING_PREPARE_RAM(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_SCREAMING_RAM_IMPACT(ServerVersion.V1_17, v(null, true)), + ENTITY_GOAT_STEP(ServerVersion.V1_17, v(null, true)), + ENTITY_MINECART_INSIDE_UNDERWATER(ServerVersion.V1_17, v(null, true)), + ENTITY_PARROT_IMITATE_PIGLIN_BRUTE(ServerVersion.V1_17, v(null, true)), + ENTITY_PIGLIN_BRUTE_AMBIENT(ServerVersion.V1_17, v(null, true)), + ENTITY_PIGLIN_BRUTE_ANGRY(ServerVersion.V1_17, v(null, true)), + ENTITY_PIGLIN_BRUTE_CONVERTED_TO_ZOMBIFIED(ServerVersion.V1_17, v(null, true)), + ENTITY_PIGLIN_BRUTE_DEATH(ServerVersion.V1_17, v(null, true)), + ENTITY_PIGLIN_BRUTE_HURT(ServerVersion.V1_17, v(null, true)), + ENTITY_PIGLIN_BRUTE_STEP(ServerVersion.V1_17, v(null, true)), + ENTITY_PLAYER_HURT_FREEZE(ServerVersion.V1_17, v(null, true)), + ENTITY_SKELETON_CONVERTED_TO_STRAY(ServerVersion.V1_17, v(null, true)), + ITEM_AXE_SCRAPE(ServerVersion.V1_17, v(null, true)), + ITEM_AXE_WAX_OFF(ServerVersion.V1_17, v(null, true)), + ITEM_BONE_MEAL_USE(ServerVersion.V1_17, v(null, true)), + ITEM_BUCKET_EMPTY_AXOLOTL(ServerVersion.V1_17, v(null, true)), + ITEM_BUCKET_EMPTY_POWDER_SNOW(ServerVersion.V1_17, v(null, true)), + ITEM_BUCKET_FILL_AXOLOTL(ServerVersion.V1_17, v(null, true)), + ITEM_BUCKET_FILL_POWDER_SNOW(ServerVersion.V1_17, v(null, true)), + ITEM_GLOW_INK_SAC_USE(ServerVersion.V1_17, v(null, true)), + ITEM_HONEYCOMB_WAX_ON(ServerVersion.V1_17, v(null, true)), + ITEM_INK_SAC_USE(ServerVersion.V1_17, v(null, true)), + ITEM_SPYGLASS_STOP_USING(ServerVersion.V1_17, v(null, true)), + ITEM_SPYGLASS_USE(ServerVersion.V1_17, v(null, true)), + ITEM_DYE_USE(ServerVersion.V1_17, v(null, true)), + + /* 1.16 */ + // TODO: add similar sounds for older versions + AMBIENT_BASALT_DELTAS_ADDITIONS(ServerVersion.V1_16, v(null, true)), + AMBIENT_BASALT_DELTAS_LOOP(ServerVersion.V1_16, v(null, true)), + AMBIENT_BASALT_DELTAS_MOOD(ServerVersion.V1_16, v(null, true)), + AMBIENT_CRIMSON_FOREST_ADDITIONS(ServerVersion.V1_16, v(null, true)), + AMBIENT_CRIMSON_FOREST_LOOP(ServerVersion.V1_16, v(null, true)), + AMBIENT_CRIMSON_FOREST_MOOD(ServerVersion.V1_16, v(null, true)), + AMBIENT_NETHER_WASTES_ADDITIONS(ServerVersion.V1_16, v(null, true)), + AMBIENT_NETHER_WASTES_LOOP(ServerVersion.V1_16, v(null, true)), + AMBIENT_NETHER_WASTES_MOOD(ServerVersion.V1_16, v(null, true)), + AMBIENT_SOUL_SAND_VALLEY_ADDITIONS(ServerVersion.V1_16, v(null, true)), + AMBIENT_SOUL_SAND_VALLEY_LOOP(ServerVersion.V1_16, v(null, true)), + AMBIENT_SOUL_SAND_VALLEY_MOOD(ServerVersion.V1_16, v(null, true)), + AMBIENT_WARPED_FOREST_ADDITIONS(ServerVersion.V1_16, v(null, true)), + AMBIENT_WARPED_FOREST_LOOP(ServerVersion.V1_16, v(null, true)), + AMBIENT_WARPED_FOREST_MOOD(ServerVersion.V1_16, v(null, true)), + BLOCK_ANCIENT_DEBRIS_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_ANCIENT_DEBRIS_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_ANCIENT_DEBRIS_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_ANCIENT_DEBRIS_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_ANCIENT_DEBRIS_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_BASALT_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_BASALT_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_BASALT_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_BASALT_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_BASALT_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_BONE_BLOCK_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_BONE_BLOCK_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_BONE_BLOCK_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_BONE_BLOCK_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_BONE_BLOCK_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_CHAIN_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_CHAIN_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_CHAIN_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_CHAIN_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_CHAIN_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_FUNGUS_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_FUNGUS_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_FUNGUS_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_FUNGUS_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_FUNGUS_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_GILDED_BLACKSTONE_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_GILDED_BLACKSTONE_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_GILDED_BLACKSTONE_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_GILDED_BLACKSTONE_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_GILDED_BLACKSTONE_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_LODESTONE_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_LODESTONE_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_LODESTONE_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_LODESTONE_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_LODESTONE_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERITE_BLOCK_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERITE_BLOCK_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERITE_BLOCK_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERITE_BLOCK_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERITE_BLOCK_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERRACK_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERRACK_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERRACK_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERRACK_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHERRACK_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_BRICKS_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_BRICKS_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_BRICKS_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_BRICKS_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_BRICKS_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_GOLD_ORE_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_GOLD_ORE_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_GOLD_ORE_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_GOLD_ORE_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_GOLD_ORE_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_ORE_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_ORE_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_ORE_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_ORE_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_ORE_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_SPROUTS_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_SPROUTS_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_SPROUTS_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_SPROUTS_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_NETHER_SPROUTS_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_NYLIUM_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_NYLIUM_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_NYLIUM_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_NYLIUM_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_NYLIUM_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_RESPAWN_ANCHOR_AMBIENT(ServerVersion.V1_16, v(null, true)), + BLOCK_RESPAWN_ANCHOR_CHARGE(ServerVersion.V1_16, v(null, true)), + BLOCK_RESPAWN_ANCHOR_DEPLETE(ServerVersion.V1_16, v(null, true)), + BLOCK_RESPAWN_ANCHOR_SET_SPAWN(ServerVersion.V1_16, v(null, true)), + BLOCK_ROOTS_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_ROOTS_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_ROOTS_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_ROOTS_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_ROOTS_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_SHROOMLIGHT_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_SHROOMLIGHT_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_SHROOMLIGHT_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_SHROOMLIGHT_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_SHROOMLIGHT_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_SMITHING_TABLE_USE(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SAND_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SAND_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SAND_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SAND_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SAND_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SOIL_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SOIL_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SOIL_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SOIL_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_SOUL_SOIL_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_STEM_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_STEM_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_STEM_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_STEM_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_STEM_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_VINE_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_WART_BLOCK_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_WART_BLOCK_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_WART_BLOCK_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_WART_BLOCK_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_WART_BLOCK_STEP(ServerVersion.V1_16, v(null, true)), + BLOCK_WEEPING_VINES_BREAK(ServerVersion.V1_16, v(null, true)), + BLOCK_WEEPING_VINES_FALL(ServerVersion.V1_16, v(null, true)), + BLOCK_WEEPING_VINES_HIT(ServerVersion.V1_16, v(null, true)), + BLOCK_WEEPING_VINES_PLACE(ServerVersion.V1_16, v(null, true)), + BLOCK_WEEPING_VINES_STEP(ServerVersion.V1_16, v(null, true)), + ENTITY_DONKEY_EAT(ServerVersion.V1_16, v(null, true)), + ENTITY_FOX_TELEPORT(ServerVersion.V1_16, v(null, true)), + ENTITY_MULE_ANGRY(ServerVersion.V1_16, v(null, true)), + ENTITY_MULE_EAT(ServerVersion.V1_16, v(null, true)), + ENTITY_PARROT_IMITATE_HOGLIN(ServerVersion.V1_16, v(null, true)), + ENTITY_PARROT_IMITATE_PIGLIN(ServerVersion.V1_16, v(null, true)), + ENTITY_PARROT_IMITATE_ZOGLIN(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_ADMIRING_ITEM(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_AMBIENT(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_ANGRY(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_CELEBRATE(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_CONVERTED_TO_ZOMBIFIED(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_DEATH(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_HURT(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_JEALOUS(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_RETREAT(ServerVersion.V1_16, v(null, true)), + ENTITY_PIGLIN_STEP(ServerVersion.V1_16, v(null, true)), + ENTITY_SNOW_GOLEM_SHEAR(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_AMBIENT(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_DEATH(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_EAT(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_HAPPY(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_HURT(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_RETREAT(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_SADDLE(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_STEP(ServerVersion.V1_16, v(null, true)), + ENTITY_STRIDER_STEP_LAVA(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOGLIN_AMBIENT(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOGLIN_ANGRY(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOGLIN_ATTACK(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOGLIN_DEATH(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOGLIN_HURT(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOGLIN_STEP(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOMBIFIED_PIGLIN_AMBIENT(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOMBIFIED_PIGLIN_ANGRY(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOMBIFIED_PIGLIN_DEATH(ServerVersion.V1_16, v(null, true)), + ENTITY_ZOMBIFIED_PIGLIN_HURT(ServerVersion.V1_16, v(null, true)), + ITEM_ARMOR_EQUIP_NETHERITE(ServerVersion.V1_16, v(null, true)), + ITEM_LODESTONE_COMPASS_LOCK(ServerVersion.V1_16, v(null, true)), + MUSIC_DISC_PIGSTEP(ServerVersion.V1_16, v(null, true)), + MUSIC_NETHER_BASALT_DELTAS(ServerVersion.V1_16, v(null, true)), + MUSIC_NETHER_CRIMSON_FOREST(ServerVersion.V1_16, v(null, true)), + MUSIC_NETHER_NETHER_WASTES(ServerVersion.V1_16, v(null, true)), + MUSIC_NETHER_SOUL_SAND_VALLEY(ServerVersion.V1_16, v(null, true)), + MUSIC_NETHER_WARPED_FOREST(ServerVersion.V1_16, v(null, true)), + PARTICLE_SOUL_ESCAPE(ServerVersion.V1_16, v(null, true)), + + /* 1.15 */ + // TODO: add similar sounds for older versions + BLOCK_BEEHIVE_DRIP(ServerVersion.V1_15, v(null, true)), + BLOCK_BEEHIVE_ENTER(ServerVersion.V1_15, v(null, true)), + BLOCK_BEEHIVE_EXIT(ServerVersion.V1_15, v(null, true)), + BLOCK_BEEHIVE_SHEAR(ServerVersion.V1_15, v(null, true)), + BLOCK_BEEHIVE_WORK(ServerVersion.V1_15, v(null, true)), + BLOCK_HONEY_BLOCK_BREAK(ServerVersion.V1_15, v(null, true)), + BLOCK_HONEY_BLOCK_FALL(ServerVersion.V1_15, v(null, true)), + BLOCK_HONEY_BLOCK_HIT(ServerVersion.V1_15, v(null, true)), + BLOCK_HONEY_BLOCK_PLACE(ServerVersion.V1_15, v(null, true)), + BLOCK_HONEY_BLOCK_SLIDE(ServerVersion.V1_15, v(null, true)), + BLOCK_HONEY_BLOCK_STEP(ServerVersion.V1_15, v(null, true)), + ENTITY_BEE_DEATH(ServerVersion.V1_15, v(null, true)), + ENTITY_BEE_HURT(ServerVersion.V1_15, v(null, true)), + ENTITY_BEE_LOOP(ServerVersion.V1_15, v(null, true)), + ENTITY_BEE_LOOP_AGGRESSIVE(ServerVersion.V1_15, v(null, true)), + ENTITY_BEE_POLLINATE(ServerVersion.V1_15, v(null, true)), + ENTITY_BEE_STING(ServerVersion.V1_15, v(null, true)), + ENTITY_IRON_GOLEM_DAMAGE(ServerVersion.V1_15, v(null, true)), + ENTITY_IRON_GOLEM_REPAIR(ServerVersion.V1_15, v(null, true)), + ITEM_HONEY_BOTTLE_DRINK(ServerVersion.V1_15, v(null, true)), + + AMBIENT_CAVE(ServerVersion.V1_9, v("AMBIENCE_CAVE")), + AMBIENT_UNDERWATER_ENTER, + AMBIENT_UNDERWATER_EXIT, + AMBIENT_UNDERWATER_LOOP, + AMBIENT_UNDERWATER_LOOP_ADDITIONS, + AMBIENT_UNDERWATER_LOOP_ADDITIONS_RARE, + AMBIENT_UNDERWATER_LOOP_ADDITIONS_ULTRA_RARE, + BLOCK_ANVIL_BREAK(ServerVersion.V1_9, v("ANVIL_BREAK")), + BLOCK_ANVIL_DESTROY(ServerVersion.V1_9, v("ANVIL_BREAK", true)), + BLOCK_ANVIL_FALL(ServerVersion.V1_9, v("ANVIL_LAND", true)), + BLOCK_ANVIL_HIT(ServerVersion.V1_9, v("ANVIL_LAND", true)), + BLOCK_ANVIL_LAND(ServerVersion.V1_9, v("ANVIL_LAND")), + BLOCK_ANVIL_PLACE(ServerVersion.V1_9, v("ANVIL_LAND", true)), + BLOCK_ANVIL_STEP(ServerVersion.V1_9, v("ANVIL_LAND", true)), + BLOCK_ANVIL_USE("ANVIL_USE"), + BLOCK_BAMBOO_BREAK(ServerVersion.V1_14, v(ServerVersion.V1_9, "BLOCK_WOOD_BREAK"), v(ServerVersion.V1_8, "DIG_WOOD")), + BLOCK_BAMBOO_FALL, + BLOCK_BAMBOO_HIT, + BLOCK_BAMBOO_PLACE, + BLOCK_BAMBOO_SAPLING_BREAK, + BLOCK_BAMBOO_SAPLING_HIT, + BLOCK_BAMBOO_SAPLING_PLACE, + BLOCK_BAMBOO_STEP, + BLOCK_BARREL_CLOSE, + BLOCK_BARREL_OPEN, + BLOCK_BEACON_ACTIVATE, + BLOCK_BEACON_AMBIENT, + BLOCK_BEACON_DEACTIVATE, + BLOCK_BEACON_POWER_SELECT, + BLOCK_BELL_RESONATE, + BLOCK_BELL_USE, + BLOCK_BLASTFURNACE_FIRE_CRACKLE, + BLOCK_BREWING_STAND_BREW(ServerVersion.V1_9, v("LAVA_POP", true)), + BLOCK_BUBBLE_COLUMN_BUBBLE_POP, + BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT, + BLOCK_BUBBLE_COLUMN_UPWARDS_INSIDE, + BLOCK_BUBBLE_COLUMN_WHIRLPOOL_AMBIENT, + BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE, + BLOCK_CAMPFIRE_CRACKLE, + BLOCK_CHEST_CLOSE(ServerVersion.V1_9, v("CHEST_CLOSE")), + BLOCK_CHEST_LOCKED(ServerVersion.V1_9, v("CHEST_CLOSE", true)), + BLOCK_CHEST_OPEN(ServerVersion.V1_9, v("CHEST_OPEN")), + BLOCK_CHORUS_FLOWER_DEATH(ServerVersion.V1_9, v(null, true)), // I have no idea.. + BLOCK_CHORUS_FLOWER_GROW(ServerVersion.V1_9, v(null, true)), // I have no idea.. + BLOCK_COMPARATOR_CLICK(ServerVersion.V1_9, v("WOOD_CLICK", true)), + BLOCK_COMPOSTER_EMPTY, + BLOCK_COMPOSTER_FILL, + BLOCK_COMPOSTER_FILL_SUCCESS, + BLOCK_COMPOSTER_READY, + BLOCK_CONDUIT_ACTIVATE, + BLOCK_CONDUIT_AMBIENT, + BLOCK_CONDUIT_AMBIENT_SHORT, + BLOCK_CONDUIT_ATTACK_TARGET, + BLOCK_CONDUIT_DEACTIVATE, + BLOCK_CORAL_BLOCK_BREAK, + BLOCK_CORAL_BLOCK_FALL, + BLOCK_CORAL_BLOCK_HIT, + BLOCK_CORAL_BLOCK_PLACE, + BLOCK_CORAL_BLOCK_STEP, + BLOCK_CROP_BREAK, + BLOCK_DISPENSER_DISPENSE(ServerVersion.V1_9, v("SHOOT_ARROW", true)), + BLOCK_DISPENSER_FAIL(ServerVersion.V1_9, v("WOOD_CLICK", true)), + BLOCK_DISPENSER_LAUNCH(ServerVersion.V1_9, v("GHAST_FIREBALL", true)), + BLOCK_ENCHANTMENT_TABLE_USE, + BLOCK_ENDER_CHEST_CLOSE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_CLOSE"), v("CHEST_CLOSE", true)), + BLOCK_ENDER_CHEST_OPEN(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_OPEN"), v("CHEST_OPEN", true)), + BLOCK_END_GATEWAY_SPAWN(ServerVersion.V1_9, v("PORTAL_TRIGGER", true)), + BLOCK_END_PORTAL_FRAME_FILL, + BLOCK_END_PORTAL_SPAWN, + BLOCK_FENCE_GATE_CLOSE("DOOR_CLOSE"), + BLOCK_FENCE_GATE_OPEN("DOOR_OPEN"), + BLOCK_FIRE_AMBIENT("FIRE"), + BLOCK_FIRE_EXTINGUISH("FIZZ"), + BLOCK_FURNACE_FIRE_CRACKLE(ServerVersion.V1_9, v("FIRE", true)), + BLOCK_GLASS_BREAK("GLASS"), + BLOCK_GLASS_FALL(ServerVersion.V1_9, v("STEP_GRASS", true)), + BLOCK_GLASS_HIT(ServerVersion.V1_9, v("STEP_GRASS", true)), + BLOCK_GLASS_PLACE(ServerVersion.V1_9, v("STEP_GRASS", true)), + BLOCK_GLASS_STEP(ServerVersion.V1_9, v("STEP_STONE", true)), + BLOCK_GRASS_BREAK("DIG_GRASS"), + BLOCK_GRASS_FALL(ServerVersion.V1_9, v("STEP_GRASS", true)), + BLOCK_GRASS_HIT(ServerVersion.V1_9, v("STEP_GRASS", true)), + BLOCK_GRASS_PLACE(ServerVersion.V1_9, v("STEP_GRASS", true)), + BLOCK_GRASS_STEP("STEP_GRASS"), + BLOCK_GRAVEL_BREAK("DIG_GRAVEL"), + BLOCK_GRAVEL_FALL(ServerVersion.V1_9, v("STEP_GRAVEL", true)), + BLOCK_GRAVEL_HIT(ServerVersion.V1_9, v("STEP_GRAVEL", true)), + BLOCK_GRAVEL_PLACE(ServerVersion.V1_9, v("STEP_GRAVEL", true)), + BLOCK_GRAVEL_STEP("STEP_GRAVEL"), + BLOCK_GRINDSTONE_USE, + BLOCK_IRON_DOOR_CLOSE("DOOR_CLOSE"), + BLOCK_IRON_DOOR_OPEN("DOOR_OPEN"), + BLOCK_IRON_TRAPDOOR_CLOSE("DOOR_CLOSE"), + BLOCK_IRON_TRAPDOOR_OPEN("DOOR_OPEN"), + BLOCK_LADDER_BREAK(ServerVersion.V1_9, v(null, true)), + BLOCK_LADDER_FALL(ServerVersion.V1_9, v("STEP_LADDER", true)), + BLOCK_LADDER_HIT(ServerVersion.V1_9, v(null, true)), + BLOCK_LADDER_PLACE(ServerVersion.V1_9, v(null, true)), + BLOCK_LADDER_STEP("STEP_LADDER"), + BLOCK_LANTERN_BREAK, + BLOCK_LANTERN_FALL, + BLOCK_LANTERN_HIT, + BLOCK_LANTERN_PLACE, + BLOCK_LANTERN_STEP, + BLOCK_LAVA_AMBIENT("LAVA"), + BLOCK_LAVA_EXTINGUISH("FIZZ"), + BLOCK_LAVA_POP("LAVA_POP"), + BLOCK_LEVER_CLICK("WOOD_CLICK"), + BLOCK_LILY_PAD_PLACE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WATERLILY_PLACE"), v(null, true)), + BLOCK_METAL_BREAK(ServerVersion.V1_9, v(null, true)), + BLOCK_METAL_FALL(ServerVersion.V1_9, v(null, true)), + BLOCK_METAL_HIT(ServerVersion.V1_9, v(null, true)), + BLOCK_METAL_PLACE(ServerVersion.V1_9, v(null, true)), + BLOCK_METAL_PRESSURE_PLATE_CLICK_OFF(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_METAL_PRESSUREPLATE_CLICK_OFF"), v("WOOD_CLICK", true)), + BLOCK_METAL_PRESSURE_PLATE_CLICK_ON(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_METAL_PRESSUREPLATE_CLICK_ON"), v("WOOD_CLICK", true)), + BLOCK_METAL_STEP(ServerVersion.V1_9, v("STEP_STONE", true)), + BLOCK_NETHER_WART_BREAK, + BLOCK_NOTE_BLOCK_BANJO(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_GUITAR", true), v(ServerVersion.V1_12, "BLOCK_NOTE_GUITAR", true), v(ServerVersion.V1_9, "BLOCK_NOTE_BASS"), v("NOTE_BASS_GUITAR", true)), + BLOCK_NOTE_BLOCK_BASEDRUM(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_BASEDRUM"), v("NOTE_BASS_DRUM")), + BLOCK_NOTE_BLOCK_BASS(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_BASS"), v("NOTE_BASS")), + BLOCK_NOTE_BLOCK_BELL(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_BELL"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_PLING", true)), + BLOCK_NOTE_BLOCK_BIT(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_BELL", true), v(ServerVersion.V1_12, "BLOCK_NOTE_BELL", true), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_PLING", true)), + BLOCK_NOTE_BLOCK_CHIME(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_CHIME"), v(ServerVersion.V1_9, "BLOCK_NOTE_PLING", true), v("NOTE_PLING", true)), + BLOCK_NOTE_BLOCK_COW_BELL(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_BELL", true), v(ServerVersion.V1_12, "BLOCK_NOTE_BELL"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_PLING", true)), + BLOCK_NOTE_BLOCK_DIDGERIDOO(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_FLUTE", true), v(ServerVersion.V1_12, "BLOCK_NOTE_FLUTE", true), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_BASS_GUITAR", true)), + BLOCK_NOTE_BLOCK_FLUTE(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_FLUTE"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_BASS_GUITAR", true)), + BLOCK_NOTE_BLOCK_GUITAR(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_GUITAR"), v(ServerVersion.V1_9, "BLOCK_NOTE_HARP", true), v("NOTE_BASS_GUITAR")), // This value disappeared from the API from 1.9-1.11 (returned in 12) + BLOCK_NOTE_BLOCK_HARP(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_HARP"), v("NOTE_PIANO")), + BLOCK_NOTE_BLOCK_HAT(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_HAT"), v("NOTE_STICKS")), + BLOCK_NOTE_BLOCK_IRON_XYLOPHONE(ServerVersion.V1_14, v(ServerVersion.V1_13, "BLOCK_NOTE_BLOCK_XYLOPHONE", true), v(ServerVersion.V1_12, "BLOCK_NOTE_XYLOPHONE"), v(ServerVersion.V1_9, "BLOCK_NOTE_PLING", true), v("NOTE_PLING", true)), + BLOCK_NOTE_BLOCK_PLING(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_PLING"), v("NOTE_PLING")), + BLOCK_NOTE_BLOCK_SNARE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_NOTE_SNARE"), v("NOTE_SNARE_DRUM")), + BLOCK_NOTE_BLOCK_XYLOPHONE(ServerVersion.V1_13, v(ServerVersion.V1_12, "BLOCK_NOTE_XYLOPHONE"), v(ServerVersion.V1_9, "BLOCK_NOTE_PLING", true), v("NOTE_PLING", true)), + BLOCK_PISTON_CONTRACT("PISTON_RETRACT"), + BLOCK_PISTON_EXTEND("PISTON_EXTEND"), + BLOCK_PORTAL_AMBIENT("PORTAL"), + BLOCK_PORTAL_TRAVEL("PORTAL_TRAVEL"), + BLOCK_PORTAL_TRIGGER("PORTAL_TRIGGER"), + BLOCK_PUMPKIN_CARVE, + BLOCK_REDSTONE_TORCH_BURNOUT("FIZZ"), + BLOCK_SAND_BREAK("DIG_SAND"), + BLOCK_SAND_FALL(ServerVersion.V1_9, v("STEP_SAND", true)), + BLOCK_SAND_HIT(ServerVersion.V1_9, v("STEP_SAND", true)), + BLOCK_SAND_PLACE(ServerVersion.V1_9, v("STEP_SAND", true)), + BLOCK_SAND_STEP("STEP_SAND"), + BLOCK_SCAFFOLDING_BREAK, + BLOCK_SCAFFOLDING_FALL, + BLOCK_SCAFFOLDING_HIT, + BLOCK_SCAFFOLDING_PLACE, + BLOCK_SCAFFOLDING_STEP, + BLOCK_SHULKER_BOX_CLOSE(ServerVersion.V1_11, v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_CLOSE", true), v("CHEST_CLOSE", true)), + BLOCK_SHULKER_BOX_OPEN(ServerVersion.V1_11, v(ServerVersion.V1_9, "BLOCK_ENDERCHEST_OPEN", true), v("CHEST_OPEN", true)), + BLOCK_SLIME_BLOCK_BREAK(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_BREAK"), v(null, true)), + BLOCK_SLIME_BLOCK_FALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_FALL"), v(null, true)), + BLOCK_SLIME_BLOCK_HIT(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_HIT"), v(null, true)), + BLOCK_SLIME_BLOCK_PLACE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_PLACE"), v(null, true)), + BLOCK_SLIME_BLOCK_STEP(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_SLIME_STEP"), v(null, true)), + BLOCK_SMOKER_SMOKE, + BLOCK_SNOW_BREAK("DIG_SNOW"), + BLOCK_SNOW_FALL(ServerVersion.V1_9, v("STEP_SNOW", true)), + BLOCK_SNOW_HIT(ServerVersion.V1_9, v("STEP_SNOW", true)), + BLOCK_SNOW_PLACE(ServerVersion.V1_9, v("STEP_SNOW", true)), + BLOCK_SNOW_STEP("STEP_SNOW"), + BLOCK_STONE_BREAK("DIG_STONE"), + BLOCK_STONE_BUTTON_CLICK_OFF(ServerVersion.V1_9, v("WOOD_CLICK", true)), + BLOCK_STONE_BUTTON_CLICK_ON(ServerVersion.V1_9, v("WOOD_CLICK", true)), + BLOCK_STONE_FALL, + BLOCK_STONE_HIT, + BLOCK_STONE_PLACE, + BLOCK_STONE_PRESSURE_PLATE_CLICK_OFF, + BLOCK_STONE_PRESSURE_PLATE_CLICK_ON, + BLOCK_STONE_STEP("STEP_STONE"), + BLOCK_SWEET_BERRY_BUSH_BREAK, + BLOCK_SWEET_BERRY_BUSH_PLACE, + BLOCK_TRIPWIRE_ATTACH(ServerVersion.V1_9, v("WOOD_CLICK", true)), + BLOCK_TRIPWIRE_CLICK_OFF(ServerVersion.V1_9, v("WOOD_CLICK", true)), + BLOCK_TRIPWIRE_CLICK_ON(ServerVersion.V1_9, v("WOOD_CLICK", true)), + BLOCK_TRIPWIRE_DETACH(ServerVersion.V1_9, v("WOOD_CLICK", true)), + BLOCK_WATER_AMBIENT("WATER"), + BLOCK_WET_GRASS_BREAK, + BLOCK_WET_GRASS_FALL, + BLOCK_WET_GRASS_HIT, + BLOCK_WET_GRASS_PLACE, + BLOCK_WET_GRASS_STEP, + BLOCK_WOODEN_BUTTON_CLICK_OFF(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_BUTTON_CLICK_ON"), v("WOOD_CLICK")), + BLOCK_WOODEN_BUTTON_CLICK_ON(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_BUTTON_CLICK_ON"), v("WOOD_CLICK")), + BLOCK_WOODEN_DOOR_CLOSE("DOOR_CLOSE"), + BLOCK_WOODEN_DOOR_OPEN("DOOR_OPEN"), + BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_PRESSUREPLATE_CLICK_OFF"), v("WOOD_CLICK", true)), + BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_WOOD_PRESSUREPLATE_CLICK_ON"), v("WOOD_CLICK", true)), + BLOCK_WOODEN_TRAPDOOR_CLOSE("DOOR_OPEN"), + BLOCK_WOODEN_TRAPDOOR_OPEN("DOOR_OPEN"), + BLOCK_WOOD_BREAK("DIG_WOOD"), + BLOCK_WOOD_FALL(ServerVersion.V1_9, v("STEP_WOOD", true)), + BLOCK_WOOD_HIT(ServerVersion.V1_9, v("STEP_WOOD", true)), + BLOCK_WOOD_PLACE(ServerVersion.V1_9, v("STEP_WOOD", true)), + BLOCK_WOOD_STEP("STEP_WOOD"), + BLOCK_WOOL_BREAK(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_BREAK"), v("DIG_WOOL")), + BLOCK_WOOL_FALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_STEP", true), v("STEP_WOOL", true)), + BLOCK_WOOL_HIT(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_STEP", true), v("STEP_WOOL", true)), + BLOCK_WOOL_PLACE(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_STEP", true), v("STEP_WOOL", true)), + BLOCK_WOOL_STEP(ServerVersion.V1_13, v(ServerVersion.V1_9, "BLOCK_CLOTH_STEP"), v("STEP_WOOL")), + ENCHANT_THORNS_HIT, + ENTITY_ARMOR_STAND_BREAK, + ENTITY_ARMOR_STAND_FALL, + ENTITY_ARMOR_STAND_HIT, + ENTITY_ARMOR_STAND_PLACE, + ENTITY_ARROW_HIT("SUCCESSFUL_HIT"), // these may be reversed.. + ENTITY_ARROW_HIT_PLAYER("ARROW_HIT"), + ENTITY_ARROW_SHOOT("SHOOT_ARROW"), + ENTITY_BAT_AMBIENT("BAT_IDLE"), + ENTITY_BAT_DEATH("BAT_DEATH"), + ENTITY_BAT_HURT("BAT_HURT"), + ENTITY_BAT_LOOP("BAT_LOOP"), + ENTITY_BAT_TAKEOFF("BAT_TAKEOFF"), + ENTITY_BLAZE_AMBIENT("BLAZE_BREATH"), + ENTITY_BLAZE_BURN("BLAZE_HIT"), + ENTITY_BLAZE_DEATH("BLAZE_DEATH"), + ENTITY_BLAZE_HURT("BLAZE_HIT"), + ENTITY_BLAZE_SHOOT, + ENTITY_BOAT_PADDLE_LAND, + ENTITY_BOAT_PADDLE_WATER, + ENTITY_CAT_AMBIENT(ServerVersion.V1_9, v("CAT_MEOW")), + ENTITY_CAT_BEG_FOR_FOOD(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_CAT_AMBIENT", true), v("CAT_MEOW", true)), + ENTITY_CAT_DEATH, + ENTITY_CAT_EAT(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT"), v("EAT")), + ENTITY_CAT_HISS("CAT_HISS"), + ENTITY_CAT_HURT("CAT_HIT"), + ENTITY_CAT_PURR("CAT_PURR"), + ENTITY_CAT_PURREOW("CAT_PURREOW"), + ENTITY_CAT_STRAY_AMBIENT, + ENTITY_CHICKEN_AMBIENT("CHICKEN_IDLE"), + ENTITY_CHICKEN_DEATH, + ENTITY_CHICKEN_EGG("CHICKEN_EGG_POP"), + ENTITY_CHICKEN_HURT("CHICKEN_HURT"), + ENTITY_CHICKEN_STEP("CHICKEN_WALK"), + ENTITY_COD_AMBIENT, + ENTITY_COD_DEATH, + ENTITY_COD_FLOP, + ENTITY_COD_HURT, + ENTITY_COW_AMBIENT("COW_IDLE"), + ENTITY_COW_DEATH("COW_HURT"), + ENTITY_COW_HURT("COW_HURT"), + ENTITY_COW_MILK, + ENTITY_COW_STEP("COW_WALK"), + ENTITY_CREEPER_DEATH("CREEPER_DEATH"), + ENTITY_CREEPER_HURT, + ENTITY_CREEPER_PRIMED("CREEPER_HISS"), + ENTITY_DOLPHIN_AMBIENT, + ENTITY_DOLPHIN_AMBIENT_WATER, + ENTITY_DOLPHIN_ATTACK, + ENTITY_DOLPHIN_DEATH, + ENTITY_DOLPHIN_EAT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), + ENTITY_DOLPHIN_HURT, + ENTITY_DOLPHIN_JUMP, + ENTITY_DOLPHIN_PLAY, + ENTITY_DOLPHIN_SPLASH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_GENERIC_SPLASH", true), v("SPLASH", true)), + ENTITY_DOLPHIN_SWIM, + ENTITY_DONKEY_AMBIENT("DONKEY_IDLE"), + ENTITY_DONKEY_ANGRY("DONKEY_ANGRY"), + ENTITY_DONKEY_CHEST, + ENTITY_DONKEY_DEATH("DONKEY_DEATH"), + ENTITY_DONKEY_HURT("DONKEY_HIT"), + ENTITY_DRAGON_FIREBALL_EXPLODE, + ENTITY_DROWNED_AMBIENT, + ENTITY_DROWNED_AMBIENT_WATER, + ENTITY_DROWNED_DEATH, + ENTITY_DROWNED_DEATH_WATER, + ENTITY_DROWNED_HURT, + ENTITY_DROWNED_HURT_WATER, + ENTITY_DROWNED_SHOOT, + ENTITY_DROWNED_STEP, + ENTITY_DROWNED_SWIM, + ENTITY_EGG_THROW(ServerVersion.V1_9, v("SHOOT_ARROW", true)), + ENTITY_ELDER_GUARDIAN_AMBIENT, + ENTITY_ELDER_GUARDIAN_AMBIENT_LAND, + ENTITY_ELDER_GUARDIAN_CURSE, + ENTITY_ELDER_GUARDIAN_DEATH, + ENTITY_ELDER_GUARDIAN_DEATH_LAND, + ENTITY_ELDER_GUARDIAN_FLOP, + ENTITY_ELDER_GUARDIAN_HURT, + ENTITY_ELDER_GUARDIAN_HURT_LAND, + ENTITY_ENDERMAN_AMBIENT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_AMBIENT"), v("ENDERMAN_IDLE")), + ENTITY_ENDERMAN_DEATH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_DEATH"), v("ENDERMAN_DEATH")), + ENTITY_ENDERMAN_HURT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_HURT"), v("ENDERMAN_HIT")), + ENTITY_ENDERMAN_SCREAM(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_SCREAM"), v("ENDERMAN_SCREAM")), + ENTITY_ENDERMAN_STARE(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_STARE"), v("ENDERMAN_STARE")), + ENTITY_ENDERMAN_TELEPORT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERMEN_TELEPORT"), v("ENDERMAN_TELEPORT")), + ENTITY_ENDERMITE_AMBIENT, + ENTITY_ENDERMITE_DEATH, + ENTITY_ENDERMITE_HURT, + ENTITY_ENDERMITE_STEP, + ENTITY_ENDER_DRAGON_AMBIENT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_AMBIENT"), v("ENDERDRAGON_GROWL", true)), + ENTITY_ENDER_DRAGON_DEATH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_DEATH"), v("ENDERDRAGON_DEATH")), + ENTITY_ENDER_DRAGON_FLAP(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_FLAP"), v("ENDERDRAGON_WINGS")), + ENTITY_ENDER_DRAGON_GROWL(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_GROWL"), v("ENDERDRAGON_GROWL")), + ENTITY_ENDER_DRAGON_HURT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_HURT"), v("ENDERDRAGON_HIT")), + ENTITY_ENDER_DRAGON_SHOOT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDERDRAGON_SHOOT"), v("GHAST_FIREBALL", true)), + ENTITY_ENDER_EYE_DEATH(ServerVersion.V1_13, v(ServerVersion.V1_12, "ENTITY_ENDEREYE_DEATH"), v(ServerVersion.V1_9, "BLOCK_GLASS_BREAK", true), v("GLASS", true)), + ENTITY_ENDER_EYE_LAUNCH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ENDEREYE_LAUNCH"), v(ServerVersion.V1_9, "BLOCK_PORTAL_TRIGGER", true), v("PORTAL_TRIGGER", true)), + ENTITY_ENDER_PEARL_THROW, + ENTITY_EVOKER_AMBIENT, + ENTITY_EVOKER_CAST_SPELL, + ENTITY_EVOKER_CELEBRATE, + ENTITY_EVOKER_DEATH, + ENTITY_EVOKER_FANGS_ATTACK, + ENTITY_EVOKER_HURT, + ENTITY_EVOKER_PREPARE_ATTACK, + ENTITY_EVOKER_PREPARE_SUMMON, + ENTITY_EVOKER_PREPARE_WOLOLO, + ENTITY_EXPERIENCE_BOTTLE_THROW, + ENTITY_EXPERIENCE_ORB_PICKUP("ORB_PICKUP"), + ENTITY_FIREWORK_ROCKET_BLAST(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_BLAST"), v("FIREWORK_BLAST")), + ENTITY_FIREWORK_ROCKET_BLAST_FAR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_BLAST_FAR"), v("FIREWORK_BLAST2")), + ENTITY_FIREWORK_ROCKET_LARGE_BLAST(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_LARGE_BLAST"), v("FIREWORK_LARGE_BLAST")), + ENTITY_FIREWORK_ROCKET_LARGE_BLAST_FAR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_LARGE_BLAST_FAR"), v("FIREWORK_LARGE_BLAST2")), + ENTITY_FIREWORK_ROCKET_LAUNCH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_LAUNCH"), v("FIREWORK_LAUNCH")), + ENTITY_FIREWORK_ROCKET_SHOOT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_SHOOT"), v("FIREWORK_LAUNCH", true)), + ENTITY_FIREWORK_ROCKET_TWINKLE(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_TWINKLE"), v("FIREWORK_TWINKLE")), + ENTITY_FIREWORK_ROCKET_TWINKLE_FAR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_FIREWORK_TWINKLE_FAR"), v("FIREWORK_TWINKLE2")), + ENTITY_FISHING_BOBBER_RETRIEVE, + ENTITY_FISHING_BOBBER_SPLASH, + ENTITY_FISHING_BOBBER_THROW, + ENTITY_FISH_SWIM, + ENTITY_FOX_AGGRO, + ENTITY_FOX_AMBIENT, + ENTITY_FOX_BITE, + ENTITY_FOX_DEATH, + ENTITY_FOX_EAT(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), + ENTITY_FOX_HURT, + ENTITY_FOX_SCREECH, + ENTITY_FOX_SLEEP, + ENTITY_FOX_SNIFF, + ENTITY_FOX_SPIT, + ENTITY_GENERIC_BIG_FALL("FALL_BIG"), + ENTITY_GENERIC_BURN, + ENTITY_GENERIC_DEATH, + ENTITY_GENERIC_DRINK("DRINK"), + ENTITY_GENERIC_EAT("EAT"), + ENTITY_GENERIC_EXPLODE("EXPLODE"), + ENTITY_GENERIC_EXTINGUISH_FIRE("FIZZ"), + ENTITY_GENERIC_HURT("HURT_FLESH"), + ENTITY_GENERIC_SMALL_FALL("FALL_SMALL"), + ENTITY_GENERIC_SPLASH(ServerVersion.V1_9, v("SPLASH", true)), + ENTITY_GENERIC_SWIM, + ENTITY_GHAST_AMBIENT("GHAST_MOAN"), + ENTITY_GHAST_DEATH("GHAST_DEATH"), + ENTITY_GHAST_HURT("GHAST_SCREAM2"), + ENTITY_GHAST_SCREAM("GHAST_SCREAM"), + ENTITY_GHAST_SHOOT("GHAST_FIREBALL"), + ENTITY_GHAST_WARN("GHAST_CHARGE"), + ENTITY_GUARDIAN_AMBIENT, + ENTITY_GUARDIAN_AMBIENT_LAND, + ENTITY_GUARDIAN_ATTACK, + ENTITY_GUARDIAN_DEATH, + ENTITY_GUARDIAN_DEATH_LAND, + ENTITY_GUARDIAN_FLOP, + ENTITY_GUARDIAN_HURT, + ENTITY_GUARDIAN_HURT_LAND, + ENTITY_HORSE_AMBIENT("HORSE_IDLE"), + ENTITY_HORSE_ANGRY("HORSE_ANGRY"), + ENTITY_HORSE_ARMOR("HORSE_ARMOR"), + ENTITY_HORSE_BREATHE("HORSE_BREATHE"), + ENTITY_HORSE_DEATH("HORSE_DEATH"), + ENTITY_HORSE_EAT("EAT"), + ENTITY_HORSE_GALLOP("HORSE_GALLOP"), + ENTITY_HORSE_HURT("HORSE_HIT"), + ENTITY_HORSE_JUMP("HORSE_JUMP"), + ENTITY_HORSE_LAND("HORSE_LAND"), + ENTITY_HORSE_SADDLE("HORSE_SADDLE"), + ENTITY_HORSE_STEP("HORSE_SOFT"), + ENTITY_HORSE_STEP_WOOD("HORSE_WOOD"), + ENTITY_HOSTILE_BIG_FALL, + ENTITY_HOSTILE_DEATH, + ENTITY_HOSTILE_HURT, + ENTITY_HOSTILE_SMALL_FALL, + ENTITY_HOSTILE_SPLASH(ServerVersion.V1_9, v("SPLASH", true)), + ENTITY_HOSTILE_SWIM, + ENTITY_HUSK_AMBIENT, + ENTITY_HUSK_CONVERTED_TO_ZOMBIE, + ENTITY_HUSK_DEATH, + ENTITY_HUSK_HURT, + ENTITY_HUSK_STEP, + ENTITY_ILLUSIONER_AMBIENT, + ENTITY_ILLUSIONER_CAST_SPELL, + ENTITY_ILLUSIONER_DEATH, + ENTITY_ILLUSIONER_HURT, + ENTITY_ILLUSIONER_MIRROR_MOVE, + ENTITY_ILLUSIONER_PREPARE_BLINDNESS, + ENTITY_ILLUSIONER_PREPARE_MIRROR, + ENTITY_IRON_GOLEM_ATTACK(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_IRONGOLEM_ATTACK"), v("IRONGOLEM_THROW")), + ENTITY_IRON_GOLEM_DEATH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_IRONGOLEM_DEATH"), v("IRONGOLEM_DEATH")), + ENTITY_IRON_GOLEM_HURT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_IRONGOLEM_HURT"), v("IRONGOLEM_HIT")), + ENTITY_IRON_GOLEM_STEP(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_IRONGOLEM_STEP"), v("IRONGOLEM_WALK")), + ENTITY_ITEM_BREAK("ITEM_BREAK"), + ENTITY_ITEM_FRAME_ADD_ITEM, + ENTITY_ITEM_FRAME_BREAK, + ENTITY_ITEM_FRAME_PLACE, + ENTITY_ITEM_FRAME_REMOVE_ITEM, + ENTITY_ITEM_FRAME_ROTATE_ITEM, + ENTITY_ITEM_PICKUP("ITEM_PICKUP"), + ENTITY_LEASH_KNOT_BREAK, + ENTITY_LEASH_KNOT_PLACE, + ENTITY_LIGHTNING_BOLT_IMPACT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_LIGHTNING_IMPACT"), v("AMBIENCE_THUNDER", true)), + ENTITY_LIGHTNING_BOLT_THUNDER(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_LIGHTNING_THUNDER"), v("AMBIENCE_THUNDER")), + ENTITY_LINGERING_POTION_THROW, + ENTITY_LLAMA_AMBIENT, + ENTITY_LLAMA_ANGRY(v(ServerVersion.V1_11, "ENTITY_HORSE_ANGRY"), v("HORSE_ANGRY")), + ENTITY_LLAMA_CHEST, + ENTITY_LLAMA_DEATH(v(ServerVersion.V1_11, "ENTITY_HORSE_DEATH"), v("HORSE_DEATH")), + ENTITY_LLAMA_EAT(v(ServerVersion.V1_11, "ENTITY_HORSE_EAT"), v("EAT")), + ENTITY_LLAMA_HURT(v(ServerVersion.V1_11, "ENTITY_HORSE_HURT"), v("HORSE_HIT")), + ENTITY_LLAMA_SPIT, + ENTITY_LLAMA_STEP, + ENTITY_LLAMA_SWAG, + ENTITY_MAGMA_CUBE_DEATH, // ENTITY_MAGMACUBE_DEATH + ENTITY_MAGMA_CUBE_DEATH_SMALL, + ENTITY_MAGMA_CUBE_HURT, // ENTITY_MAGMACUBE_HURT + ENTITY_MAGMA_CUBE_HURT_SMALL, + ENTITY_MAGMA_CUBE_JUMP(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_MAGMACUBE_JUMP"), v("MAGMACUBE_JUMP")), + ENTITY_MAGMA_CUBE_SQUISH(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_MAGMACUBE_SQUISH"), v("MAGMACUBE_WALK")), + ENTITY_MAGMA_CUBE_SQUISH_SMALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_MAGMACUBE_SQUISH", true), v("MAGMACUBE_WALK2")), + ENTITY_MINECART_INSIDE("MINECART_INSIDE"), + ENTITY_MINECART_RIDING("MINECART_BASE"), + ENTITY_MOOSHROOM_CONVERT, + ENTITY_MOOSHROOM_EAT(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), + ENTITY_MOOSHROOM_MILK, + ENTITY_MOOSHROOM_SHEAR, + ENTITY_MOOSHROOM_SUSPICIOUS_MILK, + ENTITY_MULE_AMBIENT, + ENTITY_MULE_CHEST, + ENTITY_MULE_DEATH, + ENTITY_MULE_HURT, + ENTITY_OCELOT_AMBIENT, + ENTITY_OCELOT_DEATH, + ENTITY_OCELOT_HURT, + ENTITY_PAINTING_BREAK, + ENTITY_PAINTING_PLACE, + ENTITY_PANDA_AGGRESSIVE_AMBIENT, + ENTITY_PANDA_AMBIENT, + ENTITY_PANDA_BITE, + ENTITY_PANDA_CANT_BREED, + ENTITY_PANDA_DEATH, + ENTITY_PANDA_EAT(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), + ENTITY_PANDA_HURT, + ENTITY_PANDA_PRE_SNEEZE, + ENTITY_PANDA_SNEEZE, + ENTITY_PANDA_STEP, + ENTITY_PANDA_WORRIED_AMBIENT, + ENTITY_PARROT_AMBIENT, + ENTITY_PARROT_DEATH, + ENTITY_PARROT_EAT(ServerVersion.V1_12, v(ServerVersion.V1_9, "ENTITY_GENERIC_EAT", true), v("EAT", true)), + ENTITY_PARROT_FLY, + ENTITY_PARROT_HURT, + ENTITY_PARROT_IMITATE_BLAZE, + ENTITY_PARROT_IMITATE_CREEPER, + ENTITY_PARROT_IMITATE_DROWNED, + ENTITY_PARROT_IMITATE_ELDER_GUARDIAN, + ENTITY_PARROT_IMITATE_ENDERMAN, + ENTITY_PARROT_IMITATE_ENDERMITE, + ENTITY_PARROT_IMITATE_ENDER_DRAGON, + ENTITY_PARROT_IMITATE_EVOKER, + ENTITY_PARROT_IMITATE_GHAST, + ENTITY_PARROT_IMITATE_GUARDIAN, + ENTITY_PARROT_IMITATE_HUSK, + ENTITY_PARROT_IMITATE_ILLUSIONER, + ENTITY_PARROT_IMITATE_MAGMA_CUBE, + ENTITY_PARROT_IMITATE_PANDA, + ENTITY_PARROT_IMITATE_PHANTOM, + ENTITY_PARROT_IMITATE_PILLAGER, + ENTITY_PARROT_IMITATE_POLAR_BEAR, + ENTITY_PARROT_IMITATE_RAVAGER, + ENTITY_PARROT_IMITATE_SHULKER, + ENTITY_PARROT_IMITATE_SILVERFISH, + ENTITY_PARROT_IMITATE_SKELETON, + ENTITY_PARROT_IMITATE_SLIME, + ENTITY_PARROT_IMITATE_SPIDER, + ENTITY_PARROT_IMITATE_STRAY, + ENTITY_PARROT_IMITATE_VEX, + ENTITY_PARROT_IMITATE_VINDICATOR, + ENTITY_PARROT_IMITATE_WITCH, + ENTITY_PARROT_IMITATE_WITHER, + ENTITY_PARROT_IMITATE_WITHER_SKELETON, + ENTITY_PARROT_IMITATE_WOLF, + ENTITY_PARROT_IMITATE_ZOMBIE, + ENTITY_PARROT_IMITATE_ZOMBIE_PIGMAN, + ENTITY_PARROT_IMITATE_ZOMBIE_VILLAGER, + ENTITY_PARROT_STEP, + ENTITY_PHANTOM_AMBIENT, + ENTITY_PHANTOM_BITE, + ENTITY_PHANTOM_DEATH, + ENTITY_PHANTOM_FLAP, + ENTITY_PHANTOM_HURT, + ENTITY_PHANTOM_SWOOP, + ENTITY_PIG_AMBIENT("PIG_IDLE"), + ENTITY_PIG_DEATH("PIG_DEATH"), + ENTITY_PIG_HURT, + ENTITY_PIG_SADDLE, + ENTITY_PIG_STEP("PIG_WALK"), + ENTITY_PILLAGER_AMBIENT, + ENTITY_PILLAGER_CELEBRATE, + ENTITY_PILLAGER_DEATH, + ENTITY_PILLAGER_HURT, + ENTITY_PLAYER_ATTACK_CRIT, + ENTITY_PLAYER_ATTACK_KNOCKBACK, + ENTITY_PLAYER_ATTACK_NODAMAGE, + ENTITY_PLAYER_ATTACK_STRONG, + ENTITY_PLAYER_ATTACK_SWEEP, + ENTITY_PLAYER_ATTACK_WEAK, + ENTITY_PLAYER_BIG_FALL, + ENTITY_PLAYER_BREATH, + ENTITY_PLAYER_BURP("BURP"), + ENTITY_PLAYER_DEATH, + ENTITY_PLAYER_HURT, + ENTITY_PLAYER_HURT_DROWN, + ENTITY_PLAYER_HURT_ON_FIRE, + ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH, + ENTITY_PLAYER_LEVELUP("LEVEL_UP"), + ENTITY_PLAYER_SMALL_FALL, + ENTITY_PLAYER_SPLASH("SPLASH"), + ENTITY_PLAYER_SPLASH_HIGH_SPEED(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_GENERIC_SPLASH"), v("SPLASH2", true)), + ENTITY_PLAYER_SWIM("SWIM"), + ENTITY_POLAR_BEAR_AMBIENT, + ENTITY_POLAR_BEAR_AMBIENT_BABY, + ENTITY_POLAR_BEAR_DEATH, + ENTITY_POLAR_BEAR_HURT, + ENTITY_POLAR_BEAR_STEP, + ENTITY_POLAR_BEAR_WARNING, + ENTITY_PUFFER_FISH_AMBIENT, + ENTITY_PUFFER_FISH_BLOW_OUT, + ENTITY_PUFFER_FISH_BLOW_UP, + ENTITY_PUFFER_FISH_DEATH, + ENTITY_PUFFER_FISH_FLOP, + ENTITY_PUFFER_FISH_HURT, + ENTITY_PUFFER_FISH_STING, + ENTITY_RABBIT_AMBIENT, + ENTITY_RABBIT_ATTACK, + ENTITY_RABBIT_DEATH, + ENTITY_RABBIT_HURT, + ENTITY_RABBIT_JUMP, + ENTITY_RAVAGER_AMBIENT, + ENTITY_RAVAGER_ATTACK, + ENTITY_RAVAGER_CELEBRATE, + ENTITY_RAVAGER_DEATH, + ENTITY_RAVAGER_HURT, + ENTITY_RAVAGER_ROAR, + ENTITY_RAVAGER_STEP, + ENTITY_RAVAGER_STUNNED, + ENTITY_SALMON_AMBIENT, + ENTITY_SALMON_DEATH, + ENTITY_SALMON_FLOP, + ENTITY_SALMON_HURT, + ENTITY_SHEEP_AMBIENT("SHEEP_IDLE"), + ENTITY_SHEEP_DEATH, + ENTITY_SHEEP_HURT, + ENTITY_SHEEP_SHEAR("SHEEP_SHEAR"), + ENTITY_SHEEP_STEP("SHEEP_WALK"), + ENTITY_SHULKER_AMBIENT, + ENTITY_SHULKER_BULLET_HIT, + ENTITY_SHULKER_BULLET_HURT, + ENTITY_SHULKER_CLOSE, + ENTITY_SHULKER_DEATH, + ENTITY_SHULKER_HURT, + ENTITY_SHULKER_HURT_CLOSED, + ENTITY_SHULKER_OPEN, + ENTITY_SHULKER_SHOOT, + ENTITY_SHULKER_TELEPORT, + ENTITY_SILVERFISH_AMBIENT("SILVERFISH_IDLE"), + ENTITY_SILVERFISH_DEATH("SILVERFISH_KILL"), + ENTITY_SILVERFISH_HURT("SILVERFISH_HIT"), + ENTITY_SILVERFISH_STEP("SILVERFISH_WALK"), + ENTITY_SKELETON_AMBIENT("SKELETON_IDLE"), + ENTITY_SKELETON_DEATH("SKELETON_DEATH"), + ENTITY_SKELETON_HORSE_AMBIENT("HORSE_SKELETON_IDLE"), + ENTITY_SKELETON_HORSE_AMBIENT_WATER, + ENTITY_SKELETON_HORSE_DEATH("HORSE_SKELETON_DEATH"), + ENTITY_SKELETON_HORSE_GALLOP_WATER, + ENTITY_SKELETON_HORSE_HURT("HORSE_SKELETON_HIT"), + ENTITY_SKELETON_HORSE_JUMP_WATER, + ENTITY_SKELETON_HORSE_STEP_WATER, + ENTITY_SKELETON_HORSE_SWIM, + ENTITY_SKELETON_HURT("SKELETON_HURT"), + ENTITY_SKELETON_SHOOT(ServerVersion.V1_9, v("SHOOT_ARROW", true)), + ENTITY_SKELETON_STEP("SKELETON_WALK"), + ENTITY_SLIME_ATTACK("SLIME_ATTACK"), + ENTITY_SLIME_DEATH, + ENTITY_SLIME_DEATH_SMALL, + ENTITY_SLIME_HURT, + ENTITY_SLIME_HURT_SMALL, + ENTITY_SLIME_JUMP("SLIME_WALK"), // Not sure which is 1 or 2 + ENTITY_SLIME_JUMP_SMALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_SLIME_JUMP", true), v("SLIME_WALK", true)), + ENTITY_SLIME_SQUISH("SLIME_WALK2"), + ENTITY_SLIME_SQUISH_SMALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_SLIME_JUMP", true), v("SLIME_WALK2", true)), + ENTITY_SNOWBALL_THROW, + ENTITY_SNOW_GOLEM_AMBIENT, + ENTITY_SNOW_GOLEM_DEATH, + ENTITY_SNOW_GOLEM_HURT, + ENTITY_SNOW_GOLEM_SHOOT(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_SNOWMAN_SHOOT"), v("SHOOT_ARROW", true)), // this is missing from 1.8 API for some reason + ENTITY_SPIDER_AMBIENT("SPIDER_IDLE"), + ENTITY_SPIDER_DEATH("SPIDER_DEATH"), + ENTITY_SPIDER_HURT, + ENTITY_SPIDER_STEP("SPIDER_WALK"), + ENTITY_SPLASH_POTION_BREAK, + ENTITY_SPLASH_POTION_THROW, + ENTITY_SQUID_AMBIENT, + ENTITY_SQUID_DEATH, + ENTITY_SQUID_HURT, + ENTITY_SQUID_SQUIRT, + ENTITY_STRAY_AMBIENT, + ENTITY_STRAY_DEATH, + ENTITY_STRAY_HURT, + ENTITY_STRAY_STEP, + ENTITY_TNT_PRIMED("FUSE"), + ENTITY_TROPICAL_FISH_AMBIENT, + ENTITY_TROPICAL_FISH_DEATH, + ENTITY_TROPICAL_FISH_FLOP, + ENTITY_TROPICAL_FISH_HURT, + ENTITY_TURTLE_AMBIENT_LAND, + ENTITY_TURTLE_DEATH, + ENTITY_TURTLE_DEATH_BABY, + ENTITY_TURTLE_EGG_BREAK, + ENTITY_TURTLE_EGG_CRACK, + ENTITY_TURTLE_EGG_HATCH, + ENTITY_TURTLE_HURT, + ENTITY_TURTLE_HURT_BABY, + ENTITY_TURTLE_LAY_EGG, + ENTITY_TURTLE_SHAMBLE, + ENTITY_TURTLE_SHAMBLE_BABY, + ENTITY_TURTLE_SWIM, + ENTITY_VEX_AMBIENT, + ENTITY_VEX_CHARGE, + ENTITY_VEX_DEATH, + ENTITY_VEX_HURT, + ENTITY_VILLAGER_AMBIENT("VILLAGER_IDLE"), + ENTITY_VILLAGER_CELEBRATE, + ENTITY_VILLAGER_DEATH("VILLAGER_DEATH"), + ENTITY_VILLAGER_HURT("VILLAGER_HIT"), + ENTITY_VILLAGER_NO("VILLAGER_NO"), + ENTITY_VILLAGER_TRADE(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_VILLAGER_TRADING"), v("VILLAGER_HAGGLE")), + ENTITY_VILLAGER_WORK_ARMORER, + ENTITY_VILLAGER_WORK_BUTCHER, + ENTITY_VILLAGER_WORK_CARTOGRAPHER, + ENTITY_VILLAGER_WORK_CLERIC, + ENTITY_VILLAGER_WORK_FARMER, + ENTITY_VILLAGER_WORK_FISHERMAN, + ENTITY_VILLAGER_WORK_FLETCHER, + ENTITY_VILLAGER_WORK_LEATHERWORKER, + ENTITY_VILLAGER_WORK_LIBRARIAN, + ENTITY_VILLAGER_WORK_MASON, + ENTITY_VILLAGER_WORK_SHEPHERD, + ENTITY_VILLAGER_WORK_TOOLSMITH, + ENTITY_VILLAGER_WORK_WEAPONSMITH, + ENTITY_VILLAGER_YES("VILLAGER_YES"), + ENTITY_VINDICATOR_AMBIENT, + ENTITY_VINDICATOR_CELEBRATE, + ENTITY_VINDICATOR_DEATH, + ENTITY_VINDICATOR_HURT, + ENTITY_WANDERING_TRADER_AMBIENT, + ENTITY_WANDERING_TRADER_DEATH, + ENTITY_WANDERING_TRADER_DISAPPEARED, + ENTITY_WANDERING_TRADER_DRINK_MILK(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_DRINK", true), v("DRINK", true)), + ENTITY_WANDERING_TRADER_DRINK_POTION(ServerVersion.V1_14, v(ServerVersion.V1_9, "ENTITY_GENERIC_DRINK", true), v("DRINK", true)), + ENTITY_WANDERING_TRADER_HURT, + ENTITY_WANDERING_TRADER_NO, + ENTITY_WANDERING_TRADER_REAPPEARED, + ENTITY_WANDERING_TRADER_TRADE, + ENTITY_WANDERING_TRADER_YES, + ENTITY_WITCH_AMBIENT, + ENTITY_WITCH_CELEBRATE, + ENTITY_WITCH_DEATH, + ENTITY_WITCH_DRINK("DRINK"), + ENTITY_WITCH_HURT, + ENTITY_WITCH_THROW, + ENTITY_WITHER_AMBIENT("WITHER_IDLE"), + ENTITY_WITHER_BREAK_BLOCK("WITHER_SPAWN"), + ENTITY_WITHER_DEATH("WITHER_DEATH"), + ENTITY_WITHER_HURT("WITHER_HURT"), + ENTITY_WITHER_SHOOT("WITHER_SHOOT"), + ENTITY_WITHER_SKELETON_AMBIENT, + ENTITY_WITHER_SKELETON_DEATH, + ENTITY_WITHER_SKELETON_HURT, + ENTITY_WITHER_SKELETON_STEP, + ENTITY_WITHER_SPAWN, + ENTITY_WOLF_AMBIENT("WOLF_BARK"), + ENTITY_WOLF_DEATH("WOLF_DEATH"), + ENTITY_WOLF_GROWL("WOLF_GROWL"), + ENTITY_WOLF_HOWL("WOLF_HOWL"), + ENTITY_WOLF_HURT("WOLF_HURT"), + ENTITY_WOLF_PANT("WOLF_PANT"), + ENTITY_WOLF_SHAKE("WOLF_SHAKE"), + ENTITY_WOLF_STEP("WOLF_WALK"), + ENTITY_WOLF_WHINE("WOLF_WHINE"), + ENTITY_ZOMBIE_AMBIENT("ZOMBIE_IDLE"), + ENTITY_ZOMBIE_ATTACK_IRON_DOOR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ZOMBIE_ATTACK_IRON_DOOR", true), v("ZOMBIE_METAL")), + ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ZOMBIE_ATTACK_DOOR_WOOD", true), v("ZOMBIE_WOOD")), + ENTITY_ZOMBIE_BREAK_WOODEN_DOOR(ServerVersion.V1_13, v(ServerVersion.V1_9, "ENTITY_ZOMBIE_BREAK_DOOR_WOOD", true), v("ZOMBIE_WOODBREAK")), + ENTITY_ZOMBIE_CONVERTED_TO_DROWNED, + ENTITY_ZOMBIE_DEATH("ZOMBIE_DEATH"), + ENTITY_ZOMBIE_DESTROY_EGG, + ENTITY_ZOMBIE_HORSE_AMBIENT("HORSE_ZOMBIE_IDLE"), + ENTITY_ZOMBIE_HORSE_DEATH("HORSE_ZOMBIE_DEATH"), + ENTITY_ZOMBIE_HORSE_HURT("HORSE_ZOMBIE_HIT"), + ENTITY_ZOMBIE_HURT("ZOMBIE_HURT"), + ENTITY_ZOMBIE_INFECT("ZOMBIE_INFECT"), + ENTITY_ZOMBIE_STEP("ZOMBIE_WALK"), + ENTITY_ZOMBIE_VILLAGER_AMBIENT, + ENTITY_ZOMBIE_VILLAGER_CONVERTED("ZOMBIE_REMEDY"), + ENTITY_ZOMBIE_VILLAGER_CURE("ZOMBIE_UNFECT"), + ENTITY_ZOMBIE_VILLAGER_DEATH, + ENTITY_ZOMBIE_VILLAGER_HURT, + ENTITY_ZOMBIE_VILLAGER_STEP, + EVENT_RAID_HORN, + ITEM_ARMOR_EQUIP_CHAIN(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), + ITEM_ARMOR_EQUIP_DIAMOND(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), + ITEM_ARMOR_EQUIP_ELYTRA(ServerVersion.V1_11, v(ServerVersion.V1_9, "ITEM_ARMOR_EQUIP_GENERIC", true), v("SUCCESSFUL_HIT", true)), + ITEM_ARMOR_EQUIP_GENERIC(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), + ITEM_ARMOR_EQUIP_GOLD(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), + ITEM_ARMOR_EQUIP_IRON(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), + ITEM_ARMOR_EQUIP_LEATHER(ServerVersion.V1_9, v("SUCCESSFUL_HIT", true)), + ITEM_ARMOR_EQUIP_TURTLE(ServerVersion.V1_13, v(ServerVersion.V1_9, "ITEM_ARMOR_EQUIP_GENERIC", true), v("SUCCESSFUL_HIT", true)), + ITEM_AXE_STRIP, + ITEM_BOOK_PAGE_TURN, + ITEM_BOOK_PUT, + ITEM_BOTTLE_EMPTY, + ITEM_BOTTLE_FILL, + ITEM_BOTTLE_FILL_DRAGONBREATH, + ITEM_BUCKET_EMPTY, + ITEM_BUCKET_EMPTY_FISH, + ITEM_BUCKET_EMPTY_LAVA, + ITEM_BUCKET_FILL, + ITEM_BUCKET_FILL_FISH, + ITEM_BUCKET_FILL_LAVA, + ITEM_CHORUS_FRUIT_TELEPORT, + ITEM_CROP_PLANT, + ITEM_CROSSBOW_HIT, + ITEM_CROSSBOW_LOADING_END, + ITEM_CROSSBOW_LOADING_MIDDLE, + ITEM_CROSSBOW_LOADING_START, + ITEM_CROSSBOW_QUICK_CHARGE_1, + ITEM_CROSSBOW_QUICK_CHARGE_2, + ITEM_CROSSBOW_QUICK_CHARGE_3, + ITEM_CROSSBOW_SHOOT, + ITEM_ELYTRA_FLYING, + ITEM_FIRECHARGE_USE(ServerVersion.V1_9, v("GHAST_FIREBALL", true)), + ITEM_FLINTANDSTEEL_USE("FIRE_IGNITE"), + ITEM_HOE_TILL, + ITEM_NETHER_WART_PLANT, + ITEM_SHIELD_BLOCK, + ITEM_SHIELD_BREAK, + ITEM_SHOVEL_FLATTEN, + ITEM_TOTEM_USE, + ITEM_TRIDENT_HIT, + ITEM_TRIDENT_HIT_GROUND, + ITEM_TRIDENT_RETURN, + ITEM_TRIDENT_RIPTIDE_1, + ITEM_TRIDENT_RIPTIDE_2, + ITEM_TRIDENT_RIPTIDE_3, + ITEM_TRIDENT_THROW, + ITEM_TRIDENT_THUNDER, + MUSIC_CREATIVE, + MUSIC_CREDITS, + MUSIC_DISC_11(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_11"), v("WOOD_CLICK", true)), + MUSIC_DISC_13(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_13"), v("WOOD_CLICK", true)), + MUSIC_DISC_BLOCKS(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_BLOCKS"), v("WOOD_CLICK", true)), + MUSIC_DISC_CAT(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_CAT"), v("WOOD_CLICK", true)), + MUSIC_DISC_CHIRP(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_CHIRP"), v("WOOD_CLICK", true)), + MUSIC_DISC_FAR(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_FAR"), v("WOOD_CLICK", true)), + MUSIC_DISC_MALL(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_MALL"), v("WOOD_CLICK", true)), + MUSIC_DISC_MELLOHI(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_MELLOHI"), v("WOOD_CLICK", true)), + MUSIC_DISC_STAL(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_STAL"), v("WOOD_CLICK", true)), + MUSIC_DISC_STRAD(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_STRAD"), v("WOOD_CLICK", true)), + MUSIC_DISC_WAIT(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_WAIT"), v("WOOD_CLICK", true)), + MUSIC_DISC_WARD(ServerVersion.V1_13, v(ServerVersion.V1_9, "RECORD_WARD"), v("WOOD_CLICK", true)), // records are missing from 1.8 API + MUSIC_DRAGON, + MUSIC_END, + MUSIC_GAME, + MUSIC_MENU, + MUSIC_NETHER, + MUSIC_UNDER_WATER, + UI_BUTTON_CLICK("CLICK"), + UI_CARTOGRAPHY_TABLE_TAKE_RESULT, + UI_LOOM_SELECT_PATTERN, + UI_LOOM_TAKE_RESULT, + UI_STONECUTTER_SELECT_RECIPE, + UI_STONECUTTER_TAKE_RESULT, + UI_TOAST_CHALLENGE_COMPLETE, + UI_TOAST_IN, + UI_TOAST_OUT, + WEATHER_RAIN("AMBIENCE_RAIN"), + WEATHER_RAIN_ABOVE; + + protected /*final*/ Sound sound; + protected /*final*/ boolean compatibilityMode; + protected static final boolean DEBUG = false; + + private CompatibleSound() { + // This could get risky, since we haven't finished this + //sound = Sound.valueOf(name()); + Sound find = null; + for (Sound s : Sound.values()) { + if (s.name().equals(name())) { + find = s; + break; + } + } + if (DEBUG && find == null) { + System.out.println("Sound for " + name() + " Not found!"); + } + sound = find; + compatibilityMode = find == null; + } + + // if the sound ony ever changed from 1.8 -> 1.9 + private CompatibleSound(String compatibility_18) { + try { + compatibilityMode = false; + if (ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) { + sound = Sound.valueOf(compatibility_18); + } else { + sound = Sound.valueOf(name()); + } + } catch (Exception e) { + System.out.println("ERROR loading " + name()); + e.printStackTrace(); + } + } + + private CompatibleSound(Version... versions) { + try { + for (Version v : versions) { + if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) { + sound = Sound.valueOf(v.sound); + compatibilityMode = v.compatibilityMode; + return; + } + } + } catch (Exception e) { + System.out.println("ERROR loading " + name()); + for (Version v : versions) { + System.out.println(v.version + " - " + v.sound); + } + e.printStackTrace(); + } + Sound find = null; + for (Sound s : Sound.values()) { + if (s.name().equals(name())) { + find = s; + break; + } + } + sound = find; + compatibilityMode = find == null; + } + + private CompatibleSound(ServerVersion minVersion, Version... versions) { + try { + if (ServerVersion.isServerVersionAtLeast(minVersion)) { + // should be good to use this sound + sound = Sound.valueOf(name()); + compatibilityMode = false; + } else { + for (Version v : versions) { + if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) { + sound = Sound.valueOf(v.sound); + compatibilityMode = v.compatibilityMode; + return; + } + } + sound = null; + compatibilityMode = false; + } + } catch (Exception e) { + System.out.println("ERROR loading " + name() + " (" + minVersion); + for (Version v : versions) { + System.out.println(v.version + " - " + v.sound); + } + e.printStackTrace(); + } + } + + /** + * Get a Bukkit API sound that matches this sound + * + * @return Returns either the matching sound or a similar sound + */ + public Sound getSound() { + return sound != null ? sound : UI_BUTTON_CLICK.sound; + } + + /** + * Send a sound to a specific player + * + * @param sendTo player to send the sound to + */ + public void play(Player sendTo) { + sendTo.playSound(sendTo.getLocation(), getSound(), 1F, 1F); + } + + /** + * Send a sound to a specific player + * + * @param sendTo player to send the sound to + * @param volume the volume of the sound + * @param pitch the pitch of the sound + */ + public void play(Player sendTo, float volume, float pitch) { + sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch); + } + + /** + * Send a sound to a specific player + * + * @param sendTo player to send the sound to + * @param location where the sound should come from + * @param volume the volume of the sound + * @param pitch the pitch of the sound + */ + public void play(Player sendTo, Location location, float volume, float pitch) { + sendTo.playSound(sendTo.getLocation(), getSound(), volume, pitch); + } + + /** + * Play a sound in a world + * + * @param sendTo world to send the sound to + * @param location where the sound should come from + * @param volume the volume of the sound + * @param pitch the pitch of the sound + */ + public void play(World sendTo, Location location, float volume, float pitch) { + sendTo.playSound(location, getSound(), volume, pitch); + } + + /** + * Stop a currently active sound from playing for a player + * + * @param sendTo player to stop the sound for + */ + public void stop(Player sendTo) { + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10)) { + sendTo.stopSound(getSound()); + } + } + + /** + * Check to see if this sound is available on this server. + * + * @return Returns false if we are using a different sound. + */ + public boolean usesCompatibility() { + return !compatibilityMode; + } + + private static Version v(String sound) { + return new Version(ServerVersion.UNKNOWN, sound, false); + } + + private static Version v(ServerVersion version, String sound) { + return new Version(version, sound, false); + } + + private static Version v(ServerVersion version, String sound, boolean compatibility) { + return new Version(version, sound, compatibility); + } + + private static Version v(String sound, boolean compatibility) { + return new Version(ServerVersion.UNKNOWN, sound, compatibility); + } + + private static class Version { + + final ServerVersion version; + final String sound; + final boolean compatibilityMode; + + public Version(ServerVersion version, String sound, boolean compatibility) { + this.version = version; + this.sound = sound; + this.compatibilityMode = compatibility; + } + } +} diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java b/Compatibility/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java index b92f0a0a..137cc7d7 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/LegacyMaterialBlockType.java @@ -1,129 +1,128 @@ -package com.songoda.core.compatibility; - -import org.bukkit.Material; - -import java.util.HashMap; -import java.util.Map; - -/** - * Starting in Minecraft 1.13, separate materials for blocks and items were - * phased out. This provides a translation for those values. - * - * @author jascotty2 - * @since 2019-09-12 - */ -public enum LegacyMaterialBlockType { - - OAK_LEAVES("LEAVES", (byte)8, true), - SPRUCE_LEAVES("LEAVES", (byte)9, true), - BIRCH_LEAVES("LEAVES", (byte)10, true), - JUNGLE_LEAVES("LEAVES", (byte)11, true), - ACACIA_LEAVES("LEAVES_2", (byte)8, true), - DARK_OAK_LEAVES("LEAVES_2", (byte)9, true), - - ACACIA_DOOR("ACACIA_DOOR", true), - BED("BED_BLOCK", true), - BIRCH_DOOR("BIRCH_DOOR", true), - FURNACE("FURNACE", "BURNING_FURNACE"), - CAKE("CAKE_BLOCK"), - CARROTS("CARROT"), // totally makes sense, lol - CAULDRON("CAULDRON_BLOCK"), - COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON"), - DARK_OAK_DOOR("DARK_OAK_DOOR", true), - DAYLIGHT_DETECTOR("DAYLIGHT_DETECTOR", "DAYLIGHT_DETECTOR_INVERTED"), - /* - < DOUBLE_STEP, - < DOUBLE_STONE_SLAB2, - */ - FLOWER_POT("FLOWER_POT"), - IRON_DOOR("IRON_DOOR_BLOCK", true), - JUNGLE_DOOR("JUNGLE_DOOR", true), - LAVA("STATIONARY_LAVA"), - NETHER_WART("NETHER_WARTS"), - /* - < PURPUR_DOUBLE_SLAB - */ - POTATOES("POTATO"), - REDSTONE_LAMP("REDSTONE_LAMP_OFF", "REDSTONE_LAMP_ON"), - REDSTONE_ORE("REDSTONE_ORE", "GLOWING_REDSTONE_ORE"), - REDSTONE_TORCH("REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"), - SPRUCE_DOOR("SPRUCE_DOOR"), - SUGAR_CANE("SUGAR_CANE_BLOCK"), - WATER("STATIONARY_WATER"), - WHEAT("CROPS"); - final String blockMaterialName; - final byte blockData; - final String alternateBlockMaterialName; - final Material blockMaterial, alternateBlockMaterial; - final boolean requiresData; // some blocks require data to render properly (double blocks) - final static Map lookupTable = new HashMap(); - final static Map reverseLookupTable = new HashMap(); - - static { - for (LegacyMaterialBlockType t : values()) { - lookupTable.put(t.name(), t); - reverseLookupTable.put(t.blockMaterialName + ":" + t.blockData, t); - if (t.alternateBlockMaterialName != null) { - reverseLookupTable.put(t.alternateBlockMaterialName, t); - } - } - } - - private LegacyMaterialBlockType(String blockMaterial) { - this(blockMaterial, (byte)-1, null,false); - } - - private LegacyMaterialBlockType(String blockMaterial, boolean requiresData) { - this(blockMaterial, (byte)-1, null, requiresData); - } - - private LegacyMaterialBlockType(String blockMaterial, byte data, boolean requiresData) { - this(blockMaterial, data, null, requiresData); - } - - private LegacyMaterialBlockType(String blockMaterial, String alternateMaterial) { - this(blockMaterial, (byte)-1, alternateMaterial, false); - } - - private LegacyMaterialBlockType(String blockMaterial, byte data, String alternateMaterial, boolean requiresData) { - this.blockMaterialName = blockMaterial; - this.alternateBlockMaterialName = alternateMaterial; - this.requiresData = requiresData; - this.blockMaterial = Material.getMaterial(blockMaterialName); - this.alternateBlockMaterial = Material.getMaterial(alternateBlockMaterialName); - this.blockData = data; - } - - public String getBlockMaterialName() { - return blockMaterialName; - } - - public String getAlternateMaterialName() { - return alternateBlockMaterialName; - } - - public Material getBlockMaterial() { - return blockMaterial; - } - - public Material getAlternateBlockMaterial() { - return alternateBlockMaterial; - } - - public boolean requiresData() { - return requiresData; - } - - public static LegacyMaterialBlockType getMaterial(String lookup) { - return lookupTable.get(lookup); - } - - public static LegacyMaterialBlockType getFromLegacy(String lookup, byte data) { - return reverseLookupTable.get(lookup + ":" + data); - } - - public static LegacyMaterialBlockType getFromLegacy(String lookup) { - return getFromLegacy(lookup, (byte)-1); - } - -} +package com.songoda.core.compatibility; + +import org.bukkit.Material; + +import java.util.HashMap; +import java.util.Map; + +/** + * Starting in Minecraft 1.13, separate materials for blocks and items were + * phased out. This provides a translation for those values. + * + * @author jascotty2 + * @since 2019-09-12 + */ +public enum LegacyMaterialBlockType { + + OAK_LEAVES("LEAVES", (byte) 8, true), + SPRUCE_LEAVES("LEAVES", (byte) 9, true), + BIRCH_LEAVES("LEAVES", (byte) 10, true), + JUNGLE_LEAVES("LEAVES", (byte) 11, true), + ACACIA_LEAVES("LEAVES_2", (byte) 8, true), + DARK_OAK_LEAVES("LEAVES_2", (byte) 9, true), + + ACACIA_DOOR("ACACIA_DOOR", true), + BED("BED_BLOCK", true), + BIRCH_DOOR("BIRCH_DOOR", true), + FURNACE("FURNACE", "BURNING_FURNACE"), + CAKE("CAKE_BLOCK"), + CARROTS("CARROT"), // totally makes sense, lol + CAULDRON("CAULDRON_BLOCK"), + COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON"), + DARK_OAK_DOOR("DARK_OAK_DOOR", true), + DAYLIGHT_DETECTOR("DAYLIGHT_DETECTOR", "DAYLIGHT_DETECTOR_INVERTED"), + /* + < DOUBLE_STEP, + < DOUBLE_STONE_SLAB2, + */ + FLOWER_POT("FLOWER_POT"), + IRON_DOOR("IRON_DOOR_BLOCK", true), + JUNGLE_DOOR("JUNGLE_DOOR", true), + LAVA("STATIONARY_LAVA"), + NETHER_WART("NETHER_WARTS"), + /* + < PURPUR_DOUBLE_SLAB + */ + POTATOES("POTATO"), + REDSTONE_LAMP("REDSTONE_LAMP_OFF", "REDSTONE_LAMP_ON"), + REDSTONE_ORE("REDSTONE_ORE", "GLOWING_REDSTONE_ORE"), + REDSTONE_TORCH("REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"), + SPRUCE_DOOR("SPRUCE_DOOR"), + SUGAR_CANE("SUGAR_CANE_BLOCK"), + WATER("STATIONARY_WATER"), + WHEAT("CROPS"); + final String blockMaterialName; + final byte blockData; + final String alternateBlockMaterialName; + final Material blockMaterial, alternateBlockMaterial; + final boolean requiresData; // some blocks require data to render properly (double blocks) + final static Map lookupTable = new HashMap(); + final static Map reverseLookupTable = new HashMap(); + + static { + for (LegacyMaterialBlockType t : values()) { + lookupTable.put(t.name(), t); + reverseLookupTable.put(t.blockMaterialName + ":" + t.blockData, t); + if (t.alternateBlockMaterialName != null) { + reverseLookupTable.put(t.alternateBlockMaterialName, t); + } + } + } + + private LegacyMaterialBlockType(String blockMaterial) { + this(blockMaterial, (byte) -1, null, false); + } + + private LegacyMaterialBlockType(String blockMaterial, boolean requiresData) { + this(blockMaterial, (byte) -1, null, requiresData); + } + + private LegacyMaterialBlockType(String blockMaterial, byte data, boolean requiresData) { + this(blockMaterial, data, null, requiresData); + } + + private LegacyMaterialBlockType(String blockMaterial, String alternateMaterial) { + this(blockMaterial, (byte) -1, alternateMaterial, false); + } + + private LegacyMaterialBlockType(String blockMaterial, byte data, String alternateMaterial, boolean requiresData) { + this.blockMaterialName = blockMaterial; + this.alternateBlockMaterialName = alternateMaterial; + this.requiresData = requiresData; + this.blockMaterial = Material.getMaterial(blockMaterialName); + this.alternateBlockMaterial = Material.getMaterial(alternateBlockMaterialName); + this.blockData = data; + } + + public String getBlockMaterialName() { + return blockMaterialName; + } + + public String getAlternateMaterialName() { + return alternateBlockMaterialName; + } + + public Material getBlockMaterial() { + return blockMaterial; + } + + public Material getAlternateBlockMaterial() { + return alternateBlockMaterial; + } + + public boolean requiresData() { + return requiresData; + } + + public static LegacyMaterialBlockType getMaterial(String lookup) { + return lookupTable.get(lookup); + } + + public static LegacyMaterialBlockType getFromLegacy(String lookup, byte data) { + return reverseLookupTable.get(lookup + ":" + data); + } + + public static LegacyMaterialBlockType getFromLegacy(String lookup) { + return getFromLegacy(lookup, (byte) -1); + } +} diff --git a/Compatibility/src/main/java/com/songoda/core/compatibility/ServerProject.java b/Compatibility/src/main/java/com/songoda/core/compatibility/ServerProject.java index e421cc5e..da85c478 100644 --- a/Compatibility/src/main/java/com/songoda/core/compatibility/ServerProject.java +++ b/Compatibility/src/main/java/com/songoda/core/compatibility/ServerProject.java @@ -1,54 +1,53 @@ -package com.songoda.core.compatibility; - -import org.apache.commons.lang.ArrayUtils; -import org.bukkit.Bukkit; - -public enum ServerProject { - - UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE; - private final static ServerProject serverProject = checkProject(); - - private static ServerProject checkProject() { - String serverPath = Bukkit.getServer().getClass().getName(); - if (serverPath.contains("glowstone")) { - return GLOWSTONE; - } - // taco is pretty easy to check. it uses paper stuff, though, so should be checked first - try { - Class.forName("net.techcable.tacospigot.TacoSpigotConfig"); - return TACO; - } catch (ClassNotFoundException ex) { - } - // paper used to be called "paperclip" - try { - Class.forName("com.destroystokyo.paperclip.Paperclip"); - return PAPER; - } catch (ClassNotFoundException ex) { - } - try { - Class.forName("com.destroystokyo.paper.PaperConfig"); - return PAPER; - } catch (ClassNotFoundException ex) { - } - // spigot is the fork that pretty much all builds are based on anymore - try { - Class.forName("org.spigotmc.SpigotConfig"); - return SPIGOT; - } catch (ClassNotFoundException ex) { - } - return serverPath.contains("craftbukkit") ? CRAFTBUKKIT : UNKNOWN; - } - - public static ServerProject getServerVersion() { - return serverProject; - } - - public static boolean isServer(ServerProject version) { - return serverProject == version; - } - - public static boolean isServer(ServerProject... versions) { - return ArrayUtils.contains(versions, serverProject); - } - -} +package com.songoda.core.compatibility; + +import org.apache.commons.lang.ArrayUtils; +import org.bukkit.Bukkit; + +public enum ServerProject { + + UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE; + private final static ServerProject serverProject = checkProject(); + + private static ServerProject checkProject() { + String serverPath = Bukkit.getServer().getClass().getName(); + if (serverPath.contains("glowstone")) { + return GLOWSTONE; + } + // taco is pretty easy to check. it uses paper stuff, though, so should be checked first + try { + Class.forName("net.techcable.tacospigot.TacoSpigotConfig"); + return TACO; + } catch (ClassNotFoundException ex) { + } + // paper used to be called "paperclip" + try { + Class.forName("com.destroystokyo.paperclip.Paperclip"); + return PAPER; + } catch (ClassNotFoundException ex) { + } + try { + Class.forName("com.destroystokyo.paper.PaperConfig"); + return PAPER; + } catch (ClassNotFoundException ex) { + } + // spigot is the fork that pretty much all builds are based on anymore + try { + Class.forName("org.spigotmc.SpigotConfig"); + return SPIGOT; + } catch (ClassNotFoundException ex) { + } + return serverPath.contains("craftbukkit") ? CRAFTBUKKIT : UNKNOWN; + } + + public static ServerProject getServerVersion() { + return serverProject; + } + + public static boolean isServer(ServerProject version) { + return serverProject == version; + } + + public static boolean isServer(ServerProject... versions) { + return ArrayUtils.contains(versions, serverProject); + } +} diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index e8a9bd2d..ab913230 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -9,8 +9,6 @@ import com.songoda.core.core.PluginInfoModule; import com.songoda.core.core.SongodaCoreCommand; import com.songoda.core.core.SongodaCoreDiagCommand; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; @@ -22,7 +20,6 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; -import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; @@ -73,7 +70,7 @@ public class SongodaCore { public static boolean hasShading() { // sneaky hack to check the package name since maven tries to re-shade all references to the package string - return !SongodaCore.class.getPackage().getName().equals(new String(new char[]{'c', 'o', 'm', '.', 's', 'o', 'n', 'g', 'o', 'd', 'a', '.', 'c', 'o', 'r', 'e'})); + return !SongodaCore.class.getPackage().getName().equals(new String(new char[] {'c', 'o', 'm', '.', 's', 'o', 'n', 'g', 'o', 'd', 'a', '.', 'c', 'o', 'r', 'e'})); } public static void registerPlugin(JavaPlugin plugin, int pluginID, CompatibleMaterial icon) { @@ -315,7 +312,7 @@ public class SongodaCore { if (!via && (via = event.getPlugin().getName().equals("ViaVersion"))) { Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin())); } else if (!proto && (proto = event.getPlugin().getName().equals("ProtocolSupport"))) { - Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin())); + Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin())); } } } diff --git a/Core/src/main/java/com/songoda/core/SongodaPlugin.java b/Core/src/main/java/com/songoda/core/SongodaPlugin.java index 48faa0de..e7c8ebc5 100644 --- a/Core/src/main/java/com/songoda/core/SongodaPlugin.java +++ b/Core/src/main/java/com/songoda/core/SongodaPlugin.java @@ -1,177 +1,178 @@ -package com.songoda.core; - -import com.songoda.core.configuration.Config; -import com.songoda.core.locale.Locale; -import com.songoda.core.utils.Metrics; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.List; -import java.util.logging.Level; - -/** - * REMINDER: When converting plugins to use this, REMOVE METRICS
- * Must not have two instances of Metrics enabled! - * - * @author jascotty2 - */ -public abstract class SongodaPlugin extends JavaPlugin { - - protected Locale locale; - protected Config config = new Config(this); - protected long dataLoadDelay = 20L; - - protected ConsoleCommandSender console = Bukkit.getConsoleSender(); - private boolean emergencyStop = false; - - public abstract void onPluginLoad(); - - public abstract void onPluginEnable(); - - public abstract void onPluginDisable(); - - public abstract void onDataLoad(); - - /** - * Called after reloadConfig​() is called - */ - public abstract void onConfigReload(); - - /** - * Any other plugin configuration files used by the plugin. - * - * @return a list of Configs that are used in addition to the main config. - */ - public abstract List getExtraConfig(); - - @Override - public FileConfiguration getConfig() { - return config.getFileConfig(); - } - - public Config getCoreConfig() { - return config; - } - - @Override - public void reloadConfig() { - config.load(); - onConfigReload(); - } - - @Override - public void saveConfig() { - config.save(); - } - - @Override - public final void onLoad() { - try { - onPluginLoad(); - } catch (Throwable t) { - Bukkit.getLogger().log(Level.SEVERE, - "Unexpected error while loading " + getDescription().getName() - + " v" + getDescription().getVersion() - + " c" + SongodaCore.getCoreLibraryVersion() - + ": Disabling plugin!", t); - emergencyStop = true; - } - } - - @Override - public final void onEnable() { - if (emergencyStop) { - setEnabled(false); - return; - } - - console.sendMessage(" "); // blank line to separate chatter - console.sendMessage(ChatColor.GREEN + "============================="); - console.sendMessage(String.format("%s%s %s by %sSongoda <3!", ChatColor.GRAY.toString(), - getDescription().getName(), getDescription().getVersion(), ChatColor.DARK_PURPLE.toString())); - console.sendMessage(String.format("%sAction: %s%s%s...", ChatColor.GRAY.toString(), - ChatColor.GREEN.toString(), "Enabling", ChatColor.GRAY.toString())); - - try { - locale = Locale.loadDefaultLocale(this, "en_US"); - // plugin setup - onPluginEnable(); - // Load Data. - Bukkit.getScheduler().runTaskLater(this, this::onDataLoad, dataLoadDelay); - if (emergencyStop) { - console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - console.sendMessage(" "); - return; - } - // Start Metrics - Metrics.start(this); - } catch (Throwable t) { - Bukkit.getLogger().log(Level.SEVERE, - "Unexpected error while loading " + getDescription().getName() - + " v" + getDescription().getVersion() - + " c" + SongodaCore.getCoreLibraryVersion() - + ": Disabling plugin!", t); - emergencyStop(); - console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - console.sendMessage(" "); - return; - } - - console.sendMessage(ChatColor.GREEN + "============================="); - console.sendMessage(" "); // blank line to separate chatter - } - - protected void emergencyStop() { - emergencyStop = true; - Bukkit.getPluginManager().disablePlugin(this); - } - - @Override - public final void onDisable() { - if (emergencyStop) { - return; - } - console.sendMessage(" "); // blank line to speparate chatter - console.sendMessage(ChatColor.GREEN + "============================="); - console.sendMessage(String.format("%s%s %s by %sSongoda <3!", ChatColor.GRAY.toString(), - getDescription().getName(), getDescription().getVersion(), ChatColor.DARK_PURPLE.toString())); - console.sendMessage(String.format("%sAction: %s%s%s...", ChatColor.GRAY.toString(), - ChatColor.RED.toString(), "Disabling", ChatColor.GRAY.toString())); - onPluginDisable(); - console.sendMessage(ChatColor.GREEN + "============================="); - console.sendMessage(" "); // blank line to speparate chatter - } - - public ConsoleCommandSender getConsole() { - return console; - } - - public Locale getLocale() { - return locale; - } - - /** - * Set the plugin's locale to a specific language - * - * @param localeName locale to use, eg "en_US" - * @param reload optionally reload the loaded locale if the locale didn't - * change - * @return true if the locale exists and was loaded successfully - */ - public boolean setLocale(String localeName, boolean reload) { - if (locale != null && locale.getName().equals(localeName)) { - return !reload || locale.reloadMessages(); - } else { - Locale l = Locale.loadLocale(this, localeName); - if (l != null) { - locale = l; - return true; - } else { - return false; - } - } - } -} +package com.songoda.core; + +import com.songoda.core.configuration.Config; +import com.songoda.core.locale.Locale; +import com.songoda.core.utils.Metrics; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.List; +import java.util.logging.Level; + +/** + * REMINDER: When converting plugins to use this, REMOVE METRICS
+ * Must not have two instances of Metrics enabled! + * + * @author jascotty2 + */ +public abstract class SongodaPlugin extends JavaPlugin { + + protected Locale locale; + protected Config config = new Config(this); + protected long dataLoadDelay = 20L; + + protected ConsoleCommandSender console = Bukkit.getConsoleSender(); + private boolean emergencyStop = false; + + public abstract void onPluginLoad(); + + public abstract void onPluginEnable(); + + public abstract void onPluginDisable(); + + public abstract void onDataLoad(); + + /** + * Called after reloadConfig​() is called + */ + public abstract void onConfigReload(); + + /** + * Any other plugin configuration files used by the plugin. + * + * @return a list of Configs that are used in addition to the main config. + */ + public abstract List getExtraConfig(); + + @Override + public FileConfiguration getConfig() { + return config.getFileConfig(); + } + + public Config getCoreConfig() { + return config; + } + + @Override + public void reloadConfig() { + config.load(); + onConfigReload(); + } + + @Override + public void saveConfig() { + config.save(); + } + + @Override + public final void onLoad() { + try { + onPluginLoad(); + } catch (Throwable t) { + Bukkit.getLogger().log(Level.SEVERE, + "Unexpected error while loading " + getDescription().getName() + + " v" + getDescription().getVersion() + + " c" + SongodaCore.getCoreLibraryVersion() + + ": Disabling plugin!", t); + emergencyStop = true; + } + } + + @Override + public final void onEnable() { + if (emergencyStop) { + setEnabled(false); + return; + } + + console.sendMessage(" "); // blank line to separate chatter + console.sendMessage(ChatColor.GREEN + "============================="); + console.sendMessage(String.format("%s%s %s by %sSongoda <3!", ChatColor.GRAY.toString(), + getDescription().getName(), getDescription().getVersion(), ChatColor.DARK_PURPLE.toString())); + console.sendMessage(String.format("%sAction: %s%s%s...", ChatColor.GRAY.toString(), + ChatColor.GREEN.toString(), "Enabling", ChatColor.GRAY.toString())); + + try { + locale = Locale.loadDefaultLocale(this, "en_US"); + // plugin setup + onPluginEnable(); + // Load Data. + Bukkit.getScheduler().runTaskLater(this, this::onDataLoad, dataLoadDelay); + if (emergencyStop) { + console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + console.sendMessage(" "); + return; + } + // Start Metrics + Metrics.start(this); + } catch (Throwable t) { + Bukkit.getLogger().log(Level.SEVERE, + "Unexpected error while loading " + getDescription().getName() + + " v" + getDescription().getVersion() + + " c" + SongodaCore.getCoreLibraryVersion() + + ": Disabling plugin!", t); + emergencyStop(); + console.sendMessage(ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + console.sendMessage(" "); + return; + } + + console.sendMessage(ChatColor.GREEN + "============================="); + console.sendMessage(" "); // blank line to separate chatter + } + + protected void emergencyStop() { + emergencyStop = true; + Bukkit.getPluginManager().disablePlugin(this); + } + + @Override + public final void onDisable() { + if (emergencyStop) { + return; + } + console.sendMessage(" "); // blank line to speparate chatter + console.sendMessage(ChatColor.GREEN + "============================="); + console.sendMessage(String.format("%s%s %s by %sSongoda <3!", ChatColor.GRAY.toString(), + getDescription().getName(), getDescription().getVersion(), ChatColor.DARK_PURPLE.toString())); + console.sendMessage(String.format("%sAction: %s%s%s...", ChatColor.GRAY.toString(), + ChatColor.RED.toString(), "Disabling", ChatColor.GRAY.toString())); + onPluginDisable(); + console.sendMessage(ChatColor.GREEN + "============================="); + console.sendMessage(" "); // blank line to speparate chatter + } + + public ConsoleCommandSender getConsole() { + return console; + } + + public Locale getLocale() { + return locale; + } + + /** + * Set the plugin's locale to a specific language + * + * @param localeName locale to use, eg "en_US" + * @param reload optionally reload the loaded locale if the locale didn't + * change + * + * @return true if the locale exists and was loaded successfully + */ + public boolean setLocale(String localeName, boolean reload) { + if (locale != null && locale.getName().equals(localeName)) { + return !reload || locale.reloadMessages(); + } else { + Locale l = Locale.loadLocale(this, localeName); + if (l != null) { + locale = l; + return true; + } else { + return false; + } + } + } +} diff --git a/Core/src/main/java/com/songoda/core/chat/ChatMessage.java b/Core/src/main/java/com/songoda/core/chat/ChatMessage.java index 06668198..9fb20b41 100644 --- a/Core/src/main/java/com/songoda/core/chat/ChatMessage.java +++ b/Core/src/main/java/com/songoda/core/chat/ChatMessage.java @@ -1,274 +1,273 @@ -package com.songoda.core.chat; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; -import com.songoda.core.compatibility.ServerVersion; -import com.songoda.core.compatibility.ClassMapping; -import com.songoda.core.utils.TextUtils; -import net.minecraft.network.chat.IChatBaseComponent; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class ChatMessage { - - private static final Gson gson = new GsonBuilder().create(); - private final List textList = new ArrayList<>(); - - public void clear() { - textList.clear(); - } - - public ChatMessage fromText(String text) { - return fromText(text, false); - } - - public ChatMessage fromText(String text, boolean noHex) { - Pattern pattern = Pattern.compile("(.*?)(?!&([omnlk]))(?=(&([123456789abcdefr#])|$)|#([a-f]|[A-F]|[0-9]){6})", - Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher(text); - - while (matcher.find()) { - ColorContainer color = null; - String match1 = matcher.group(1); - - if (matcher.groupCount() == 0 || match1.length() == 0) continue; - - char colorChar = '-'; - - if (matcher.start() != 0) - colorChar = text.substring(matcher.start() - 1, matcher.start()).charAt(0); - - if (colorChar != '-') { - if (colorChar == '#') { - color = new ColorContainer(match1.substring(0, 6), noHex); - match1 = match1.substring(5); - } else if (colorChar == '&') { - color = new ColorContainer(ColorCode.getByChar(Character.toLowerCase(match1.charAt(0)))); - } - } - - Pattern subPattern = Pattern.compile("(.*?)(?=&([omnlk])|$)"); - Matcher subMatcher = subPattern.matcher(match1); - - List stackedCodes = new ArrayList<>(); - while (subMatcher.find()) { - String match2 = subMatcher.group(1); - if (match2.length() == 0) continue; - - ColorCode code = ColorCode.getByChar(Character.toLowerCase(match2.charAt(0))); - - if (code != null && code != ColorCode.RESET) - stackedCodes.add(code); - - if (color != null) - match2 = match2.substring(1); - - if (match2.length() == 0) continue; - - addMessage(match2, color, stackedCodes); - } - } - - return this; - } - - public String toText() { - return toText(false); - } - - public String toText(boolean noHex) { - StringBuilder text = new StringBuilder(); - for (JsonObject object : textList) { - if (object.has("color")) { - String color = object.get("color").getAsString(); - text.append("&"); - if (color.length() == 7) { - text.append(new ColorContainer(color, noHex).getColor().getCode()); - } else { - text.append(ColorCode.valueOf(color.toUpperCase()).getCode()); - } - } - for (ColorCode code : ColorCode.values()) { - if (code.isColor()) continue; - String c = code.name().toLowerCase(); - if (object.has(c) && object.get(c).getAsBoolean()) - text.append("&").append(code.getCode()); - } - text.append(object.get("text").getAsString()); - } - return text.toString(); - } - - public ChatMessage addMessage(String s) { - JsonObject txt = new JsonObject(); - txt.addProperty("text", s); - textList.add(txt); - return this; - } - - public ChatMessage addMessage(String text, ColorContainer color) { - return addMessage(text, color, Collections.emptyList()); - } - - public ChatMessage addMessage(String text, ColorContainer color, List colorCodes) { - JsonObject txt = new JsonObject(); - txt.addProperty("text", text); - - if (color != null) - txt.addProperty("color", color.getHexCode() != null ? "#" + color.getHexCode() : color.getColorCode().name().toLowerCase()); - for (ColorCode code : ColorCode.values()) { - if (!code.isColor()) - txt.addProperty(code.name().toLowerCase(), colorCodes.contains(code)); - } - - textList.add(txt); - return this; - } - - public ChatMessage addRunCommand(String text, String hoverText, String cmd) { - JsonObject txt = new JsonObject(); - txt.addProperty("text", text); - JsonObject hover = new JsonObject(); - hover.addProperty("action", "show_text"); - hover.addProperty("value", hoverText); - txt.add("hoverEvent", hover); - JsonObject click = new JsonObject(); - click.addProperty("action", "run_command"); - click.addProperty("value", cmd); - txt.add("clickEvent", click); - textList.add(txt); - return this; - } - - public ChatMessage addPromptCommand(String text, String hoverText, String cmd) { - JsonObject txt = new JsonObject(); - txt.addProperty("text", text); - JsonObject hover = new JsonObject(); - hover.addProperty("action", "show_text"); - hover.addProperty("value", hoverText); - txt.add("hoverEvent", hover); - JsonObject click = new JsonObject(); - click.addProperty("action", "suggest_command"); - click.addProperty("value", cmd); - txt.add("clickEvent", click); - textList.add(txt); - return this; - } - - public ChatMessage addURL(String text, String hoverText, String url) { - JsonObject txt = new JsonObject(); - txt.addProperty("text", text); - JsonObject hover = new JsonObject(); - hover.addProperty("action", "show_text"); - hover.addProperty("value", hoverText); - txt.add("hoverEvent", hover); - JsonObject click = new JsonObject(); - click.addProperty("action", "open_url"); - click.addProperty("value", url); - txt.add("clickEvent", hover); - textList.add(txt); - return this; - } - - @Override - public String toString() { - return gson.toJson(textList); - } - - public void sendTo(CommandSender sender) { - sendTo(null, sender); - } - - public void sendTo(ChatMessage prefix, CommandSender sender) { - if (sender instanceof Player && enabled) { - try { - List textList = prefix == null ? new ArrayList<>() : new ArrayList<>(prefix.textList); - textList.addAll(this.textList); - - Object packet; - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) { - packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)), mc_chatMessageType_Chat.get(null), ((Player) sender).getUniqueId()); - } else { - packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList))); - } - Object cbPlayer = cb_craftPlayer_getHandle.invoke(sender); - Object mcConnection = mc_entityPlayer_playerConnection.get(cbPlayer); - mc_playerConnection_sendPacket.invoke(mcConnection, packet); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Bukkit.getLogger().log(Level.WARNING, "Problem preparing raw chat packets (disabling further packets)", ex); - enabled = false; - } - } else { - sender.sendMessage(TextUtils.formatText((prefix == null ? "" : prefix.toText(true) + " ") + toText(true))); - } - } - - private static boolean enabled = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_8); - - private static Class mc_ChatMessageType; - private static Method mc_IChatBaseComponent_ChatSerializer_a, cb_craftPlayer_getHandle, mc_playerConnection_sendPacket; - private static Constructor mc_PacketPlayOutChat_new; - private static Field mc_entityPlayer_playerConnection, mc_chatMessageType_Chat; - - static { - init(); - } - - static void init() { - if (enabled) { - try { - - final String version = ServerVersion.getServerVersionString(); - Class cb_craftPlayerClazz, mc_entityPlayerClazz, mc_playerConnectionClazz, mc_PacketInterface, - mc_IChatBaseComponent, mc_IChatBaseComponent_ChatSerializer, mc_PacketPlayOutChat; - - cb_craftPlayerClazz = ClassMapping.CRAFT_PLAYER.getClazz(); - cb_craftPlayer_getHandle = cb_craftPlayerClazz.getDeclaredMethod("getHandle"); - mc_entityPlayerClazz = ClassMapping.ENTITY_PLAYER.getClazz(); - mc_entityPlayer_playerConnection = mc_entityPlayerClazz.getDeclaredField(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) ? "b" : "playerConnection"); - mc_playerConnectionClazz = ClassMapping.PLAYER_CONNECTION.getClazz(); - mc_PacketInterface = ClassMapping.PACKET.getClazz(); - mc_playerConnection_sendPacket = mc_playerConnectionClazz.getDeclaredMethod("sendPacket", mc_PacketInterface); - mc_IChatBaseComponent = ClassMapping.I_CHAT_BASE_COMPONENT.getClazz(); - mc_IChatBaseComponent_ChatSerializer = ClassMapping.I_CHAT_BASE_COMPONENT.getClazz("ChatSerializer"); - mc_IChatBaseComponent_ChatSerializer_a = mc_IChatBaseComponent_ChatSerializer.getMethod("a", String.class); - mc_PacketPlayOutChat = ClassMapping.PACKET_PLAY_OUT_CHAT.getClazz(); - - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) { - mc_ChatMessageType = ClassMapping.CHAT_MESSAGE_TYPE.getClazz(); - mc_chatMessageType_Chat = mc_ChatMessageType.getField(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) ? "a" : "CHAT"); - mc_PacketPlayOutChat_new = mc_PacketPlayOutChat.getConstructor(mc_IChatBaseComponent, mc_ChatMessageType, UUID.class); - } else { - mc_PacketPlayOutChat_new = mc_PacketPlayOutChat.getConstructor(mc_IChatBaseComponent); - } - } catch (Throwable ex) { - Bukkit.getLogger().log(Level.WARNING, "Problem preparing raw chat packets (disabling further packets)", ex); - enabled = false; - } - } - } - - public ChatMessage replaceAll(String toReplace, String replaceWith) { - for (JsonObject object : textList) { - String text = object.get("text").getAsString() - .replaceAll(toReplace, replaceWith); - object.remove("text"); - object.addProperty("text", text); - } - return this; - } -} +package com.songoda.core.chat; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.songoda.core.compatibility.ClassMapping; +import com.songoda.core.compatibility.ServerVersion; +import com.songoda.core.utils.TextUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ChatMessage { + + private static final Gson gson = new GsonBuilder().create(); + private final List textList = new ArrayList<>(); + + public void clear() { + textList.clear(); + } + + public ChatMessage fromText(String text) { + return fromText(text, false); + } + + public ChatMessage fromText(String text, boolean noHex) { + Pattern pattern = Pattern.compile("(.*?)(?!&([omnlk]))(?=(&([123456789abcdefr#])|$)|#([a-f]|[A-F]|[0-9]){6})", + Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(text); + + while (matcher.find()) { + ColorContainer color = null; + String match1 = matcher.group(1); + + if (matcher.groupCount() == 0 || match1.length() == 0) continue; + + char colorChar = '-'; + + if (matcher.start() != 0) + colorChar = text.substring(matcher.start() - 1, matcher.start()).charAt(0); + + if (colorChar != '-') { + if (colorChar == '#') { + color = new ColorContainer(match1.substring(0, 6), noHex); + match1 = match1.substring(5); + } else if (colorChar == '&') { + color = new ColorContainer(ColorCode.getByChar(Character.toLowerCase(match1.charAt(0)))); + } + } + + Pattern subPattern = Pattern.compile("(.*?)(?=&([omnlk])|$)"); + Matcher subMatcher = subPattern.matcher(match1); + + List stackedCodes = new ArrayList<>(); + while (subMatcher.find()) { + String match2 = subMatcher.group(1); + if (match2.length() == 0) continue; + + ColorCode code = ColorCode.getByChar(Character.toLowerCase(match2.charAt(0))); + + if (code != null && code != ColorCode.RESET) + stackedCodes.add(code); + + if (color != null) + match2 = match2.substring(1); + + if (match2.length() == 0) continue; + + addMessage(match2, color, stackedCodes); + } + } + + return this; + } + + public String toText() { + return toText(false); + } + + public String toText(boolean noHex) { + StringBuilder text = new StringBuilder(); + for (JsonObject object : textList) { + if (object.has("color")) { + String color = object.get("color").getAsString(); + text.append("&"); + if (color.length() == 7) { + text.append(new ColorContainer(color, noHex).getColor().getCode()); + } else { + text.append(ColorCode.valueOf(color.toUpperCase()).getCode()); + } + } + for (ColorCode code : ColorCode.values()) { + if (code.isColor()) continue; + String c = code.name().toLowerCase(); + if (object.has(c) && object.get(c).getAsBoolean()) + text.append("&").append(code.getCode()); + } + text.append(object.get("text").getAsString()); + } + return text.toString(); + } + + public ChatMessage addMessage(String s) { + JsonObject txt = new JsonObject(); + txt.addProperty("text", s); + textList.add(txt); + return this; + } + + public ChatMessage addMessage(String text, ColorContainer color) { + return addMessage(text, color, Collections.emptyList()); + } + + public ChatMessage addMessage(String text, ColorContainer color, List colorCodes) { + JsonObject txt = new JsonObject(); + txt.addProperty("text", text); + + if (color != null) + txt.addProperty("color", color.getHexCode() != null ? "#" + color.getHexCode() : color.getColorCode().name().toLowerCase()); + for (ColorCode code : ColorCode.values()) { + if (!code.isColor()) + txt.addProperty(code.name().toLowerCase(), colorCodes.contains(code)); + } + + textList.add(txt); + return this; + } + + public ChatMessage addRunCommand(String text, String hoverText, String cmd) { + JsonObject txt = new JsonObject(); + txt.addProperty("text", text); + JsonObject hover = new JsonObject(); + hover.addProperty("action", "show_text"); + hover.addProperty("value", hoverText); + txt.add("hoverEvent", hover); + JsonObject click = new JsonObject(); + click.addProperty("action", "run_command"); + click.addProperty("value", cmd); + txt.add("clickEvent", click); + textList.add(txt); + return this; + } + + public ChatMessage addPromptCommand(String text, String hoverText, String cmd) { + JsonObject txt = new JsonObject(); + txt.addProperty("text", text); + JsonObject hover = new JsonObject(); + hover.addProperty("action", "show_text"); + hover.addProperty("value", hoverText); + txt.add("hoverEvent", hover); + JsonObject click = new JsonObject(); + click.addProperty("action", "suggest_command"); + click.addProperty("value", cmd); + txt.add("clickEvent", click); + textList.add(txt); + return this; + } + + public ChatMessage addURL(String text, String hoverText, String url) { + JsonObject txt = new JsonObject(); + txt.addProperty("text", text); + JsonObject hover = new JsonObject(); + hover.addProperty("action", "show_text"); + hover.addProperty("value", hoverText); + txt.add("hoverEvent", hover); + JsonObject click = new JsonObject(); + click.addProperty("action", "open_url"); + click.addProperty("value", url); + txt.add("clickEvent", hover); + textList.add(txt); + return this; + } + + @Override + public String toString() { + return gson.toJson(textList); + } + + public void sendTo(CommandSender sender) { + sendTo(null, sender); + } + + public void sendTo(ChatMessage prefix, CommandSender sender) { + if (sender instanceof Player && enabled) { + try { + List textList = prefix == null ? new ArrayList<>() : new ArrayList<>(prefix.textList); + textList.addAll(this.textList); + + Object packet; + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) { + packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList)), mc_chatMessageType_Chat.get(null), ((Player) sender).getUniqueId()); + } else { + packet = mc_PacketPlayOutChat_new.newInstance(mc_IChatBaseComponent_ChatSerializer_a.invoke(null, gson.toJson(textList))); + } + Object cbPlayer = cb_craftPlayer_getHandle.invoke(sender); + Object mcConnection = mc_entityPlayer_playerConnection.get(cbPlayer); + mc_playerConnection_sendPacket.invoke(mcConnection, packet); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + Bukkit.getLogger().log(Level.WARNING, "Problem preparing raw chat packets (disabling further packets)", ex); + enabled = false; + } + } else { + sender.sendMessage(TextUtils.formatText((prefix == null ? "" : prefix.toText(true) + " ") + toText(true))); + } + } + + private static boolean enabled = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_8); + + private static Class mc_ChatMessageType; + private static Method mc_IChatBaseComponent_ChatSerializer_a, cb_craftPlayer_getHandle, mc_playerConnection_sendPacket; + private static Constructor mc_PacketPlayOutChat_new; + private static Field mc_entityPlayer_playerConnection, mc_chatMessageType_Chat; + + static { + init(); + } + + static void init() { + if (enabled) { + try { + + final String version = ServerVersion.getServerVersionString(); + Class cb_craftPlayerClazz, mc_entityPlayerClazz, mc_playerConnectionClazz, mc_PacketInterface, + mc_IChatBaseComponent, mc_IChatBaseComponent_ChatSerializer, mc_PacketPlayOutChat; + + cb_craftPlayerClazz = ClassMapping.CRAFT_PLAYER.getClazz(); + cb_craftPlayer_getHandle = cb_craftPlayerClazz.getDeclaredMethod("getHandle"); + mc_entityPlayerClazz = ClassMapping.ENTITY_PLAYER.getClazz(); + mc_entityPlayer_playerConnection = mc_entityPlayerClazz.getDeclaredField(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) ? "b" : "playerConnection"); + mc_playerConnectionClazz = ClassMapping.PLAYER_CONNECTION.getClazz(); + mc_PacketInterface = ClassMapping.PACKET.getClazz(); + mc_playerConnection_sendPacket = mc_playerConnectionClazz.getDeclaredMethod("sendPacket", mc_PacketInterface); + mc_IChatBaseComponent = ClassMapping.I_CHAT_BASE_COMPONENT.getClazz(); + mc_IChatBaseComponent_ChatSerializer = ClassMapping.I_CHAT_BASE_COMPONENT.getClazz("ChatSerializer"); + mc_IChatBaseComponent_ChatSerializer_a = mc_IChatBaseComponent_ChatSerializer.getMethod("a", String.class); + mc_PacketPlayOutChat = ClassMapping.PACKET_PLAY_OUT_CHAT.getClazz(); + + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) { + mc_ChatMessageType = ClassMapping.CHAT_MESSAGE_TYPE.getClazz(); + mc_chatMessageType_Chat = mc_ChatMessageType.getField(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) ? "a" : "CHAT"); + mc_PacketPlayOutChat_new = mc_PacketPlayOutChat.getConstructor(mc_IChatBaseComponent, mc_ChatMessageType, UUID.class); + } else { + mc_PacketPlayOutChat_new = mc_PacketPlayOutChat.getConstructor(mc_IChatBaseComponent); + } + } catch (Throwable ex) { + Bukkit.getLogger().log(Level.WARNING, "Problem preparing raw chat packets (disabling further packets)", ex); + enabled = false; + } + } + } + + public ChatMessage replaceAll(String toReplace, String replaceWith) { + for (JsonObject object : textList) { + String text = object.get("text").getAsString() + .replaceAll(toReplace, replaceWith); + object.remove("text"); + object.addProperty("text", text); + } + return this; + } +} diff --git a/Core/src/main/java/com/songoda/core/chat/ColorCode.java b/Core/src/main/java/com/songoda/core/chat/ColorCode.java index ce54c2a3..43ae8da9 100644 --- a/Core/src/main/java/com/songoda/core/chat/ColorCode.java +++ b/Core/src/main/java/com/songoda/core/chat/ColorCode.java @@ -50,7 +50,6 @@ public enum ColorCode { ColorCode color = var0[i]; BY_CHAR.put(color.code, color); } - } public static ColorCode getByChar(char code) { @@ -68,4 +67,4 @@ public enum ColorCode { public boolean isColor() { return this.isColor; } -} \ No newline at end of file +} diff --git a/Core/src/main/java/com/songoda/core/chat/ColorContainer.java b/Core/src/main/java/com/songoda/core/chat/ColorContainer.java index d400e190..92b77b61 100644 --- a/Core/src/main/java/com/songoda/core/chat/ColorContainer.java +++ b/Core/src/main/java/com/songoda/core/chat/ColorContainer.java @@ -3,7 +3,7 @@ package com.songoda.core.chat; import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.utils.ColorUtils; -import java.awt.*; +import java.awt.Color; public class ColorContainer { @@ -40,4 +40,4 @@ public class ColorContainer { Integer.valueOf(hexCode.substring(4, 6), 16)); return ColorUtils.fromRGB(jColor.getRed(), jColor.getGreen(), jColor.getBlue()); } -} \ No newline at end of file +} diff --git a/Core/src/main/java/com/songoda/core/commands/CommandManager.java b/Core/src/main/java/com/songoda/core/commands/CommandManager.java index b0b7758b..a21d1c1d 100644 --- a/Core/src/main/java/com/songoda/core/commands/CommandManager.java +++ b/Core/src/main/java/com/songoda/core/commands/CommandManager.java @@ -10,11 +10,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.command.SimpleCommandMap; import org.bukkit.command.TabCompleter; -import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; import java.lang.reflect.Constructor; import java.lang.reflect.Field; diff --git a/Core/src/main/java/com/songoda/core/commands/MainCommand.java b/Core/src/main/java/com/songoda/core/commands/MainCommand.java index 54a94f86..a8bbf3f8 100644 --- a/Core/src/main/java/com/songoda/core/commands/MainCommand.java +++ b/Core/src/main/java/com/songoda/core/commands/MainCommand.java @@ -1,120 +1,119 @@ -package com.songoda.core.commands; - -import com.songoda.core.chat.ChatMessage; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -public class MainCommand extends AbstractCommand { - - String header = null; - String description; - boolean sortHelp = false; - final String command; - final Plugin plugin; - protected final SimpleNestedCommand nestedCommands; - - public MainCommand(Plugin plugin, String command) { - super(CommandType.CONSOLE_OK, command); - this.command = command; - this.plugin = plugin; - this.description = "Shows the command help page for /" + command; - this.nestedCommands = new SimpleNestedCommand(this); - } - - public MainCommand setHeader(String header) { - this.header = header; - return this; - } - - public MainCommand setDescription(String description) { - this.description = description; - return this; - } - - public MainCommand setSortHelp(boolean sortHelp) { - this.sortHelp = sortHelp; - return this; - } - - public MainCommand addSubCommand(AbstractCommand command) { - nestedCommands.addSubCommand(command); - return this; - } - - public MainCommand addSubCommands(AbstractCommand... commands) { - nestedCommands.addSubCommands(commands); - return this; - } - - @Override - protected ReturnType runCommand(CommandSender sender, String... args) { - sender.sendMessage(""); - if (header != null) { - sender.sendMessage(header); - } else { - new ChatMessage().fromText(String.format("#ff8080&l%s &8» &7Version %s Created with <3 by #ec4e74&l&oS#fa5b65&l&oo#ff6c55&l&on#ff7f44&l&og#ff9432&l&oo#ffaa1e&l&od#f4c009&l&oa", - plugin.getDescription().getName(), plugin.getDescription().getVersion()), sender instanceof ConsoleCommandSender) - .sendTo(sender); - } - sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + "/songoda" + ChatColor.GRAY + " - Opens the Songoda plugin GUI"); - sender.sendMessage(""); - - if (nestedCommands != null) { - List commands = nestedCommands.children.values().stream().distinct().map(c -> c.getCommands().get(0)).collect(Collectors.toList()); - if (sortHelp) { - Collections.sort(commands); - } - boolean isPlayer = sender instanceof Player; - // todo? pagation if commands.size is too large? (player-only) - sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + getSyntax() + ChatColor.GRAY + " - " + getDescription()); - for (String cmdStr : commands) { - final AbstractCommand cmd = nestedCommands.children.get(cmdStr); - if (cmd == null) continue; - if (!isPlayer) { - sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + cmd.getSyntax() + ChatColor.GRAY + " - " + cmd.getDescription()); - } else if (cmd.getPermissionNode() == null || sender.hasPermission(cmd.getPermissionNode())) { - ChatMessage chatMessage = new ChatMessage(); - final String c = "/" + command + " "; - chatMessage.addMessage(ChatColor.DARK_GRAY + "- ") - .addPromptCommand(ChatColor.YELLOW + c + cmd.getSyntax(), ChatColor.YELLOW + c + cmdStr, c + cmdStr) - .addMessage(ChatColor.GRAY + " - " + cmd.getDescription()); - chatMessage.sendTo((Player) sender); - } - } - } - - sender.sendMessage(""); - - return ReturnType.SUCCESS; - } - - @Override - protected List onTab(CommandSender sender, String... args) { - // don't need to worry about tab for a root command - handled by the manager - return null; - } - - @Override - public String getPermissionNode() { - // permissions for a root command should be handled in the plugin.yml - return null; - } - - @Override - public String getSyntax() { - return "/" + command; - } - - @Override - public String getDescription() { - return description; - } - -} +package com.songoda.core.commands; + +import com.songoda.core.chat.ChatMessage; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class MainCommand extends AbstractCommand { + + String header = null; + String description; + boolean sortHelp = false; + final String command; + final Plugin plugin; + protected final SimpleNestedCommand nestedCommands; + + public MainCommand(Plugin plugin, String command) { + super(CommandType.CONSOLE_OK, command); + this.command = command; + this.plugin = plugin; + this.description = "Shows the command help page for /" + command; + this.nestedCommands = new SimpleNestedCommand(this); + } + + public MainCommand setHeader(String header) { + this.header = header; + return this; + } + + public MainCommand setDescription(String description) { + this.description = description; + return this; + } + + public MainCommand setSortHelp(boolean sortHelp) { + this.sortHelp = sortHelp; + return this; + } + + public MainCommand addSubCommand(AbstractCommand command) { + nestedCommands.addSubCommand(command); + return this; + } + + public MainCommand addSubCommands(AbstractCommand... commands) { + nestedCommands.addSubCommands(commands); + return this; + } + + @Override + protected ReturnType runCommand(CommandSender sender, String... args) { + sender.sendMessage(""); + if (header != null) { + sender.sendMessage(header); + } else { + new ChatMessage().fromText(String.format("#ff8080&l%s &8» &7Version %s Created with <3 by #ec4e74&l&oS#fa5b65&l&oo#ff6c55&l&on#ff7f44&l&og#ff9432&l&oo#ffaa1e&l&od#f4c009&l&oa", + plugin.getDescription().getName(), plugin.getDescription().getVersion()), sender instanceof ConsoleCommandSender) + .sendTo(sender); + } + sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + "/songoda" + ChatColor.GRAY + " - Opens the Songoda plugin GUI"); + sender.sendMessage(""); + + if (nestedCommands != null) { + List commands = nestedCommands.children.values().stream().distinct().map(c -> c.getCommands().get(0)).collect(Collectors.toList()); + if (sortHelp) { + Collections.sort(commands); + } + boolean isPlayer = sender instanceof Player; + // todo? pagation if commands.size is too large? (player-only) + sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + getSyntax() + ChatColor.GRAY + " - " + getDescription()); + for (String cmdStr : commands) { + final AbstractCommand cmd = nestedCommands.children.get(cmdStr); + if (cmd == null) continue; + if (!isPlayer) { + sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + cmd.getSyntax() + ChatColor.GRAY + " - " + cmd.getDescription()); + } else if (cmd.getPermissionNode() == null || sender.hasPermission(cmd.getPermissionNode())) { + ChatMessage chatMessage = new ChatMessage(); + final String c = "/" + command + " "; + chatMessage.addMessage(ChatColor.DARK_GRAY + "- ") + .addPromptCommand(ChatColor.YELLOW + c + cmd.getSyntax(), ChatColor.YELLOW + c + cmdStr, c + cmdStr) + .addMessage(ChatColor.GRAY + " - " + cmd.getDescription()); + chatMessage.sendTo((Player) sender); + } + } + } + + sender.sendMessage(""); + + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(CommandSender sender, String... args) { + // don't need to worry about tab for a root command - handled by the manager + return null; + } + + @Override + public String getPermissionNode() { + // permissions for a root command should be handled in the plugin.yml + return null; + } + + @Override + public String getSyntax() { + return "/" + command; + } + + @Override + public String getDescription() { + return description; + } +} diff --git a/Core/src/main/java/com/songoda/core/commands/SelectorArguments.java b/Core/src/main/java/com/songoda/core/commands/SelectorArguments.java index 67366ee6..e8d57a1e 100644 --- a/Core/src/main/java/com/songoda/core/commands/SelectorArguments.java +++ b/Core/src/main/java/com/songoda/core/commands/SelectorArguments.java @@ -1,193 +1,194 @@ -package com.songoda.core.commands; - -import com.songoda.core.compatibility.EntityNamespace; -import org.bukkit.Location; -import org.bukkit.command.BlockCommandSender; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class SelectorArguments { - - static Pattern selectorPattern = Pattern.compile("^(@[apers])(\\[(.*?)\\])?$"); - static Pattern selectorRangePattern = Pattern.compile("^([0-9]{1,9}(\\.[0-9]{1,9})?)?(\\.\\.)?([0-9]{1,9}(\\.[0-9]{1,9})?)?$"); - - /** - * Parse a command selector using Minecraft's selector format.
- * Currently only supports distance and entity type - * - * @param sender CommandBlock or Player running the command - * @param argument argument with the selector to parse - * @return SelectorArguments Object for grabbing the list of entities, or null if the selector is invalid - */ - @Nullable - public static SelectorArguments parseSelector(@NotNull CommandSender sender, @NotNull String argument) { - if (!(sender instanceof BlockCommandSender || sender instanceof Player)) { - return null; - } - Matcher m = selectorPattern.matcher(argument); - if (!m.find()) { - return null; - } - SelectorType type = SelectorType.getType(m.group(1)); - if (type == null) { - return null; - } - SelectorArguments selector = new SelectorArguments(sender, type); - - if (m.group(3) != null) { - selector.parseArguments(m.group(3)); - } - - return selector; - } - - protected final CommandSender sender; - protected final SelectorType selector; - protected double rangeMin = 0, rangeMax = Double.POSITIVE_INFINITY; - protected EntityType entityType; - - public SelectorArguments(CommandSender sender, SelectorType type) { - this.sender = sender; - this.selector = type; - } - - private void parseArguments(String selectorArgs) { - String[] args = selectorArgs.split(","); - for (String s : args) { - if (s.contains("=")) { - String[] v = s.split("="); - if (v[0].equals("distance")) { - // 10 = d == 10 - // 10..12 = d > 10 && d <= 12 - // 5.. = d >= 5 - // ..5 = d <= 15 - Matcher distGroup = selectorRangePattern.matcher(v[1]); - if (distGroup.find()) { - if (distGroup.group(1) != null) { - rangeMin = Double.parseDouble(distGroup.group(1)); - } - if (distGroup.group(3) == null) { - rangeMax = rangeMin; - } else if (distGroup.group(4) != null) { - rangeMax = Double.parseDouble(distGroup.group(4)); - } - } - } else if (v[0].equals("type")) { - entityType = EntityNamespace.minecraftToBukkit(v[1]); - } - // more arguments can be parsed here (TODO) - } - } - /* - advancements Advancement earned by entity. - distance Distance to entity. - dx Entities between x and x + dx. - dy Entities between y and y + dy. - dz Entities between z and z + dz. - gamemode Players with gamemode. It can be one of the following values: adventure, creative, spectator, survival, !adventure, !creative, !spectator, !survival - level Experience level. It must be an integer value that is 0 or greater. - limit Maximum number of entities to target. It must be an integer value that is 1 or greater. - name Entity name. - nbt NBT tag. - scores Score. - sort Sort the entities. It must be one of the following values: arbitrary, furthest, nearest, random - tag Scoreboard tag. - team Entities on team. - type Entity type (target must be the specified entity type - https://www.digminecraft.com/lists/entity_list_pc.php ). - x Entity's x-coordinate position. - x_rotation Entity's x rotation (vertical rotation). - y Entity's y-coordinate position. - y_rotation Entity's y rotation (horizontal rotation). - z Entity's z-coordinate position. - target selector arguments are case-sensitive - @e[type=cow,limit=5] - */ - } - - public Collection getSelection() { - final Location location = sender instanceof Player ? ((Player) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); - Collection list = preSelect(location); - if (list.isEmpty()) { - return list; - } - List list2 = filter(location, list); - if (list2.isEmpty()) { - return list2; - } - switch (selector) { - case PLAYER: - Collections.sort(list2, (o1, o2) -> (int) (o1.getLocation().distanceSquared(location) - o2.getLocation().distanceSquared(location))); - return Arrays.asList(list2.get(0)); - case RANDOM_PLAYER: - Collections.shuffle(list2); - return Arrays.asList(list2.get(0)); - case ALL_PLAYER: - case ALL_ENTITIES: - case SELF: - return list2; - } - return list2; - } - - protected Collection preSelect(Location location) { - switch (selector) { - case PLAYER: - case RANDOM_PLAYER: - case ALL_PLAYER: - return rangeMax == Double.POSITIVE_INFINITY - ? location.getWorld().getEntitiesByClasses(Player.class) - : location.getWorld().getNearbyEntities(location, rangeMax * 2, rangeMax * 2, rangeMax * 2).stream() - .filter(e -> e instanceof Player).collect(Collectors.toSet()); - case ALL_ENTITIES: - return rangeMax == Double.POSITIVE_INFINITY - ? location.getWorld().getEntities() - : location.getWorld().getNearbyEntities(location, rangeMax * 2, rangeMax * 2, rangeMax * 2); - case SELF: - return sender instanceof Entity ? Arrays.asList((Entity) sender) : Collections.EMPTY_LIST; - } - return Collections.EMPTY_LIST; - } - - protected List filter(Location location, Collection list) { - Stream stream = list.stream() - .filter(p -> rangeMin == 0 || p.getLocation().distance(location) > rangeMin) - .filter(e -> entityType == null || e.getType() == entityType); - return stream.collect(Collectors.toList()); - } - - public static enum SelectorType { - - PLAYER, RANDOM_PLAYER, ALL_PLAYER, ALL_ENTITIES, SELF; - - public static SelectorType getType(String str) { - if (str != null) { - switch (str.toLowerCase()) { - case "@p": - return PLAYER; - case "@r": - return RANDOM_PLAYER; - case "@a": - return ALL_PLAYER; - case "@e": - return ALL_ENTITIES; - case "@s": - return SELF; - } - } - return null; - } - } -} +package com.songoda.core.commands; + +import com.songoda.core.compatibility.EntityNamespace; +import org.bukkit.Location; +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SelectorArguments { + + static Pattern selectorPattern = Pattern.compile("^(@[apers])(\\[(.*?)\\])?$"); + static Pattern selectorRangePattern = Pattern.compile("^([0-9]{1,9}(\\.[0-9]{1,9})?)?(\\.\\.)?([0-9]{1,9}(\\.[0-9]{1,9})?)?$"); + + /** + * Parse a command selector using Minecraft's selector format.
+ * Currently only supports distance and entity type + * + * @param sender CommandBlock or Player running the command + * @param argument argument with the selector to parse + * + * @return SelectorArguments Object for grabbing the list of entities, or null if the selector is invalid + */ + @Nullable + public static SelectorArguments parseSelector(@NotNull CommandSender sender, @NotNull String argument) { + if (!(sender instanceof BlockCommandSender || sender instanceof Player)) { + return null; + } + Matcher m = selectorPattern.matcher(argument); + if (!m.find()) { + return null; + } + SelectorType type = SelectorType.getType(m.group(1)); + if (type == null) { + return null; + } + SelectorArguments selector = new SelectorArguments(sender, type); + + if (m.group(3) != null) { + selector.parseArguments(m.group(3)); + } + + return selector; + } + + protected final CommandSender sender; + protected final SelectorType selector; + protected double rangeMin = 0, rangeMax = Double.POSITIVE_INFINITY; + protected EntityType entityType; + + public SelectorArguments(CommandSender sender, SelectorType type) { + this.sender = sender; + this.selector = type; + } + + private void parseArguments(String selectorArgs) { + String[] args = selectorArgs.split(","); + for (String s : args) { + if (s.contains("=")) { + String[] v = s.split("="); + if (v[0].equals("distance")) { + // 10 = d == 10 + // 10..12 = d > 10 && d <= 12 + // 5.. = d >= 5 + // ..5 = d <= 15 + Matcher distGroup = selectorRangePattern.matcher(v[1]); + if (distGroup.find()) { + if (distGroup.group(1) != null) { + rangeMin = Double.parseDouble(distGroup.group(1)); + } + if (distGroup.group(3) == null) { + rangeMax = rangeMin; + } else if (distGroup.group(4) != null) { + rangeMax = Double.parseDouble(distGroup.group(4)); + } + } + } else if (v[0].equals("type")) { + entityType = EntityNamespace.minecraftToBukkit(v[1]); + } + // more arguments can be parsed here (TODO) + } + } + /* + advancements Advancement earned by entity. + distance Distance to entity. + dx Entities between x and x + dx. + dy Entities between y and y + dy. + dz Entities between z and z + dz. + gamemode Players with gamemode. It can be one of the following values: adventure, creative, spectator, survival, !adventure, !creative, !spectator, !survival + level Experience level. It must be an integer value that is 0 or greater. + limit Maximum number of entities to target. It must be an integer value that is 1 or greater. + name Entity name. + nbt NBT tag. + scores Score. + sort Sort the entities. It must be one of the following values: arbitrary, furthest, nearest, random + tag Scoreboard tag. + team Entities on team. + type Entity type (target must be the specified entity type - https://www.digminecraft.com/lists/entity_list_pc.php ). + x Entity's x-coordinate position. + x_rotation Entity's x rotation (vertical rotation). + y Entity's y-coordinate position. + y_rotation Entity's y rotation (horizontal rotation). + z Entity's z-coordinate position. + target selector arguments are case-sensitive + @e[type=cow,limit=5] + */ + } + + public Collection getSelection() { + final Location location = sender instanceof Player ? ((Player) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); + Collection list = preSelect(location); + if (list.isEmpty()) { + return list; + } + List list2 = filter(location, list); + if (list2.isEmpty()) { + return list2; + } + switch (selector) { + case PLAYER: + Collections.sort(list2, (o1, o2) -> (int) (o1.getLocation().distanceSquared(location) - o2.getLocation().distanceSquared(location))); + return Arrays.asList(list2.get(0)); + case RANDOM_PLAYER: + Collections.shuffle(list2); + return Arrays.asList(list2.get(0)); + case ALL_PLAYER: + case ALL_ENTITIES: + case SELF: + return list2; + } + return list2; + } + + protected Collection preSelect(Location location) { + switch (selector) { + case PLAYER: + case RANDOM_PLAYER: + case ALL_PLAYER: + return rangeMax == Double.POSITIVE_INFINITY + ? location.getWorld().getEntitiesByClasses(Player.class) + : location.getWorld().getNearbyEntities(location, rangeMax * 2, rangeMax * 2, rangeMax * 2).stream() + .filter(e -> e instanceof Player).collect(Collectors.toSet()); + case ALL_ENTITIES: + return rangeMax == Double.POSITIVE_INFINITY + ? location.getWorld().getEntities() + : location.getWorld().getNearbyEntities(location, rangeMax * 2, rangeMax * 2, rangeMax * 2); + case SELF: + return sender instanceof Entity ? Arrays.asList((Entity) sender) : Collections.EMPTY_LIST; + } + return Collections.EMPTY_LIST; + } + + protected List filter(Location location, Collection list) { + Stream stream = list.stream() + .filter(p -> rangeMin == 0 || p.getLocation().distance(location) > rangeMin) + .filter(e -> entityType == null || e.getType() == entityType); + return stream.collect(Collectors.toList()); + } + + public static enum SelectorType { + + PLAYER, RANDOM_PLAYER, ALL_PLAYER, ALL_ENTITIES, SELF; + + public static SelectorType getType(String str) { + if (str != null) { + switch (str.toLowerCase()) { + case "@p": + return PLAYER; + case "@r": + return RANDOM_PLAYER; + case "@a": + return ALL_PLAYER; + case "@e": + return ALL_ENTITIES; + case "@s": + return SELF; + } + } + return null; + } + } +} diff --git a/Core/src/main/java/com/songoda/core/commands/SimpleNestedCommand.java b/Core/src/main/java/com/songoda/core/commands/SimpleNestedCommand.java index 2f4e51fe..ce1a4149 100644 --- a/Core/src/main/java/com/songoda/core/commands/SimpleNestedCommand.java +++ b/Core/src/main/java/com/songoda/core/commands/SimpleNestedCommand.java @@ -1,25 +1,24 @@ -package com.songoda.core.commands; - -import java.util.LinkedHashMap; -import java.util.stream.Stream; - -public class SimpleNestedCommand { - - final AbstractCommand parent; - final LinkedHashMap children = new LinkedHashMap<>(); - - protected SimpleNestedCommand(AbstractCommand parent) { - this.parent = parent; - } - - public SimpleNestedCommand addSubCommand(AbstractCommand command) { - command.getCommands().forEach(cmd -> children.put(cmd.toLowerCase(), command)); - return this; - } - - public SimpleNestedCommand addSubCommands(AbstractCommand... commands) { - Stream.of(commands).forEach(command -> command.getCommands().forEach(cmd -> children.put(cmd.toLowerCase(), command))); - return this; - } - -} +package com.songoda.core.commands; + +import java.util.LinkedHashMap; +import java.util.stream.Stream; + +public class SimpleNestedCommand { + + final AbstractCommand parent; + final LinkedHashMap children = new LinkedHashMap<>(); + + protected SimpleNestedCommand(AbstractCommand parent) { + this.parent = parent; + } + + public SimpleNestedCommand addSubCommand(AbstractCommand command) { + command.getCommands().forEach(cmd -> children.put(cmd.toLowerCase(), command)); + return this; + } + + public SimpleNestedCommand addSubCommands(AbstractCommand... commands) { + Stream.of(commands).forEach(command -> command.getCommands().forEach(cmd -> children.put(cmd.toLowerCase(), command))); + return this; + } +} diff --git a/Core/src/main/java/com/songoda/core/configuration/Config.java b/Core/src/main/java/com/songoda/core/configuration/Config.java index 74ea821b..9d51f6e6 100644 --- a/Core/src/main/java/com/songoda/core/configuration/Config.java +++ b/Core/src/main/java/com/songoda/core/configuration/Config.java @@ -1,725 +1,740 @@ -package com.songoda.core.configuration; - -import com.songoda.core.utils.TextUtils; -import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConstructor; -import org.bukkit.configuration.file.YamlRepresenter; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.error.YAMLException; -import org.yaml.snakeyaml.representer.Representer; - -import java.io.*; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -/** - * Configuration settings for a plugin - * - * @author jascotty2 - * @since 2019-08-28 - */ -public class Config extends ConfigSection { - - /* - Serialization notes: - // implements ConfigurationSerializable: - //public Map serialize(); - - // Class must contain one of: - // public static Object deserialize(@NotNull Map args); - // public static valueOf(Map args); - // public new (Map args) - */ - protected static final String BLANK_CONFIG = "{}\n"; - - protected File file; - protected final ConfigFileConfigurationAdapter config = new ConfigFileConfigurationAdapter(this); - protected Comment headerComment = null; - protected Comment footerComment = null; - final String dirName, fileName; - final Plugin plugin; - final DumperOptions yamlOptions = new DumperOptions(); - final Representer yamlRepresenter = new YamlRepresenter(); - final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); - Charset defaultCharset = StandardCharsets.UTF_8; - SaveTask saveTask; - Timer autosaveTimer; - ////////////// Config settings //////////////// - /** - * save file whenever a change is made - */ - boolean autosave = false; - /** - * time in seconds to start a save after a change is made - */ - int autosaveInterval = 60; - /** - * remove nodes not defined in defaults - */ - boolean autoremove = false; - /** - * load comments when loading the file - */ - boolean loadComments = true; - /** - * Default comment applied to config nodes - */ - ConfigFormattingRules.CommentStyle defaultNodeCommentFormat = ConfigFormattingRules.CommentStyle.SIMPLE; - /** - * Default comment applied to section nodes - */ - ConfigFormattingRules.CommentStyle defaultSectionCommentFormat = ConfigFormattingRules.CommentStyle.SPACED; - /** - * Extra lines to put between root nodes - */ - int rootNodeSpacing = 1; - /** - * Extra lines to put in front of comments.
- * This is separate from rootNodeSpacing, if applicable. - */ - int commentSpacing = 1; - - public Config() { - this.plugin = null; - this.file = null; - dirName = null; - fileName = null; - } - - public Config(@NotNull File file) { - this.plugin = null; - this.file = file.getAbsoluteFile(); - dirName = null; - fileName = null; - } - - public Config(@NotNull Plugin plugin) { - this.plugin = plugin; - dirName = null; - fileName = null; - } - - public Config(@NotNull Plugin plugin, @NotNull String file) { - this.plugin = plugin; - dirName = null; - fileName = file; - } - - public Config(@NotNull Plugin plugin, @Nullable String directory, @NotNull String file) { - this.plugin = plugin; - dirName = directory; - fileName = file; - } - - @NotNull - public ConfigFileConfigurationAdapter getFileConfig() { - return config; - } - - @NotNull - public File getFile() { - if (file == null) { - if (dirName != null) { - this.file = new File(plugin.getDataFolder() + dirName, fileName != null ? fileName : "config.yml"); - } else { - this.file = new File(plugin.getDataFolder(), fileName != null ? fileName : "config.yml"); - } - } - return file; - } - - public Charset getDefaultCharset() { - return defaultCharset; - } - - /** - * Set the Charset that will be used to save this config - * - * @param defaultCharset Charset to use - * @return this class - */ - public Config setDefaultCharset(Charset defaultCharset) { - this.defaultCharset = defaultCharset; - return this; - } - - /** - * Set the default charset to use UTF-16 - * - * @return this class - */ - public Config setUseUTF16() { - this.defaultCharset = StandardCharsets.UTF_16; - return this; - } - - public boolean getLoadComments() { - return loadComments; - } - - /** - * Should comments from the config file be loaded when loading? - * - * @param loadComments set to false if you do not want to preserve node comments - */ - public void setLoadComments(boolean loadComments) { - this.loadComments = loadComments; - } - - public boolean getAutosave() { - return autosave; - } - - /** - * Should the configuration automatically save whenever it's been changed?
- * All saves are done asynchronously, so this should not impact server performance. - * - * @param autosave set to true if autosaving is enabled. - * @return this class - */ - @NotNull - public Config setAutosave(boolean autosave) { - this.autosave = autosave; - return this; - } - - public int getAutosaveInterval() { - return autosaveInterval; - } - - /** - * If autosave is enabled, this is the delay between a change and when the save is started.
- * If the configuration is changed within this period, the timer is not reset. - * - * @param autosaveInterval time in seconds - * @return this class - */ - @NotNull - public Config setAutosaveInterval(int autosaveInterval) { - this.autosaveInterval = autosaveInterval; - return this; - } - - public boolean getAutoremove() { - return autoremove; - } - - /** - * This setting is used to prevent users to from adding extraneous settings - * to the config and to remove deprecated settings.
- * If this is enabled, the config will delete any nodes that are not defined - * as a default setting. - * - * @param autoremove Remove settings that don't exist as defaults - * @return this class - */ - @NotNull - public Config setAutoremove(boolean autoremove) { - this.autoremove = autoremove; - return this; - } - - /** - * Default comment applied to config nodes - */ - @Nullable - public ConfigFormattingRules.CommentStyle getDefaultNodeCommentFormat() { - return defaultNodeCommentFormat; - } - - /** - * Default comment applied to config nodes - * - * @return this config - */ - @NotNull - public Config setDefaultNodeCommentFormat(@Nullable ConfigFormattingRules.CommentStyle defaultNodeCommentFormat) { - this.defaultNodeCommentFormat = defaultNodeCommentFormat; - return this; - } - - /** - * Default comment applied to section nodes - */ - @Nullable - public ConfigFormattingRules.CommentStyle getDefaultSectionCommentFormat() { - return defaultSectionCommentFormat; - } - - /** - * Default comment applied to section nodes - * - * @return this config - */ - @NotNull - public Config setDefaultSectionCommentFormat(@Nullable ConfigFormattingRules.CommentStyle defaultSectionCommentFormat) { - this.defaultSectionCommentFormat = defaultSectionCommentFormat; - return this; - } - - /** - * Extra lines to put between root nodes - */ - public int getRootNodeSpacing() { - return rootNodeSpacing; - } - - /** - * Extra lines to put between root nodes - * - * @return this config - */ - @NotNull - public Config setRootNodeSpacing(int rootNodeSpacing) { - this.rootNodeSpacing = rootNodeSpacing; - return this; - } - - /** - * Extra lines to put in front of comments.
- * This is separate from rootNodeSpacing, if applicable. - */ - public int getCommentSpacing() { - return commentSpacing; - } - - /** - * Extra lines to put in front of comments.
- * This is separate from rootNodeSpacing, if applicable. - * - * @return this config - */ - @NotNull - public Config setCommentSpacing(int commentSpacing) { - this.commentSpacing = commentSpacing; - return this; - } - - @NotNull - public Config setHeader(@NotNull String... description) { - if (description.length == 0) { - headerComment = null; - } else { - headerComment = new Comment(description); - } - return this; - } - - @NotNull - public Config setHeader(@Nullable ConfigFormattingRules.CommentStyle commentStyle, @NotNull String... description) { - if (description.length == 0) { - headerComment = null; - } else { - headerComment = new Comment(commentStyle, description); - } - return this; - } - - @NotNull - public Config setHeader(@Nullable List description) { - if (description == null || description.isEmpty()) { - headerComment = null; - } else { - headerComment = new Comment(description); - } - return this; - } - - @NotNull - public Config setHeader(@Nullable ConfigFormattingRules.CommentStyle commentStyle, @Nullable List description) { - if (description == null || description.isEmpty()) { - headerComment = null; - } else { - headerComment = new Comment(commentStyle, description); - } - return this; - } - - @NotNull - public List getHeader() { - if (headerComment != null) { - return headerComment.getLines(); - } else { - return Collections.EMPTY_LIST; - } - } - - public Config clearConfig(boolean clearDefaults) { - root.values.clear(); - root.configComments.clear(); - if (clearDefaults) { - root.defaultComments.clear(); - root.defaults.clear(); - } - return this; - } - - public Config clearDefaults() { - root.defaultComments.clear(); - root.defaults.clear(); - return this; - } - - public boolean load() { - return load(getFile()); - } - - public boolean load(@NotNull File file) { - Validate.notNull(file, "File cannot be null"); - if (file.exists()) { - try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) { - Charset charset = TextUtils.detectCharset(stream, StandardCharsets.UTF_8); - // upgrade charset if file was saved in a more complex format - if (charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) { - defaultCharset = StandardCharsets.UTF_16; - } - this.load(new InputStreamReader(stream, charset)); - return true; - } catch (IOException | InvalidConfigurationException ex) { - (plugin != null ? plugin.getLogger() : Bukkit.getLogger()).log(Level.SEVERE, "Failed to load config file: " + file.getName(), ex); - } - return false; - } - return true; - } - - public void load(@NotNull Reader reader) throws IOException, InvalidConfigurationException { - StringBuilder builder = new StringBuilder(); - - try (BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader)) { - String line; - boolean firstLine = true; - while ((line = input.readLine()) != null) { - if (firstLine) { - line = line.replaceAll("[\uFEFF\uFFFE\u200B]", ""); // clear BOM markers - firstLine = false; - } - builder.append(line).append('\n'); - } - } - this.loadFromString(builder.toString()); - } - - public void loadFromString(@NotNull String contents) throws InvalidConfigurationException { - Map input; - try { - input = (Map) this.yaml.load(contents); - } catch (YAMLException e2) { - throw new InvalidConfigurationException(e2); - } catch (ClassCastException e3) { - throw new InvalidConfigurationException("Top level is not a Map."); - } - if (input != null) { - if (loadComments) { - this.parseComments(contents, input); - } - this.convertMapsToSections(input, this); - } - } - - protected void convertMapsToSections(@NotNull Map input, @NotNull ConfigSection section) { - // TODO: make this non-recursive - for (Map.Entry entry : input.entrySet()) { - String key = entry.getKey().toString(); - Object value = entry.getValue(); - if (value instanceof Map) { - this.convertMapsToSections((Map) value, section.createSection(key)); - continue; - } - section.set(key, value); - } - } - - protected void parseComments(@NotNull String contents, @NotNull Map input) { - // if starts with a comment, load all nonbreaking comments as a header - // then load all comments and assign to the next valid node loaded - // (Only load comments that are on their own line) - - BufferedReader in = new BufferedReader(new StringReader(contents)); - String line; - boolean insideScalar = false; - boolean firstNode = true; - int index = 0; - LinkedList currentPath = new LinkedList(); - ArrayList commentBlock = new ArrayList(); - try { - while ((line = in.readLine()) != null) { - if (line.isEmpty()) { - if (firstNode && !commentBlock.isEmpty()) { - // header comment - firstNode = false; - headerComment = Comment.loadComment(commentBlock); - commentBlock.clear(); - } - continue; - } else if (line.trim().startsWith("#")) { - // only load full-line comments - commentBlock.add(line.trim()); - continue; - } - - // check to see if this is a line that we can process - int lineOffset = getOffset(line); - insideScalar &= lineOffset <= index; - Matcher m; - if (!insideScalar && (m = yamlNode.matcher(line)).find()) { - // we found a config node! ^.^ - // check to see what the full path is - int depth = (m.group(1).length() / indentation); - while (depth < currentPath.size()) { - currentPath.removeLast(); - } - currentPath.add(m.group(2)); - - // do we have a comment for this node? - if (!commentBlock.isEmpty()) { - String path = currentPath.stream().collect(Collectors.joining(String.valueOf(pathChar))); - Comment comment = Comment.loadComment(commentBlock); - commentBlock.clear(); - setComment(path, comment); - } - - firstNode = false; // we're no longer on the first node - - // ignore scalars - index = lineOffset; - if (m.group(3).trim().equals("|") || m.group(3).trim().equals(">")) { - insideScalar = true; - } - } - } - if (!commentBlock.isEmpty()) { - footerComment = Comment.loadComment(commentBlock); - commentBlock.clear(); - } - } catch (IOException ex) { - } - - } - - public void deleteNonDefaultSettings() { - // Delete old config values (thread-safe) - List defaultKeys = Arrays.asList(defaults.keySet().toArray(new String[0])); - for (String key : values.keySet().toArray(new String[0])) { - if (!defaultKeys.contains(key)) { - values.remove(key); - } - } - } - - @Override - protected void onChange() { - if (autosave) { - delaySave(); - } - } - - public void delaySave() { - // save async even if no plugin or if plugin disabled - if (saveTask == null && (changed || hasNewDefaults())) { - autosaveTimer = new Timer((plugin != null ? plugin.getName() + "-ConfigSave-" : "ConfigSave-") + getFile().getName()); - autosaveTimer.schedule(saveTask = new SaveTask(), autosaveInterval * 1000L); - } - } - - public boolean saveChanges() { - boolean saved = true; - if (changed || hasNewDefaults()) { - saved = save(); - } - if (saveTask != null) { - //Close Threads - saveTask.cancel(); - autosaveTimer.cancel(); - saveTask = null; - autosaveTimer = null; - } - return saved; - } - - boolean hasNewDefaults() { - if (file != null && !file.exists()) return true; - for (String def : defaults.keySet()) { - if (!values.containsKey(def)) return true; - } - return false; - } - - public boolean save() { - if (saveTask != null) { - //Close Threads - saveTask.cancel(); - autosaveTimer.cancel(); - saveTask = null; - autosaveTimer = null; - } - return save(getFile()); - } - - public boolean save(@NotNull String file) { - Validate.notNull(file, "File cannot be null"); - return this.save(new File(file)); - } - - public boolean save(@NotNull File file) { - Validate.notNull(file, "File cannot be null"); - if (file.getParentFile() != null && !file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - String data = this.saveToString(); - try (OutputStreamWriter writer = new OutputStreamWriter((OutputStream) new FileOutputStream(file), defaultCharset);) { - writer.write(data); - } catch (IOException e) { - return false; - } - return true; - } - - @NotNull - public String saveToString() { - try { - if (autoremove) { - deleteNonDefaultSettings(); - } - yamlOptions.setIndent(indentation); - yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - yamlOptions.setSplitLines(false); - yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - StringWriter str = new StringWriter(); - if (headerComment != null) { - headerComment.writeComment(str, 0, ConfigFormattingRules.CommentStyle.BLOCKED); - str.write("\n"); // add one space after the header - } - String dump = yaml.dump(this.getValues(false)); - if (!dump.equals(BLANK_CONFIG)) { - writeComments(dump, str); - } - if (footerComment != null) { - str.write("\n"); - footerComment.writeComment(str, 0, ConfigFormattingRules.CommentStyle.BLOCKED); - } - return str.toString(); - } catch (Throwable ex) { - Logger.getLogger(Config.class.getName()).log(Level.SEVERE, "Error saving config", ex); - delaySave(); - } - return ""; - } - - protected final Pattern yamlNode = Pattern.compile("^( *)([^:\\{\\}\\[\\],&\\*#\\?\\|\\-<>=!%@`]+):(.*)$"); - - protected void writeComments(String data, Writer out) throws IOException { - // line-by-line apply line spacing formatting and comments per-node - BufferedReader in = new BufferedReader(new StringReader(data)); - String line; - boolean insideScalar = false; - boolean firstNode = true; - int index = 0; - LinkedList currentPath = new LinkedList(); - while ((line = in.readLine()) != null) { - // ignore comments and empty lines (there shouldn't be any, but just in case) - if (line.trim().startsWith("#") || line.isEmpty()) { - continue; - } - - // check to see if this is a line that we can process - int lineOffset = getOffset(line); - insideScalar &= lineOffset <= index; - Matcher m; - if (!insideScalar && (m = yamlNode.matcher(line)).find()) { - // we found a config node! ^.^ - // check to see what the full path is - int depth = (m.group(1).length() / indentation); - while (depth < currentPath.size()) { - currentPath.removeLast(); - } - currentPath.add(m.group(2)); - String path = currentPath.stream().collect(Collectors.joining(String.valueOf(pathChar))); - - // if this is a root-level node, apply extra spacing if we aren't the first node - if (!firstNode && depth == 0 && rootNodeSpacing > 0) { - out.write((new String(new char[rootNodeSpacing])).replace("\0", "\n")); // yes it's silly, but it works :> - } - firstNode = false; // we're no longer on the first node - - // insert the relavant comment - Comment comment = getComment(path); - if (comment != null) { - // add spacing between previous nodes and comments - if (depth != 0) { - out.write((new String(new char[commentSpacing])).replace("\0", "\n")); - } - - // formatting style for this node - ConfigFormattingRules.CommentStyle style = comment.getCommentStyle(); - if (style == null) { - // check to see what type of node this is - if (!m.group(3).trim().isEmpty()) { - // setting node - style = defaultNodeCommentFormat; - } else { - // probably a section? (need to peek ahead to check if this is a list) - in.mark(1000); - String nextLine = in.readLine().trim(); - in.reset(); - if (nextLine.startsWith("-")) { - // not a section :P - style = defaultNodeCommentFormat; - } else { - style = defaultSectionCommentFormat; - } - } - } - - // write it down! - comment.writeComment(out, lineOffset, style); - } - // ignore scalars - index = lineOffset; - if (m.group(3).trim().equals("|") || m.group(3).trim().equals(">")) { - insideScalar = true; - } - } - - out.write(line); - out.write("\n"); - } - } - - protected static int getOffset(String s) { - char[] chars = s.toCharArray(); - for (int i = 0; i < chars.length; ++i) { - if (chars[i] != ' ') { - return i; - } - } - return -1; - } - - class SaveTask extends TimerTask { - - @Override - public void run() { - saveChanges(); - } - } -} +package com.songoda.core.configuration; + +import com.songoda.core.utils.TextUtils; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConstructor; +import org.bukkit.configuration.file.YamlRepresenter; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.error.YAMLException; +import org.yaml.snakeyaml.representer.Representer; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * Configuration settings for a plugin + * + * @author jascotty2 + * @since 2019-08-28 + */ +public class Config extends ConfigSection { + + /* + Serialization notes: + // implements ConfigurationSerializable: + //public Map serialize(); + + // Class must contain one of: + // public static Object deserialize(@NotNull Map args); + // public static valueOf(Map args); + // public new (Map args) + */ + protected static final String BLANK_CONFIG = "{}\n"; + + protected File file; + protected final ConfigFileConfigurationAdapter config = new ConfigFileConfigurationAdapter(this); + protected Comment headerComment = null; + protected Comment footerComment = null; + final String dirName, fileName; + final Plugin plugin; + final DumperOptions yamlOptions = new DumperOptions(); + final Representer yamlRepresenter = new YamlRepresenter(); + final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); + Charset defaultCharset = StandardCharsets.UTF_8; + SaveTask saveTask; + Timer autosaveTimer; + ////////////// Config settings //////////////// + /** + * save file whenever a change is made + */ + boolean autosave = false; + /** + * time in seconds to start a save after a change is made + */ + int autosaveInterval = 60; + /** + * remove nodes not defined in defaults + */ + boolean autoremove = false; + /** + * load comments when loading the file + */ + boolean loadComments = true; + /** + * Default comment applied to config nodes + */ + ConfigFormattingRules.CommentStyle defaultNodeCommentFormat = ConfigFormattingRules.CommentStyle.SIMPLE; + /** + * Default comment applied to section nodes + */ + ConfigFormattingRules.CommentStyle defaultSectionCommentFormat = ConfigFormattingRules.CommentStyle.SPACED; + /** + * Extra lines to put between root nodes + */ + int rootNodeSpacing = 1; + /** + * Extra lines to put in front of comments.
+ * This is separate from rootNodeSpacing, if applicable. + */ + int commentSpacing = 1; + + public Config() { + this.plugin = null; + this.file = null; + dirName = null; + fileName = null; + } + + public Config(@NotNull File file) { + this.plugin = null; + this.file = file.getAbsoluteFile(); + dirName = null; + fileName = null; + } + + public Config(@NotNull Plugin plugin) { + this.plugin = plugin; + dirName = null; + fileName = null; + } + + public Config(@NotNull Plugin plugin, @NotNull String file) { + this.plugin = plugin; + dirName = null; + fileName = file; + } + + public Config(@NotNull Plugin plugin, @Nullable String directory, @NotNull String file) { + this.plugin = plugin; + dirName = directory; + fileName = file; + } + + @NotNull + public ConfigFileConfigurationAdapter getFileConfig() { + return config; + } + + @NotNull + public File getFile() { + if (file == null) { + if (dirName != null) { + this.file = new File(plugin.getDataFolder() + dirName, fileName != null ? fileName : "config.yml"); + } else { + this.file = new File(plugin.getDataFolder(), fileName != null ? fileName : "config.yml"); + } + } + return file; + } + + public Charset getDefaultCharset() { + return defaultCharset; + } + + /** + * Set the Charset that will be used to save this config + * + * @param defaultCharset Charset to use + * + * @return this class + */ + public Config setDefaultCharset(Charset defaultCharset) { + this.defaultCharset = defaultCharset; + return this; + } + + /** + * Set the default charset to use UTF-16 + * + * @return this class + */ + public Config setUseUTF16() { + this.defaultCharset = StandardCharsets.UTF_16; + return this; + } + + public boolean getLoadComments() { + return loadComments; + } + + /** + * Should comments from the config file be loaded when loading? + * + * @param loadComments set to false if you do not want to preserve node comments + */ + public void setLoadComments(boolean loadComments) { + this.loadComments = loadComments; + } + + public boolean getAutosave() { + return autosave; + } + + /** + * Should the configuration automatically save whenever it's been changed?
+ * All saves are done asynchronously, so this should not impact server performance. + * + * @param autosave set to true if autosaving is enabled. + * + * @return this class + */ + @NotNull + public Config setAutosave(boolean autosave) { + this.autosave = autosave; + return this; + } + + public int getAutosaveInterval() { + return autosaveInterval; + } + + /** + * If autosave is enabled, this is the delay between a change and when the save is started.
+ * If the configuration is changed within this period, the timer is not reset. + * + * @param autosaveInterval time in seconds + * + * @return this class + */ + @NotNull + public Config setAutosaveInterval(int autosaveInterval) { + this.autosaveInterval = autosaveInterval; + return this; + } + + public boolean getAutoremove() { + return autoremove; + } + + /** + * This setting is used to prevent users to from adding extraneous settings + * to the config and to remove deprecated settings.
+ * If this is enabled, the config will delete any nodes that are not defined + * as a default setting. + * + * @param autoremove Remove settings that don't exist as defaults + * + * @return this class + */ + @NotNull + public Config setAutoremove(boolean autoremove) { + this.autoremove = autoremove; + return this; + } + + /** + * Default comment applied to config nodes + */ + @Nullable + public ConfigFormattingRules.CommentStyle getDefaultNodeCommentFormat() { + return defaultNodeCommentFormat; + } + + /** + * Default comment applied to config nodes + * + * @return this config + */ + @NotNull + public Config setDefaultNodeCommentFormat(@Nullable ConfigFormattingRules.CommentStyle defaultNodeCommentFormat) { + this.defaultNodeCommentFormat = defaultNodeCommentFormat; + return this; + } + + /** + * Default comment applied to section nodes + */ + @Nullable + public ConfigFormattingRules.CommentStyle getDefaultSectionCommentFormat() { + return defaultSectionCommentFormat; + } + + /** + * Default comment applied to section nodes + * + * @return this config + */ + @NotNull + public Config setDefaultSectionCommentFormat(@Nullable ConfigFormattingRules.CommentStyle defaultSectionCommentFormat) { + this.defaultSectionCommentFormat = defaultSectionCommentFormat; + return this; + } + + /** + * Extra lines to put between root nodes + */ + public int getRootNodeSpacing() { + return rootNodeSpacing; + } + + /** + * Extra lines to put between root nodes + * + * @return this config + */ + @NotNull + public Config setRootNodeSpacing(int rootNodeSpacing) { + this.rootNodeSpacing = rootNodeSpacing; + return this; + } + + /** + * Extra lines to put in front of comments.
+ * This is separate from rootNodeSpacing, if applicable. + */ + public int getCommentSpacing() { + return commentSpacing; + } + + /** + * Extra lines to put in front of comments.
+ * This is separate from rootNodeSpacing, if applicable. + * + * @return this config + */ + @NotNull + public Config setCommentSpacing(int commentSpacing) { + this.commentSpacing = commentSpacing; + return this; + } + + @NotNull + public Config setHeader(@NotNull String... description) { + if (description.length == 0) { + headerComment = null; + } else { + headerComment = new Comment(description); + } + return this; + } + + @NotNull + public Config setHeader(@Nullable ConfigFormattingRules.CommentStyle commentStyle, @NotNull String... description) { + if (description.length == 0) { + headerComment = null; + } else { + headerComment = new Comment(commentStyle, description); + } + return this; + } + + @NotNull + public Config setHeader(@Nullable List description) { + if (description == null || description.isEmpty()) { + headerComment = null; + } else { + headerComment = new Comment(description); + } + return this; + } + + @NotNull + public Config setHeader(@Nullable ConfigFormattingRules.CommentStyle commentStyle, @Nullable List description) { + if (description == null || description.isEmpty()) { + headerComment = null; + } else { + headerComment = new Comment(commentStyle, description); + } + return this; + } + + @NotNull + public List getHeader() { + if (headerComment != null) { + return headerComment.getLines(); + } else { + return Collections.EMPTY_LIST; + } + } + + public Config clearConfig(boolean clearDefaults) { + root.values.clear(); + root.configComments.clear(); + if (clearDefaults) { + root.defaultComments.clear(); + root.defaults.clear(); + } + return this; + } + + public Config clearDefaults() { + root.defaultComments.clear(); + root.defaults.clear(); + return this; + } + + public boolean load() { + return load(getFile()); + } + + public boolean load(@NotNull File file) { + Validate.notNull(file, "File cannot be null"); + if (file.exists()) { + try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) { + Charset charset = TextUtils.detectCharset(stream, StandardCharsets.UTF_8); + // upgrade charset if file was saved in a more complex format + if (charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) { + defaultCharset = StandardCharsets.UTF_16; + } + this.load(new InputStreamReader(stream, charset)); + return true; + } catch (IOException | InvalidConfigurationException ex) { + (plugin != null ? plugin.getLogger() : Bukkit.getLogger()).log(Level.SEVERE, "Failed to load config file: " + file.getName(), ex); + } + return false; + } + return true; + } + + public void load(@NotNull Reader reader) throws IOException, InvalidConfigurationException { + StringBuilder builder = new StringBuilder(); + + try (BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader)) { + String line; + boolean firstLine = true; + while ((line = input.readLine()) != null) { + if (firstLine) { + line = line.replaceAll("[\uFEFF\uFFFE\u200B]", ""); // clear BOM markers + firstLine = false; + } + builder.append(line).append('\n'); + } + } + this.loadFromString(builder.toString()); + } + + public void loadFromString(@NotNull String contents) throws InvalidConfigurationException { + Map input; + try { + input = (Map) this.yaml.load(contents); + } catch (YAMLException e2) { + throw new InvalidConfigurationException(e2); + } catch (ClassCastException e3) { + throw new InvalidConfigurationException("Top level is not a Map."); + } + if (input != null) { + if (loadComments) { + this.parseComments(contents, input); + } + this.convertMapsToSections(input, this); + } + } + + protected void convertMapsToSections(@NotNull Map input, @NotNull ConfigSection section) { + // TODO: make this non-recursive + for (Map.Entry entry : input.entrySet()) { + String key = entry.getKey().toString(); + Object value = entry.getValue(); + if (value instanceof Map) { + this.convertMapsToSections((Map) value, section.createSection(key)); + continue; + } + section.set(key, value); + } + } + + protected void parseComments(@NotNull String contents, @NotNull Map input) { + // if starts with a comment, load all nonbreaking comments as a header + // then load all comments and assign to the next valid node loaded + // (Only load comments that are on their own line) + + BufferedReader in = new BufferedReader(new StringReader(contents)); + String line; + boolean insideScalar = false; + boolean firstNode = true; + int index = 0; + LinkedList currentPath = new LinkedList(); + ArrayList commentBlock = new ArrayList(); + try { + while ((line = in.readLine()) != null) { + if (line.isEmpty()) { + if (firstNode && !commentBlock.isEmpty()) { + // header comment + firstNode = false; + headerComment = Comment.loadComment(commentBlock); + commentBlock.clear(); + } + continue; + } else if (line.trim().startsWith("#")) { + // only load full-line comments + commentBlock.add(line.trim()); + continue; + } + + // check to see if this is a line that we can process + int lineOffset = getOffset(line); + insideScalar &= lineOffset <= index; + Matcher m; + if (!insideScalar && (m = yamlNode.matcher(line)).find()) { + // we found a config node! ^.^ + // check to see what the full path is + int depth = (m.group(1).length() / indentation); + while (depth < currentPath.size()) { + currentPath.removeLast(); + } + currentPath.add(m.group(2)); + + // do we have a comment for this node? + if (!commentBlock.isEmpty()) { + String path = currentPath.stream().collect(Collectors.joining(String.valueOf(pathChar))); + Comment comment = Comment.loadComment(commentBlock); + commentBlock.clear(); + setComment(path, comment); + } + + firstNode = false; // we're no longer on the first node + + // ignore scalars + index = lineOffset; + if (m.group(3).trim().equals("|") || m.group(3).trim().equals(">")) { + insideScalar = true; + } + } + } + if (!commentBlock.isEmpty()) { + footerComment = Comment.loadComment(commentBlock); + commentBlock.clear(); + } + } catch (IOException ex) { + } + } + + public void deleteNonDefaultSettings() { + // Delete old config values (thread-safe) + List defaultKeys = Arrays.asList(defaults.keySet().toArray(new String[0])); + for (String key : values.keySet().toArray(new String[0])) { + if (!defaultKeys.contains(key)) { + values.remove(key); + } + } + } + + @Override + protected void onChange() { + if (autosave) { + delaySave(); + } + } + + public void delaySave() { + // save async even if no plugin or if plugin disabled + if (saveTask == null && (changed || hasNewDefaults())) { + autosaveTimer = new Timer((plugin != null ? plugin.getName() + "-ConfigSave-" : "ConfigSave-") + getFile().getName()); + autosaveTimer.schedule(saveTask = new SaveTask(), autosaveInterval * 1000L); + } + } + + public boolean saveChanges() { + boolean saved = true; + if (changed || hasNewDefaults()) { + saved = save(); + } + if (saveTask != null) { + //Close Threads + saveTask.cancel(); + autosaveTimer.cancel(); + saveTask = null; + autosaveTimer = null; + } + return saved; + } + + boolean hasNewDefaults() { + if (file != null && !file.exists()) return true; + for (String def : defaults.keySet()) { + if (!values.containsKey(def)) return true; + } + return false; + } + + public boolean save() { + if (saveTask != null) { + //Close Threads + saveTask.cancel(); + autosaveTimer.cancel(); + saveTask = null; + autosaveTimer = null; + } + return save(getFile()); + } + + public boolean save(@NotNull String file) { + Validate.notNull(file, "File cannot be null"); + return this.save(new File(file)); + } + + public boolean save(@NotNull File file) { + Validate.notNull(file, "File cannot be null"); + if (file.getParentFile() != null && !file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + String data = this.saveToString(); + try (OutputStreamWriter writer = new OutputStreamWriter((OutputStream) new FileOutputStream(file), defaultCharset);) { + writer.write(data); + } catch (IOException e) { + return false; + } + return true; + } + + @NotNull + public String saveToString() { + try { + if (autoremove) { + deleteNonDefaultSettings(); + } + yamlOptions.setIndent(indentation); + yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + yamlOptions.setSplitLines(false); + yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + StringWriter str = new StringWriter(); + if (headerComment != null) { + headerComment.writeComment(str, 0, ConfigFormattingRules.CommentStyle.BLOCKED); + str.write("\n"); // add one space after the header + } + String dump = yaml.dump(this.getValues(false)); + if (!dump.equals(BLANK_CONFIG)) { + writeComments(dump, str); + } + if (footerComment != null) { + str.write("\n"); + footerComment.writeComment(str, 0, ConfigFormattingRules.CommentStyle.BLOCKED); + } + return str.toString(); + } catch (Throwable ex) { + Logger.getLogger(Config.class.getName()).log(Level.SEVERE, "Error saving config", ex); + delaySave(); + } + return ""; + } + + protected final Pattern yamlNode = Pattern.compile("^( *)([^:\\{\\}\\[\\],&\\*#\\?\\|\\-<>=!%@`]+):(.*)$"); + + protected void writeComments(String data, Writer out) throws IOException { + // line-by-line apply line spacing formatting and comments per-node + BufferedReader in = new BufferedReader(new StringReader(data)); + String line; + boolean insideScalar = false; + boolean firstNode = true; + int index = 0; + LinkedList currentPath = new LinkedList(); + while ((line = in.readLine()) != null) { + // ignore comments and empty lines (there shouldn't be any, but just in case) + if (line.trim().startsWith("#") || line.isEmpty()) { + continue; + } + + // check to see if this is a line that we can process + int lineOffset = getOffset(line); + insideScalar &= lineOffset <= index; + Matcher m; + if (!insideScalar && (m = yamlNode.matcher(line)).find()) { + // we found a config node! ^.^ + // check to see what the full path is + int depth = (m.group(1).length() / indentation); + while (depth < currentPath.size()) { + currentPath.removeLast(); + } + currentPath.add(m.group(2)); + String path = currentPath.stream().collect(Collectors.joining(String.valueOf(pathChar))); + + // if this is a root-level node, apply extra spacing if we aren't the first node + if (!firstNode && depth == 0 && rootNodeSpacing > 0) { + out.write((new String(new char[rootNodeSpacing])).replace("\0", "\n")); // yes it's silly, but it works :> + } + firstNode = false; // we're no longer on the first node + + // insert the relavant comment + Comment comment = getComment(path); + if (comment != null) { + // add spacing between previous nodes and comments + if (depth != 0) { + out.write((new String(new char[commentSpacing])).replace("\0", "\n")); + } + + // formatting style for this node + ConfigFormattingRules.CommentStyle style = comment.getCommentStyle(); + if (style == null) { + // check to see what type of node this is + if (!m.group(3).trim().isEmpty()) { + // setting node + style = defaultNodeCommentFormat; + } else { + // probably a section? (need to peek ahead to check if this is a list) + in.mark(1000); + String nextLine = in.readLine().trim(); + in.reset(); + if (nextLine.startsWith("-")) { + // not a section :P + style = defaultNodeCommentFormat; + } else { + style = defaultSectionCommentFormat; + } + } + } + + // write it down! + comment.writeComment(out, lineOffset, style); + } + // ignore scalars + index = lineOffset; + if (m.group(3).trim().equals("|") || m.group(3).trim().equals(">")) { + insideScalar = true; + } + } + + out.write(line); + out.write("\n"); + } + } + + protected static int getOffset(String s) { + char[] chars = s.toCharArray(); + for (int i = 0; i < chars.length; ++i) { + if (chars[i] != ' ') { + return i; + } + } + return -1; + } + + class SaveTask extends TimerTask { + + @Override + public void run() { + saveChanges(); + } + } +} diff --git a/Core/src/main/java/com/songoda/core/configuration/ConfigFormattingRules.java b/Core/src/main/java/com/songoda/core/configuration/ConfigFormattingRules.java index 33335467..7a16791b 100644 --- a/Core/src/main/java/com/songoda/core/configuration/ConfigFormattingRules.java +++ b/Core/src/main/java/com/songoda/core/configuration/ConfigFormattingRules.java @@ -1,94 +1,93 @@ -package com.songoda.core.configuration; - -import java.util.List; - -public class ConfigFormattingRules { - - int spacesBetweenMainCategories; - int spacesBetweenValues; - CommentStyle rootCommentStyle = CommentStyle.BLOCKSPACED; - CommentStyle mainCategoryCommentStyle = CommentStyle.SPACED; - - public static enum CommentStyle { - - /** - * # Comment - */ - SIMPLE(false, false, " ", ""), - /** - * #
- * # Comment
- * #
- */ - SPACED(false, true, " ", ""), - /** - * ###########
- * # Comment #
- * ###########
- */ - BLOCKED(true, false, " ", " "), - /** - * #############
- * #|¯¯¯¯¯¯¯¯¯|#
- * #| Comment |#
- * #|_________|#
- * #############
- */ - BLOCKSPACED(true, true, "|\u00AF", '\u00AF', "\u00AF|", "| ", " |", "|_", '_', "_|"); - - final boolean drawBorder, drawSpace; - final String commentPrefix, spacePrefixTop, spacePrefixBottom; - final String commentSuffix, spaceSuffixTop, spaceSuffixBottom; - final char spaceCharTop, spaceCharBottom; - - private CommentStyle(boolean drawBorder, boolean drawSpace, - String spacePrefixTop, char spaceCharTop, String spaceSuffixTop, - String commentPrefix, String commentSuffix, - String spacePrefixBottom, char spaceCharBottom, String spaceSuffixBottom) { - this.drawBorder = drawBorder; - this.drawSpace = drawSpace; - this.commentPrefix = commentPrefix; - this.spacePrefixTop = spacePrefixTop; - this.spacePrefixBottom = spacePrefixBottom; - this.commentSuffix = commentSuffix; - this.spaceSuffixTop = spaceSuffixTop; - this.spaceSuffixBottom = spaceSuffixBottom; - this.spaceCharTop = spaceCharTop; - this.spaceCharBottom = spaceCharBottom; - } - - private CommentStyle(boolean drawBorder, boolean drawSpace, String commentPrefix, String commentSuffix) { - this.drawBorder = drawBorder; - this.drawSpace = drawSpace; - this.commentPrefix = commentPrefix; - this.commentSuffix = commentSuffix; - this.spacePrefixTop = this.spacePrefixBottom = ""; - this.spaceCharTop = this.spaceCharBottom = ' '; - this.spaceSuffixTop = this.spaceSuffixBottom = ""; - } - - } - - public static CommentStyle parseStyle(List lines) { - if (lines == null || lines.size() <= 2) { - return CommentStyle.SIMPLE; - } else if (lines.size() > 2 && lines.get(0).trim().equals("#") && lines.get(lines.size() - 1).trim().equals("#")) { - return CommentStyle.SPACED; - } - boolean hasBorders = lines.size() > 2 && lines.get(0).trim().matches("^##+$") && lines.get(lines.size() - 1).trim().matches("^##+$"); - if (!hasBorders) { - // default return - return CommentStyle.SIMPLE; - } - // now need to figure out if this is blocked or not - if (lines.size() > 4 && lines.get(1).trim().matches(("^#" - + CommentStyle.BLOCKSPACED.spacePrefixTop + CommentStyle.BLOCKSPACED.spaceCharTop + "+" - + CommentStyle.BLOCKSPACED.spaceSuffixTop + "#$").replace("|", "\\|")) - && lines.get(1).trim().matches(("^#" - + CommentStyle.BLOCKSPACED.spacePrefixTop + CommentStyle.BLOCKSPACED.spaceCharTop + "+" - + CommentStyle.BLOCKSPACED.spaceSuffixTop + "#$").replace("|", "\\|"))) { - return CommentStyle.BLOCKSPACED; - } - return CommentStyle.BLOCKED; - } -} +package com.songoda.core.configuration; + +import java.util.List; + +public class ConfigFormattingRules { + + int spacesBetweenMainCategories; + int spacesBetweenValues; + CommentStyle rootCommentStyle = CommentStyle.BLOCKSPACED; + CommentStyle mainCategoryCommentStyle = CommentStyle.SPACED; + + public static enum CommentStyle { + + /** + * # Comment + */ + SIMPLE(false, false, " ", ""), + /** + * #
+ * # Comment
+ * #
+ */ + SPACED(false, true, " ", ""), + /** + * ###########
+ * # Comment #
+ * ###########
+ */ + BLOCKED(true, false, " ", " "), + /** + * #############
+ * #|¯¯¯¯¯¯¯¯¯|#
+ * #| Comment |#
+ * #|_________|#
+ * #############
+ */ + BLOCKSPACED(true, true, "|\u00AF", '\u00AF', "\u00AF|", "| ", " |", "|_", '_', "_|"); + + final boolean drawBorder, drawSpace; + final String commentPrefix, spacePrefixTop, spacePrefixBottom; + final String commentSuffix, spaceSuffixTop, spaceSuffixBottom; + final char spaceCharTop, spaceCharBottom; + + private CommentStyle(boolean drawBorder, boolean drawSpace, + String spacePrefixTop, char spaceCharTop, String spaceSuffixTop, + String commentPrefix, String commentSuffix, + String spacePrefixBottom, char spaceCharBottom, String spaceSuffixBottom) { + this.drawBorder = drawBorder; + this.drawSpace = drawSpace; + this.commentPrefix = commentPrefix; + this.spacePrefixTop = spacePrefixTop; + this.spacePrefixBottom = spacePrefixBottom; + this.commentSuffix = commentSuffix; + this.spaceSuffixTop = spaceSuffixTop; + this.spaceSuffixBottom = spaceSuffixBottom; + this.spaceCharTop = spaceCharTop; + this.spaceCharBottom = spaceCharBottom; + } + + private CommentStyle(boolean drawBorder, boolean drawSpace, String commentPrefix, String commentSuffix) { + this.drawBorder = drawBorder; + this.drawSpace = drawSpace; + this.commentPrefix = commentPrefix; + this.commentSuffix = commentSuffix; + this.spacePrefixTop = this.spacePrefixBottom = ""; + this.spaceCharTop = this.spaceCharBottom = ' '; + this.spaceSuffixTop = this.spaceSuffixBottom = ""; + } + } + + public static CommentStyle parseStyle(List lines) { + if (lines == null || lines.size() <= 2) { + return CommentStyle.SIMPLE; + } else if (lines.size() > 2 && lines.get(0).trim().equals("#") && lines.get(lines.size() - 1).trim().equals("#")) { + return CommentStyle.SPACED; + } + boolean hasBorders = lines.size() > 2 && lines.get(0).trim().matches("^##+$") && lines.get(lines.size() - 1).trim().matches("^##+$"); + if (!hasBorders) { + // default return + return CommentStyle.SIMPLE; + } + // now need to figure out if this is blocked or not + if (lines.size() > 4 && lines.get(1).trim().matches(("^#" + + CommentStyle.BLOCKSPACED.spacePrefixTop + CommentStyle.BLOCKSPACED.spaceCharTop + "+" + + CommentStyle.BLOCKSPACED.spaceSuffixTop + "#$").replace("|", "\\|")) + && lines.get(1).trim().matches(("^#" + + CommentStyle.BLOCKSPACED.spacePrefixTop + CommentStyle.BLOCKSPACED.spaceCharTop + "+" + + CommentStyle.BLOCKSPACED.spaceSuffixTop + "#$").replace("|", "\\|"))) { + return CommentStyle.BLOCKSPACED; + } + return CommentStyle.BLOCKED; + } +} diff --git a/Core/src/main/java/com/songoda/core/configuration/ConfigSetting.java b/Core/src/main/java/com/songoda/core/configuration/ConfigSetting.java index c47959ed..3e7ebae3 100644 --- a/Core/src/main/java/com/songoda/core/configuration/ConfigSetting.java +++ b/Core/src/main/java/com/songoda/core/configuration/ConfigSetting.java @@ -129,5 +129,4 @@ public class ConfigSetting { return mat != null ? mat : def; } - } diff --git a/Core/src/main/java/com/songoda/core/configuration/SimpleDataStore.java b/Core/src/main/java/com/songoda/core/configuration/SimpleDataStore.java index f14d4005..c1947ccc 100644 --- a/Core/src/main/java/com/songoda/core/configuration/SimpleDataStore.java +++ b/Core/src/main/java/com/songoda/core/configuration/SimpleDataStore.java @@ -1,265 +1,270 @@ -package com.songoda.core.configuration; - -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.function.Function; -import java.util.logging.Level; - -/** - * Used to easily store a set of one data value - * - * @param DataObject class that is used to store the data - * @author jascotty2 - * @since 2019-09-06 - */ -public class SimpleDataStore { - - protected final Plugin plugin; - protected final String filename, dirName; - private final Function getFromSection; - protected final HashMap data = new HashMap(); - private File file; - private final Object lock = new Object(); - SaveTask saveTask; - Timer autosaveTimer; - /** - * time in seconds to start a save after a change is made - */ - int autosaveInterval = 60; - - public SimpleDataStore(@NotNull Plugin plugin, @NotNull String filename, @NotNull Function loadFunction) { - this.plugin = plugin; - this.filename = filename; - dirName = null; - this.getFromSection = loadFunction; - } - - public SimpleDataStore(@NotNull Plugin plugin, @Nullable String directory, @NotNull String filename, @NotNull Function loadFunction) { - this.plugin = plugin; - this.filename = filename; - this.dirName = directory; - this.getFromSection = loadFunction; - } - - @NotNull - public File getFile() { - if (file == null) { - if (dirName != null) { - this.file = new File(plugin.getDataFolder() + dirName, filename != null ? filename : "data.yml"); - } else { - this.file = new File(plugin.getDataFolder(), filename != null ? filename : "data.yml"); - } - } - return file; - } - - /** - * @return a directly-modifiable instance of the data mapping for this - * storage - */ - public Map getData() { - return data; - } - - /** - * Returns the value to which the specified key is mapped, or {@code null} - * if this map contains no mapping for the key. - * - * @param key key whose mapping is to be retrieved from this storage - * @return the value associated with key, or - * null if there was no mapping for key. - */ - @Nullable - public T get(Object key) { - return data.get(key); - } - - /** - * Removes the mapping for the specified key from this storage if present. - * - * @param key key whose mapping is to be removed from this storage - * @return the previous value associated with key, or - * null if there was no mapping for key. - */ - @Nullable - public T remove(@NotNull Object key) { - T temp; - synchronized (lock) { - temp = data.remove(key); - } - save(); - return temp; - } - - /** - * Removes the mapping for the specified key from this storage if present. - * - * @param value value whose mapping is to be removed from this storage - * @return the previous value associated with key, or - * null if there was no mapping for key. - */ - @Nullable - public T remove(@NotNull T value) { - if (value == null) { - return null; - } - T temp; - synchronized (lock) { - temp = data.remove(value.getKey()); - } - save(); - return temp; - } - - /** - * Adds the specified value in this storage. If the map previously contained - * a mapping for the key, the old value is replaced. - * - * @param value value to be added - * @return the previous value associated with value.getKey(), or - * null if there was no mapping for value.getKey(). - */ - @Nullable - public T add(@NotNull T value) { - if (value == null) { - return null; - } - T temp; - synchronized (lock) { - temp = data.put(value.getKey(), value); - } - save(); - return temp; - } - - /** - * Adds the specified value in this storage. If the map previously contained - * a mapping for the key, the old value is replaced. - * - * @param value values to be added - */ - @Nullable - public void addAll(@NotNull T[] value) { - if (value == null) { - return; - } - synchronized (lock) { - for (int i = 0; i < value.length; ++i) { - if (value[i] != null) { - data.put(value[i].getKey(), value[i]); - } - } - } - save(); - } - - /** - * Adds the specified value in this storage. If the map previously contained - * a mapping for the key, the old value is replaced. - * - * @param value values to be added - */ - @Nullable - public void addAll(@NotNull Collection value) { - if (value == null) { - return; - } - synchronized (lock) { - for (T v : value) { - if (v != null) { - data.put(v.getKey(), v); - } - } - } - save(); - } - - /** - * Load data from the associated file - */ - public void load() { - if (!getFile().exists()) { - return; - } - try { - YamlConfiguration f = new YamlConfiguration(); - f.options().pathSeparator('\0'); - f.load(file); - - synchronized (lock) { - data.clear(); - f.getValues(false).entrySet().stream() - .filter(d -> d.getValue() instanceof ConfigurationSection) - .map(Map.Entry::getValue) - .map(v -> getFromSection.apply((ConfigurationSection) v)) - .forEach(v -> data.put(v.getKey(), v)); - } - } catch (IOException | InvalidConfigurationException ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to load data from " + file.getName(), ex); - } - } - - /** - * Optionally save this storage's data to file if there have been changes - * made - */ - public void saveChanges() { - if (saveTask != null || data.values().stream().anyMatch(v -> v.hasChanged())) { - flushSave(); - } - } - - /** - * Save this file data. This saves later asynchronously. - */ - public void save() { - // save async even if no plugin or if plugin disabled - if (saveTask == null) { - autosaveTimer = new Timer((plugin != null ? plugin.getName() + "-DataStoreSave-" : "DataStoreSave-") + getFile().getName()); - autosaveTimer.schedule(saveTask = new SaveTask(), autosaveInterval * 1000L); - } - } - - /** - * Force a new save of this storage's data - */ - public void flushSave() { - if (saveTask != null) { - //Close Threads - saveTask.cancel(); - autosaveTimer.cancel(); - saveTask = null; - autosaveTimer = null; - } - YamlConfiguration f = new YamlConfiguration(); - synchronized (lock) { - data.values().stream().forEach(e -> e.saveToSection(f.createSection(e.getConfigKey()))); - } - try { - f.save(getFile()); - data.values().stream().forEach(e -> e.setChanged(false)); - } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to save data to " + file.getName(), ex); - } - } - - class SaveTask extends TimerTask { - - @Override - public void run() { - flushSave(); - } - } -} +package com.songoda.core.configuration; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.function.Function; +import java.util.logging.Level; + +/** + * Used to easily store a set of one data value + * + * @param DataObject class that is used to store the data + * + * @author jascotty2 + * @since 2019-09-06 + */ +public class SimpleDataStore { + + protected final Plugin plugin; + protected final String filename, dirName; + private final Function getFromSection; + protected final HashMap data = new HashMap(); + private File file; + private final Object lock = new Object(); + SaveTask saveTask; + Timer autosaveTimer; + /** + * time in seconds to start a save after a change is made + */ + int autosaveInterval = 60; + + public SimpleDataStore(@NotNull Plugin plugin, @NotNull String filename, @NotNull Function loadFunction) { + this.plugin = plugin; + this.filename = filename; + dirName = null; + this.getFromSection = loadFunction; + } + + public SimpleDataStore(@NotNull Plugin plugin, @Nullable String directory, @NotNull String filename, @NotNull Function loadFunction) { + this.plugin = plugin; + this.filename = filename; + this.dirName = directory; + this.getFromSection = loadFunction; + } + + @NotNull + public File getFile() { + if (file == null) { + if (dirName != null) { + this.file = new File(plugin.getDataFolder() + dirName, filename != null ? filename : "data.yml"); + } else { + this.file = new File(plugin.getDataFolder(), filename != null ? filename : "data.yml"); + } + } + return file; + } + + /** + * @return a directly-modifiable instance of the data mapping for this + * storage + */ + public Map getData() { + return data; + } + + /** + * Returns the value to which the specified key is mapped, or {@code null} + * if this map contains no mapping for the key. + * + * @param key key whose mapping is to be retrieved from this storage + * + * @return the value associated with key, or + * null if there was no mapping for key. + */ + @Nullable + public T get(Object key) { + return data.get(key); + } + + /** + * Removes the mapping for the specified key from this storage if present. + * + * @param key key whose mapping is to be removed from this storage + * + * @return the previous value associated with key, or + * null if there was no mapping for key. + */ + @Nullable + public T remove(@NotNull Object key) { + T temp; + synchronized (lock) { + temp = data.remove(key); + } + save(); + return temp; + } + + /** + * Removes the mapping for the specified key from this storage if present. + * + * @param value value whose mapping is to be removed from this storage + * + * @return the previous value associated with key, or + * null if there was no mapping for key. + */ + @Nullable + public T remove(@NotNull T value) { + if (value == null) { + return null; + } + T temp; + synchronized (lock) { + temp = data.remove(value.getKey()); + } + save(); + return temp; + } + + /** + * Adds the specified value in this storage. If the map previously contained + * a mapping for the key, the old value is replaced. + * + * @param value value to be added + * + * @return the previous value associated with value.getKey(), or + * null if there was no mapping for value.getKey(). + */ + @Nullable + public T add(@NotNull T value) { + if (value == null) { + return null; + } + T temp; + synchronized (lock) { + temp = data.put(value.getKey(), value); + } + save(); + return temp; + } + + /** + * Adds the specified value in this storage. If the map previously contained + * a mapping for the key, the old value is replaced. + * + * @param value values to be added + */ + @Nullable + public void addAll(@NotNull T[] value) { + if (value == null) { + return; + } + synchronized (lock) { + for (int i = 0; i < value.length; ++i) { + if (value[i] != null) { + data.put(value[i].getKey(), value[i]); + } + } + } + save(); + } + + /** + * Adds the specified value in this storage. If the map previously contained + * a mapping for the key, the old value is replaced. + * + * @param value values to be added + */ + @Nullable + public void addAll(@NotNull Collection value) { + if (value == null) { + return; + } + synchronized (lock) { + for (T v : value) { + if (v != null) { + data.put(v.getKey(), v); + } + } + } + save(); + } + + /** + * Load data from the associated file + */ + public void load() { + if (!getFile().exists()) { + return; + } + try { + YamlConfiguration f = new YamlConfiguration(); + f.options().pathSeparator('\0'); + f.load(file); + + synchronized (lock) { + data.clear(); + f.getValues(false).entrySet().stream() + .filter(d -> d.getValue() instanceof ConfigurationSection) + .map(Map.Entry::getValue) + .map(v -> getFromSection.apply((ConfigurationSection) v)) + .forEach(v -> data.put(v.getKey(), v)); + } + } catch (IOException | InvalidConfigurationException ex) { + plugin.getLogger().log(Level.SEVERE, "Failed to load data from " + file.getName(), ex); + } + } + + /** + * Optionally save this storage's data to file if there have been changes + * made + */ + public void saveChanges() { + if (saveTask != null || data.values().stream().anyMatch(v -> v.hasChanged())) { + flushSave(); + } + } + + /** + * Save this file data. This saves later asynchronously. + */ + public void save() { + // save async even if no plugin or if plugin disabled + if (saveTask == null) { + autosaveTimer = new Timer((plugin != null ? plugin.getName() + "-DataStoreSave-" : "DataStoreSave-") + getFile().getName()); + autosaveTimer.schedule(saveTask = new SaveTask(), autosaveInterval * 1000L); + } + } + + /** + * Force a new save of this storage's data + */ + public void flushSave() { + if (saveTask != null) { + //Close Threads + saveTask.cancel(); + autosaveTimer.cancel(); + saveTask = null; + autosaveTimer = null; + } + YamlConfiguration f = new YamlConfiguration(); + synchronized (lock) { + data.values().stream().forEach(e -> e.saveToSection(f.createSection(e.getConfigKey()))); + } + try { + f.save(getFile()); + data.values().stream().forEach(e -> e.setChanged(false)); + } catch (IOException ex) { + plugin.getLogger().log(Level.SEVERE, "Failed to save data to " + file.getName(), ex); + } + } + + class SaveTask extends TimerTask { + + @Override + public void run() { + flushSave(); + } + } +} diff --git a/Core/src/main/java/com/songoda/core/configuration/editor/ConfigEditorGui.java b/Core/src/main/java/com/songoda/core/configuration/editor/ConfigEditorGui.java index 8843a557..4d9e6b39 100644 --- a/Core/src/main/java/com/songoda/core/configuration/editor/ConfigEditorGui.java +++ b/Core/src/main/java/com/songoda/core/configuration/editor/ConfigEditorGui.java @@ -1,308 +1,306 @@ -package com.songoda.core.configuration.editor; - -import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.configuration.Config; -import com.songoda.core.gui.Gui; -import com.songoda.core.gui.GuiUtils; -import com.songoda.core.gui.SimplePagedGui; -import com.songoda.core.input.ChatPrompt; -import com.songoda.core.utils.ItemUtils; -import org.bukkit.ChatColor; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.MemoryConfiguration; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.logging.Level; - -/** - * Edit a configuration file for a specific plugin - * - * @author jascotty2 - * @since 2019-08-31 - */ -public class ConfigEditorGui extends SimplePagedGui { - - final JavaPlugin plugin; - final String file; - final MemoryConfiguration config; - final ConfigurationSection node; - final Player player; - Method configSection_getCommentString = null; - boolean edits = false; - List sections = new ArrayList(); - List settings = new ArrayList(); - - protected ConfigEditorGui(Player player, JavaPlugin plugin, Gui parent, String file, MemoryConfiguration config) { - this(player, plugin, parent, file, config, config); - } - - protected ConfigEditorGui(Player player, JavaPlugin plugin, Gui parent, String file, MemoryConfiguration config, ConfigurationSection node) { - super(parent); - this.player = player; - this.plugin = plugin; - this.file = file; - this.config = config; - this.node = node; - this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE); - - if (!(parent instanceof ConfigEditorGui)) { - setOnClose((gui) -> save()); - } else { - setOnClose((gui) -> ((ConfigEditorGui) parent).edits |= edits); - } - - // if we have a ConfigSection, we can also grab comments - try { - configSection_getCommentString = node.getClass().getDeclaredMethod("getCommentString", String.class); - } catch (Exception ex) { - } - - // decorate header - this.setTitle(ChatColor.DARK_BLUE + file); - this.setUseHeader(true); - headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem()); - final String path = node.getCurrentPath(); - this.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, !path.isEmpty() ? path : file, config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString())); - this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); - - // compile list of settings - for (String key : node.getKeys(false)) { - if (node.isConfigurationSection(key)) { - sections.add(key); - } else { - settings.add(key); - } - } - - // next we need to display the config settings - int index = 9; - for (final String sectionKey : sections) { - setButton(index++, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"), - (event) -> event.manager.showGUI(event.player, new ConfigEditorGui(player, plugin, this, file, config, node.getConfigurationSection(sectionKey)))); - } - - // now display individual settings - for (final String settingKey : settings) { - final Object val = node.get(settingKey); - if (val == null) continue; - else if (val instanceof Boolean) { - // toggle switch - setButton(index, configItem(CompatibleMaterial.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Boolean) val), "Click to toggle this setting"), - (event) -> this.toggle(event.slot, settingKey)); - if ((Boolean) val) { - highlightItem(index); - } - } else if (isNumber(val)) { - // number dial - this.setButton(index, configItem(CompatibleMaterial.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Number) val), "Click to edit this setting"), - (event) -> { - event.gui.exit(); - ChatPrompt.showPrompt(plugin, event.player, "Enter a new number value for " + settingKey + ":", response -> { - if (!setNumber(event.slot, settingKey, response.getMessage().trim())) { - event.player.sendMessage(ChatColor.RED + "Error: \"" + response.getMessage().trim() + "\" is not a number!"); - } - }).setOnClose(() -> event.manager.showGUI(event.player, this)) - .setOnCancel(() -> { - event.player.sendMessage(ChatColor.RED + "Edit canceled"); - event.manager.showGUI(event.player, this); - }); - }); - } else if (isMaterial(val)) { - // changing a block - // isMaterial is more of a guess, to be honest. - setButton(index, configItem(CompatibleMaterial.STONE, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"), - (event) -> { - SimplePagedGui paged = new SimplePagedGui(this); - paged.setTitle(ChatColor.BLUE + settingKey); - paged.setHeaderBackItem(headerBackItem).setFooterBackItem(footerBackItem).setDefaultItem(blankItem); - paged.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to")); - int i = 9; - for (CompatibleMaterial mat : CompatibleMaterial.getAllValidItemMaterials()) { - paged.setButton(i++, GuiUtils.createButtonItem(mat, mat.name()), ClickType.LEFT, (matEvent) -> { - setMaterial(event.slot, settingKey, matEvent.clickedItem); - matEvent.player.closeInventory(); - }); - } - event.manager.showGUI(event.player, paged); - }); - - } else if (val instanceof String) { - // changing a "string" value (or change to a feather for writing quill) - setButton(index, configItem(CompatibleMaterial.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"), - (event) -> { - event.gui.exit(); - ChatPrompt.showPrompt(plugin, event.player, "Enter a new value for " + settingKey + ":", response -> { - node.set(settingKey, response.getMessage().trim()); - updateValue(event.slot, settingKey); - }).setOnClose(() -> event.manager.showGUI(event.player, this)) - .setOnCancel(() -> { - event.player.sendMessage(ChatColor.RED + "Edit canceled"); - event.manager.showGUI(event.player, this); - }); - }); - } else if (val instanceof List) { - setButton(index, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List) val).size()), "Click to edit this setting"), - (event) -> { - event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> { - if (((ConfigEditorListEditorGui) gui.gui).saveChanges) { - setList(event.slot, settingKey, ((ConfigEditorListEditorGui) gui.gui).values); - } - })); - }); - } else { - // idk. should we display uneditable values? - } - - ++index; - } - - } - - public ConfigurationSection getCurrentNode() { - return node; - } - - protected void updateValue(int clickCell, String path) { - ItemStack item = inventory.getItem(clickCell); - if (item == null || item == AIR) return; - ItemMeta meta = item.getItemMeta(); - Object val = node.get(path); - if (meta != null && val != null) { - String valStr; - if (val instanceof List) { - valStr = String.format("(%d values)", ((List) val).size()); - } else { - valStr = val.toString(); - } - List lore = meta.getLore(); - if (lore == null || lore.isEmpty()) { - meta.setLore(Arrays.asList(valStr)); - } else { - lore.set(0, valStr); - meta.setLore(lore); - } - item.setItemMeta(meta); - setItem(clickCell, item); - } - edits = true; - } - - void toggle(int clickCell, String path) { - boolean val = !node.getBoolean(path); - node.set(path, val); - if (val) { - setItem(clickCell, ItemUtils.addGlow(inventory.getItem(clickCell))); - } else { - setItem(clickCell, ItemUtils.removeGlow(inventory.getItem(clickCell))); - } - updateValue(clickCell, path); - } - - boolean setNumber(int clickCell, String path, String input) { - try { - if (node.isInt(path)) { - node.set(path, Integer.parseInt(input)); - } else if (node.isDouble(path)) { - node.set(path, Double.parseDouble(input)); - } else if (node.isLong(path)) { - node.set(path, Long.parseLong(input)); - } - updateValue(clickCell, path); - } catch (NumberFormatException e) { - return false; - } - return true; - } - - void setMaterial(int clickCell, String path, ItemStack item) { - CompatibleMaterial mat = CompatibleMaterial.getMaterial(item); - if (mat == null) { - node.set(path, CompatibleMaterial.STONE.name()); - } else { - node.set(path, mat.name()); - } - updateValue(clickCell, path); - } - - void setList(int clickCell, String path, List list) { - node.set(path, list); - updateValue(clickCell, path); - } - - void save() { - if (!edits) { - return; - } - // could also check and call saveChanges() - if (config instanceof FileConfiguration) { - try { - ((FileConfiguration) config).save(new File(plugin.getDataFolder(), file)); - } catch (IOException ex) { - plugin.getLogger().log(Level.SEVERE, "Failed to save config changes to " + file, ex); - return; - } - } else if (config instanceof Config) { - ((Config) config).save(); - } else { - player.sendMessage(ChatColor.RED + "Unknown configuration type '" + config.getClass().getName() + "' - Please report this error!"); - plugin.getLogger().log(Level.WARNING, "Unknown configuration type '" + config.getClass().getName() + "' - Please report this error!"); - return; - } - plugin.reloadConfig(); - player.sendMessage(ChatColor.GREEN + "Config " + file + " saved!"); - } - - private boolean isNumber(Object value) { - return value != null && ( - value instanceof Long - || value instanceof Integer - || value instanceof Float - || value instanceof Double); - } - - private boolean isMaterial(Object value) { - CompatibleMaterial m; - return value instanceof String && value.toString().equals(value.toString().toUpperCase()) - && (m = CompatibleMaterial.getMaterial(value.toString())) != null && m.isValidItem(); - } - - protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String def) { - String[] info = null; - if (configSection_getCommentString != null) { - try { - Object comment = configSection_getCommentString.invoke(node, path); - if (comment != null) { - info = comment.toString().split("\n"); - } - } catch (Exception ex) { - } - } - return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? def.split("\n") : null)); - } - - protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String value, String def) { - if (value == null) value = ""; - String[] info = null; - if (configSection_getCommentString != null) { - try { - Object comment = configSection_getCommentString.invoke(node, path); - if (comment != null) { - info = (value + "\n" + comment.toString()).split("\n"); - } - } catch (Exception ex) { - } - } - return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? (value + "\n" + def).split("\n") : null)); - } -} +package com.songoda.core.configuration.editor; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.configuration.Config; +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiUtils; +import com.songoda.core.gui.SimplePagedGui; +import com.songoda.core.input.ChatPrompt; +import com.songoda.core.utils.ItemUtils; +import org.bukkit.ChatColor; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.MemoryConfiguration; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; + +/** + * Edit a configuration file for a specific plugin + * + * @author jascotty2 + * @since 2019-08-31 + */ +public class ConfigEditorGui extends SimplePagedGui { + + final JavaPlugin plugin; + final String file; + final MemoryConfiguration config; + final ConfigurationSection node; + final Player player; + Method configSection_getCommentString = null; + boolean edits = false; + List sections = new ArrayList(); + List settings = new ArrayList(); + + protected ConfigEditorGui(Player player, JavaPlugin plugin, Gui parent, String file, MemoryConfiguration config) { + this(player, plugin, parent, file, config, config); + } + + protected ConfigEditorGui(Player player, JavaPlugin plugin, Gui parent, String file, MemoryConfiguration config, ConfigurationSection node) { + super(parent); + this.player = player; + this.plugin = plugin; + this.file = file; + this.config = config; + this.node = node; + this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE); + + if (!(parent instanceof ConfigEditorGui)) { + setOnClose((gui) -> save()); + } else { + setOnClose((gui) -> ((ConfigEditorGui) parent).edits |= edits); + } + + // if we have a ConfigSection, we can also grab comments + try { + configSection_getCommentString = node.getClass().getDeclaredMethod("getCommentString", String.class); + } catch (Exception ex) { + } + + // decorate header + this.setTitle(ChatColor.DARK_BLUE + file); + this.setUseHeader(true); + headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem()); + final String path = node.getCurrentPath(); + this.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, !path.isEmpty() ? path : file, config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString())); + this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); + + // compile list of settings + for (String key : node.getKeys(false)) { + if (node.isConfigurationSection(key)) { + sections.add(key); + } else { + settings.add(key); + } + } + + // next we need to display the config settings + int index = 9; + for (final String sectionKey : sections) { + setButton(index++, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"), + (event) -> event.manager.showGUI(event.player, new ConfigEditorGui(player, plugin, this, file, config, node.getConfigurationSection(sectionKey)))); + } + + // now display individual settings + for (final String settingKey : settings) { + final Object val = node.get(settingKey); + if (val == null) continue; + else if (val instanceof Boolean) { + // toggle switch + setButton(index, configItem(CompatibleMaterial.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Boolean) val), "Click to toggle this setting"), + (event) -> this.toggle(event.slot, settingKey)); + if ((Boolean) val) { + highlightItem(index); + } + } else if (isNumber(val)) { + // number dial + this.setButton(index, configItem(CompatibleMaterial.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf((Number) val), "Click to edit this setting"), + (event) -> { + event.gui.exit(); + ChatPrompt.showPrompt(plugin, event.player, "Enter a new number value for " + settingKey + ":", response -> { + if (!setNumber(event.slot, settingKey, response.getMessage().trim())) { + event.player.sendMessage(ChatColor.RED + "Error: \"" + response.getMessage().trim() + "\" is not a number!"); + } + }).setOnClose(() -> event.manager.showGUI(event.player, this)) + .setOnCancel(() -> { + event.player.sendMessage(ChatColor.RED + "Edit canceled"); + event.manager.showGUI(event.player, this); + }); + }); + } else if (isMaterial(val)) { + // changing a block + // isMaterial is more of a guess, to be honest. + setButton(index, configItem(CompatibleMaterial.STONE, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"), + (event) -> { + SimplePagedGui paged = new SimplePagedGui(this); + paged.setTitle(ChatColor.BLUE + settingKey); + paged.setHeaderBackItem(headerBackItem).setFooterBackItem(footerBackItem).setDefaultItem(blankItem); + paged.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to")); + int i = 9; + for (CompatibleMaterial mat : CompatibleMaterial.getAllValidItemMaterials()) { + paged.setButton(i++, GuiUtils.createButtonItem(mat, mat.name()), ClickType.LEFT, (matEvent) -> { + setMaterial(event.slot, settingKey, matEvent.clickedItem); + matEvent.player.closeInventory(); + }); + } + event.manager.showGUI(event.player, paged); + }); + } else if (val instanceof String) { + // changing a "string" value (or change to a feather for writing quill) + setButton(index, configItem(CompatibleMaterial.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"), + (event) -> { + event.gui.exit(); + ChatPrompt.showPrompt(plugin, event.player, "Enter a new value for " + settingKey + ":", response -> { + node.set(settingKey, response.getMessage().trim()); + updateValue(event.slot, settingKey); + }).setOnClose(() -> event.manager.showGUI(event.player, this)) + .setOnCancel(() -> { + event.player.sendMessage(ChatColor.RED + "Edit canceled"); + event.manager.showGUI(event.player, this); + }); + }); + } else if (val instanceof List) { + setButton(index, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List) val).size()), "Click to edit this setting"), + (event) -> { + event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> { + if (((ConfigEditorListEditorGui) gui.gui).saveChanges) { + setList(event.slot, settingKey, ((ConfigEditorListEditorGui) gui.gui).values); + } + })); + }); + } else { + // idk. should we display uneditable values? + } + + ++index; + } + } + + public ConfigurationSection getCurrentNode() { + return node; + } + + protected void updateValue(int clickCell, String path) { + ItemStack item = inventory.getItem(clickCell); + if (item == null || item == AIR) return; + ItemMeta meta = item.getItemMeta(); + Object val = node.get(path); + if (meta != null && val != null) { + String valStr; + if (val instanceof List) { + valStr = String.format("(%d values)", ((List) val).size()); + } else { + valStr = val.toString(); + } + List lore = meta.getLore(); + if (lore == null || lore.isEmpty()) { + meta.setLore(Arrays.asList(valStr)); + } else { + lore.set(0, valStr); + meta.setLore(lore); + } + item.setItemMeta(meta); + setItem(clickCell, item); + } + edits = true; + } + + void toggle(int clickCell, String path) { + boolean val = !node.getBoolean(path); + node.set(path, val); + if (val) { + setItem(clickCell, ItemUtils.addGlow(inventory.getItem(clickCell))); + } else { + setItem(clickCell, ItemUtils.removeGlow(inventory.getItem(clickCell))); + } + updateValue(clickCell, path); + } + + boolean setNumber(int clickCell, String path, String input) { + try { + if (node.isInt(path)) { + node.set(path, Integer.parseInt(input)); + } else if (node.isDouble(path)) { + node.set(path, Double.parseDouble(input)); + } else if (node.isLong(path)) { + node.set(path, Long.parseLong(input)); + } + updateValue(clickCell, path); + } catch (NumberFormatException e) { + return false; + } + return true; + } + + void setMaterial(int clickCell, String path, ItemStack item) { + CompatibleMaterial mat = CompatibleMaterial.getMaterial(item); + if (mat == null) { + node.set(path, CompatibleMaterial.STONE.name()); + } else { + node.set(path, mat.name()); + } + updateValue(clickCell, path); + } + + void setList(int clickCell, String path, List list) { + node.set(path, list); + updateValue(clickCell, path); + } + + void save() { + if (!edits) { + return; + } + // could also check and call saveChanges() + if (config instanceof FileConfiguration) { + try { + ((FileConfiguration) config).save(new File(plugin.getDataFolder(), file)); + } catch (IOException ex) { + plugin.getLogger().log(Level.SEVERE, "Failed to save config changes to " + file, ex); + return; + } + } else if (config instanceof Config) { + ((Config) config).save(); + } else { + player.sendMessage(ChatColor.RED + "Unknown configuration type '" + config.getClass().getName() + "' - Please report this error!"); + plugin.getLogger().log(Level.WARNING, "Unknown configuration type '" + config.getClass().getName() + "' - Please report this error!"); + return; + } + plugin.reloadConfig(); + player.sendMessage(ChatColor.GREEN + "Config " + file + " saved!"); + } + + private boolean isNumber(Object value) { + return value != null && ( + value instanceof Long + || value instanceof Integer + || value instanceof Float + || value instanceof Double); + } + + private boolean isMaterial(Object value) { + CompatibleMaterial m; + return value instanceof String && value.toString().equals(value.toString().toUpperCase()) + && (m = CompatibleMaterial.getMaterial(value.toString())) != null && m.isValidItem(); + } + + protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String def) { + String[] info = null; + if (configSection_getCommentString != null) { + try { + Object comment = configSection_getCommentString.invoke(node, path); + if (comment != null) { + info = comment.toString().split("\n"); + } + } catch (Exception ex) { + } + } + return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? def.split("\n") : null)); + } + + protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String value, String def) { + if (value == null) value = ""; + String[] info = null; + if (configSection_getCommentString != null) { + try { + Object comment = configSection_getCommentString.invoke(node, path); + if (comment != null) { + info = (value + "\n" + comment.toString()).split("\n"); + } + } catch (Exception ex) { + } + } + return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? (value + "\n" + def).split("\n") : null)); + } +} diff --git a/Core/src/main/java/com/songoda/core/configuration/editor/ConfigEditorListEditorGui.java b/Core/src/main/java/com/songoda/core/configuration/editor/ConfigEditorListEditorGui.java index 43f51cab..2fb6d418 100644 --- a/Core/src/main/java/com/songoda/core/configuration/editor/ConfigEditorListEditorGui.java +++ b/Core/src/main/java/com/songoda/core/configuration/editor/ConfigEditorListEditorGui.java @@ -1,85 +1,84 @@ -package com.songoda.core.configuration.editor; - -import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.gui.GuiUtils; -import com.songoda.core.gui.SimplePagedGui; -import com.songoda.core.input.ChatPrompt; -import org.bukkit.ChatColor; -import org.bukkit.event.inventory.ClickType; - -import java.util.ArrayList; -import java.util.List; - -/** - * Edit a string list - * - * @author jascotty2 - * @since 2019-08-31 - */ -public class ConfigEditorListEditorGui extends SimplePagedGui { - - final ConfigEditorGui current; - - public boolean saveChanges = false; - public List values; - - public ConfigEditorListEditorGui(ConfigEditorGui current, String key, List val) { - super(current); - this.current = current; - this.blankItem = current.getDefaultItem(); - headerBackItem = footerBackItem = current.getHeaderBackItem(); - setTitle(ChatColor.DARK_BLUE + "String List Editor"); - this.setUseHeader(true); - this.setItem(4, current.configItem(CompatibleMaterial.FILLED_MAP, key, current.getCurrentNode(), key, null)); - this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); - this.values = new ArrayList(val); - - this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory()); - this.setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, ChatColor.GREEN + "Save"), (event) -> { - saveChanges = true; - event.player.closeInventory(); - }); - this.setButton(1, GuiUtils.createButtonItem(CompatibleMaterial.CHEST, ChatColor.BLUE + "Add Item"), - (event) -> { - event.gui.exit(); - ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a new value to add:", response -> { - values.add(response.getMessage().trim()); - redraw(); - }).setOnClose(() -> { - event.manager.showGUI(event.player, this); - }) - .setOnCancel(() -> { - event.player.sendMessage(ChatColor.RED + "Edit canceled"); - event.manager.showGUI(event.player, this); - }); - }); - - redraw(); - } - - void redraw() { - page = 1; - // clear old display - if (inventory != null) { - for (Integer i : cellItems.keySet().toArray(new Integer[0])) { - if (i > 8) { - cellItems.remove(i); - conditionalButtons.remove(i); - } - } - } - - // update items - int i = 9; - for (String item : values) { - final int index = i - 9; - setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, item, "Right-click to remove"), ClickType.RIGHT, (event) -> { - values.remove(index); - redraw(); - }); - } - // update display - update(); - } - -} +package com.songoda.core.configuration.editor; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.gui.GuiUtils; +import com.songoda.core.gui.SimplePagedGui; +import com.songoda.core.input.ChatPrompt; +import org.bukkit.ChatColor; +import org.bukkit.event.inventory.ClickType; + +import java.util.ArrayList; +import java.util.List; + +/** + * Edit a string list + * + * @author jascotty2 + * @since 2019-08-31 + */ +public class ConfigEditorListEditorGui extends SimplePagedGui { + + final ConfigEditorGui current; + + public boolean saveChanges = false; + public List values; + + public ConfigEditorListEditorGui(ConfigEditorGui current, String key, List val) { + super(current); + this.current = current; + this.blankItem = current.getDefaultItem(); + headerBackItem = footerBackItem = current.getHeaderBackItem(); + setTitle(ChatColor.DARK_BLUE + "String List Editor"); + this.setUseHeader(true); + this.setItem(4, current.configItem(CompatibleMaterial.FILLED_MAP, key, current.getCurrentNode(), key, null)); + this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); + this.values = new ArrayList(val); + + this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory()); + this.setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, ChatColor.GREEN + "Save"), (event) -> { + saveChanges = true; + event.player.closeInventory(); + }); + this.setButton(1, GuiUtils.createButtonItem(CompatibleMaterial.CHEST, ChatColor.BLUE + "Add Item"), + (event) -> { + event.gui.exit(); + ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a new value to add:", response -> { + values.add(response.getMessage().trim()); + redraw(); + }).setOnClose(() -> { + event.manager.showGUI(event.player, this); + }) + .setOnCancel(() -> { + event.player.sendMessage(ChatColor.RED + "Edit canceled"); + event.manager.showGUI(event.player, this); + }); + }); + + redraw(); + } + + void redraw() { + page = 1; + // clear old display + if (inventory != null) { + for (Integer i : cellItems.keySet().toArray(new Integer[0])) { + if (i > 8) { + cellItems.remove(i); + conditionalButtons.remove(i); + } + } + } + + // update items + int i = 9; + for (String item : values) { + final int index = i - 9; + setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, item, "Right-click to remove"), ClickType.RIGHT, (event) -> { + values.remove(index); + redraw(); + }); + } + // update display + update(); + } +} diff --git a/Core/src/main/java/com/songoda/core/configuration/editor/PluginConfigGui.java b/Core/src/main/java/com/songoda/core/configuration/editor/PluginConfigGui.java index f773782f..8d857920 100644 --- a/Core/src/main/java/com/songoda/core/configuration/editor/PluginConfigGui.java +++ b/Core/src/main/java/com/songoda/core/configuration/editor/PluginConfigGui.java @@ -1,99 +1,98 @@ -package com.songoda.core.configuration.editor; - -import com.songoda.core.SongodaPlugin; -import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.configuration.Config; -import com.songoda.core.gui.Gui; -import com.songoda.core.gui.GuiUtils; -import com.songoda.core.gui.SimplePagedGui; -import org.bukkit.ChatColor; -import org.bukkit.configuration.MemoryConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * Edit all configuration files for a specific plugin - * - * @author jascotty2 - * @since 2019-08-31 - */ -public class PluginConfigGui extends SimplePagedGui { - - final JavaPlugin plugin; - LinkedHashMap configs = new LinkedHashMap(); - - public PluginConfigGui(SongodaPlugin plugin) { - this(plugin, null); - } - - public PluginConfigGui(SongodaPlugin plugin, Gui parent) { - super(parent); - this.plugin = plugin; - - // collect list of plugins - configs.put(plugin.getCoreConfig().getFile().getName(), plugin.getCoreConfig()); - List more = plugin.getExtraConfig(); - if (more != null && !more.isEmpty()) { - for (Config cfg : more) { - configs.put(cfg.getFile().getName(), cfg); - } - } - init(); - } - - public PluginConfigGui(JavaPlugin plugin) { - this(plugin, null); - } - - public PluginConfigGui(JavaPlugin plugin, Gui parent) { - super(parent); - this.plugin = plugin; - - // collect list of plugins - configs.put("config.yml", plugin.getConfig()); - - try { - // can we also grab extra config from this mysterious plugin? - Object more = plugin.getClass().getDeclaredMethod("getExtraConfig").invoke(plugin); - if (more != null && more instanceof List && !((List) more).isEmpty()) { - try { - // if we have the getExtraConfig function, we should also be able to get the file - Method method_Config_getFile = ((List) more).get(0).getClass().getDeclaredMethod("getFile"); - for (Object cfg : ((List) more)) { - configs.put(((File) method_Config_getFile.invoke(cfg)).getName(), (MemoryConfiguration) cfg); - } - } catch (Exception ex) { - // include a failsafe, I guess - ((List) more).forEach(cfg -> configs.put("(File " + configs.size() + ")", (MemoryConfiguration) cfg)); - } - } - } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - // I guess not! - } - init(); - } - - private void init() { - this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE); - - // decorate header - this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config"); - this.setUseHeader(true); - headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem()); - this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); - - // List out all config files that this plugin has - int i = 9; - for (Map.Entry config : configs.entrySet()) { - this.setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"), - (event) -> event.manager.showGUI(event.player, new ConfigEditorGui(event.player, plugin, this, config.getKey(), config.getValue()))); - } - } - -} +package com.songoda.core.configuration.editor; + +import com.songoda.core.SongodaPlugin; +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.configuration.Config; +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiUtils; +import com.songoda.core.gui.SimplePagedGui; +import org.bukkit.ChatColor; +import org.bukkit.configuration.MemoryConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Edit all configuration files for a specific plugin + * + * @author jascotty2 + * @since 2019-08-31 + */ +public class PluginConfigGui extends SimplePagedGui { + + final JavaPlugin plugin; + LinkedHashMap configs = new LinkedHashMap(); + + public PluginConfigGui(SongodaPlugin plugin) { + this(plugin, null); + } + + public PluginConfigGui(SongodaPlugin plugin, Gui parent) { + super(parent); + this.plugin = plugin; + + // collect list of plugins + configs.put(plugin.getCoreConfig().getFile().getName(), plugin.getCoreConfig()); + List more = plugin.getExtraConfig(); + if (more != null && !more.isEmpty()) { + for (Config cfg : more) { + configs.put(cfg.getFile().getName(), cfg); + } + } + init(); + } + + public PluginConfigGui(JavaPlugin plugin) { + this(plugin, null); + } + + public PluginConfigGui(JavaPlugin plugin, Gui parent) { + super(parent); + this.plugin = plugin; + + // collect list of plugins + configs.put("config.yml", plugin.getConfig()); + + try { + // can we also grab extra config from this mysterious plugin? + Object more = plugin.getClass().getDeclaredMethod("getExtraConfig").invoke(plugin); + if (more != null && more instanceof List && !((List) more).isEmpty()) { + try { + // if we have the getExtraConfig function, we should also be able to get the file + Method method_Config_getFile = ((List) more).get(0).getClass().getDeclaredMethod("getFile"); + for (Object cfg : ((List) more)) { + configs.put(((File) method_Config_getFile.invoke(cfg)).getName(), (MemoryConfiguration) cfg); + } + } catch (Exception ex) { + // include a failsafe, I guess + ((List) more).forEach(cfg -> configs.put("(File " + configs.size() + ")", (MemoryConfiguration) cfg)); + } + } + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + // I guess not! + } + init(); + } + + private void init() { + this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE); + + // decorate header + this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config"); + this.setUseHeader(true); + headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem()); + this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory()); + + // List out all config files that this plugin has + int i = 9; + for (Map.Entry config : configs.entrySet()) { + this.setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"), + (event) -> event.manager.showGUI(event.player, new ConfigEditorGui(event.player, plugin, this, config.getKey(), config.getValue()))); + } + } +} diff --git a/Core/src/main/java/com/songoda/core/core/PluginInfoModule.java b/Core/src/main/java/com/songoda/core/core/PluginInfoModule.java index 5725198b..f6c32293 100644 --- a/Core/src/main/java/com/songoda/core/core/PluginInfoModule.java +++ b/Core/src/main/java/com/songoda/core/core/PluginInfoModule.java @@ -3,5 +3,4 @@ package com.songoda.core.core; public interface PluginInfoModule { void run(PluginInfo plugin); - } diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreCommand.java index 77b0b364..d0463959 100644 --- a/Core/src/main/java/com/songoda/core/core/SongodaCoreCommand.java +++ b/Core/src/main/java/com/songoda/core/core/SongodaCoreCommand.java @@ -1,52 +1,51 @@ -package com.songoda.core.core; - -import com.songoda.core.SongodaCore; -import com.songoda.core.commands.AbstractCommand; -import com.songoda.core.gui.GuiManager; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.List; - -public class SongodaCoreCommand extends AbstractCommand { - - protected GuiManager guiManager; - - public SongodaCoreCommand() { - super(false, "songoda"); - } - - @Override - protected ReturnType runCommand(CommandSender sender, String... args) { - if (sender instanceof Player) { - if (guiManager == null || guiManager.isClosed()) { - guiManager = new GuiManager(SongodaCore.getHijackedPlugin()); - } - guiManager.showGUI((Player) sender, new SongodaCoreOverviewGUI()); - } else { - sender.sendMessage("/songoda diag"); - } - return ReturnType.SUCCESS; - } - - @Override - public String getPermissionNode() { - return "songoda.admin"; - } - - @Override - public String getSyntax() { - return "/songoda"; - } - - @Override - public String getDescription() { - return "Displays this interface."; - } - - @Override - protected List onTab(CommandSender sender, String... args) { - return null; - } - -} +package com.songoda.core.core; + +import com.songoda.core.SongodaCore; +import com.songoda.core.commands.AbstractCommand; +import com.songoda.core.gui.GuiManager; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; + +public class SongodaCoreCommand extends AbstractCommand { + + protected GuiManager guiManager; + + public SongodaCoreCommand() { + super(false, "songoda"); + } + + @Override + protected ReturnType runCommand(CommandSender sender, String... args) { + if (sender instanceof Player) { + if (guiManager == null || guiManager.isClosed()) { + guiManager = new GuiManager(SongodaCore.getHijackedPlugin()); + } + guiManager.showGUI((Player) sender, new SongodaCoreOverviewGUI()); + } else { + sender.sendMessage("/songoda diag"); + } + return ReturnType.SUCCESS; + } + + @Override + public String getPermissionNode() { + return "songoda.admin"; + } + + @Override + public String getSyntax() { + return "/songoda"; + } + + @Override + public String getDescription() { + return "Displays this interface."; + } + + @Override + protected List onTab(CommandSender sender, String... args) { + return null; + } +} diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreDiagCommand.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreDiagCommand.java index 1c4d4036..3fbbe741 100644 --- a/Core/src/main/java/com/songoda/core/core/SongodaCoreDiagCommand.java +++ b/Core/src/main/java/com/songoda/core/core/SongodaCoreDiagCommand.java @@ -2,9 +2,9 @@ package com.songoda.core.core; import com.songoda.core.SongodaCore; import com.songoda.core.commands.AbstractCommand; +import com.songoda.core.compatibility.ClassMapping; import com.songoda.core.compatibility.ServerProject; import com.songoda.core.compatibility.ServerVersion; -import com.songoda.core.compatibility.ClassMapping; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; diff --git a/Core/src/main/java/com/songoda/core/core/SongodaCoreOverviewGUI.java b/Core/src/main/java/com/songoda/core/core/SongodaCoreOverviewGUI.java index 16570ec7..48c9cde0 100644 --- a/Core/src/main/java/com/songoda/core/core/SongodaCoreOverviewGUI.java +++ b/Core/src/main/java/com/songoda/core/core/SongodaCoreOverviewGUI.java @@ -25,26 +25,26 @@ final class SongodaCoreOverviewGUI extends Gui { final PluginInfo plugin = plugins.get(i); if (plugin.hasUpdate()) { setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : CompatibleMaterial.STONE, - ChatColor.GOLD + plugin.getJavaPlugin().getName(), - ChatColor.GRAY + "Latest Version: " + plugin.getLatestVersion(), - ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(), - "", - "Change log:", - plugin.getChangeLog(), - "", - ChatColor.GOLD + "Click for the marketplace page link.", - ChatColor.GOLD + "Right Click to edit plugin settings." + ChatColor.GOLD + plugin.getJavaPlugin().getName(), + ChatColor.GRAY + "Latest Version: " + plugin.getLatestVersion(), + ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(), + "", + "Change log:", + plugin.getChangeLog(), + "", + ChatColor.GOLD + "Click for the marketplace page link.", + ChatColor.GOLD + "Right Click to edit plugin settings." ), ClickType.LEFT, (event) -> event.player.sendMessage(plugin.getMarketplaceLink())); setAction(i, ClickType.RIGHT, (event) -> event.manager.showGUI(event.player, new PluginConfigGui(plugin.getJavaPlugin(), event.gui))); highlightItem(i); } else { setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : CompatibleMaterial.STONE, - ChatColor.GOLD + plugin.getJavaPlugin().getName(), - ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(), - "", - ChatColor.GOLD + "Click for the marketplace page link.", - ChatColor.GOLD + "Right Click to edit plugin settings." + ChatColor.GOLD + plugin.getJavaPlugin().getName(), + ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(), + "", + ChatColor.GOLD + "Click for the marketplace page link.", + ChatColor.GOLD + "Right Click to edit plugin settings." ), ClickType.LEFT, (event) -> event.player.sendMessage(plugin.getMarketplaceLink())); setAction(i, ClickType.RIGHT, (event) -> event.manager.showGUI(event.player, new PluginConfigGui(plugin.getJavaPlugin(), event.gui))); diff --git a/Core/src/main/java/com/songoda/core/database/DataMigration.java b/Core/src/main/java/com/songoda/core/database/DataMigration.java index b98f95e6..7b8dfb03 100644 --- a/Core/src/main/java/com/songoda/core/database/DataMigration.java +++ b/Core/src/main/java/com/songoda/core/database/DataMigration.java @@ -19,5 +19,4 @@ public abstract class DataMigration { public int getRevision() { return this.revision; } - } diff --git a/Core/src/main/java/com/songoda/core/database/DataMigrationManager.java b/Core/src/main/java/com/songoda/core/database/DataMigrationManager.java index 61d15645..b285b82c 100644 --- a/Core/src/main/java/com/songoda/core/database/DataMigrationManager.java +++ b/Core/src/main/java/com/songoda/core/database/DataMigrationManager.java @@ -100,5 +100,4 @@ public class DataMigrationManager { private String getMigrationsTableName() { return this.dataManagerAbstract.getTablePrefix() + "migrations"; } - } diff --git a/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java b/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java index 62c81e60..894df693 100644 --- a/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java +++ b/Core/src/main/java/com/songoda/core/database/DatabaseConnector.java @@ -30,5 +30,4 @@ public interface DatabaseConnector { interface ConnectionCallback { void accept(Connection connection) throws SQLException; } - } diff --git a/Core/src/main/java/com/songoda/core/database/MySQLConnector.java b/Core/src/main/java/com/songoda/core/database/MySQLConnector.java index d26ab86f..a86b48b3 100644 --- a/Core/src/main/java/com/songoda/core/database/MySQLConnector.java +++ b/Core/src/main/java/com/songoda/core/database/MySQLConnector.java @@ -51,5 +51,4 @@ public class MySQLConnector implements DatabaseConnector { ex.printStackTrace(); } } - } diff --git a/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java b/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java index c2d1441f..af8b0bf6 100644 --- a/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java +++ b/Core/src/main/java/com/songoda/core/database/SQLiteConnector.java @@ -57,5 +57,4 @@ public class SQLiteConnector implements DatabaseConnector { ex.printStackTrace(); } } - } diff --git a/Core/src/main/java/com/songoda/core/gui/BackgroundType.java b/Core/src/main/java/com/songoda/core/gui/BackgroundType.java index 2d002629..5d071041 100644 --- a/Core/src/main/java/com/songoda/core/gui/BackgroundType.java +++ b/Core/src/main/java/com/songoda/core/gui/BackgroundType.java @@ -10,5 +10,4 @@ public enum BackgroundType { private BackgroundType() { this.key = "minecraft:textures/gui/advancements/backgrounds/" + name().toLowerCase() + ".png"; } - } diff --git a/Core/src/main/java/com/songoda/core/gui/CustomizableGui.java b/Core/src/main/java/com/songoda/core/gui/CustomizableGui.java index 794debb6..13cf9f22 100644 --- a/Core/src/main/java/com/songoda/core/gui/CustomizableGui.java +++ b/Core/src/main/java/com/songoda/core/gui/CustomizableGui.java @@ -1,760 +1,756 @@ -package com.songoda.core.gui; - -import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.compatibility.ServerVersion; -import com.songoda.core.configuration.Config; -import com.songoda.core.configuration.ConfigSection; -import com.songoda.core.gui.methods.Clickable; -import com.songoda.core.utils.TextUtils; -import org.bukkit.Bukkit; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class CustomizableGui extends Gui { - - private static boolean showGuiKeys = false; - private int activationCount = 0; - - private static final Map loadedGuis = new HashMap<>(); - private final CustomContent customContent; - - public CustomizableGui(Plugin plugin, String guiKey) { - this(plugin, guiKey, null); - } - - public CustomizableGui(@NotNull Plugin plugin, @NotNull String guiKey, @Nullable Gui parent) { - super(parent); - - if (!loadedGuis.containsKey(guiKey) || showGuiKeys) { - File localeFolder = new File(plugin.getDataFolder(), "gui/"); - if (!localeFolder.exists()) localeFolder.mkdir(); - - Config config = new Config(plugin, "gui/" + guiKey + ".yml"); - config.load(); - - if (!config.isConfigurationSection("overrides")) { - config.setDefault("overrides.example.item", CompatibleMaterial.STONE.name(), - "This is the icon material you would like to replace", - "the current material with.") - .setDefault("overrides.example.position", 5, - "This is the current position of the icon you would like to move.", - "The number represents the cell the icon currently resides in.") - .setDefaultComment("overrides.example", - "This is just an example and does not override to any items", - "in this GUI.") - .setDefaultComment("overrides", - "For information on how to apply overrides please visit", - "https://wiki.songoda.com/Gui"); - config.saveChanges(); - } - - - if (!config.isConfigurationSection("disabled")) { - config.setDefault("disabled", Arrays.asList("example3", "example4", "example5"), - "All keys on this list will be disabled. You can add any items key here", - "if you no longer want that item in the GUI."); - config.saveChanges(); - } - - CustomContent customContent = loadedGuis.computeIfAbsent(guiKey, g -> new CustomContent(guiKey)); - loadedGuis.put(guiKey, customContent); - this.customContent = customContent; - - int rows = config.getInt("overrides.__ROWS__", -1); - if (rows != -1) - customContent.setRows(rows); - - for (ConfigSection section : config.getSections("overrides")) { - if (section.contains("row") || section.contains("col") - || section.contains("mirrorrow") || section.contains("mirrorcol")) { - if (section.contains("mirrorrow") || section.contains("mirrorcol")) - customContent.addButton(section.getNodeKey(), section.getInt("row", -1), - section.getInt("col", -1), - section.getBoolean("mirrorrow", false), - section.getBoolean("mirrorcol", false), - section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null); - else - customContent.addButton(section.getNodeKey(), section.getInt("row", -1), - section.getInt("col", -1), - section.getString("title", null), - section.isSet("lore") ? section.getStringList("lore") : null, - section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null); - } else { - customContent.addButton(section.getNodeKey(), section.getString("position", "-1"), - section.getString("title", null), - section.isSet("lore") ? section.getStringList("lore") : null, - section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null); - } - } - - for (String disabled : config.getStringList("disabled")) - customContent.disableButton(disabled); - } else { - customContent = loadedGuis.get(guiKey); - } - setPrivateDefaultAction(event -> { - if (event.clickType == ClickType.SHIFT_RIGHT) - activationCount ++; - if (activationCount >= 8 && event.player.hasPermission("songoda.admin")) { - showGuiKeys = !showGuiKeys; - activationCount = 0; - event.player.sendMessage("Gui keys " + (showGuiKeys ? "enabled" : "disabled") + "."); - } - }); - - if (customContent.isButtonCustomized("__DEFAULT__")) - blankItem = GuiUtils.getBorderItem(customContent.getCustomizedButton("__DEFAULT__").item); - } - - @NotNull - public Gui setRows(int rows) { - int customRows = customContent.getRows(); - return super.setRows(customRows != -1 ? customRows : rows); - } - - @NotNull - protected Inventory generateInventory(@NotNull GuiManager manager) { - applyCustomItems(); - return super.generateInventory(manager); - } - - public void update() { - applyCustomItems(); - super.update(); - } - - private void applyCustomItems() { - for (CustomButton customButton : customContent.getCustomButtons().values()) - if (customButton instanceof MirrorFill) - applyCustomItem(customButton); - for (CustomButton customButton : customContent.getCustomButtons().values()) - if (!(customButton instanceof MirrorFill)) - applyCustomItem(customButton); - } - - private void applyCustomItem(CustomButton customButton) { - if (customButton.row != -1 && customButton.col != -1) - if (customButton instanceof MirrorFill) - mirrorFill(customButton.key, customButton.row, customButton.col, - ((MirrorFill) customButton).mirrorRow, ((MirrorFill) customButton).mirrorCol, - customButton.createItem()); - else - setItem(customButton.key, customButton.row, customButton.col, customButton.createItem()); - else - for (Integer position : customButton.positions) - setItem(customButton.key, position, customButton.createItem()); - } - - @NotNull - public Gui setDefaultItem(@Nullable ItemStack item) { - if (item == null) return this; - applyShowGuiKeys("__DEFAULT__", item); - if (customContent.isButtonCustomized("__DEFAULT__")) - return this; - return super.setDefaultItem(item); - } - - @NotNull - public Gui setItem(@NotNull String key, int cell, @Nullable ItemStack item) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - applyShowGuiKeys(key, item); - if (customContent.isButtonCustomized(key)) { - CustomButton btn = customContent.getCustomizedButton(key); - cells = btn.applyPosition(cell); - btn.applyItem(item); - } - for (int c : cells) - setItem(c, item); - return this; - } - - @NotNull - public Gui setItem(@NotNull String key, int row, int col, @Nullable ItemStack item) { - final int cell = col + row * inventoryType.columns; - return setItem(key, cell, item); - } - - public Gui mirrorFill(@NotNull String key, int row, int col, boolean mirrorRow, boolean mirrorCol, @NotNull ItemStack item) { - if (customContent.isButtonDisabled(key)) return this; - ItemStack newItem = item.clone(); - boolean isShow = applyShowGuiKeys(key, newItem); - if (customContent.isButtonCustomized(key)) { - CustomButton btn = customContent.getCustomizedButton(key); - row = btn.applyPositionRow(row); - col = btn.applyPositionCol(col); - if (btn.applyItem(newItem)) - isShow = true; - if (btn instanceof MirrorFill) { - MirrorFill mf = (MirrorFill) btn; - mirrorRow = mf.mirrorRow; - mirrorCol = mf.mirrorCol; - } - } - return mirrorFill(row, col, mirrorRow, mirrorCol, isShow ? newItem : item); - } - - @NotNull - public Gui highlightItem(@NotNull String key, int cell) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - highlightItem(c); - return this; - } - - @NotNull - public Gui highlightItem(@NotNull String key, int row, int col) { - if (customContent.isButtonDisabled(key)) return this; - final int cell = col + row * inventoryType.columns; - return highlightItem(key, cell); - } - - @NotNull - public Gui removeHighlight(@NotNull String key, int cell) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - removeHighlight(c); - return this; - } - - @NotNull - public Gui removeHighlight(@NotNull String key, int row, int col) { - if (customContent.isButtonDisabled(key)) return this; - final int cell = col + row * inventoryType.columns; - return removeHighlight(key, cell); - } - - @NotNull - public Gui updateItemLore(@NotNull String key, int row, int col, @NotNull String... lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItemLore(key, col + row * inventoryType.columns, lore); - } - - @NotNull - public Gui updateItemLore(@NotNull String key, int cell, @NotNull String... lore) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - updateItemLore(c, lore); - return this; - } - - @NotNull - public Gui updateItemLore(@NotNull String key, int row, int col, @Nullable List lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItemLore(key, col + row * inventoryType.columns, lore); - } - - @NotNull - public Gui updateItemLore(@NotNull String key, int cell, @Nullable List lore) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - updateItemLore(c, lore); - return this; - } - - @NotNull - public Gui updateItemName(@NotNull String key, int row, int col, @Nullable String name) { - if (customContent.isButtonDisabled(key)) return this; - return updateItemName(key, col + row * inventoryType.columns, name); - } - - @NotNull - public Gui updateItemName(@NotNull String key, int cell, @Nullable String name) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - updateItemName(c, name); - return this; - } - - - @NotNull - public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @NotNull String... lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItem(key, col + row * inventoryType.columns, name, lore); - } - - @NotNull - public Gui updateItem(@NotNull String key, int cell, @Nullable String name, @NotNull String... lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItem(key, cell, name, Arrays.asList(lore)); - } - - @NotNull - public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @Nullable List lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItem(key, col + row * inventoryType.columns, name, lore); - } - - @NotNull - public Gui updateItem(@NotNull String key, int cell, @NotNull String name, @Nullable List lore) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - lore = applyShowGuiKeys(key, lore); - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - updateItem(c, name, lore); - return this; - } - - @NotNull - public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); - } - - @NotNull - public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - updateItem(c, itemTo, title, lore); - return this; - } - - @NotNull - public Gui updateItem(@NotNull String key, int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); - } - - @NotNull - public Gui updateItem(@NotNull String key, int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - updateItem(key, c, itemTo, title, lore); - return this; - } - - @NotNull - public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); - } - - @NotNull - public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List lore) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - updateItem(key, c, itemTo, title, lore); - return this; - } - - @NotNull - public Gui updateItem(@NotNull String key, int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List lore) { - if (customContent.isButtonDisabled(key)) return this; - return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); - } - - @NotNull - public Gui updateItem(@NotNull String key, int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List lore) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - updateItem(key, c, itemTo, title, lore); - return this; - } - - @NotNull - public Gui setAction(@NotNull String key, int cell, @Nullable Clickable action) { - if (customContent.isButtonDisabled(key)) return this; - setConditional(key, cell, null, action); - return this; - } - - @NotNull - public Gui setAction(@NotNull String key, int row, int col, @Nullable Clickable action) { - if (customContent.isButtonDisabled(key)) return this; - setConditional(key, col + row * inventoryType.columns, null, action); - return this; - } - - @NotNull - public Gui setAction(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) { - if (customContent.isButtonDisabled(key)) return this; - setConditional(key, cell, type, action); - return this; - } - - @NotNull - public Gui setAction(@NotNull String key, int row, int col, @Nullable ClickType type, @Nullable Clickable action) { - if (customContent.isButtonDisabled(key)) return this; - setConditional(key, col + row * inventoryType.columns, type, action); - return this; - } - - @NotNull - public Gui clearActions(@NotNull String key, int cell) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - clearActions(c); - return this; - } - - @NotNull - public Gui clearActions(@NotNull String key, int row, int col) { - if (customContent.isButtonDisabled(key)) return this; - return clearActions(key, col + row * inventoryType.columns); - } - - @NotNull - public Gui setButton(@NotNull String key, int cell, ItemStack item, @Nullable Clickable action) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - applyShowGuiKeys(key, item); - if (customContent.isButtonCustomized(key)) { - CustomButton btn = customContent.getCustomizedButton(key); - cells = btn.applyPosition(cell); - btn.applyItem(item); - } - - for (int c : cells) { - setItem(c, item); - setConditional(c, null, action); - } - return this; - } - - @NotNull - public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable Clickable action) { - if (customContent.isButtonDisabled(key)) return this; - return setButton(key, col + row * inventoryType.columns, item, action); - } - - @NotNull - public Gui setButton(@NotNull String key, int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return this; - applyShowGuiKeys(key, item); - if (customContent.isButtonCustomized(key)) { - CustomButton btn = customContent.getCustomizedButton(key); - cells = btn.applyPosition(cell); - btn.applyItem(item); - } - - for (int c : cells) - setButton(c, item, type, action); - return this; - } - - @NotNull - public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { - if (customContent.isButtonDisabled(key)) return this; - return setButton(key, col + row + inventoryType.columns, item, type, action); - } - - protected void setConditional(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) { - List cells = Collections.singletonList(cell); - if (customContent.isButtonDisabled(key)) return; - if (customContent.isButtonCustomized(key)) - cells = customContent.getCustomizedButton(key).applyPosition(cell); - - for (int c : cells) - setConditional(c, type, action); - } - - - public Gui setNextPage(ItemStack item) { - applyShowGuiKeys("__NEXT__", item); - if (customContent.isButtonCustomized("__NEXT__")) - customContent.getCustomizedButton("__NEXT__").applyItem(item); - - return super.setNextPage(item); - } - - public Gui setPrevPage(ItemStack item) { - applyShowGuiKeys("__PREV__", item); - if (customContent.isButtonCustomized("__PREV__")) - customContent.getCustomizedButton("__PREV__").applyItem(item); - - return super.setPrevPage(item); - } - - @NotNull - public Gui setNextPage(int cell, @NotNull ItemStack item) { - List cells = Collections.singletonList(cell); - applyShowGuiKeys("__NEXT__", item); - if (customContent.isButtonCustomized("__NEXT__")) { - CustomButton btn = customContent.getCustomizedButton("__NEXT__"); - cells = btn.applyPosition(cell); - btn.applyItem(item); - } - - for (int c : cells) - return super.setNextPage(c, item); - return this; - } - - @NotNull - public Gui setNextPage(int row, int col, @NotNull ItemStack item) { - applyShowGuiKeys("__NEXT__", item); - return setNextPage(col + row * inventoryType.columns, item); - } - - @NotNull - public Gui setPrevPage(int cell, @NotNull ItemStack item) { - List cells = Collections.singletonList(cell); - applyShowGuiKeys("__PREV__", item); - if (customContent.isButtonCustomized("__PREV__")) { - CustomButton btn = customContent.getCustomizedButton("__PREV__"); - cells = btn.applyPosition(cell); - btn.applyItem(item); - } - - for (int c : cells) - super.setPrevPage(c, item); - return this; - } - - @NotNull - public Gui setPrevPage(int row, int col, @NotNull ItemStack item) { - applyShowGuiKeys("__PREV__", item); - return setPrevPage(col + row * inventoryType.columns, item); - } - - private boolean applyShowGuiKeys(String key, ItemStack item) { - if (!showGuiKeys) return false; - ItemMeta meta = item.getItemMeta(); - if (meta == null) meta = Bukkit.getItemFactory().getItemMeta(item.getType()); - List lore = new ArrayList<>(Collections.singletonList("Key: " + key)); - if (meta.hasLore()) - lore.addAll(meta.getLore()); - meta.setLore(lore); - item.setItemMeta(meta); - return true; - } - - private List applyShowGuiKeys(String key, List lore) { - if (!showGuiKeys) return lore; - List newLore = new ArrayList<>(Collections.singletonList("Key: " + key)); - newLore.addAll(lore); - return newLore; - } - - private class CustomButton { - - private final String key; - - private final List positions; - private final int row; - private final int col; - - private final String title; - private final List lore; - - private final CompatibleMaterial item; - - public CustomButton(String key, List positions, String title, List lore, CompatibleMaterial item) { - this.key = key; - this.positions = positions; - this.row = -1; - this.col = -1; - this.item = item; - this.title = title; - this.lore = lore; - } - - public CustomButton(String key, int row, int col, String title, List lore, CompatibleMaterial item) { - this.key = key; - this.positions = null; - this.row = row; - this.col = col; - this.item = item; - this.title = title; - this.lore = lore; - } - - - public String getKey() { - return key; - } - - public boolean applyItem(ItemStack item) { - if (item == null) return false; - item.setType(this.item.getMaterial()); - if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_13)) - item.setDurability(this.item.getData()); - applyMeta(item); - return true; - } - - public ItemStack createItem() { - ItemStack item = this.item.getItem(); - applyMeta(item); - return item; - } - - private void applyMeta(ItemStack item) { - ItemMeta meta = item.getItemMeta(); - if (title != null) - meta.setDisplayName(TextUtils.formatText(title)); - if (lore != null) - meta.setLore(TextUtils.formatText(lore)); - item.setItemMeta(meta); - } - - public List applyPosition(int cell) { - if (row != -1 && col != -1) - return Collections.singletonList(col + row * inventoryType.columns); - return positions == null ? Collections.singletonList(cell) : positions; - } - - public int applyPositionRow(int row) { - return row == -1 ? row : row; - } - - public int applyPositionCol(int col) { - return col == -1 ? col : col; - } - } - - private class MirrorFill extends CustomButton { - - private final boolean mirrorRow; - private final boolean mirrorCol; - - public MirrorFill(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, CompatibleMaterial item) { - super(key, row, col, null, null, item); - this.mirrorRow = mirrorRow; - this.mirrorCol = mirrorCol; - } - - public boolean isMirrorRow() { - return mirrorRow; - } - - public boolean isMirrorCol() { - return mirrorCol; - } - } - - private class CustomContent { - - private final String guiKey; - private final Map customizedButtons = new HashMap<>(); - private final Map customButtons = new HashMap<>(); - private final List disabledButtons = new ArrayList<>(); - - private int rows = -1; - - public CustomContent(String guiKey) { - this.guiKey = guiKey; - } - - public String getGuiKey() { - return guiKey; - } - - public CustomButton getCustomizedButton(String key) { - return customizedButtons.get(key); - } - - public CustomButton getCustomButton(String key) { - return customizedButtons.get(key); - } - - public Map getCustomButtons() { - return Collections.unmodifiableMap(customButtons); - } - - public void addButton(String key, String position, String title, List lore, CompatibleMaterial item) { - List positions = Arrays.stream(position.split(",")) - .map(Integer::parseInt).collect(Collectors.toList()); - - CustomButton customButton = new CustomButton(key, positions, title, lore, item); - if (key.startsWith("custom_")) - customButtons.put(key, customButton); - else - customizedButtons.put(key, customButton); - } - - public void addButton(String key, int row, int col, String title, List lore, CompatibleMaterial item) { - CustomButton customButton = new CustomButton(key, row, col, title, lore, item); - if (key.startsWith("custom_")) - customButtons.put(key, customButton); - else - customizedButtons.put(key, customButton); - } - - public void addButton(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, CompatibleMaterial item) { - MirrorFill mirrorFill = new MirrorFill(key, row, col, mirrorRow, mirrorCol, item); - if (key.startsWith("custom_")) - customButtons.put(key, mirrorFill); - else - customizedButtons.put(key, mirrorFill); - } - - public boolean isButtonCustomized(String key) { - return customizedButtons.containsKey(key); - } - - public void disableButton(String button) { - disabledButtons.add(button); - } - - public boolean isButtonDisabled(String button) { - return disabledButtons.contains(button); - } - - public int getRows() { - return rows; - } - - public void setRows(int rows) { - this.rows = rows; - } - } -} +package com.songoda.core.gui; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.ServerVersion; +import com.songoda.core.configuration.Config; +import com.songoda.core.configuration.ConfigSection; +import com.songoda.core.gui.methods.Clickable; +import com.songoda.core.utils.TextUtils; +import org.bukkit.Bukkit; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class CustomizableGui extends Gui { + + private static boolean showGuiKeys = false; + private int activationCount = 0; + + private static final Map loadedGuis = new HashMap<>(); + private final CustomContent customContent; + + public CustomizableGui(Plugin plugin, String guiKey) { + this(plugin, guiKey, null); + } + + public CustomizableGui(@NotNull Plugin plugin, @NotNull String guiKey, @Nullable Gui parent) { + super(parent); + + if (!loadedGuis.containsKey(guiKey) || showGuiKeys) { + File localeFolder = new File(plugin.getDataFolder(), "gui/"); + if (!localeFolder.exists()) localeFolder.mkdir(); + + Config config = new Config(plugin, "gui/" + guiKey + ".yml"); + config.load(); + + if (!config.isConfigurationSection("overrides")) { + config.setDefault("overrides.example.item", CompatibleMaterial.STONE.name(), + "This is the icon material you would like to replace", + "the current material with.") + .setDefault("overrides.example.position", 5, + "This is the current position of the icon you would like to move.", + "The number represents the cell the icon currently resides in.") + .setDefaultComment("overrides.example", + "This is just an example and does not override to any items", + "in this GUI.") + .setDefaultComment("overrides", + "For information on how to apply overrides please visit", + "https://wiki.songoda.com/Gui"); + config.saveChanges(); + } + + if (!config.isConfigurationSection("disabled")) { + config.setDefault("disabled", Arrays.asList("example3", "example4", "example5"), + "All keys on this list will be disabled. You can add any items key here", + "if you no longer want that item in the GUI."); + config.saveChanges(); + } + + CustomContent customContent = loadedGuis.computeIfAbsent(guiKey, g -> new CustomContent(guiKey)); + loadedGuis.put(guiKey, customContent); + this.customContent = customContent; + + int rows = config.getInt("overrides.__ROWS__", -1); + if (rows != -1) + customContent.setRows(rows); + + for (ConfigSection section : config.getSections("overrides")) { + if (section.contains("row") || section.contains("col") + || section.contains("mirrorrow") || section.contains("mirrorcol")) { + if (section.contains("mirrorrow") || section.contains("mirrorcol")) + customContent.addButton(section.getNodeKey(), section.getInt("row", -1), + section.getInt("col", -1), + section.getBoolean("mirrorrow", false), + section.getBoolean("mirrorcol", false), + section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null); + else + customContent.addButton(section.getNodeKey(), section.getInt("row", -1), + section.getInt("col", -1), + section.getString("title", null), + section.isSet("lore") ? section.getStringList("lore") : null, + section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null); + } else { + customContent.addButton(section.getNodeKey(), section.getString("position", "-1"), + section.getString("title", null), + section.isSet("lore") ? section.getStringList("lore") : null, + section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null); + } + } + + for (String disabled : config.getStringList("disabled")) + customContent.disableButton(disabled); + } else { + customContent = loadedGuis.get(guiKey); + } + setPrivateDefaultAction(event -> { + if (event.clickType == ClickType.SHIFT_RIGHT) + activationCount++; + if (activationCount >= 8 && event.player.hasPermission("songoda.admin")) { + showGuiKeys = !showGuiKeys; + activationCount = 0; + event.player.sendMessage("Gui keys " + (showGuiKeys ? "enabled" : "disabled") + "."); + } + }); + + if (customContent.isButtonCustomized("__DEFAULT__")) + blankItem = GuiUtils.getBorderItem(customContent.getCustomizedButton("__DEFAULT__").item); + } + + @NotNull + public Gui setRows(int rows) { + int customRows = customContent.getRows(); + return super.setRows(customRows != -1 ? customRows : rows); + } + + @NotNull + protected Inventory generateInventory(@NotNull GuiManager manager) { + applyCustomItems(); + return super.generateInventory(manager); + } + + public void update() { + applyCustomItems(); + super.update(); + } + + private void applyCustomItems() { + for (CustomButton customButton : customContent.getCustomButtons().values()) + if (customButton instanceof MirrorFill) + applyCustomItem(customButton); + for (CustomButton customButton : customContent.getCustomButtons().values()) + if (!(customButton instanceof MirrorFill)) + applyCustomItem(customButton); + } + + private void applyCustomItem(CustomButton customButton) { + if (customButton.row != -1 && customButton.col != -1) + if (customButton instanceof MirrorFill) + mirrorFill(customButton.key, customButton.row, customButton.col, + ((MirrorFill) customButton).mirrorRow, ((MirrorFill) customButton).mirrorCol, + customButton.createItem()); + else + setItem(customButton.key, customButton.row, customButton.col, customButton.createItem()); + else + for (Integer position : customButton.positions) + setItem(customButton.key, position, customButton.createItem()); + } + + @NotNull + public Gui setDefaultItem(@Nullable ItemStack item) { + if (item == null) return this; + applyShowGuiKeys("__DEFAULT__", item); + if (customContent.isButtonCustomized("__DEFAULT__")) + return this; + return super.setDefaultItem(item); + } + + @NotNull + public Gui setItem(@NotNull String key, int cell, @Nullable ItemStack item) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + applyShowGuiKeys(key, item); + if (customContent.isButtonCustomized(key)) { + CustomButton btn = customContent.getCustomizedButton(key); + cells = btn.applyPosition(cell); + btn.applyItem(item); + } + for (int c : cells) + setItem(c, item); + return this; + } + + @NotNull + public Gui setItem(@NotNull String key, int row, int col, @Nullable ItemStack item) { + final int cell = col + row * inventoryType.columns; + return setItem(key, cell, item); + } + + public Gui mirrorFill(@NotNull String key, int row, int col, boolean mirrorRow, boolean mirrorCol, @NotNull ItemStack item) { + if (customContent.isButtonDisabled(key)) return this; + ItemStack newItem = item.clone(); + boolean isShow = applyShowGuiKeys(key, newItem); + if (customContent.isButtonCustomized(key)) { + CustomButton btn = customContent.getCustomizedButton(key); + row = btn.applyPositionRow(row); + col = btn.applyPositionCol(col); + if (btn.applyItem(newItem)) + isShow = true; + if (btn instanceof MirrorFill) { + MirrorFill mf = (MirrorFill) btn; + mirrorRow = mf.mirrorRow; + mirrorCol = mf.mirrorCol; + } + } + return mirrorFill(row, col, mirrorRow, mirrorCol, isShow ? newItem : item); + } + + @NotNull + public Gui highlightItem(@NotNull String key, int cell) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + highlightItem(c); + return this; + } + + @NotNull + public Gui highlightItem(@NotNull String key, int row, int col) { + if (customContent.isButtonDisabled(key)) return this; + final int cell = col + row * inventoryType.columns; + return highlightItem(key, cell); + } + + @NotNull + public Gui removeHighlight(@NotNull String key, int cell) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + removeHighlight(c); + return this; + } + + @NotNull + public Gui removeHighlight(@NotNull String key, int row, int col) { + if (customContent.isButtonDisabled(key)) return this; + final int cell = col + row * inventoryType.columns; + return removeHighlight(key, cell); + } + + @NotNull + public Gui updateItemLore(@NotNull String key, int row, int col, @NotNull String... lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItemLore(key, col + row * inventoryType.columns, lore); + } + + @NotNull + public Gui updateItemLore(@NotNull String key, int cell, @NotNull String... lore) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + updateItemLore(c, lore); + return this; + } + + @NotNull + public Gui updateItemLore(@NotNull String key, int row, int col, @Nullable List lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItemLore(key, col + row * inventoryType.columns, lore); + } + + @NotNull + public Gui updateItemLore(@NotNull String key, int cell, @Nullable List lore) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + updateItemLore(c, lore); + return this; + } + + @NotNull + public Gui updateItemName(@NotNull String key, int row, int col, @Nullable String name) { + if (customContent.isButtonDisabled(key)) return this; + return updateItemName(key, col + row * inventoryType.columns, name); + } + + @NotNull + public Gui updateItemName(@NotNull String key, int cell, @Nullable String name) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + updateItemName(c, name); + return this; + } + + @NotNull + public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @NotNull String... lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItem(key, col + row * inventoryType.columns, name, lore); + } + + @NotNull + public Gui updateItem(@NotNull String key, int cell, @Nullable String name, @NotNull String... lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItem(key, cell, name, Arrays.asList(lore)); + } + + @NotNull + public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @Nullable List lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItem(key, col + row * inventoryType.columns, name, lore); + } + + @NotNull + public Gui updateItem(@NotNull String key, int cell, @NotNull String name, @Nullable List lore) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + lore = applyShowGuiKeys(key, lore); + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + updateItem(c, name, lore); + return this; + } + + @NotNull + public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); + } + + @NotNull + public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + updateItem(c, itemTo, title, lore); + return this; + } + + @NotNull + public Gui updateItem(@NotNull String key, int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); + } + + @NotNull + public Gui updateItem(@NotNull String key, int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + updateItem(key, c, itemTo, title, lore); + return this; + } + + @NotNull + public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); + } + + @NotNull + public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List lore) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + updateItem(key, c, itemTo, title, lore); + return this; + } + + @NotNull + public Gui updateItem(@NotNull String key, int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List lore) { + if (customContent.isButtonDisabled(key)) return this; + return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore); + } + + @NotNull + public Gui updateItem(@NotNull String key, int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List lore) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + updateItem(key, c, itemTo, title, lore); + return this; + } + + @NotNull + public Gui setAction(@NotNull String key, int cell, @Nullable Clickable action) { + if (customContent.isButtonDisabled(key)) return this; + setConditional(key, cell, null, action); + return this; + } + + @NotNull + public Gui setAction(@NotNull String key, int row, int col, @Nullable Clickable action) { + if (customContent.isButtonDisabled(key)) return this; + setConditional(key, col + row * inventoryType.columns, null, action); + return this; + } + + @NotNull + public Gui setAction(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) { + if (customContent.isButtonDisabled(key)) return this; + setConditional(key, cell, type, action); + return this; + } + + @NotNull + public Gui setAction(@NotNull String key, int row, int col, @Nullable ClickType type, @Nullable Clickable action) { + if (customContent.isButtonDisabled(key)) return this; + setConditional(key, col + row * inventoryType.columns, type, action); + return this; + } + + @NotNull + public Gui clearActions(@NotNull String key, int cell) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + clearActions(c); + return this; + } + + @NotNull + public Gui clearActions(@NotNull String key, int row, int col) { + if (customContent.isButtonDisabled(key)) return this; + return clearActions(key, col + row * inventoryType.columns); + } + + @NotNull + public Gui setButton(@NotNull String key, int cell, ItemStack item, @Nullable Clickable action) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + applyShowGuiKeys(key, item); + if (customContent.isButtonCustomized(key)) { + CustomButton btn = customContent.getCustomizedButton(key); + cells = btn.applyPosition(cell); + btn.applyItem(item); + } + + for (int c : cells) { + setItem(c, item); + setConditional(c, null, action); + } + return this; + } + + @NotNull + public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable Clickable action) { + if (customContent.isButtonDisabled(key)) return this; + return setButton(key, col + row * inventoryType.columns, item, action); + } + + @NotNull + public Gui setButton(@NotNull String key, int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return this; + applyShowGuiKeys(key, item); + if (customContent.isButtonCustomized(key)) { + CustomButton btn = customContent.getCustomizedButton(key); + cells = btn.applyPosition(cell); + btn.applyItem(item); + } + + for (int c : cells) + setButton(c, item, type, action); + return this; + } + + @NotNull + public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { + if (customContent.isButtonDisabled(key)) return this; + return setButton(key, col + row + inventoryType.columns, item, type, action); + } + + protected void setConditional(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) { + List cells = Collections.singletonList(cell); + if (customContent.isButtonDisabled(key)) return; + if (customContent.isButtonCustomized(key)) + cells = customContent.getCustomizedButton(key).applyPosition(cell); + + for (int c : cells) + setConditional(c, type, action); + } + + public Gui setNextPage(ItemStack item) { + applyShowGuiKeys("__NEXT__", item); + if (customContent.isButtonCustomized("__NEXT__")) + customContent.getCustomizedButton("__NEXT__").applyItem(item); + + return super.setNextPage(item); + } + + public Gui setPrevPage(ItemStack item) { + applyShowGuiKeys("__PREV__", item); + if (customContent.isButtonCustomized("__PREV__")) + customContent.getCustomizedButton("__PREV__").applyItem(item); + + return super.setPrevPage(item); + } + + @NotNull + public Gui setNextPage(int cell, @NotNull ItemStack item) { + List cells = Collections.singletonList(cell); + applyShowGuiKeys("__NEXT__", item); + if (customContent.isButtonCustomized("__NEXT__")) { + CustomButton btn = customContent.getCustomizedButton("__NEXT__"); + cells = btn.applyPosition(cell); + btn.applyItem(item); + } + + for (int c : cells) + return super.setNextPage(c, item); + return this; + } + + @NotNull + public Gui setNextPage(int row, int col, @NotNull ItemStack item) { + applyShowGuiKeys("__NEXT__", item); + return setNextPage(col + row * inventoryType.columns, item); + } + + @NotNull + public Gui setPrevPage(int cell, @NotNull ItemStack item) { + List cells = Collections.singletonList(cell); + applyShowGuiKeys("__PREV__", item); + if (customContent.isButtonCustomized("__PREV__")) { + CustomButton btn = customContent.getCustomizedButton("__PREV__"); + cells = btn.applyPosition(cell); + btn.applyItem(item); + } + + for (int c : cells) + super.setPrevPage(c, item); + return this; + } + + @NotNull + public Gui setPrevPage(int row, int col, @NotNull ItemStack item) { + applyShowGuiKeys("__PREV__", item); + return setPrevPage(col + row * inventoryType.columns, item); + } + + private boolean applyShowGuiKeys(String key, ItemStack item) { + if (!showGuiKeys) return false; + ItemMeta meta = item.getItemMeta(); + if (meta == null) meta = Bukkit.getItemFactory().getItemMeta(item.getType()); + List lore = new ArrayList<>(Collections.singletonList("Key: " + key)); + if (meta.hasLore()) + lore.addAll(meta.getLore()); + meta.setLore(lore); + item.setItemMeta(meta); + return true; + } + + private List applyShowGuiKeys(String key, List lore) { + if (!showGuiKeys) return lore; + List newLore = new ArrayList<>(Collections.singletonList("Key: " + key)); + newLore.addAll(lore); + return newLore; + } + + private class CustomButton { + + private final String key; + + private final List positions; + private final int row; + private final int col; + + private final String title; + private final List lore; + + private final CompatibleMaterial item; + + public CustomButton(String key, List positions, String title, List lore, CompatibleMaterial item) { + this.key = key; + this.positions = positions; + this.row = -1; + this.col = -1; + this.item = item; + this.title = title; + this.lore = lore; + } + + public CustomButton(String key, int row, int col, String title, List lore, CompatibleMaterial item) { + this.key = key; + this.positions = null; + this.row = row; + this.col = col; + this.item = item; + this.title = title; + this.lore = lore; + } + + public String getKey() { + return key; + } + + public boolean applyItem(ItemStack item) { + if (item == null) return false; + item.setType(this.item.getMaterial()); + if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_13)) + item.setDurability(this.item.getData()); + applyMeta(item); + return true; + } + + public ItemStack createItem() { + ItemStack item = this.item.getItem(); + applyMeta(item); + return item; + } + + private void applyMeta(ItemStack item) { + ItemMeta meta = item.getItemMeta(); + if (title != null) + meta.setDisplayName(TextUtils.formatText(title)); + if (lore != null) + meta.setLore(TextUtils.formatText(lore)); + item.setItemMeta(meta); + } + + public List applyPosition(int cell) { + if (row != -1 && col != -1) + return Collections.singletonList(col + row * inventoryType.columns); + return positions == null ? Collections.singletonList(cell) : positions; + } + + public int applyPositionRow(int row) { + return row == -1 ? row : row; + } + + public int applyPositionCol(int col) { + return col == -1 ? col : col; + } + } + + private class MirrorFill extends CustomButton { + + private final boolean mirrorRow; + private final boolean mirrorCol; + + public MirrorFill(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, CompatibleMaterial item) { + super(key, row, col, null, null, item); + this.mirrorRow = mirrorRow; + this.mirrorCol = mirrorCol; + } + + public boolean isMirrorRow() { + return mirrorRow; + } + + public boolean isMirrorCol() { + return mirrorCol; + } + } + + private class CustomContent { + + private final String guiKey; + private final Map customizedButtons = new HashMap<>(); + private final Map customButtons = new HashMap<>(); + private final List disabledButtons = new ArrayList<>(); + + private int rows = -1; + + public CustomContent(String guiKey) { + this.guiKey = guiKey; + } + + public String getGuiKey() { + return guiKey; + } + + public CustomButton getCustomizedButton(String key) { + return customizedButtons.get(key); + } + + public CustomButton getCustomButton(String key) { + return customizedButtons.get(key); + } + + public Map getCustomButtons() { + return Collections.unmodifiableMap(customButtons); + } + + public void addButton(String key, String position, String title, List lore, CompatibleMaterial item) { + List positions = Arrays.stream(position.split(",")) + .map(Integer::parseInt).collect(Collectors.toList()); + + CustomButton customButton = new CustomButton(key, positions, title, lore, item); + if (key.startsWith("custom_")) + customButtons.put(key, customButton); + else + customizedButtons.put(key, customButton); + } + + public void addButton(String key, int row, int col, String title, List lore, CompatibleMaterial item) { + CustomButton customButton = new CustomButton(key, row, col, title, lore, item); + if (key.startsWith("custom_")) + customButtons.put(key, customButton); + else + customizedButtons.put(key, customButton); + } + + public void addButton(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, CompatibleMaterial item) { + MirrorFill mirrorFill = new MirrorFill(key, row, col, mirrorRow, mirrorCol, item); + if (key.startsWith("custom_")) + customButtons.put(key, mirrorFill); + else + customizedButtons.put(key, mirrorFill); + } + + public boolean isButtonCustomized(String key) { + return customizedButtons.containsKey(key); + } + + public void disableButton(String button) { + disabledButtons.add(button); + } + + public boolean isButtonDisabled(String button) { + return disabledButtons.contains(button); + } + + public int getRows() { + return rows; + } + + public void setRows(int rows) { + this.rows = rows; + } + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/Gui.java b/Core/src/main/java/com/songoda/core/gui/Gui.java index 77c4dd3c..8f99e8cc 100644 --- a/Core/src/main/java/com/songoda/core/gui/Gui.java +++ b/Core/src/main/java/com/songoda/core/gui/Gui.java @@ -1,876 +1,875 @@ -package com.songoda.core.gui; - -import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.compatibility.CompatibleSound; -import com.songoda.core.compatibility.ServerVersion; -import com.songoda.core.gui.events.GuiClickEvent; -import com.songoda.core.gui.events.GuiCloseEvent; -import com.songoda.core.gui.events.GuiDropItemEvent; -import com.songoda.core.gui.events.GuiOpenEvent; -import com.songoda.core.gui.events.GuiPageEvent; -import com.songoda.core.gui.methods.Clickable; -import com.songoda.core.gui.methods.Closable; -import com.songoda.core.gui.methods.Droppable; -import com.songoda.core.gui.methods.Openable; -import com.songoda.core.gui.methods.Pagable; -import com.songoda.core.utils.ItemUtils; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * TODO: animated buttons - * - * @author jascotty2 - * @since 2019-08-25 - */ -public class Gui { - - protected Inventory inventory; - protected String title; - protected GuiType inventoryType = GuiType.STANDARD; - protected int rows, page = 1, pages = 1; - protected boolean acceptsItems = false; - protected boolean allowDropItems = true; - protected boolean allowClose = true; - protected final Map unlockedCells = new HashMap<>(); - protected final Map cellItems = new HashMap<>(); - protected final Map> conditionalButtons = new HashMap<>(); - protected ItemStack blankItem = GuiUtils.getBorderGlassItem(); - protected int nextPageIndex = -1, prevPageIndex = -1; - protected ItemStack nextPageItem, prevPageItem; - protected ItemStack nextPage, prevPage; - protected Gui parent = null; - protected static ItemStack AIR = new ItemStack(Material.AIR); - - protected GuiManager guiManager; - protected boolean open = false; - protected Clickable defaultClicker = null; - protected Clickable privateDefaultClicker = null; - protected Openable opener = null; - protected Closable closer = null; - protected Droppable dropper = null; - protected Pagable pager = null; - protected CompatibleSound defaultSound = CompatibleSound.UI_BUTTON_CLICK; - - public Gui() { - this.rows = 3; - } - - public Gui(@NotNull GuiType type) { - this.inventoryType = type; - switch (type) { - case HOPPER: - case DISPENSER: - this.rows = 1; - break; - default: - this.rows = 3; - } - } - - public Gui(@Nullable Gui parent) { - this.parent = parent; - } - - public Gui(int rows) { - this.rows = Math.max(1, Math.min(6, rows)); - } - - public Gui(int rows, @Nullable Gui parent) { - this.parent = parent; - this.rows = Math.max(1, Math.min(6, rows)); - } - - @NotNull - public List getPlayers() { - return inventory == null ? Collections.EMPTY_LIST - : inventory.getViewers().stream() - .filter(e -> e instanceof Player) - .map(e -> (Player) e) - .collect(Collectors.toList()); - } - - public boolean isOpen() { - // double check - if (inventory != null && inventory.getViewers().isEmpty()) { - open = false; - } - return open; - } - - public boolean getAcceptsItems() { - return acceptsItems; - } - - public Gui setAcceptsItems(boolean acceptsItems) { - this.acceptsItems = acceptsItems; - return this; - } - - /** - * If this is true, then items in the player's cursor when the GUI is closed - * will be cleared - */ - public boolean getAllowDrops() { - return allowDropItems; - } - - /** - * Set if items in the player's cursor will be cleared when the GUI is - * closed - */ - public Gui setAllowDrops(boolean allow) { - this.allowDropItems = allow; - return this; - } - - public boolean getAllowClose() { - return allowClose; - } - - public Gui setAllowClose(boolean allow) { - this.allowClose = allow; - return this; - } - - /** - * Close the GUI without calling onClose() and without opening any parent - * GUIs - */ - public void exit() { - allowClose = true; - open = false; - inventory.getViewers().stream() - .filter(e -> e instanceof Player) - .map(e -> (Player) e) - .collect(Collectors.toList()) - .forEach(Player::closeInventory); - } - - /** - * Close the GUI as if the player closed it normally - */ - public void close() { - allowClose = true; - inventory.getViewers().stream() - .filter(e -> e instanceof Player) - .map(e -> (Player) e) - .collect(Collectors.toList()) - .forEach(Player::closeInventory); - } - - @NotNull - public GuiType getType() { - return inventoryType; - } - - @NotNull - public Gui setUnlocked(int cell) { - unlockedCells.put(cell, true); - return this; - } - - @NotNull - public Gui setUnlocked(int row, int col) { - final int cell = col + row * inventoryType.columns; - unlockedCells.put(cell, true); - return this; - } - - @NotNull - public Gui setUnlockedRange(int cellFirst, int cellLast) { - for (int cell = cellFirst; cell <= cellLast; ++cell) { - unlockedCells.put(cell, true); - } - return this; - } - - @NotNull - public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) { - for (int cell = cellFirst; cell <= cellLast; ++cell) { - unlockedCells.put(cell, open); - } - return this; - } - - @NotNull - public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) { - final int last = cellColLast + cellRowLast * inventoryType.columns; - for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { - unlockedCells.put(cell, true); - } - return this; - } - - @NotNull - public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) { - final int last = cellColLast + cellRowLast * inventoryType.columns; - for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { - unlockedCells.put(cell, open); - } - return this; - } - - @NotNull - public Gui setUnlocked(int cell, boolean open) { - unlockedCells.put(cell, open); - return this; - } - - @NotNull - public Gui setUnlocked(int row, int col, boolean open) { - final int cell = col + row * inventoryType.columns; - unlockedCells.put(cell, open); - return this; - } - - @NotNull - public Gui setTitle(String title) { - if (title == null) title = ""; - if (!title.equals(this.title)) { - this.title = title; - if (inventory != null) { - // update active inventory - List toUpdate = getPlayers(); - boolean isAllowClose = allowClose; - exit(); - Inventory oldInv = inventory; - createInventory(); - inventory.setContents(oldInv.getContents()); - toUpdate.forEach(player -> player.openInventory(inventory)); - allowClose = isAllowClose; - } - } - return this; - } - - public int getRows() { - return rows; - } - - @NotNull - public Gui setRows(int rows) { - switch (inventoryType) { - case HOPPER: - case DISPENSER: - break; - default: - this.rows = Math.max(1, Math.min(6, rows)); - } - return this; - } - - @NotNull - public Gui setDefaultAction(@Nullable Clickable action) { - defaultClicker = action; - return this; - } - - @NotNull - protected Gui setPrivateDefaultAction(@Nullable Clickable action) { - privateDefaultClicker = action; - return this; - } - - @NotNull - public Gui setDefaultItem(@Nullable ItemStack item) { - blankItem = item; - return this; - } - - @Nullable - public ItemStack getDefaultItem() { - return blankItem; - } - - @Nullable - public ItemStack getItem(int cell) { - if (inventory != null && unlockedCells.getOrDefault(cell, false)) { - return inventory.getItem(cell); - } - return cellItems.get(cell); - } - - @Nullable - public ItemStack getItem(int row, int col) { - final int cell = col + row * inventoryType.columns; - if (inventory != null && unlockedCells.getOrDefault(cell, false)) { - return inventory.getItem(cell); - } - return cellItems.get(cell); - } - - @NotNull - public Gui setItem(int cell, @Nullable ItemStack item) { - cellItems.put(cell, item); - if (inventory != null && cell >= 0 && cell < inventory.getSize()) { - inventory.setItem(cell, item); - } - return this; - } - - @NotNull - public Gui setItem(int row, int col, @Nullable ItemStack item) { - final int cell = col + row * inventoryType.columns; - return setItem(cell, item); - } - - @NotNull - public Gui mirrorFill(int row, int col, boolean mirrorRow, boolean mirrorCol, ItemStack item) { - setItem(row, col, item); - if (mirrorRow) - setItem(rows - row - 1, col, item); - if (mirrorCol) - setItem(row, 8 - col, item); - if (mirrorRow && mirrorCol) - setItem(rows - row - 1, 8 - col, item); - return this; - } - - @NotNull - public Gui highlightItem(int cell) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, ItemUtils.addGlow(item)); - } - return this; - } - - @NotNull - public Gui highlightItem(int row, int col) { - final int cell = col + row * inventoryType.columns; - return highlightItem(cell); - } - - @NotNull - public Gui removeHighlight(int cell) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, ItemUtils.removeGlow(item)); - } - return this; - } - - @NotNull - public Gui removeHighlight(int row, int col) { - final int cell = col + row * inventoryType.columns; - return removeHighlight(cell); - } - - @NotNull - public Gui updateItemLore(int row, int col, @NotNull String... lore) { - return updateItemLore(col + row * inventoryType.columns, lore); - } - - @NotNull - public Gui updateItemLore(int cell, @NotNull String... lore) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, GuiUtils.updateItemLore(item, lore)); - } - return this; - } - - @NotNull - public Gui updateItemLore(int row, int col, @Nullable List lore) { - return updateItemLore(col + row * inventoryType.columns, lore); - } - - @NotNull - public Gui updateItemLore(int cell, @Nullable List lore) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, GuiUtils.updateItemLore(item, lore)); - } - return this; - } - - @NotNull - public Gui updateItemName(int row, int col, @Nullable String name) { - return updateItemName(col + row * inventoryType.columns, name); - } - - @NotNull - public Gui updateItemName(int cell, @Nullable String name) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, GuiUtils.updateItemName(item, name)); - } - return this; - } - - @NotNull - public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) { - return updateItem(col + row * inventoryType.columns, name, lore); - } - - @NotNull - public Gui updateItem(int cell, @Nullable String name, @NotNull String... lore) { - return updateItem(cell, name, Arrays.asList(lore)); - } - - @NotNull - public Gui updateItem(int row, int col, @Nullable String name, @Nullable List lore) { - return updateItem(col + row * inventoryType.columns, name, lore); - } - - @NotNull - public Gui updateItem(int cell, @NotNull String name, @Nullable List lore) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, GuiUtils.updateItem(item, name, lore)); - } - return this; - } - - @NotNull - public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { - return updateItem(col + row * inventoryType.columns, itemTo, title, lore); - } - - @NotNull - public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); - } - return this; - } - - @NotNull - public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) { - return updateItem(col + row * inventoryType.columns, itemTo, title, lore); - } - - @NotNull - public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); - } - return this; - } - - @NotNull - public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List lore) { - return updateItem(col + row * inventoryType.columns, itemTo, title, lore); - } - - @NotNull - public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List lore) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); - } - return this; - } - - @NotNull - public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List lore) { - return updateItem(col + row * inventoryType.columns, itemTo, title, lore); - } - - @NotNull - public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List lore) { - ItemStack item = cellItems.get(cell); - if (item != null && item.getType() != Material.AIR) { - setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); - } - return this; - } - - @NotNull - public Gui setAction(int cell, @Nullable Clickable action) { - setConditional(cell, null, action); - return this; - } - - @NotNull - public Gui setAction(int row, int col, @Nullable Clickable action) { - setConditional(col + row * inventoryType.columns, null, action); - return this; - } - - @NotNull - public Gui setAction(int cell, @Nullable ClickType type, @Nullable Clickable action) { - setConditional(cell, type, action); - return this; - } - - @NotNull - public Gui setAction(int row, int col, @Nullable ClickType type, @Nullable Clickable action) { - setConditional(col + row * inventoryType.columns, type, action); - return this; - } - - @NotNull - public Gui setActionForRange(int cellFirst, int cellLast, @Nullable Clickable action) { - for (int cell = cellFirst; cell <= cellLast; ++cell) { - setConditional(cell, null, action); - } - return this; - } - - @NotNull - public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable Clickable action) { - final int last = cellColLast + cellRowLast * inventoryType.columns; - for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { - setConditional(cell, null, action); - } - return this; - } - - @NotNull - public Gui setActionForRange(int cellFirst, int cellLast, @Nullable ClickType type, @Nullable Clickable action) { - for (int cell = cellFirst; cell <= cellLast; ++cell) { - setConditional(cell, type, action); - } - return this; - } - - @NotNull - public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable ClickType type, @Nullable Clickable action) { - final int last = cellColLast + cellRowLast * inventoryType.columns; - for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { - setConditional(cell, type, action); - } - return this; - } - - @NotNull - public Gui clearActions(int cell) { - conditionalButtons.remove(cell); - return this; - } - - @NotNull - public Gui clearActions(int row, int col) { - return clearActions(col + row * inventoryType.columns); - } - - @NotNull - public Gui setButton(int cell, ItemStack item, @Nullable Clickable action) { - setItem(cell, item); - setConditional(cell, null, action); - return this; - } - - @NotNull - public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable Clickable action) { - final int cell = col + row * inventoryType.columns; - setItem(cell, item); - setConditional(cell, null, action); - return this; - } - - @NotNull - public Gui setButton(int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { - setItem(cell, item); - setConditional(cell, type, action); - return this; - } - - @NotNull - public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { - final int cell = col + row * inventoryType.columns; - setItem(cell, item); - setConditional(cell, type, action); - return this; - } - - protected void setConditional(int cell, @Nullable ClickType type, @Nullable Clickable action) { - Map conditionals = conditionalButtons.computeIfAbsent(cell, k -> new HashMap()); - conditionals.put(type, action); - } - - @NotNull - public Gui setOnOpen(@Nullable Openable action) { - opener = action; - return this; - } - - @NotNull - public Gui setOnClose(@Nullable Closable action) { - closer = action; - return this; - } - - @NotNull - public Gui setOnDrop(@Nullable Droppable action) { - dropper = action; - return this; - } - - @NotNull - public Gui setOnPage(@Nullable Pagable action) { - pager = action; - return this; - } - - public Gui setNextPage(ItemStack item) { - nextPage = item; - return this; - } - - public Gui setPrevPage(ItemStack item) { - prevPage = item; - return this; - } - - public void reset() { - if (inventory != null) - inventory.clear(); - - setActionForRange(0, 53, null); - cellItems.clear(); - update(); - } - - @NotNull - public Gui setNextPage(int cell, @NotNull ItemStack item) { - nextPageItem = cellItems.get(cell); - nextPageIndex = cell; - nextPage = item; - if (page < pages) { - setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage()); - } - return this; - } - - @NotNull - public Gui setNextPage(int row, int col, @NotNull ItemStack item) { - return setNextPage(col + row * inventoryType.columns, item); - } - - @NotNull - public Gui setPrevPage(int cell, @NotNull ItemStack item) { - prevPageItem = cellItems.get(cell); - prevPageIndex = cell; - prevPage = item; - if (page > 1) { - setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage()); - } - return this; - } - - @NotNull - public Gui setPrevPage(int row, int col, @NotNull ItemStack item) { - return setPrevPage(col + row * inventoryType.columns, item); - } - - public void setPages(int pages) { - this.pages = Math.max(1, pages); - if (page > pages) { - setPage(pages); - } - } - - public void setPage(int page) { - int lastPage = this.page; - this.page = Math.max(1, Math.min(pages, page)); - if (pager != null && this.page != lastPage) { - pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); - // page markers - updatePageNavigation(); - } - } - - public void changePage(int direction) { - int lastPage = page; - this.page = Math.max(1, Math.min(pages, page + direction)); - if (pager != null && this.page != lastPage) { - pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); - // page markers - updatePageNavigation(); - } - } - - public void nextPage() { - if (page < pages) { - int lastPage = page; - ++page; - // page switch events - if (pager != null) { - pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); - - // page markers - updatePageNavigation(); - - // push new inventory to the view inventory - // shouldn't be needed since adding inventory update to setItem - //update(); - } - } - } - - public void prevPage() { - if (page > 1) { - int lastPage = page; - --page; - if (pager != null) { - pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); - - // page markers - updatePageNavigation(); - - // push new inventory to the view inventory - // shouldn't be needed since adding inventory update to setItem - //update(); - } - } - } - - protected void updatePageNavigation() { - if (prevPage != null) { - if (page > 1) { - this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage()); - } else { - this.setItem(prevPageIndex, prevPageItem); - this.clearActions(prevPageIndex); - } - } - if (nextPage != null) { - if (pages > 1 && page != pages) { - this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage()); - } else { - this.setItem(nextPageIndex, nextPageItem); - this.clearActions(nextPageIndex); - } - } - } - - @NotNull - protected Inventory getOrCreateInventory(@NotNull GuiManager manager) { - return inventory != null ? inventory : generateInventory(manager); - } - - @NotNull - protected Inventory generateInventory(@NotNull GuiManager manager) { - this.guiManager = manager; - final int cells = rows * inventoryType.columns; - - createInventory(); - for (int i = 0; i < cells; ++i) { - final ItemStack item = cellItems.get(i); - inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem)); - } - - - return inventory; - } - - protected void createInventory() { - final InventoryType t = inventoryType == null ? InventoryType.CHEST : inventoryType.type; - - switch (t) { - case DISPENSER: - case HOPPER: - inventory = new GuiHolder(guiManager, this).newInventory(t, - title == null ? "" : trimTitle(title)); - break; - default: - inventory = new GuiHolder(guiManager, this).newInventory(rows * 9, - title == null ? "" : trimTitle(title)); - } - } - - @Nullable - public Gui getParent() { - return parent; - } - - public void update() { - if (inventory == null) - return; - - final int cells = rows * inventoryType.columns; - for (int i = 0; i < cells; ++i) { - final ItemStack item = cellItems.get(i); - inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem)); - } - } - - protected static String trimTitle(String title) { - if (title == null) { - return ""; - } else if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8) && title.length() > 32) { - return title.charAt(30) == '\u00A7' ? title.substring(0, 30) : title.substring(0, 31); - } - return title; - } - - protected boolean onClickOutside(@NotNull GuiManager manager, @NotNull Player player, @NotNull InventoryClickEvent event) { - return dropper == null || dropper.onDrop(new GuiDropItemEvent(manager, this, player, event)); - } - - protected boolean onClick(@NotNull GuiManager manager, @NotNull Player player, @NotNull Inventory inventory, @NotNull InventoryClickEvent event) { - final int cell = event.getSlot(); - Map conditionals = conditionalButtons.get(cell); - Clickable button; - if (conditionals != null - && ((button = conditionals.get(event.getClick())) != null || (button = conditionals.get(null)) != null)) { - button.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); - } else { - // no event for this button - if (defaultClicker != null) { - // this is a default action, not a triggered action - defaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); - } - if (privateDefaultClicker != null) { - // this is a private default action, not a triggered action - privateDefaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); - } - return false; - } - return true; - } - - protected boolean onClickPlayerInventory(@NotNull GuiManager manager, @NotNull Player player, @NotNull Inventory openInv, @NotNull InventoryClickEvent event) { - // no events for this yet - return false; - } - - public void onOpen(@NotNull GuiManager manager, @NotNull Player player) { - open = true; - guiManager = manager; - if (opener != null) { - opener.onOpen(new GuiOpenEvent(manager, this, player)); - } - } - - public void onClose(@NotNull GuiManager manager, @NotNull Player player) { - if (!allowClose) { - manager.showGUI(player, this); - return; - } - boolean showParent = open && parent != null; - if (closer != null) { - closer.onClose(new GuiCloseEvent(manager, this, player)); - } - if (showParent) { - manager.showGUI(player, parent); - } - } - - public CompatibleSound getDefaultSound() { - return defaultSound; - } - - public void setDefaultSound(CompatibleSound sound) { - defaultSound = sound; - } -} +package com.songoda.core.gui; + +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.core.compatibility.ServerVersion; +import com.songoda.core.gui.events.GuiClickEvent; +import com.songoda.core.gui.events.GuiCloseEvent; +import com.songoda.core.gui.events.GuiDropItemEvent; +import com.songoda.core.gui.events.GuiOpenEvent; +import com.songoda.core.gui.events.GuiPageEvent; +import com.songoda.core.gui.methods.Clickable; +import com.songoda.core.gui.methods.Closable; +import com.songoda.core.gui.methods.Droppable; +import com.songoda.core.gui.methods.Openable; +import com.songoda.core.gui.methods.Pagable; +import com.songoda.core.utils.ItemUtils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * TODO: animated buttons + * + * @author jascotty2 + * @since 2019-08-25 + */ +public class Gui { + + protected Inventory inventory; + protected String title; + protected GuiType inventoryType = GuiType.STANDARD; + protected int rows, page = 1, pages = 1; + protected boolean acceptsItems = false; + protected boolean allowDropItems = true; + protected boolean allowClose = true; + protected final Map unlockedCells = new HashMap<>(); + protected final Map cellItems = new HashMap<>(); + protected final Map> conditionalButtons = new HashMap<>(); + protected ItemStack blankItem = GuiUtils.getBorderGlassItem(); + protected int nextPageIndex = -1, prevPageIndex = -1; + protected ItemStack nextPageItem, prevPageItem; + protected ItemStack nextPage, prevPage; + protected Gui parent = null; + protected static ItemStack AIR = new ItemStack(Material.AIR); + + protected GuiManager guiManager; + protected boolean open = false; + protected Clickable defaultClicker = null; + protected Clickable privateDefaultClicker = null; + protected Openable opener = null; + protected Closable closer = null; + protected Droppable dropper = null; + protected Pagable pager = null; + protected CompatibleSound defaultSound = CompatibleSound.UI_BUTTON_CLICK; + + public Gui() { + this.rows = 3; + } + + public Gui(@NotNull GuiType type) { + this.inventoryType = type; + switch (type) { + case HOPPER: + case DISPENSER: + this.rows = 1; + break; + default: + this.rows = 3; + } + } + + public Gui(@Nullable Gui parent) { + this.parent = parent; + } + + public Gui(int rows) { + this.rows = Math.max(1, Math.min(6, rows)); + } + + public Gui(int rows, @Nullable Gui parent) { + this.parent = parent; + this.rows = Math.max(1, Math.min(6, rows)); + } + + @NotNull + public List getPlayers() { + return inventory == null ? Collections.EMPTY_LIST + : inventory.getViewers().stream() + .filter(e -> e instanceof Player) + .map(e -> (Player) e) + .collect(Collectors.toList()); + } + + public boolean isOpen() { + // double check + if (inventory != null && inventory.getViewers().isEmpty()) { + open = false; + } + return open; + } + + public boolean getAcceptsItems() { + return acceptsItems; + } + + public Gui setAcceptsItems(boolean acceptsItems) { + this.acceptsItems = acceptsItems; + return this; + } + + /** + * If this is true, then items in the player's cursor when the GUI is closed + * will be cleared + */ + public boolean getAllowDrops() { + return allowDropItems; + } + + /** + * Set if items in the player's cursor will be cleared when the GUI is + * closed + */ + public Gui setAllowDrops(boolean allow) { + this.allowDropItems = allow; + return this; + } + + public boolean getAllowClose() { + return allowClose; + } + + public Gui setAllowClose(boolean allow) { + this.allowClose = allow; + return this; + } + + /** + * Close the GUI without calling onClose() and without opening any parent + * GUIs + */ + public void exit() { + allowClose = true; + open = false; + inventory.getViewers().stream() + .filter(e -> e instanceof Player) + .map(e -> (Player) e) + .collect(Collectors.toList()) + .forEach(Player::closeInventory); + } + + /** + * Close the GUI as if the player closed it normally + */ + public void close() { + allowClose = true; + inventory.getViewers().stream() + .filter(e -> e instanceof Player) + .map(e -> (Player) e) + .collect(Collectors.toList()) + .forEach(Player::closeInventory); + } + + @NotNull + public GuiType getType() { + return inventoryType; + } + + @NotNull + public Gui setUnlocked(int cell) { + unlockedCells.put(cell, true); + return this; + } + + @NotNull + public Gui setUnlocked(int row, int col) { + final int cell = col + row * inventoryType.columns; + unlockedCells.put(cell, true); + return this; + } + + @NotNull + public Gui setUnlockedRange(int cellFirst, int cellLast) { + for (int cell = cellFirst; cell <= cellLast; ++cell) { + unlockedCells.put(cell, true); + } + return this; + } + + @NotNull + public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) { + for (int cell = cellFirst; cell <= cellLast; ++cell) { + unlockedCells.put(cell, open); + } + return this; + } + + @NotNull + public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) { + final int last = cellColLast + cellRowLast * inventoryType.columns; + for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { + unlockedCells.put(cell, true); + } + return this; + } + + @NotNull + public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) { + final int last = cellColLast + cellRowLast * inventoryType.columns; + for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { + unlockedCells.put(cell, open); + } + return this; + } + + @NotNull + public Gui setUnlocked(int cell, boolean open) { + unlockedCells.put(cell, open); + return this; + } + + @NotNull + public Gui setUnlocked(int row, int col, boolean open) { + final int cell = col + row * inventoryType.columns; + unlockedCells.put(cell, open); + return this; + } + + @NotNull + public Gui setTitle(String title) { + if (title == null) title = ""; + if (!title.equals(this.title)) { + this.title = title; + if (inventory != null) { + // update active inventory + List toUpdate = getPlayers(); + boolean isAllowClose = allowClose; + exit(); + Inventory oldInv = inventory; + createInventory(); + inventory.setContents(oldInv.getContents()); + toUpdate.forEach(player -> player.openInventory(inventory)); + allowClose = isAllowClose; + } + } + return this; + } + + public int getRows() { + return rows; + } + + @NotNull + public Gui setRows(int rows) { + switch (inventoryType) { + case HOPPER: + case DISPENSER: + break; + default: + this.rows = Math.max(1, Math.min(6, rows)); + } + return this; + } + + @NotNull + public Gui setDefaultAction(@Nullable Clickable action) { + defaultClicker = action; + return this; + } + + @NotNull + protected Gui setPrivateDefaultAction(@Nullable Clickable action) { + privateDefaultClicker = action; + return this; + } + + @NotNull + public Gui setDefaultItem(@Nullable ItemStack item) { + blankItem = item; + return this; + } + + @Nullable + public ItemStack getDefaultItem() { + return blankItem; + } + + @Nullable + public ItemStack getItem(int cell) { + if (inventory != null && unlockedCells.getOrDefault(cell, false)) { + return inventory.getItem(cell); + } + return cellItems.get(cell); + } + + @Nullable + public ItemStack getItem(int row, int col) { + final int cell = col + row * inventoryType.columns; + if (inventory != null && unlockedCells.getOrDefault(cell, false)) { + return inventory.getItem(cell); + } + return cellItems.get(cell); + } + + @NotNull + public Gui setItem(int cell, @Nullable ItemStack item) { + cellItems.put(cell, item); + if (inventory != null && cell >= 0 && cell < inventory.getSize()) { + inventory.setItem(cell, item); + } + return this; + } + + @NotNull + public Gui setItem(int row, int col, @Nullable ItemStack item) { + final int cell = col + row * inventoryType.columns; + return setItem(cell, item); + } + + @NotNull + public Gui mirrorFill(int row, int col, boolean mirrorRow, boolean mirrorCol, ItemStack item) { + setItem(row, col, item); + if (mirrorRow) + setItem(rows - row - 1, col, item); + if (mirrorCol) + setItem(row, 8 - col, item); + if (mirrorRow && mirrorCol) + setItem(rows - row - 1, 8 - col, item); + return this; + } + + @NotNull + public Gui highlightItem(int cell) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, ItemUtils.addGlow(item)); + } + return this; + } + + @NotNull + public Gui highlightItem(int row, int col) { + final int cell = col + row * inventoryType.columns; + return highlightItem(cell); + } + + @NotNull + public Gui removeHighlight(int cell) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, ItemUtils.removeGlow(item)); + } + return this; + } + + @NotNull + public Gui removeHighlight(int row, int col) { + final int cell = col + row * inventoryType.columns; + return removeHighlight(cell); + } + + @NotNull + public Gui updateItemLore(int row, int col, @NotNull String... lore) { + return updateItemLore(col + row * inventoryType.columns, lore); + } + + @NotNull + public Gui updateItemLore(int cell, @NotNull String... lore) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, GuiUtils.updateItemLore(item, lore)); + } + return this; + } + + @NotNull + public Gui updateItemLore(int row, int col, @Nullable List lore) { + return updateItemLore(col + row * inventoryType.columns, lore); + } + + @NotNull + public Gui updateItemLore(int cell, @Nullable List lore) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, GuiUtils.updateItemLore(item, lore)); + } + return this; + } + + @NotNull + public Gui updateItemName(int row, int col, @Nullable String name) { + return updateItemName(col + row * inventoryType.columns, name); + } + + @NotNull + public Gui updateItemName(int cell, @Nullable String name) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, GuiUtils.updateItemName(item, name)); + } + return this; + } + + @NotNull + public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) { + return updateItem(col + row * inventoryType.columns, name, lore); + } + + @NotNull + public Gui updateItem(int cell, @Nullable String name, @NotNull String... lore) { + return updateItem(cell, name, Arrays.asList(lore)); + } + + @NotNull + public Gui updateItem(int row, int col, @Nullable String name, @Nullable List lore) { + return updateItem(col + row * inventoryType.columns, name, lore); + } + + @NotNull + public Gui updateItem(int cell, @NotNull String name, @Nullable List lore) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, GuiUtils.updateItem(item, name, lore)); + } + return this; + } + + @NotNull + public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { + return updateItem(col + row * inventoryType.columns, itemTo, title, lore); + } + + @NotNull + public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); + } + return this; + } + + @NotNull + public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) { + return updateItem(col + row * inventoryType.columns, itemTo, title, lore); + } + + @NotNull + public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); + } + return this; + } + + @NotNull + public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List lore) { + return updateItem(col + row * inventoryType.columns, itemTo, title, lore); + } + + @NotNull + public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List lore) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); + } + return this; + } + + @NotNull + public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List lore) { + return updateItem(col + row * inventoryType.columns, itemTo, title, lore); + } + + @NotNull + public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List lore) { + ItemStack item = cellItems.get(cell); + if (item != null && item.getType() != Material.AIR) { + setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore)); + } + return this; + } + + @NotNull + public Gui setAction(int cell, @Nullable Clickable action) { + setConditional(cell, null, action); + return this; + } + + @NotNull + public Gui setAction(int row, int col, @Nullable Clickable action) { + setConditional(col + row * inventoryType.columns, null, action); + return this; + } + + @NotNull + public Gui setAction(int cell, @Nullable ClickType type, @Nullable Clickable action) { + setConditional(cell, type, action); + return this; + } + + @NotNull + public Gui setAction(int row, int col, @Nullable ClickType type, @Nullable Clickable action) { + setConditional(col + row * inventoryType.columns, type, action); + return this; + } + + @NotNull + public Gui setActionForRange(int cellFirst, int cellLast, @Nullable Clickable action) { + for (int cell = cellFirst; cell <= cellLast; ++cell) { + setConditional(cell, null, action); + } + return this; + } + + @NotNull + public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable Clickable action) { + final int last = cellColLast + cellRowLast * inventoryType.columns; + for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { + setConditional(cell, null, action); + } + return this; + } + + @NotNull + public Gui setActionForRange(int cellFirst, int cellLast, @Nullable ClickType type, @Nullable Clickable action) { + for (int cell = cellFirst; cell <= cellLast; ++cell) { + setConditional(cell, type, action); + } + return this; + } + + @NotNull + public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable ClickType type, @Nullable Clickable action) { + final int last = cellColLast + cellRowLast * inventoryType.columns; + for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) { + setConditional(cell, type, action); + } + return this; + } + + @NotNull + public Gui clearActions(int cell) { + conditionalButtons.remove(cell); + return this; + } + + @NotNull + public Gui clearActions(int row, int col) { + return clearActions(col + row * inventoryType.columns); + } + + @NotNull + public Gui setButton(int cell, ItemStack item, @Nullable Clickable action) { + setItem(cell, item); + setConditional(cell, null, action); + return this; + } + + @NotNull + public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable Clickable action) { + final int cell = col + row * inventoryType.columns; + setItem(cell, item); + setConditional(cell, null, action); + return this; + } + + @NotNull + public Gui setButton(int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { + setItem(cell, item); + setConditional(cell, type, action); + return this; + } + + @NotNull + public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) { + final int cell = col + row * inventoryType.columns; + setItem(cell, item); + setConditional(cell, type, action); + return this; + } + + protected void setConditional(int cell, @Nullable ClickType type, @Nullable Clickable action) { + Map conditionals = conditionalButtons.computeIfAbsent(cell, k -> new HashMap()); + conditionals.put(type, action); + } + + @NotNull + public Gui setOnOpen(@Nullable Openable action) { + opener = action; + return this; + } + + @NotNull + public Gui setOnClose(@Nullable Closable action) { + closer = action; + return this; + } + + @NotNull + public Gui setOnDrop(@Nullable Droppable action) { + dropper = action; + return this; + } + + @NotNull + public Gui setOnPage(@Nullable Pagable action) { + pager = action; + return this; + } + + public Gui setNextPage(ItemStack item) { + nextPage = item; + return this; + } + + public Gui setPrevPage(ItemStack item) { + prevPage = item; + return this; + } + + public void reset() { + if (inventory != null) + inventory.clear(); + + setActionForRange(0, 53, null); + cellItems.clear(); + update(); + } + + @NotNull + public Gui setNextPage(int cell, @NotNull ItemStack item) { + nextPageItem = cellItems.get(cell); + nextPageIndex = cell; + nextPage = item; + if (page < pages) { + setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage()); + } + return this; + } + + @NotNull + public Gui setNextPage(int row, int col, @NotNull ItemStack item) { + return setNextPage(col + row * inventoryType.columns, item); + } + + @NotNull + public Gui setPrevPage(int cell, @NotNull ItemStack item) { + prevPageItem = cellItems.get(cell); + prevPageIndex = cell; + prevPage = item; + if (page > 1) { + setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage()); + } + return this; + } + + @NotNull + public Gui setPrevPage(int row, int col, @NotNull ItemStack item) { + return setPrevPage(col + row * inventoryType.columns, item); + } + + public void setPages(int pages) { + this.pages = Math.max(1, pages); + if (page > pages) { + setPage(pages); + } + } + + public void setPage(int page) { + int lastPage = this.page; + this.page = Math.max(1, Math.min(pages, page)); + if (pager != null && this.page != lastPage) { + pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); + // page markers + updatePageNavigation(); + } + } + + public void changePage(int direction) { + int lastPage = page; + this.page = Math.max(1, Math.min(pages, page + direction)); + if (pager != null && this.page != lastPage) { + pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); + // page markers + updatePageNavigation(); + } + } + + public void nextPage() { + if (page < pages) { + int lastPage = page; + ++page; + // page switch events + if (pager != null) { + pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); + + // page markers + updatePageNavigation(); + + // push new inventory to the view inventory + // shouldn't be needed since adding inventory update to setItem + //update(); + } + } + } + + public void prevPage() { + if (page > 1) { + int lastPage = page; + --page; + if (pager != null) { + pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page)); + + // page markers + updatePageNavigation(); + + // push new inventory to the view inventory + // shouldn't be needed since adding inventory update to setItem + //update(); + } + } + } + + protected void updatePageNavigation() { + if (prevPage != null) { + if (page > 1) { + this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage()); + } else { + this.setItem(prevPageIndex, prevPageItem); + this.clearActions(prevPageIndex); + } + } + if (nextPage != null) { + if (pages > 1 && page != pages) { + this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage()); + } else { + this.setItem(nextPageIndex, nextPageItem); + this.clearActions(nextPageIndex); + } + } + } + + @NotNull + protected Inventory getOrCreateInventory(@NotNull GuiManager manager) { + return inventory != null ? inventory : generateInventory(manager); + } + + @NotNull + protected Inventory generateInventory(@NotNull GuiManager manager) { + this.guiManager = manager; + final int cells = rows * inventoryType.columns; + + createInventory(); + for (int i = 0; i < cells; ++i) { + final ItemStack item = cellItems.get(i); + inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem)); + } + + return inventory; + } + + protected void createInventory() { + final InventoryType t = inventoryType == null ? InventoryType.CHEST : inventoryType.type; + + switch (t) { + case DISPENSER: + case HOPPER: + inventory = new GuiHolder(guiManager, this).newInventory(t, + title == null ? "" : trimTitle(title)); + break; + default: + inventory = new GuiHolder(guiManager, this).newInventory(rows * 9, + title == null ? "" : trimTitle(title)); + } + } + + @Nullable + public Gui getParent() { + return parent; + } + + public void update() { + if (inventory == null) + return; + + final int cells = rows * inventoryType.columns; + for (int i = 0; i < cells; ++i) { + final ItemStack item = cellItems.get(i); + inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem)); + } + } + + protected static String trimTitle(String title) { + if (title == null) { + return ""; + } else if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_8) && title.length() > 32) { + return title.charAt(30) == '\u00A7' ? title.substring(0, 30) : title.substring(0, 31); + } + return title; + } + + protected boolean onClickOutside(@NotNull GuiManager manager, @NotNull Player player, @NotNull InventoryClickEvent event) { + return dropper == null || dropper.onDrop(new GuiDropItemEvent(manager, this, player, event)); + } + + protected boolean onClick(@NotNull GuiManager manager, @NotNull Player player, @NotNull Inventory inventory, @NotNull InventoryClickEvent event) { + final int cell = event.getSlot(); + Map conditionals = conditionalButtons.get(cell); + Clickable button; + if (conditionals != null + && ((button = conditionals.get(event.getClick())) != null || (button = conditionals.get(null)) != null)) { + button.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); + } else { + // no event for this button + if (defaultClicker != null) { + // this is a default action, not a triggered action + defaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); + } + if (privateDefaultClicker != null) { + // this is a private default action, not a triggered action + privateDefaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true)); + } + return false; + } + return true; + } + + protected boolean onClickPlayerInventory(@NotNull GuiManager manager, @NotNull Player player, @NotNull Inventory openInv, @NotNull InventoryClickEvent event) { + // no events for this yet + return false; + } + + public void onOpen(@NotNull GuiManager manager, @NotNull Player player) { + open = true; + guiManager = manager; + if (opener != null) { + opener.onOpen(new GuiOpenEvent(manager, this, player)); + } + } + + public void onClose(@NotNull GuiManager manager, @NotNull Player player) { + if (!allowClose) { + manager.showGUI(player, this); + return; + } + boolean showParent = open && parent != null; + if (closer != null) { + closer.onClose(new GuiCloseEvent(manager, this, player)); + } + if (showParent) { + manager.showGUI(player, parent); + } + } + + public CompatibleSound getDefaultSound() { + return defaultSound; + } + + public void setDefaultSound(CompatibleSound sound) { + defaultSound = sound; + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/GuiType.java b/Core/src/main/java/com/songoda/core/gui/GuiType.java index 6ee1e910..af5e3931 100644 --- a/Core/src/main/java/com/songoda/core/gui/GuiType.java +++ b/Core/src/main/java/com/songoda/core/gui/GuiType.java @@ -1,21 +1,20 @@ -package com.songoda.core.gui; - -import org.bukkit.event.inventory.InventoryType; - -public enum GuiType { - - STANDARD(InventoryType.CHEST, 6, 9), - DISPENSER(InventoryType.DISPENSER, 9, 3), - HOPPER(InventoryType.HOPPER, 5, 1); - - protected final InventoryType type; - protected final int rows; - protected final int columns; - - private GuiType(InventoryType type, int rows, int columns) { - this.type = type; - this.rows = rows; - this.columns = columns; - } - -} \ No newline at end of file +package com.songoda.core.gui; + +import org.bukkit.event.inventory.InventoryType; + +public enum GuiType { + + STANDARD(InventoryType.CHEST, 6, 9), + DISPENSER(InventoryType.DISPENSER, 9, 3), + HOPPER(InventoryType.HOPPER, 5, 1); + + protected final InventoryType type; + protected final int rows; + protected final int columns; + + private GuiType(InventoryType type, int rows, int columns) { + this.type = type; + this.rows = rows; + this.columns = columns; + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/GuiUtils.java b/Core/src/main/java/com/songoda/core/gui/GuiUtils.java index c19d75f8..65c52a90 100644 --- a/Core/src/main/java/com/songoda/core/gui/GuiUtils.java +++ b/Core/src/main/java/com/songoda/core/gui/GuiUtils.java @@ -1,412 +1,413 @@ -package com.songoda.core.gui; - -import com.songoda.core.compatibility.CompatibleMaterial; -import org.bukkit.ChatColor; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * @author jascotty2 - * @since 2019-08-25 - */ -public class GuiUtils { - - public static ItemStack getBorderGlassItem() { - ItemStack glass = CompatibleMaterial.LIGHT_BLUE_STAINED_GLASS_PANE.getItem(); - ItemMeta glassmeta = glass.getItemMeta(); - glassmeta.setDisplayName(ChatColor.BLACK.toString()); - glass.setItemMeta(glassmeta); - return glass; - } - - public static ItemStack getBorderItem(ItemStack item) { - ItemMeta glassmeta = item.getItemMeta(); - glassmeta.setDisplayName(ChatColor.BLACK.toString()); - item.setItemMeta(glassmeta); - return item; - } - - public static ItemStack getBorderItem(CompatibleMaterial mat) { - ItemStack item = mat.getItem(); - ItemMeta glassmeta = item.getItemMeta(); - glassmeta.setDisplayName(ChatColor.BLACK.toString()); - item.setItemMeta(glassmeta); - return item; - } - - public static List getSafeLore(String... lines) { - return getSafeLore(Arrays.asList(lines)); - } - - /** - * Get a lore value that will display fine on clients using auto gui scaling - * - * @param lines lines to format - * @return newline and length-corrected item lore - */ - public static List getSafeLore(List lines) { - // fix newlines - ArrayList newLore = new ArrayList(); - for (String l : lines) { - for (String l2 : l.split("\n")) { - if (l2.length() < 54) { - newLore.add(l2); - } else { - // try to shorten the string - String shorterString = l2; - ChatColor lastColor = null; // todo? probably should also track formatting codes.. - int line = 0; - while (shorterString.length() > 50) { - int breakingSpace = -1; - for (int i = 0; i < 50; ++i) { - if (shorterString.charAt(i) == ChatColor.COLOR_CHAR) { - lastColor = ChatColor.getByChar(shorterString.charAt(++i)); - } else if (shorterString.charAt(i) == ' ' || shorterString.charAt(i) == '-') { - breakingSpace = i; - } - } - if (breakingSpace == -1) { - breakingSpace = Math.max(50, shorterString.length()); - newLore.add((line != 0 && lastColor != null ? lastColor.toString() : "") + shorterString.substring(0, breakingSpace) + "-"); - shorterString = breakingSpace == shorterString.length() ? "" : shorterString.substring(breakingSpace + 1); - } else { - newLore.add((line != 0 && lastColor != null ? lastColor.toString() : "") + shorterString.substring(0, breakingSpace)); - shorterString = breakingSpace == shorterString.length() ? "" : shorterString.substring(breakingSpace + 1); - } - ++line; - } - if (!shorterString.isEmpty()) { - newLore.add((line != 0 && lastColor != null ? lastColor.toString() : "") + " " + shorterString); - } - } - } - } - return newLore; - } - - public static ItemStack createButtonItem(CompatibleMaterial mat, String title, String... lore) { - ItemStack item = mat.getItem(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, String... lore) { - ItemStack item = mat.getItem(); - item.setAmount(amount); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(ItemStack from, String title, String... lore) { - ItemStack item = from.clone(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(CompatibleMaterial mat, String title, List lore) { - ItemStack item = mat.getItem(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, List lore) { - ItemStack item = mat.getItem(); - item.setAmount(amount); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(ItemStack from, String title, List lore) { - ItemStack item = from.clone(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(CompatibleMaterial mat, String[] lore) { - ItemStack item = mat.getItem(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - if (lore != null && lore.length != 0) { - List safe = getSafeLore(lore); - meta.setDisplayName(safe.get(0)); - meta.setLore(safe.subList(1, safe.size())); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String[] lore) { - ItemStack item = mat.getItem(); - item.setAmount(amount); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - if (lore != null && lore.length != 0) { - List safe = getSafeLore(lore); - meta.setDisplayName(safe.get(0)); - meta.setLore(safe.subList(1, safe.size())); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(ItemStack from, String[] lore) { - ItemStack item = from.clone(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - if (lore != null && lore.length != 0) { - List safe = getSafeLore(lore); - meta.setDisplayName(safe.get(0)); - meta.setLore(safe.subList(1, safe.size())); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(CompatibleMaterial mat, List lore) { - ItemStack item = mat.getItem(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - if (lore != null && !lore.isEmpty()) { - List safe = getSafeLore(lore); - meta.setDisplayName(safe.get(0)); - meta.setLore(safe.subList(1, safe.size())); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, List lore) { - ItemStack item = mat.getItem(); - item.setAmount(amount); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - if (lore != null && !lore.isEmpty()) { - List safe = getSafeLore(lore); - meta.setDisplayName(safe.get(0)); - meta.setLore(safe.subList(1, safe.size())); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack createButtonItem(ItemStack from, List lore) { - ItemStack item = from.clone(); - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - if (lore != null && !lore.isEmpty()) { - List safe = getSafeLore(lore); - meta.setDisplayName(safe.get(0)); - meta.setLore(safe.subList(1, safe.size())); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItem(ItemStack item, String title, String... lore) { - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItemName(ItemStack item, String title) { - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItemLore(ItemStack item, String... lore) { - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - if (lore != null && lore.length != 0) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItemLore(ItemStack item, List lore) { - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, String... lore) { - if (!matTo.matches(item)) { - item = matTo.getItem(); - } - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItem(ItemStack item, ItemStack to, String title, String... lore) { - if (!CompatibleMaterial.getMaterial(item).matches(to)) { - item = to.clone(); - } - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItem(ItemStack item, String title, List lore) { - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, List lore) { - if (!matTo.matches(item)) { - item = matTo.getItem(); - } - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } - - public static ItemStack updateItem(ItemStack item, ItemStack to, String title, List lore) { - if (!CompatibleMaterial.getMaterial(item).matches(to)) { - item = to.clone(); - } - ItemMeta meta = item.getItemMeta(); - if (meta != null) { - meta.setDisplayName(title); - if (lore != null) { - meta.setLore(getSafeLore(lore)); - } else { - meta.setLore(Collections.EMPTY_LIST); - } - item.setItemMeta(meta); - } - return item; - } -} +package com.songoda.core.gui; + +import com.songoda.core.compatibility.CompatibleMaterial; +import org.bukkit.ChatColor; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @author jascotty2 + * @since 2019-08-25 + */ +public class GuiUtils { + + public static ItemStack getBorderGlassItem() { + ItemStack glass = CompatibleMaterial.LIGHT_BLUE_STAINED_GLASS_PANE.getItem(); + ItemMeta glassmeta = glass.getItemMeta(); + glassmeta.setDisplayName(ChatColor.BLACK.toString()); + glass.setItemMeta(glassmeta); + return glass; + } + + public static ItemStack getBorderItem(ItemStack item) { + ItemMeta glassmeta = item.getItemMeta(); + glassmeta.setDisplayName(ChatColor.BLACK.toString()); + item.setItemMeta(glassmeta); + return item; + } + + public static ItemStack getBorderItem(CompatibleMaterial mat) { + ItemStack item = mat.getItem(); + ItemMeta glassmeta = item.getItemMeta(); + glassmeta.setDisplayName(ChatColor.BLACK.toString()); + item.setItemMeta(glassmeta); + return item; + } + + public static List getSafeLore(String... lines) { + return getSafeLore(Arrays.asList(lines)); + } + + /** + * Get a lore value that will display fine on clients using auto gui scaling + * + * @param lines lines to format + * + * @return newline and length-corrected item lore + */ + public static List getSafeLore(List lines) { + // fix newlines + ArrayList newLore = new ArrayList(); + for (String l : lines) { + for (String l2 : l.split("\n")) { + if (l2.length() < 54) { + newLore.add(l2); + } else { + // try to shorten the string + String shorterString = l2; + ChatColor lastColor = null; // todo? probably should also track formatting codes.. + int line = 0; + while (shorterString.length() > 50) { + int breakingSpace = -1; + for (int i = 0; i < 50; ++i) { + if (shorterString.charAt(i) == ChatColor.COLOR_CHAR) { + lastColor = ChatColor.getByChar(shorterString.charAt(++i)); + } else if (shorterString.charAt(i) == ' ' || shorterString.charAt(i) == '-') { + breakingSpace = i; + } + } + if (breakingSpace == -1) { + breakingSpace = Math.max(50, shorterString.length()); + newLore.add((line != 0 && lastColor != null ? lastColor.toString() : "") + shorterString.substring(0, breakingSpace) + "-"); + shorterString = breakingSpace == shorterString.length() ? "" : shorterString.substring(breakingSpace + 1); + } else { + newLore.add((line != 0 && lastColor != null ? lastColor.toString() : "") + shorterString.substring(0, breakingSpace)); + shorterString = breakingSpace == shorterString.length() ? "" : shorterString.substring(breakingSpace + 1); + } + ++line; + } + if (!shorterString.isEmpty()) { + newLore.add((line != 0 && lastColor != null ? lastColor.toString() : "") + " " + shorterString); + } + } + } + } + return newLore; + } + + public static ItemStack createButtonItem(CompatibleMaterial mat, String title, String... lore) { + ItemStack item = mat.getItem(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, String... lore) { + ItemStack item = mat.getItem(); + item.setAmount(amount); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(ItemStack from, String title, String... lore) { + ItemStack item = from.clone(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(CompatibleMaterial mat, String title, List lore) { + ItemStack item = mat.getItem(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, List lore) { + ItemStack item = mat.getItem(); + item.setAmount(amount); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(ItemStack from, String title, List lore) { + ItemStack item = from.clone(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(CompatibleMaterial mat, String[] lore) { + ItemStack item = mat.getItem(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + if (lore != null && lore.length != 0) { + List safe = getSafeLore(lore); + meta.setDisplayName(safe.get(0)); + meta.setLore(safe.subList(1, safe.size())); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String[] lore) { + ItemStack item = mat.getItem(); + item.setAmount(amount); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + if (lore != null && lore.length != 0) { + List safe = getSafeLore(lore); + meta.setDisplayName(safe.get(0)); + meta.setLore(safe.subList(1, safe.size())); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(ItemStack from, String[] lore) { + ItemStack item = from.clone(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + if (lore != null && lore.length != 0) { + List safe = getSafeLore(lore); + meta.setDisplayName(safe.get(0)); + meta.setLore(safe.subList(1, safe.size())); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(CompatibleMaterial mat, List lore) { + ItemStack item = mat.getItem(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + if (lore != null && !lore.isEmpty()) { + List safe = getSafeLore(lore); + meta.setDisplayName(safe.get(0)); + meta.setLore(safe.subList(1, safe.size())); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, List lore) { + ItemStack item = mat.getItem(); + item.setAmount(amount); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + if (lore != null && !lore.isEmpty()) { + List safe = getSafeLore(lore); + meta.setDisplayName(safe.get(0)); + meta.setLore(safe.subList(1, safe.size())); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack createButtonItem(ItemStack from, List lore) { + ItemStack item = from.clone(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + if (lore != null && !lore.isEmpty()) { + List safe = getSafeLore(lore); + meta.setDisplayName(safe.get(0)); + meta.setLore(safe.subList(1, safe.size())); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItem(ItemStack item, String title, String... lore) { + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItemName(ItemStack item, String title) { + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItemLore(ItemStack item, String... lore) { + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + if (lore != null && lore.length != 0) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItemLore(ItemStack item, List lore) { + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, String... lore) { + if (!matTo.matches(item)) { + item = matTo.getItem(); + } + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItem(ItemStack item, ItemStack to, String title, String... lore) { + if (!CompatibleMaterial.getMaterial(item).matches(to)) { + item = to.clone(); + } + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItem(ItemStack item, String title, List lore) { + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, List lore) { + if (!matTo.matches(item)) { + item = matTo.getItem(); + } + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } + + public static ItemStack updateItem(ItemStack item, ItemStack to, String title, List lore) { + if (!CompatibleMaterial.getMaterial(item).matches(to)) { + item = to.clone(); + } + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.setDisplayName(title); + if (lore != null) { + meta.setLore(getSafeLore(lore)); + } else { + meta.setLore(Collections.EMPTY_LIST); + } + item.setItemMeta(meta); + } + return item; + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/PopupMessage.java b/Core/src/main/java/com/songoda/core/gui/PopupMessage.java index 0d88cf45..76067e85 100644 --- a/Core/src/main/java/com/songoda/core/gui/PopupMessage.java +++ b/Core/src/main/java/com/songoda/core/gui/PopupMessage.java @@ -1,187 +1,186 @@ -package com.songoda.core.gui; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.compatibility.ServerVersion; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.chat.ComponentSerializer; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; -import org.bukkit.advancement.Advancement; -import org.bukkit.advancement.AdvancementProgress; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import java.util.HashSet; -import java.util.UUID; - -/** - * Instance of a popup message that can be sent to a player
- * Popup toast messages only work on Minecraft 1.12+
- * Calling this class on anything below 1.12 will cause ClassLoader Exceptions! - */ -class PopupMessage { - - private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - private static final HashSet registeredMessages = new HashSet(); - - final UUID id = UUID.randomUUID(); - private final NamespacedKey key; - private final TextComponent title; - CompatibleMaterial icon; - TriggerType trigger = TriggerType.IMPOSSIBLE; - FrameType frame = FrameType.GOAL; // TASK is the default - BackgroundType background = BackgroundType.ADVENTURE; - - PopupMessage(Plugin source, CompatibleMaterial icon, String title) { - this.key = new NamespacedKey(source, "popup/" + id); - this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "...")); - this.icon = icon; - } - - PopupMessage(Plugin source, CompatibleMaterial icon, String title, BackgroundType background) { - this.key = new NamespacedKey(source, "popup/" + id); - this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "...")); - this.icon = icon; - this.background = background; - } - - private String getJSON() { - JsonObject json = new JsonObject(); - JsonObject advDisplay = new JsonObject(); - if (this.icon != null) { - JsonObject displayIcon = new JsonObject(); - displayIcon.addProperty("item", "minecraft:" + this.icon.getMaterial().name().toLowerCase()); - if (this.icon.usesData()) { - displayIcon.addProperty("data", this.icon.getData()); - } - advDisplay.add("icon", displayIcon); - } - advDisplay.add("title", gson.fromJson(ComponentSerializer.toString(this.title), JsonElement.class)); - advDisplay.addProperty("background", background.key); - advDisplay.addProperty("description", ""); - advDisplay.addProperty("frame", this.frame.id); - advDisplay.addProperty("announce_to_chat", false); - advDisplay.addProperty("show_toast", true); - advDisplay.addProperty("hidden", true); - json.add("display", advDisplay); - - JsonObject advCriteria = new JsonObject(); - json.add("criteria", advCriteria); - - JsonObject advTrigger = new JsonObject(); - advTrigger.addProperty("trigger", this.trigger.getKey()); - /*if() { - JsonObject advConditions = new JsonObject(); - // can add items to this list with [item,amount,data] - advTrigger.add("conditions", advConditions); - }*/ - advCriteria.add("mentioned", advTrigger); - - return gson.toJson(json); - } - - protected void grant(final Player pl) { - final Advancement adv = getAdvancement(); - final AdvancementProgress progress = pl.getAdvancementProgress(adv); - - if (!progress.isDone()) - progress.getRemainingCriteria().forEach((crit) -> progress.awardCriteria(crit)); - } - - protected void revoke(final Player pl) { - final Advancement adv = getAdvancement(); - final AdvancementProgress prog = pl.getAdvancementProgress(adv); - - if (prog.isDone()) - prog.getAwardedCriteria().forEach((crit) -> prog.revokeCriteria(crit)); - } - - protected void add() { - if (!registeredMessages.contains(id)) { - registeredMessages.add(id); - try { - Bukkit.getUnsafe().loadAdvancement(key, getJSON()); - } catch (IllegalArgumentException e) { - Bukkit.getLogger().warning("Failed to create popup advancement!"); - } - } - } - - protected void remove() { - if (registeredMessages.contains(id)) { - registeredMessages.remove(id); - Bukkit.getUnsafe().removeAdvancement(key); - } - } - - public Advancement getAdvancement() { - return Bukkit.getAdvancement(key); - } - - public static enum FrameType { - TASK, - CHALLENGE, - GOAL; - final String id; - - private FrameType() { - id = name().toLowerCase(); - } - } - - public static enum TriggerType { - ARBITRARY_PLAYER_TICK(ServerVersion.V1_13, "TICK"), - BRED_ANIMALS, - BREWED_POTION, - CHANGED_DIMENSION, - CONSTRUCT_BEACON, - CONSUME_ITEM, - CURED_ZOMBIE_VILLAGER, - EFFECTS_CHANGED, - ENCHANTED_ITEM, - ENTER_BLOCK, - ENTITY_HURT_PLAYER, - ENTITY_KILLED_PLAYER, - IMPOSSIBLE, - INVENTORY_CHANGED, - ITEM_DURABILITY_CHANGED, - LEVITATION, - LOCATION, - NETHER_TRAVEL, - PLACED_BLOCK, - PLAYER_HURT_ENTITY, - PLAYER_KILL_ENTITY, - RECIPE_UNLOCKED, - SLEPT_IN_BED, - SUMMONED_ENTITY, - TAME_ANIMAL, - TICK, - USED_ENDER_EYE, - USED_TOTEM, - VILLAGER_TRADE; - final ServerVersion minVersion; - final String compatible; - final String key; - - private TriggerType() { - this.minVersion = ServerVersion.UNKNOWN; - this.compatible = ""; - this.key = "minecraft:" + name().toLowerCase(); - } - - private TriggerType(ServerVersion minVersion, String compatible) { - this.minVersion = minVersion; - this.compatible = compatible; - this.key = "minecraft:" + (ServerVersion.isServerVersionAtLeast(minVersion) ? name() : compatible).toLowerCase(); - } - - public String getKey() { - return key; - } - - } -} +package com.songoda.core.gui; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.ServerVersion; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.chat.ComponentSerializer; +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; +import org.bukkit.advancement.Advancement; +import org.bukkit.advancement.AdvancementProgress; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.HashSet; +import java.util.UUID; + +/** + * Instance of a popup message that can be sent to a player
+ * Popup toast messages only work on Minecraft 1.12+
+ * Calling this class on anything below 1.12 will cause ClassLoader Exceptions! + */ +class PopupMessage { + + private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + private static final HashSet registeredMessages = new HashSet(); + + final UUID id = UUID.randomUUID(); + private final NamespacedKey key; + private final TextComponent title; + CompatibleMaterial icon; + TriggerType trigger = TriggerType.IMPOSSIBLE; + FrameType frame = FrameType.GOAL; // TASK is the default + BackgroundType background = BackgroundType.ADVENTURE; + + PopupMessage(Plugin source, CompatibleMaterial icon, String title) { + this.key = new NamespacedKey(source, "popup/" + id); + this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "...")); + this.icon = icon; + } + + PopupMessage(Plugin source, CompatibleMaterial icon, String title, BackgroundType background) { + this.key = new NamespacedKey(source, "popup/" + id); + this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "...")); + this.icon = icon; + this.background = background; + } + + private String getJSON() { + JsonObject json = new JsonObject(); + JsonObject advDisplay = new JsonObject(); + if (this.icon != null) { + JsonObject displayIcon = new JsonObject(); + displayIcon.addProperty("item", "minecraft:" + this.icon.getMaterial().name().toLowerCase()); + if (this.icon.usesData()) { + displayIcon.addProperty("data", this.icon.getData()); + } + advDisplay.add("icon", displayIcon); + } + advDisplay.add("title", gson.fromJson(ComponentSerializer.toString(this.title), JsonElement.class)); + advDisplay.addProperty("background", background.key); + advDisplay.addProperty("description", ""); + advDisplay.addProperty("frame", this.frame.id); + advDisplay.addProperty("announce_to_chat", false); + advDisplay.addProperty("show_toast", true); + advDisplay.addProperty("hidden", true); + json.add("display", advDisplay); + + JsonObject advCriteria = new JsonObject(); + json.add("criteria", advCriteria); + + JsonObject advTrigger = new JsonObject(); + advTrigger.addProperty("trigger", this.trigger.getKey()); + /*if() { + JsonObject advConditions = new JsonObject(); + // can add items to this list with [item,amount,data] + advTrigger.add("conditions", advConditions); + }*/ + advCriteria.add("mentioned", advTrigger); + + return gson.toJson(json); + } + + protected void grant(final Player pl) { + final Advancement adv = getAdvancement(); + final AdvancementProgress progress = pl.getAdvancementProgress(adv); + + if (!progress.isDone()) + progress.getRemainingCriteria().forEach((crit) -> progress.awardCriteria(crit)); + } + + protected void revoke(final Player pl) { + final Advancement adv = getAdvancement(); + final AdvancementProgress prog = pl.getAdvancementProgress(adv); + + if (prog.isDone()) + prog.getAwardedCriteria().forEach((crit) -> prog.revokeCriteria(crit)); + } + + protected void add() { + if (!registeredMessages.contains(id)) { + registeredMessages.add(id); + try { + Bukkit.getUnsafe().loadAdvancement(key, getJSON()); + } catch (IllegalArgumentException e) { + Bukkit.getLogger().warning("Failed to create popup advancement!"); + } + } + } + + protected void remove() { + if (registeredMessages.contains(id)) { + registeredMessages.remove(id); + Bukkit.getUnsafe().removeAdvancement(key); + } + } + + public Advancement getAdvancement() { + return Bukkit.getAdvancement(key); + } + + public static enum FrameType { + TASK, + CHALLENGE, + GOAL; + final String id; + + private FrameType() { + id = name().toLowerCase(); + } + } + + public static enum TriggerType { + ARBITRARY_PLAYER_TICK(ServerVersion.V1_13, "TICK"), + BRED_ANIMALS, + BREWED_POTION, + CHANGED_DIMENSION, + CONSTRUCT_BEACON, + CONSUME_ITEM, + CURED_ZOMBIE_VILLAGER, + EFFECTS_CHANGED, + ENCHANTED_ITEM, + ENTER_BLOCK, + ENTITY_HURT_PLAYER, + ENTITY_KILLED_PLAYER, + IMPOSSIBLE, + INVENTORY_CHANGED, + ITEM_DURABILITY_CHANGED, + LEVITATION, + LOCATION, + NETHER_TRAVEL, + PLACED_BLOCK, + PLAYER_HURT_ENTITY, + PLAYER_KILL_ENTITY, + RECIPE_UNLOCKED, + SLEPT_IN_BED, + SUMMONED_ENTITY, + TAME_ANIMAL, + TICK, + USED_ENDER_EYE, + USED_TOTEM, + VILLAGER_TRADE; + final ServerVersion minVersion; + final String compatible; + final String key; + + private TriggerType() { + this.minVersion = ServerVersion.UNKNOWN; + this.compatible = ""; + this.key = "minecraft:" + name().toLowerCase(); + } + + private TriggerType(ServerVersion minVersion, String compatible) { + this.minVersion = minVersion; + this.compatible = compatible; + this.key = "minecraft:" + (ServerVersion.isServerVersionAtLeast(minVersion) ? name() : compatible).toLowerCase(); + } + + public String getKey() { + return key; + } + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/events/GuiClickEvent.java b/Core/src/main/java/com/songoda/core/gui/events/GuiClickEvent.java index cfa15532..7864b33b 100644 --- a/Core/src/main/java/com/songoda/core/gui/events/GuiClickEvent.java +++ b/Core/src/main/java/com/songoda/core/gui/events/GuiClickEvent.java @@ -1,29 +1,28 @@ -package com.songoda.core.gui.events; - -import com.songoda.core.gui.Gui; -import com.songoda.core.gui.GuiManager; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -public class GuiClickEvent extends GuiEvent { - public final int slot; - public final boolean guiClicked; - public final ItemStack cursor, clickedItem; - public final ClickType clickType; - public final InventoryClickEvent event; - - public GuiClickEvent(GuiManager manager, Gui gui, Player player, InventoryClickEvent event, int slot, boolean guiClicked) { - super(manager, gui, player); - this.slot = slot; - this.guiClicked = guiClicked; - this.cursor = event.getCursor(); - Inventory clicked = event.getClickedInventory(); - this.clickedItem = clicked == null ? null : clicked.getItem(event.getSlot()); - this.clickType = event.getClick(); - this.event = event; - } - -} +package com.songoda.core.gui.events; + +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiManager; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +public class GuiClickEvent extends GuiEvent { + public final int slot; + public final boolean guiClicked; + public final ItemStack cursor, clickedItem; + public final ClickType clickType; + public final InventoryClickEvent event; + + public GuiClickEvent(GuiManager manager, Gui gui, Player player, InventoryClickEvent event, int slot, boolean guiClicked) { + super(manager, gui, player); + this.slot = slot; + this.guiClicked = guiClicked; + this.cursor = event.getCursor(); + Inventory clicked = event.getClickedInventory(); + this.clickedItem = clicked == null ? null : clicked.getItem(event.getSlot()); + this.clickType = event.getClick(); + this.event = event; + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/events/GuiCloseEvent.java b/Core/src/main/java/com/songoda/core/gui/events/GuiCloseEvent.java index e70cd081..94dcedd5 100644 --- a/Core/src/main/java/com/songoda/core/gui/events/GuiCloseEvent.java +++ b/Core/src/main/java/com/songoda/core/gui/events/GuiCloseEvent.java @@ -1,13 +1,12 @@ -package com.songoda.core.gui.events; - -import com.songoda.core.gui.Gui; -import com.songoda.core.gui.GuiManager; -import org.bukkit.entity.Player; - -public class GuiCloseEvent extends GuiEvent { - - public GuiCloseEvent(GuiManager manager, Gui gui, Player player) { - super(manager, gui, player); - } - -} +package com.songoda.core.gui.events; + +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiManager; +import org.bukkit.entity.Player; + +public class GuiCloseEvent extends GuiEvent { + + public GuiCloseEvent(GuiManager manager, Gui gui, Player player) { + super(manager, gui, player); + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/events/GuiDropItemEvent.java b/Core/src/main/java/com/songoda/core/gui/events/GuiDropItemEvent.java index e9240ca9..0f90f4fa 100644 --- a/Core/src/main/java/com/songoda/core/gui/events/GuiDropItemEvent.java +++ b/Core/src/main/java/com/songoda/core/gui/events/GuiDropItemEvent.java @@ -1,22 +1,21 @@ -package com.songoda.core.gui.events; - -import com.songoda.core.gui.Gui; -import com.songoda.core.gui.GuiManager; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.ItemStack; - -public class GuiDropItemEvent extends GuiEvent { - public final ItemStack cursor; - public final ClickType clickType; - public final InventoryClickEvent event; - - public GuiDropItemEvent(GuiManager manager, Gui gui, Player player, InventoryClickEvent event) { - super(manager, gui, player); - this.cursor = event.getCursor(); - this.clickType = event.getClick(); - this.event = event; - } - -} +package com.songoda.core.gui.events; + +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiManager; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; + +public class GuiDropItemEvent extends GuiEvent { + public final ItemStack cursor; + public final ClickType clickType; + public final InventoryClickEvent event; + + public GuiDropItemEvent(GuiManager manager, Gui gui, Player player, InventoryClickEvent event) { + super(manager, gui, player); + this.cursor = event.getCursor(); + this.clickType = event.getClick(); + this.event = event; + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/events/GuiEvent.java b/Core/src/main/java/com/songoda/core/gui/events/GuiEvent.java index 1bf475a9..4bcd4e77 100644 --- a/Core/src/main/java/com/songoda/core/gui/events/GuiEvent.java +++ b/Core/src/main/java/com/songoda/core/gui/events/GuiEvent.java @@ -1,19 +1,18 @@ -package com.songoda.core.gui.events; - -import com.songoda.core.gui.Gui; -import com.songoda.core.gui.GuiManager; -import org.bukkit.entity.Player; - -public abstract class GuiEvent { - - public final GuiManager manager; - public final Gui gui; - public final Player player; - - public GuiEvent(GuiManager manager, Gui gui, Player player) { - this.manager = manager; - this.gui = gui; - this.player = player; - } - -} +package com.songoda.core.gui.events; + +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiManager; +import org.bukkit.entity.Player; + +public abstract class GuiEvent { + + public final GuiManager manager; + public final Gui gui; + public final Player player; + + public GuiEvent(GuiManager manager, Gui gui, Player player) { + this.manager = manager; + this.gui = gui; + this.player = player; + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/events/GuiOpenEvent.java b/Core/src/main/java/com/songoda/core/gui/events/GuiOpenEvent.java index 63d432df..def71475 100644 --- a/Core/src/main/java/com/songoda/core/gui/events/GuiOpenEvent.java +++ b/Core/src/main/java/com/songoda/core/gui/events/GuiOpenEvent.java @@ -1,13 +1,12 @@ -package com.songoda.core.gui.events; - -import com.songoda.core.gui.Gui; -import com.songoda.core.gui.GuiManager; -import org.bukkit.entity.Player; - -public class GuiOpenEvent extends GuiEvent { - - public GuiOpenEvent(GuiManager manager, Gui gui, Player player) { - super(manager, gui, player); - } - -} +package com.songoda.core.gui.events; + +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiManager; +import org.bukkit.entity.Player; + +public class GuiOpenEvent extends GuiEvent { + + public GuiOpenEvent(GuiManager manager, Gui gui, Player player) { + super(manager, gui, player); + } +} diff --git a/Core/src/main/java/com/songoda/core/gui/events/GuiPageEvent.java b/Core/src/main/java/com/songoda/core/gui/events/GuiPageEvent.java index e9cc065a..4d3b15fd 100644 --- a/Core/src/main/java/com/songoda/core/gui/events/GuiPageEvent.java +++ b/Core/src/main/java/com/songoda/core/gui/events/GuiPageEvent.java @@ -1,20 +1,19 @@ -package com.songoda.core.gui.events; - -import com.songoda.core.gui.Gui; -import com.songoda.core.gui.GuiManager; - -public class GuiPageEvent { - - final Gui gui; - final GuiManager manager; - final int lastPage; - final int page; - - public GuiPageEvent(Gui gui, GuiManager manager, int lastPage, int page) { - this.gui = gui; - this.manager = manager; - this.lastPage = lastPage; - this.page = page; - } - -} +package com.songoda.core.gui.events; + +import com.songoda.core.gui.Gui; +import com.songoda.core.gui.GuiManager; + +public class GuiPageEvent { + + final Gui gui; + final GuiManager manager; + final int lastPage; + final int page; + + public GuiPageEvent(Gui gui, GuiManager manager, int lastPage, int page) { + this.gui = gui; + this.manager = manager; + this.lastPage = lastPage; + this.page = page; + } +} diff --git a/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java b/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java index 7b0b36f0..5c900f58 100644 --- a/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java +++ b/Core/src/main/java/com/songoda/core/hooks/EconomyManager.java @@ -4,8 +4,6 @@ import com.songoda.core.hooks.economies.Economy; import com.songoda.core.utils.NumberUtils; import org.bukkit.OfflinePlayer; -import java.text.DecimalFormat; - /** * A convenience class for static access to an Economy HookManager */ @@ -61,6 +59,7 @@ public class EconomyManager { * Format the given amount to a human-readable string in this currency * * @param amt amount to display + * * @return a currency string as formatted by the economy plugin */ public static String formatEconomy(double amt) { @@ -71,13 +70,13 @@ public class EconomyManager { * Get the players available balance * * @param player player + * * @return the amount of available balance */ public static double getBalance(OfflinePlayer player) { if (!manager.isEnabled()) return 0; return manager.getCurrentHook().getBalance(player); - } /** @@ -86,6 +85,7 @@ public class EconomyManager { * * @param player player to check * @param cost minimum amount this player should have + * * @return true if this player can have this amount withdrawn */ public static boolean hasBalance(OfflinePlayer player, double cost) { @@ -98,6 +98,7 @@ public class EconomyManager { * * @param player player to check * @param cost amount to remove from this player + * * @return true if the total amount was withdrawn successfully */ public static boolean withdrawBalance(OfflinePlayer player, double cost) { @@ -110,6 +111,7 @@ public class EconomyManager { * * @param player player to check * @param amount amount to add to this player + * * @return true if the total amount was added successfully */ public static boolean deposit(OfflinePlayer player, double amount) { diff --git a/Core/src/main/java/com/songoda/core/hooks/HookManager.java b/Core/src/main/java/com/songoda/core/hooks/HookManager.java index 652b22e7..0f96017d 100644 --- a/Core/src/main/java/com/songoda/core/hooks/HookManager.java +++ b/Core/src/main/java/com/songoda/core/hooks/HookManager.java @@ -1,184 +1,189 @@ -package com.songoda.core.hooks; - -import org.bukkit.plugin.Plugin; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class HookManager { - - private final Class typeClass; - private T defaultHook = null; - private boolean loaded = false; - private final Map registeredHooks = new HashMap<>(); - - public HookManager(Class typeClass) { - this.typeClass = typeClass; - } - - /** - * Load all supported plugins. - */ - public void load() { - load(null); - } - - /** - * Load all supported plugins. - * - * @param hookingPlugin plugin to pass to the hook handler - */ - public void load(Plugin hookingPlugin) { - if (!loaded) { - registeredHooks.putAll(PluginHook.loadHooks(typeClass, hookingPlugin).entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, e -> (T) e.getValue()))); - if (!registeredHooks.isEmpty()) { - defaultHook = (T) registeredHooks.values().iterator().next(); - } - loaded = true; - } - } - - /** - * Get the currently selected plugin hook.
- * If none were set, then the first one found is used. - * - * @return The instance of T that was created, or null if none available. - */ - public T getCurrentHook() { - return defaultHook; - } - - /** - * Set the default hook to a different plugin, if that plugin exists.
- * If the plugin is not loaded or supported, - * the previously defined default will be used. - * - * @param name name of the plugin to use - * @return true if the default was set to this plugin - */ - public boolean setPreferredHook(String name) { - T hook = getHook(name); - if (hook != null) { - defaultHook = hook; - return true; - } - return false; - } - - /** - * Set the default hook to a different plugin, if that plugin exists.
- * If the plugin is not loaded or supported, - * the previously defined default will be used. - * - * @param plugin plugin to use - * @return true if the default was set to this plugin - */ - public boolean setPreferredHook(PluginHook plugin) { - T hook = getHook(plugin); - if (hook != null) { - defaultHook = hook; - return true; - } - return false; - } - - /** - * Try to grab the handler for this specific plugin hook. - * - * @param name plugin to use - * @return returns null if plugin is not enabled - */ - public T getHook(String name) { - if (name == null) - return null; - final String plugin = name.trim(); - return (T) registeredHooks.get(registeredHooks.keySet().stream() - .filter(type -> type.plugin.equalsIgnoreCase(plugin)) - .findFirst().orElse(null)); - } - - /** - * Try to grab the handler for this specific plugin hook. - * - * @param hook plugin to use - * @return returns null if plugin is not enabled - */ - public T getHook(PluginHook hook) { - return registeredHooks.get(hook); - } - - /** - * Grab a list of all supported and loaded plugin hooks. - * - * @return an immutable collection of the loaded handler instances - */ - public Collection getRegisteredHooks() { - return Collections.unmodifiableCollection(registeredHooks.values()); - } - - /** - * Grab a list of all supported and loaded plugin hooks. - * - * @return an immutable collection of plugin names that are loaded. - */ - public List getRegisteredPlugins() { - return registeredHooks.keySet().stream() - .map(v -> v.plugin) - .collect(Collectors.toList()); - } - - /** - * Get a list of all supported plugins that we can hook into. - * - * @return an immutable collection of plugin names that can be used. - */ - public List getPossiblePlugins() { - return PluginHook.getHooks(typeClass).stream() - .map(v -> v.plugin) - .collect(Collectors.toList()); - } - - /** - * Check to see if a specific plugin hook is enabled. - * - * @param name plugin to check - * @return true if this plugin is supported and loaded - */ - public boolean isEnabled(String name) { - return getHook(name) != null; - } - - /** - * Check to see if a specific plugin hook is enabled. - * - * @param hook plugin to check - * @return true if this plugin is supported and loaded - */ - public boolean isEnabled(PluginHook hook) { - return registeredHooks.containsKey(hook); - } - - /** - * Check to see if there is a default hook loaded. - * - * @return returns false if there are no supported plugins loaded - */ - public boolean isEnabled() { - return defaultHook != null; - } - - /** - * Get the name of the default plugin being hooked into. - * - * @return plugin name, or null if none enabled. - */ - public String getName() { - return defaultHook != null ? defaultHook.getName() : null; - } - -} +package com.songoda.core.hooks; + +import org.bukkit.plugin.Plugin; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class HookManager { + + private final Class typeClass; + private T defaultHook = null; + private boolean loaded = false; + private final Map registeredHooks = new HashMap<>(); + + public HookManager(Class typeClass) { + this.typeClass = typeClass; + } + + /** + * Load all supported plugins. + */ + public void load() { + load(null); + } + + /** + * Load all supported plugins. + * + * @param hookingPlugin plugin to pass to the hook handler + */ + public void load(Plugin hookingPlugin) { + if (!loaded) { + registeredHooks.putAll(PluginHook.loadHooks(typeClass, hookingPlugin).entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> (T) e.getValue()))); + if (!registeredHooks.isEmpty()) { + defaultHook = (T) registeredHooks.values().iterator().next(); + } + loaded = true; + } + } + + /** + * Get the currently selected plugin hook.
+ * If none were set, then the first one found is used. + * + * @return The instance of T that was created, or null if none available. + */ + public T getCurrentHook() { + return defaultHook; + } + + /** + * Set the default hook to a different plugin, if that plugin exists.
+ * If the plugin is not loaded or supported, + * the previously defined default will be used. + * + * @param name name of the plugin to use + * + * @return true if the default was set to this plugin + */ + public boolean setPreferredHook(String name) { + T hook = getHook(name); + if (hook != null) { + defaultHook = hook; + return true; + } + return false; + } + + /** + * Set the default hook to a different plugin, if that plugin exists.
+ * If the plugin is not loaded or supported, + * the previously defined default will be used. + * + * @param plugin plugin to use + * + * @return true if the default was set to this plugin + */ + public boolean setPreferredHook(PluginHook plugin) { + T hook = getHook(plugin); + if (hook != null) { + defaultHook = hook; + return true; + } + return false; + } + + /** + * Try to grab the handler for this specific plugin hook. + * + * @param name plugin to use + * + * @return returns null if plugin is not enabled + */ + public T getHook(String name) { + if (name == null) + return null; + final String plugin = name.trim(); + return (T) registeredHooks.get(registeredHooks.keySet().stream() + .filter(type -> type.plugin.equalsIgnoreCase(plugin)) + .findFirst().orElse(null)); + } + + /** + * Try to grab the handler for this specific plugin hook. + * + * @param hook plugin to use + * + * @return returns null if plugin is not enabled + */ + public T getHook(PluginHook hook) { + return registeredHooks.get(hook); + } + + /** + * Grab a list of all supported and loaded plugin hooks. + * + * @return an immutable collection of the loaded handler instances + */ + public Collection getRegisteredHooks() { + return Collections.unmodifiableCollection(registeredHooks.values()); + } + + /** + * Grab a list of all supported and loaded plugin hooks. + * + * @return an immutable collection of plugin names that are loaded. + */ + public List getRegisteredPlugins() { + return registeredHooks.keySet().stream() + .map(v -> v.plugin) + .collect(Collectors.toList()); + } + + /** + * Get a list of all supported plugins that we can hook into. + * + * @return an immutable collection of plugin names that can be used. + */ + public List getPossiblePlugins() { + return PluginHook.getHooks(typeClass).stream() + .map(v -> v.plugin) + .collect(Collectors.toList()); + } + + /** + * Check to see if a specific plugin hook is enabled. + * + * @param name plugin to check + * + * @return true if this plugin is supported and loaded + */ + public boolean isEnabled(String name) { + return getHook(name) != null; + } + + /** + * Check to see if a specific plugin hook is enabled. + * + * @param hook plugin to check + * + * @return true if this plugin is supported and loaded + */ + public boolean isEnabled(PluginHook hook) { + return registeredHooks.containsKey(hook); + } + + /** + * Check to see if there is a default hook loaded. + * + * @return returns false if there are no supported plugins loaded + */ + public boolean isEnabled() { + return defaultHook != null; + } + + /** + * Get the name of the default plugin being hooked into. + * + * @return plugin name, or null if none enabled. + */ + public String getName() { + return defaultHook != null ? defaultHook.getName() : null; + } +} diff --git a/Core/src/main/java/com/songoda/core/hooks/LogManager.java b/Core/src/main/java/com/songoda/core/hooks/LogManager.java index aba0d1d3..37e845f2 100644 --- a/Core/src/main/java/com/songoda/core/hooks/LogManager.java +++ b/Core/src/main/java/com/songoda/core/hooks/LogManager.java @@ -88,5 +88,4 @@ public class LogManager { if (manager.isEnabled()) manager.getCurrentHook().logInteraction(player, location); } - } diff --git a/Core/src/main/java/com/songoda/core/hooks/McMMOHook.java b/Core/src/main/java/com/songoda/core/hooks/McMMOHook.java index 10517b9c..558d3b39 100644 --- a/Core/src/main/java/com/songoda/core/hooks/McMMOHook.java +++ b/Core/src/main/java/com/songoda/core/hooks/McMMOHook.java @@ -1,231 +1,230 @@ -package com.songoda.core.hooks; - -import com.songoda.core.hooks.mcmmo.McMMOHandler; -import org.bukkit.block.Block; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; - -import java.util.Collection; - -public class McMMOHook { - - static boolean canHook = false; - - static { - try { - // if this class exists, we're good to use McMMO - Class.forName("com.gmail.nossr50.api.AbilityAPI"); - canHook = true; - } catch (ClassNotFoundException ex) { - } - } - - public static void addMining(Player player, Collection blocks) { - if (canHook) { - McMMOHandler.addMining(player, blocks); - } - } - - public static void addExcavation(Player player, Collection blocks) { - if (canHook) { - McMMOHandler.addExcavation(player, blocks); - } - } - - public static void addHerbalism(Player player, Collection blocks) { - if (canHook) { - McMMOHandler.addHerbalism(player, blocks); - } - } - - public static void addWoodcutting(Player player, Collection blocks) { - if (canHook) { - McMMOHandler.addWoodcutting(player, blocks); - } - } - - public static int getAcrobaticsSkill(Player player) { - return canHook ? McMMOHandler.getAcrobaticsSkill(player) : -1; - } - - public static int getAlchemySkill(Player player) { - return canHook ? McMMOHandler.getAlchemySkill(player) : -1; - } - - public static int getArcherySkill(Player player) { - return canHook ? McMMOHandler.getArcherySkill(player) : -1; - } - - public static int getAxesSkill(Player player) { - return canHook ? McMMOHandler.getAxesSkill(player) : -1; - } - - public static int getExcavationSkill(Player player) { - return canHook ? McMMOHandler.getExcavationSkill(player) : -1; - } - - public static int getFishingSkill(Player player) { - return canHook ? McMMOHandler.getFishingSkill(player) : -1; - } - - public static int getHerbalismSkill(Player player) { - return canHook ? McMMOHandler.getHerbalismSkill(player) : -1; - } - - public static int getMiningSkill(Player player) { - return canHook ? McMMOHandler.getMiningSkill(player) : -1; - } - - public static int getRepairSkill(Player player) { - return canHook ? McMMOHandler.getRepairSkill(player) : -1; - } - - public static int getSmeltingSkill(Player player) { - return canHook ? McMMOHandler.getSmeltingSkill(player) : -1; - } - - public static int getSwordsSkill(Player player) { - return canHook ? McMMOHandler.getSwordsSkill(player) : -1; - } - - public static int getTamingSkill(Player player) { - return canHook ? McMMOHandler.getTamingSkill(player) : -1; - } - - public static int getUnarmedSkill(Player player) { - return canHook ? McMMOHandler.getUnarmedSkill(player) : -1; - } - - public static int getWoodcuttingSkill(Player player) { - return canHook ? McMMOHandler.getWoodcuttingSkill(player) : -1; - } - - public static void addAcrobatics(Player player, int xp) { - if (canHook) { - McMMOHandler.addAcrobatics(player, xp); - } - } - - public static void addAlchemy(Player player, int xp) { - if (canHook) { - McMMOHandler.addAlchemy(player, xp); - } - } - - public static void addArchery(Player player, int xp) { - if (canHook) { - McMMOHandler.addArchery(player, xp); - } - } - - public static void addAxes(Player player, int xp) { - if (canHook) { - McMMOHandler.addAxes(player, xp); - } - } - - public static void addExcavation(Player player, int xp) { - if (canHook) { - McMMOHandler.addExcavation(player, xp); - } - } - - public static void addFishing(Player player, int xp) { - if (canHook) { - McMMOHandler.addFishing(player, xp); - } - } - - public static void addHerbalism(Player player, int xp) { - if (canHook) { - McMMOHandler.addHerbalism(player, xp); - } - } - - public static void addMining(Player player, int xp) { - if (canHook) { - McMMOHandler.addMining(player, xp); - } - } - - public static void addRepair(Player player, int xp) { - if (canHook) { - McMMOHandler.addRepair(player, xp); - } - } - - public static void addSmelting(Player player, int xp) { - if (canHook) { - McMMOHandler.addSmelting(player, xp); - } - } - - public static void addSwords(Player player, int xp) { - if (canHook) { - McMMOHandler.addSwords(player, xp); - } - } - - public static void addTaming(Player player, int xp) { - if (canHook) { - McMMOHandler.addTaming(player, xp); - } - } - - public static void addUnarmed(Player player, int xp) { - if (canHook) { - McMMOHandler.addUnarmed(player, xp); - } - } - - public static void addWoodcutting(Player player, int xp) { - if (canHook) { - McMMOHandler.addWoodcutting(player, xp); - } - } - - public static boolean hasHerbalismDoubleDrops(Player player) { - return canHook ? McMMOHandler.hasHerbalismDoubleDrops(player) : false; - } - - public static boolean hasMiningDoubleDrops(Player player) { - return canHook ? McMMOHandler.hasMiningDoubleDrops(player) : false; - } - - public static boolean hasWoodcuttingDoubleDrops(Player player) { - return canHook ? McMMOHandler.hasWoodcuttingDoubleDrops(player) : false; - } - - public static boolean isUsingBerserk(Player player) { - return canHook ? McMMOHandler.isUsingBerserk(player) : false; - } - - public static boolean isUsingGigaDrill(Player player) { - return canHook ? McMMOHandler.isUsingGigaDrill(player) : false; - } - - public static boolean isUsingGreenTerra(Player player) { - return canHook ? McMMOHandler.isUsingGreenTerra(player) : false; - } - - public static boolean isUsingSerratedStrikes(Player player) { - return canHook ? McMMOHandler.isUsingSerratedStrikes(player) : false; - } - - public static boolean isUsingSkullSplitter(Player player) { - return canHook ? McMMOHandler.isUsingSkullSplitter(player) : false; - } - - public static boolean isUsingSuperBreaker(Player player) { - return canHook ? McMMOHandler.isUsingSuperBreaker(player) : false; - } - - public static boolean isUsingTreeFeller(Player player) { - return canHook ? McMMOHandler.isUsingTreeFeller(player) : false; - } - - public static boolean isBleeding(LivingEntity victim) { - return canHook ? McMMOHandler.isBleeding(victim) : false; - } - -} +package com.songoda.core.hooks; + +import com.songoda.core.hooks.mcmmo.McMMOHandler; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +import java.util.Collection; + +public class McMMOHook { + + static boolean canHook = false; + + static { + try { + // if this class exists, we're good to use McMMO + Class.forName("com.gmail.nossr50.api.AbilityAPI"); + canHook = true; + } catch (ClassNotFoundException ex) { + } + } + + public static void addMining(Player player, Collection blocks) { + if (canHook) { + McMMOHandler.addMining(player, blocks); + } + } + + public static void addExcavation(Player player, Collection blocks) { + if (canHook) { + McMMOHandler.addExcavation(player, blocks); + } + } + + public static void addHerbalism(Player player, Collection blocks) { + if (canHook) { + McMMOHandler.addHerbalism(player, blocks); + } + } + + public static void addWoodcutting(Player player, Collection blocks) { + if (canHook) { + McMMOHandler.addWoodcutting(player, blocks); + } + } + + public static int getAcrobaticsSkill(Player player) { + return canHook ? McMMOHandler.getAcrobaticsSkill(player) : -1; + } + + public static int getAlchemySkill(Player player) { + return canHook ? McMMOHandler.getAlchemySkill(player) : -1; + } + + public static int getArcherySkill(Player player) { + return canHook ? McMMOHandler.getArcherySkill(player) : -1; + } + + public static int getAxesSkill(Player player) { + return canHook ? McMMOHandler.getAxesSkill(player) : -1; + } + + public static int getExcavationSkill(Player player) { + return canHook ? McMMOHandler.getExcavationSkill(player) : -1; + } + + public static int getFishingSkill(Player player) { + return canHook ? McMMOHandler.getFishingSkill(player) : -1; + } + + public static int getHerbalismSkill(Player player) { + return canHook ? McMMOHandler.getHerbalismSkill(player) : -1; + } + + public static int getMiningSkill(Player player) { + return canHook ? McMMOHandler.getMiningSkill(player) : -1; + } + + public static int getRepairSkill(Player player) { + return canHook ? McMMOHandler.getRepairSkill(player) : -1; + } + + public static int getSmeltingSkill(Player player) { + return canHook ? McMMOHandler.getSmeltingSkill(player) : -1; + } + + public static int getSwordsSkill(Player player) { + return canHook ? McMMOHandler.getSwordsSkill(player) : -1; + } + + public static int getTamingSkill(Player player) { + return canHook ? McMMOHandler.getTamingSkill(player) : -1; + } + + public static int getUnarmedSkill(Player player) { + return canHook ? McMMOHandler.getUnarmedSkill(player) : -1; + } + + public static int getWoodcuttingSkill(Player player) { + return canHook ? McMMOHandler.getWoodcuttingSkill(player) : -1; + } + + public static void addAcrobatics(Player player, int xp) { + if (canHook) { + McMMOHandler.addAcrobatics(player, xp); + } + } + + public static void addAlchemy(Player player, int xp) { + if (canHook) { + McMMOHandler.addAlchemy(player, xp); + } + } + + public static void addArchery(Player player, int xp) { + if (canHook) { + McMMOHandler.addArchery(player, xp); + } + } + + public static void addAxes(Player player, int xp) { + if (canHook) { + McMMOHandler.addAxes(player, xp); + } + } + + public static void addExcavation(Player player, int xp) { + if (canHook) { + McMMOHandler.addExcavation(player, xp); + } + } + + public static void addFishing(Player player, int xp) { + if (canHook) { + McMMOHandler.addFishing(player, xp); + } + } + + public static void addHerbalism(Player player, int xp) { + if (canHook) { + McMMOHandler.addHerbalism(player, xp); + } + } + + public static void addMining(Player player, int xp) { + if (canHook) { + McMMOHandler.addMining(player, xp); + } + } + + public static void addRepair(Player player, int xp) { + if (canHook) { + McMMOHandler.addRepair(player, xp); + } + } + + public static void addSmelting(Player player, int xp) { + if (canHook) { + McMMOHandler.addSmelting(player, xp); + } + } + + public static void addSwords(Player player, int xp) { + if (canHook) { + McMMOHandler.addSwords(player, xp); + } + } + + public static void addTaming(Player player, int xp) { + if (canHook) { + McMMOHandler.addTaming(player, xp); + } + } + + public static void addUnarmed(Player player, int xp) { + if (canHook) { + McMMOHandler.addUnarmed(player, xp); + } + } + + public static void addWoodcutting(Player player, int xp) { + if (canHook) { + McMMOHandler.addWoodcutting(player, xp); + } + } + + public static boolean hasHerbalismDoubleDrops(Player player) { + return canHook ? McMMOHandler.hasHerbalismDoubleDrops(player) : false; + } + + public static boolean hasMiningDoubleDrops(Player player) { + return canHook ? McMMOHandler.hasMiningDoubleDrops(player) : false; + } + + public static boolean hasWoodcuttingDoubleDrops(Player player) { + return canHook ? McMMOHandler.hasWoodcuttingDoubleDrops(player) : false; + } + + public static boolean isUsingBerserk(Player player) { + return canHook ? McMMOHandler.isUsingBerserk(player) : false; + } + + public static boolean isUsingGigaDrill(Player player) { + return canHook ? McMMOHandler.isUsingGigaDrill(player) : false; + } + + public static boolean isUsingGreenTerra(Player player) { + return canHook ? McMMOHandler.isUsingGreenTerra(player) : false; + } + + public static boolean isUsingSerratedStrikes(Player player) { + return canHook ? McMMOHandler.isUsingSerratedStrikes(player) : false; + } + + public static boolean isUsingSkullSplitter(Player player) { + return canHook ? McMMOHandler.isUsingSkullSplitter(player) : false; + } + + public static boolean isUsingSuperBreaker(Player player) { + return canHook ? McMMOHandler.isUsingSuperBreaker(player) : false; + } + + public static boolean isUsingTreeFeller(Player player) { + return canHook ? McMMOHandler.isUsingTreeFeller(player) : false; + } + + public static boolean isBleeding(LivingEntity victim) { + return canHook ? McMMOHandler.isBleeding(victim) : false; + } +} diff --git a/Core/src/main/java/com/songoda/core/hooks/PluginHook.java b/Core/src/main/java/com/songoda/core/hooks/PluginHook.java index f6ffc180..d4e07229 100644 --- a/Core/src/main/java/com/songoda/core/hooks/PluginHook.java +++ b/Core/src/main/java/com/songoda/core/hooks/PluginHook.java @@ -1,163 +1,169 @@ -package com.songoda.core.hooks; - -import com.songoda.core.hooks.economies.Economy; -import com.songoda.core.hooks.economies.PlayerPointsEconomy; -import com.songoda.core.hooks.economies.ReserveEconomy; -import com.songoda.core.hooks.economies.VaultEconomy; -import com.songoda.core.hooks.holograms.CMIHolograms; -import com.songoda.core.hooks.holograms.Holograms; -import com.songoda.core.hooks.holograms.HologramsHolograms; -import com.songoda.core.hooks.holograms.HolographicDisplaysHolograms; -import com.songoda.core.hooks.log.CoreProtectLog; -import com.songoda.core.hooks.log.Log; -import com.songoda.core.hooks.protection.*; -import com.songoda.core.hooks.stackers.StackMob; -import com.songoda.core.hooks.stackers.Stacker; -import com.songoda.core.hooks.stackers.UltimateStacker; -import com.songoda.core.hooks.stackers.WildStacker; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.logging.Level; -import java.util.stream.Collectors; - -public final class PluginHook { - - public static final PluginHook ECO_VAULT = new PluginHook(Economy.class, "Vault", VaultEconomy.class); - public static final PluginHook ECO_PLAYER_POINTS = new PluginHook(Economy.class, "PlayerPoints", PlayerPointsEconomy.class); - public static final PluginHook ECO_RESERVE = new PluginHook(Economy.class, "Reserve", ReserveEconomy.class); - public static final PluginHook STACKER_ULTIMATE = new PluginHook(Stacker.class, "UltimateStacker", UltimateStacker.class); - public static final PluginHook STACKER_WILD = new PluginHook(Stacker.class, "WildStacker", WildStacker.class); - public static final PluginHook STACKER_STACK_MOB = new PluginHook(Stacker.class, "StackMob", StackMob.class); - public static final PluginHook HOLO_DISPLAYS = new PluginHook(Holograms.class, "HolographicDisplays", HolographicDisplaysHolograms.class); - public static final PluginHook HOLO_HOLOGRAMS = new PluginHook(Holograms.class, "Holograms", HologramsHolograms.class); - public static final PluginHook HOLO_CMI = new PluginHook(Holograms.class, "CMI", CMIHolograms.class); - public static final PluginHook LOG_CORE_PROTECT = new PluginHook(Log.class, "CoreProtect", CoreProtectLog.class); - public static final PluginHook PROTECTION_GRIEFPREVENTION = new PluginHook(Protection.class, "GriefPrevention", GriefPreventionProtection.class); - public static final PluginHook PROTECTION_LANDS = new PluginHook(Protection.class, "Lands", LandsProtection.class); - public static final PluginHook PROTECTION_REDPROTECT = new PluginHook(Protection.class, "RedProtect", RedProtectProtection.class); - public static final PluginHook PROTECTION_ULTIMATECLAIMS = new PluginHook(Protection.class, "UltimateClaims", UltimateClaimsProtection.class); - public static final PluginHook PROTECTION_BENTOBOX = new PluginHook(Protection.class, "BentoBox", BentoBoxProtection.class); - - /******* Start Manager stuff *******/ - - protected final T hookGeneric; - protected final String plugin; - protected final Class managerClass; - protected static Map hooks; - protected Constructor pluginConstructor; // for passing the plugin loading the hook to the plugin hook - - private PluginHook(T type, String pluginName, Class handler) { - if (!Hook.class.isAssignableFrom(handler)) { - throw new RuntimeException("Tried to register a non-Hook plugin hook! " + pluginName + " -> " + handler.getName()); - } - this.hookGeneric = type; - this.plugin = pluginName; - this.managerClass = handler; - if (hooks == null) { - hooks = new LinkedHashMap(); - } - hooks.put(handler, this); - // Does this class have a plugin constructor? - try { - pluginConstructor = handler.getDeclaredConstructor(Plugin.class); - } catch (NoSuchMethodException | SecurityException ex) { - // nope! - } catch (Throwable t) { - // (can also reach here if there is a class loader exception) - hooks.remove(handler); - } - } - - /** - * Add a hook handler for us to use later.
- * NOTE: The class passed MUST extend Hook.
- * Permissible constructors are empty () or (org.bukkit.plugin.Plugin)
- * Each plugin defined must use a different handler class. - * - * @param - * @param type Generic hook type for this plugin - * @param pluginName Plugin name - * @param handler Specific class that will handle this plugin, if enabled. - * @return instance of the PluginHook that was added - */ - public static PluginHook addHook(T type, String pluginName, Class handler) { - return new PluginHook(type, pluginName, handler); - } - - protected static Map loadHooks(Class type, Plugin plugin) { - Map loaded = new LinkedHashMap<>(); - PluginManager pluginManager = Bukkit.getPluginManager(); - - for (PluginHook hook : getHooks(type)) { - if (pluginManager.isPluginEnabled(hook.plugin)) { - Hook handler = (Hook) (plugin != null ? hook.load(plugin) : hook.load()); - if (handler != null && handler.isEnabled()) { - loaded.put(hook, handler); - } - } - } - - return loaded; - } - - protected static List getHooks(Class type) { - return hooks.entrySet().parallelStream() - .filter(e -> e.getKey() == type || e.getValue().managerClass == type || type.isAssignableFrom(e.getKey())) - .map(Map.Entry::getValue) - .collect(Collectors.toList()); - } - - public String getPluginName() { - return plugin; - } - - protected Object load() { - try { - return managerClass.cast( - pluginConstructor != null - ? pluginConstructor.newInstance((Plugin) null) - : managerClass.getConstructor().newInstance()); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Unexpected Error while creating a new Hook Manager for " + plugin, ex); - } - return null; - } - - protected Object load(Plugin hookingPlugin) { - try { - return managerClass.cast( - pluginConstructor != null - ? pluginConstructor.newInstance(hookingPlugin) - : managerClass.getConstructor().newInstance()); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Unexpected Error while creating a new Hook Manager for " + plugin, ex); - } - return null; - } - - @Override - public int hashCode() { - int hash = 3; - hash = 37 * hash + Objects.hashCode(this.plugin); - hash = 37 * hash + Objects.hashCode(this.managerClass); - return hash; - } - - @Override - public boolean equals(Object obj) { - if (obj == null || getClass() != obj.getClass()) { - return false; - } - final PluginHook other = (PluginHook) obj; - return Objects.equals(this.plugin, other.plugin) - && Objects.equals(this.managerClass, other.managerClass); - } -} +package com.songoda.core.hooks; + +import com.songoda.core.hooks.economies.Economy; +import com.songoda.core.hooks.economies.PlayerPointsEconomy; +import com.songoda.core.hooks.economies.ReserveEconomy; +import com.songoda.core.hooks.economies.VaultEconomy; +import com.songoda.core.hooks.holograms.CMIHolograms; +import com.songoda.core.hooks.holograms.Holograms; +import com.songoda.core.hooks.holograms.HologramsHolograms; +import com.songoda.core.hooks.holograms.HolographicDisplaysHolograms; +import com.songoda.core.hooks.log.CoreProtectLog; +import com.songoda.core.hooks.log.Log; +import com.songoda.core.hooks.protection.BentoBoxProtection; +import com.songoda.core.hooks.protection.GriefPreventionProtection; +import com.songoda.core.hooks.protection.LandsProtection; +import com.songoda.core.hooks.protection.Protection; +import com.songoda.core.hooks.protection.RedProtectProtection; +import com.songoda.core.hooks.protection.UltimateClaimsProtection; +import com.songoda.core.hooks.stackers.StackMob; +import com.songoda.core.hooks.stackers.Stacker; +import com.songoda.core.hooks.stackers.UltimateStacker; +import com.songoda.core.hooks.stackers.WildStacker; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; +import java.util.stream.Collectors; + +public final class PluginHook { + + public static final PluginHook ECO_VAULT = new PluginHook(Economy.class, "Vault", VaultEconomy.class); + public static final PluginHook ECO_PLAYER_POINTS = new PluginHook(Economy.class, "PlayerPoints", PlayerPointsEconomy.class); + public static final PluginHook ECO_RESERVE = new PluginHook(Economy.class, "Reserve", ReserveEconomy.class); + public static final PluginHook STACKER_ULTIMATE = new PluginHook(Stacker.class, "UltimateStacker", UltimateStacker.class); + public static final PluginHook STACKER_WILD = new PluginHook(Stacker.class, "WildStacker", WildStacker.class); + public static final PluginHook STACKER_STACK_MOB = new PluginHook(Stacker.class, "StackMob", StackMob.class); + public static final PluginHook HOLO_DISPLAYS = new PluginHook(Holograms.class, "HolographicDisplays", HolographicDisplaysHolograms.class); + public static final PluginHook HOLO_HOLOGRAMS = new PluginHook(Holograms.class, "Holograms", HologramsHolograms.class); + public static final PluginHook HOLO_CMI = new PluginHook(Holograms.class, "CMI", CMIHolograms.class); + public static final PluginHook LOG_CORE_PROTECT = new PluginHook(Log.class, "CoreProtect", CoreProtectLog.class); + public static final PluginHook PROTECTION_GRIEFPREVENTION = new PluginHook(Protection.class, "GriefPrevention", GriefPreventionProtection.class); + public static final PluginHook PROTECTION_LANDS = new PluginHook(Protection.class, "Lands", LandsProtection.class); + public static final PluginHook PROTECTION_REDPROTECT = new PluginHook(Protection.class, "RedProtect", RedProtectProtection.class); + public static final PluginHook PROTECTION_ULTIMATECLAIMS = new PluginHook(Protection.class, "UltimateClaims", UltimateClaimsProtection.class); + public static final PluginHook PROTECTION_BENTOBOX = new PluginHook(Protection.class, "BentoBox", BentoBoxProtection.class); + + /******* Start Manager stuff *******/ + + protected final T hookGeneric; + protected final String plugin; + protected final Class managerClass; + protected static Map hooks; + protected Constructor pluginConstructor; // for passing the plugin loading the hook to the plugin hook + + private PluginHook(T type, String pluginName, Class handler) { + if (!Hook.class.isAssignableFrom(handler)) { + throw new RuntimeException("Tried to register a non-Hook plugin hook! " + pluginName + " -> " + handler.getName()); + } + this.hookGeneric = type; + this.plugin = pluginName; + this.managerClass = handler; + if (hooks == null) { + hooks = new LinkedHashMap(); + } + hooks.put(handler, this); + // Does this class have a plugin constructor? + try { + pluginConstructor = handler.getDeclaredConstructor(Plugin.class); + } catch (NoSuchMethodException | SecurityException ex) { + // nope! + } catch (Throwable t) { + // (can also reach here if there is a class loader exception) + hooks.remove(handler); + } + } + + /** + * Add a hook handler for us to use later.
+ * NOTE: The class passed MUST extend Hook.
+ * Permissible constructors are empty () or (org.bukkit.plugin.Plugin)
+ * Each plugin defined must use a different handler class. + * + * @param + * @param type Generic hook type for this plugin + * @param pluginName Plugin name + * @param handler Specific class that will handle this plugin, if enabled. + * + * @return instance of the PluginHook that was added + */ + public static PluginHook addHook(T type, String pluginName, Class handler) { + return new PluginHook(type, pluginName, handler); + } + + protected static Map loadHooks(Class type, Plugin plugin) { + Map loaded = new LinkedHashMap<>(); + PluginManager pluginManager = Bukkit.getPluginManager(); + + for (PluginHook hook : getHooks(type)) { + if (pluginManager.isPluginEnabled(hook.plugin)) { + Hook handler = (Hook) (plugin != null ? hook.load(plugin) : hook.load()); + if (handler != null && handler.isEnabled()) { + loaded.put(hook, handler); + } + } + } + + return loaded; + } + + protected static List getHooks(Class type) { + return hooks.entrySet().parallelStream() + .filter(e -> e.getKey() == type || e.getValue().managerClass == type || type.isAssignableFrom(e.getKey())) + .map(Map.Entry::getValue) + .collect(Collectors.toList()); + } + + public String getPluginName() { + return plugin; + } + + protected Object load() { + try { + return managerClass.cast( + pluginConstructor != null + ? pluginConstructor.newInstance((Plugin) null) + : managerClass.getConstructor().newInstance()); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Unexpected Error while creating a new Hook Manager for " + plugin, ex); + } + return null; + } + + protected Object load(Plugin hookingPlugin) { + try { + return managerClass.cast( + pluginConstructor != null + ? pluginConstructor.newInstance(hookingPlugin) + : managerClass.getConstructor().newInstance()); + } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Unexpected Error while creating a new Hook Manager for " + plugin, ex); + } + return null; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 37 * hash + Objects.hashCode(this.plugin); + hash = 37 * hash + Objects.hashCode(this.managerClass); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final PluginHook other = (PluginHook) obj; + return Objects.equals(this.plugin, other.plugin) + && Objects.equals(this.managerClass, other.managerClass); + } +} diff --git a/Core/src/main/java/com/songoda/core/hooks/WorldGuardHook.java b/Core/src/main/java/com/songoda/core/hooks/WorldGuardHook.java index a2bfc029..130c6d48 100644 --- a/Core/src/main/java/com/songoda/core/hooks/WorldGuardHook.java +++ b/Core/src/main/java/com/songoda/core/hooks/WorldGuardHook.java @@ -1,152 +1,162 @@ -package com.songoda.core.hooks; - -import com.songoda.core.hooks.worldguard.WorldGuardFlagHandler; -import com.songoda.core.hooks.worldguard.WorldGuardRegionHandler; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -public class WorldGuardHook { - - static boolean canHook = false; - - static { - try { - // if this class exists, we're good to use WG classes - Class.forName("com.sk89q.worldguard.protection.flags.Flag"); - canHook = true; - } catch (ClassNotFoundException ex) { - } - } - - /** - * Attempt to register a worldGuard flag (ALLOW/DENY)
- * Note: This must be called before WorldGuard loads, or it will fail. - * - * @param flag name of the flag to set - * @param state default value of the flag - */ - public static void addHook(@NotNull String flag, boolean state) { - if (canHook) { - WorldGuardFlagHandler.addHook(flag, state); - } - } - - /** - * Check to see if WorldGuard is installed and hooked - * - * @return true if and only if WorldGuard exists and addHook() has been - * called and added successfully - */ - public static boolean isEnabled() { - return canHook && WorldGuardFlagHandler.isEnabled(); - } - - /** - * Checks this location to see what this flag is set to - * - * @param l location to check - * @param flag ALLOW/DENY flag to check - * @return flag state, or null if undefined - */ - @Nullable - public static Boolean getBooleanFlag(@NotNull Location l, @NotNull String flag) { - return canHook ? WorldGuardFlagHandler.getBooleanFlag(l, flag) : null; - } - - /** - * Query all regions that are in or intersect this chunk - * - * @param c chunk to check for regions in - * @param flag ALLOW/DENY flag to check - * @return flag state, or null if undefined - */ - @Nullable - public static Boolean getBooleanFlag(@NotNull Chunk c, @NotNull String flag) { - return canHook ? WorldGuardFlagHandler.getBooleanFlag(c, flag) : null; - } - - /** - * Check to see if the pvp flag is set and is set to ALLOW - * - * @param loc Location to check - * @return false if the pvp flag is not set for this region, or is set to DENY - */ - public static boolean isPvpAllowed(@NotNull Location loc) { - return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "pvp"), Boolean.TRUE); - } - - /** - * Check to see if the block-break flag is set and is set to ALLOW - * - * @param loc Location to check - * @return false if the block-break flag is not set for this region, or is set to DENY - */ - public static boolean isBreakAllowed(@NotNull Location loc) { - return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "block-break"), Boolean.TRUE); - } - - /** - * Check to see if the build flag is set and is set to ALLOW - * - * @param loc Location to check - * @return false if the build flag is not set for this region, or is set to DENY - */ - public static boolean isBuildAllowed(@NotNull Player player, @NotNull Location loc) { - return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "build", player), Boolean.TRUE); - } - - /** - * Check to see if the use flag is set and is set to ALLOW - * - * @param loc Location to check - * @return false if the use flag is not set for this region, or is set to DENY - */ - public static boolean isInteractAllowed(@NotNull Location loc) { - return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "use"), Boolean.TRUE); - } - - /** - * Check to see if the other-explosion flag is set and is set to ALLOW - * - * @param loc Location to check - * @return false if the other-explosion flag is not set for this region, or is set to DENY - */ - public static boolean isExplosionsAllowed(@NotNull Location loc) { - return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "other-explosion"), Boolean.TRUE); - } - - /** - * Check to see if the mob-spawning flag is set and is set to ALLOW - * - * @param loc Location to check - * @return false if the mob-spawning flag is not set for this region, or is set to DENY - */ - public static boolean isMobSpawningAllowed(@NotNull Location loc) { - return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "mob-spawning"), Boolean.TRUE); - } - - /** - * @param loc Location to check - * @return A list of regions that contain this location. - */ - @NotNull - public static List getRegionNames(@NotNull Location loc) { - return canHook ? WorldGuardRegionHandler.getRegionNames(loc) : Collections.EMPTY_LIST; - } - - /** - * @param c Chunk to check - * @return A list of regions that contain any part of this chunk. - */ - @NotNull - public static List getRegionNames(@NotNull Chunk c) { - return canHook ? WorldGuardRegionHandler.getRegionNames(c) : Collections.EMPTY_LIST; - } -} +package com.songoda.core.hooks; + +import com.songoda.core.hooks.worldguard.WorldGuardFlagHandler; +import com.songoda.core.hooks.worldguard.WorldGuardRegionHandler; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +public class WorldGuardHook { + + static boolean canHook = false; + + static { + try { + // if this class exists, we're good to use WG classes + Class.forName("com.sk89q.worldguard.protection.flags.Flag"); + canHook = true; + } catch (ClassNotFoundException ex) { + } + } + + /** + * Attempt to register a worldGuard flag (ALLOW/DENY)
+ * Note: This must be called before WorldGuard loads, or it will fail. + * + * @param flag name of the flag to set + * @param state default value of the flag + */ + public static void addHook(@NotNull String flag, boolean state) { + if (canHook) { + WorldGuardFlagHandler.addHook(flag, state); + } + } + + /** + * Check to see if WorldGuard is installed and hooked + * + * @return true if and only if WorldGuard exists and addHook() has been + * called and added successfully + */ + public static boolean isEnabled() { + return canHook && WorldGuardFlagHandler.isEnabled(); + } + + /** + * Checks this location to see what this flag is set to + * + * @param l location to check + * @param flag ALLOW/DENY flag to check + * + * @return flag state, or null if undefined + */ + @Nullable + public static Boolean getBooleanFlag(@NotNull Location l, @NotNull String flag) { + return canHook ? WorldGuardFlagHandler.getBooleanFlag(l, flag) : null; + } + + /** + * Query all regions that are in or intersect this chunk + * + * @param c chunk to check for regions in + * @param flag ALLOW/DENY flag to check + * + * @return flag state, or null if undefined + */ + @Nullable + public static Boolean getBooleanFlag(@NotNull Chunk c, @NotNull String flag) { + return canHook ? WorldGuardFlagHandler.getBooleanFlag(c, flag) : null; + } + + /** + * Check to see if the pvp flag is set and is set to ALLOW + * + * @param loc Location to check + * + * @return false if the pvp flag is not set for this region, or is set to DENY + */ + public static boolean isPvpAllowed(@NotNull Location loc) { + return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "pvp"), Boolean.TRUE); + } + + /** + * Check to see if the block-break flag is set and is set to ALLOW + * + * @param loc Location to check + * + * @return false if the block-break flag is not set for this region, or is set to DENY + */ + public static boolean isBreakAllowed(@NotNull Location loc) { + return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "block-break"), Boolean.TRUE); + } + + /** + * Check to see if the build flag is set and is set to ALLOW + * + * @param loc Location to check + * + * @return false if the build flag is not set for this region, or is set to DENY + */ + public static boolean isBuildAllowed(@NotNull Player player, @NotNull Location loc) { + return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "build", player), Boolean.TRUE); + } + + /** + * Check to see if the use flag is set and is set to ALLOW + * + * @param loc Location to check + * + * @return false if the use flag is not set for this region, or is set to DENY + */ + public static boolean isInteractAllowed(@NotNull Location loc) { + return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "use"), Boolean.TRUE); + } + + /** + * Check to see if the other-explosion flag is set and is set to ALLOW + * + * @param loc Location to check + * + * @return false if the other-explosion flag is not set for this region, or is set to DENY + */ + public static boolean isExplosionsAllowed(@NotNull Location loc) { + return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "other-explosion"), Boolean.TRUE); + } + + /** + * Check to see if the mob-spawning flag is set and is set to ALLOW + * + * @param loc Location to check + * + * @return false if the mob-spawning flag is not set for this region, or is set to DENY + */ + public static boolean isMobSpawningAllowed(@NotNull Location loc) { + return canHook && Objects.equals(WorldGuardFlagHandler.getBooleanFlag(loc, "mob-spawning"), Boolean.TRUE); + } + + /** + * @param loc Location to check + * + * @return A list of regions that contain this location. + */ + @NotNull + public static List getRegionNames(@NotNull Location loc) { + return canHook ? WorldGuardRegionHandler.getRegionNames(loc) : Collections.EMPTY_LIST; + } + + /** + * @param c Chunk to check + * + * @return A list of regions that contain any part of this chunk. + */ + @NotNull + public static List getRegionNames(@NotNull Chunk c) { + return canHook ? WorldGuardRegionHandler.getRegionNames(c) : Collections.EMPTY_LIST; + } +} diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java b/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java index a9739310..98b7f405 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/Economy.java @@ -3,14 +3,13 @@ package com.songoda.core.hooks.economies; import com.songoda.core.hooks.Hook; import org.bukkit.OfflinePlayer; -import java.text.DecimalFormat; - public abstract class Economy implements Hook { /** * Get the players available balance * * @param player player + * * @return the amount of available balance */ public abstract double getBalance(OfflinePlayer player); @@ -20,6 +19,7 @@ public abstract class Economy implements Hook { * * @param player player to check * @param cost minimum amount this player should have + * * @return true if this player can have this amount withdrawn */ public abstract boolean hasBalance(OfflinePlayer player, double cost); @@ -29,6 +29,7 @@ public abstract class Economy implements Hook { * * @param player player to check * @param cost amount to remove from this player + * * @return true if the total amount was withdrawn successfully */ public abstract boolean withdrawBalance(OfflinePlayer player, double cost); @@ -38,6 +39,7 @@ public abstract class Economy implements Hook { * * @param player player to check * @param amount amount to add to this player + * * @return true if the total amount was added successfully */ public abstract boolean deposit(OfflinePlayer player, double amount); diff --git a/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java b/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java index 98dbf3c2..71947150 100644 --- a/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java +++ b/Core/src/main/java/com/songoda/core/hooks/economies/PlayerPointsEconomy.java @@ -35,14 +35,12 @@ public class PlayerPointsEconomy extends Economy { public boolean hasBalance(OfflinePlayer player, double cost) { int amount = convertAmount(cost); return playerPoints.getAPI().look(player.getUniqueId()) >= amount; - } @Override public boolean withdrawBalance(OfflinePlayer player, double cost) { int amount = convertAmount(cost); return playerPoints.getAPI().take(player.getUniqueId(), amount); - } @Override diff --git a/Core/src/main/java/com/songoda/core/hooks/holograms/Holograms.java b/Core/src/main/java/com/songoda/core/hooks/holograms/Holograms.java index 1cf57edc..f4daa74d 100644 --- a/Core/src/main/java/com/songoda/core/hooks/holograms/Holograms.java +++ b/Core/src/main/java/com/songoda/core/hooks/holograms/Holograms.java @@ -31,6 +31,7 @@ public abstract class Holograms implements Hook { * Center and offset this location * * @param location location to offset + * * @return copy-safe location with the applied offset. */ protected final Location fixLocation(Location location) { diff --git a/Core/src/main/java/com/songoda/core/hooks/holograms/HolographicDisplaysHolograms.java b/Core/src/main/java/com/songoda/core/hooks/holograms/HolographicDisplaysHolograms.java index a62cd67d..0e6a601a 100644 --- a/Core/src/main/java/com/songoda/core/hooks/holograms/HolographicDisplaysHolograms.java +++ b/Core/src/main/java/com/songoda/core/hooks/holograms/HolographicDisplaysHolograms.java @@ -2,7 +2,6 @@ package com.songoda.core.hooks.holograms; import com.gmail.filoghost.holographicdisplays.api.Hologram; import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; -import com.gmail.filoghost.holographicdisplays.api.line.TextLine; import org.bukkit.Location; import org.bukkit.plugin.Plugin; diff --git a/Core/src/main/java/com/songoda/core/hooks/mcmmo/McMMOHandler.java b/Core/src/main/java/com/songoda/core/hooks/mcmmo/McMMOHandler.java index 835cf036..33d37248 100644 --- a/Core/src/main/java/com/songoda/core/hooks/mcmmo/McMMOHandler.java +++ b/Core/src/main/java/com/songoda/core/hooks/mcmmo/McMMOHandler.java @@ -1,515 +1,513 @@ -package com.songoda.core.hooks.mcmmo; - -import com.gmail.nossr50.api.AbilityAPI; -import com.gmail.nossr50.api.ExperienceAPI; -import com.gmail.nossr50.config.experience.ExperienceConfig; -import com.gmail.nossr50.datatypes.experience.XPGainReason; -import com.gmail.nossr50.datatypes.experience.XPGainSource; -import com.gmail.nossr50.datatypes.skills.PrimarySkillType; -import com.gmail.nossr50.datatypes.skills.SubSkillType; -import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.player.UserManager; -import com.gmail.nossr50.util.random.RandomChanceUtil; -import com.gmail.nossr50.util.skills.RankUtils; -import com.gmail.nossr50.util.skills.SkillActivationType; -import com.songoda.core.compatibility.ServerVersion; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.Collectors; - -public class McMMOHandler { - - static boolean mcmmo_v2 = false; - static boolean legacy_v13 = false; - static boolean legacy_v12 = false; - static boolean legacy_v8 = false; - - static Class mcmmo_SkillType; - static Method mcmmo_SkillType_valueOf; - static Method mcmmo_SkillType_getDoubleDropsDisabled; - static Object mcmmo_ExperienceConfig_instance; - static Method mcmmo_ExperienceConfig_getXp; - static Method mcmmo_McMMOPlayer_getSkillLevel; - static Class mcmmo_PerksUtils; - static Method mcmmo_PerksUtils_handleLuckyPerks; - static Class mcmmo_SecondaryAbility; - static Method mcmmo_SecondaryAbility_valueOf; - static Method mcmmo_Permissions_secondaryAbilityEnabled; - static Method mcmmo_SkillUtils_activationSuccessful; - - static { - try { - Class.forName("com.gmail.nossr50.datatypes.skills.PrimarySkillType"); - mcmmo_v2 = true; - } catch (ClassNotFoundException ex) { - try { - mcmmo_SkillType = Class.forName("com.gmail.nossr50.datatypes.skills.SkillType"); - mcmmo_SkillType_valueOf = mcmmo_SkillType.getDeclaredMethod("valueOf", String.class); - mcmmo_SkillType_getDoubleDropsDisabled = mcmmo_SkillType.getDeclaredMethod("getDoubleDropsDisabled"); - mcmmo_ExperienceConfig_instance = ExperienceConfig.getInstance(); - mcmmo_McMMOPlayer_getSkillLevel = com.gmail.nossr50.datatypes.player.McMMOPlayer.class.getDeclaredMethod("getSkillLevel", mcmmo_SkillType); - mcmmo_PerksUtils = Class.forName("com.gmail.nossr50.util.skills.PerksUtils"); - mcmmo_PerksUtils_handleLuckyPerks = mcmmo_PerksUtils.getDeclaredMethod("handleLuckyPerks", Player.class, mcmmo_SkillType); - mcmmo_SecondaryAbility = Class.forName("com.gmail.nossr50.datatypes.skills.SecondaryAbility"); - mcmmo_SecondaryAbility_valueOf = mcmmo_SecondaryAbility.getDeclaredMethod("valueOf", String.class); - mcmmo_Permissions_secondaryAbilityEnabled = com.gmail.nossr50.util.Permissions.class.getDeclaredMethod("secondaryAbilityEnabled", Player.class, mcmmo_SecondaryAbility); - mcmmo_SkillUtils_activationSuccessful = com.gmail.nossr50.util.skills.SkillUtils.class.getDeclaredMethod("activationSuccessful", mcmmo_SecondaryAbility, Player.class, int.class, int.class); - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.block.data.BlockData.class); - legacy_v13 = true; - } else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) { - mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.material.MaterialData.class); - legacy_v12 = true; - } else { - mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.Material.class); - legacy_v8 = true; - } - } catch (Exception ex1) { - Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to register McMMO Legacy Hook", ex1); - } - } - } - - public static void addMining(Player player, Collection blocks) { - if (player == null || blocks == null || blocks.isEmpty()) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - addBlockSkillLegacy(player, blocks, "mining"); - return; - } - ArrayList blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new)); - ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.MINING); - } - - public static void addExcavation(Player player, Collection blocks) { - if (player == null || blocks == null || blocks.isEmpty()) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - addBlockSkillLegacy(player, blocks, "excavation"); - return; - } - ArrayList blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new)); - ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.EXCAVATION); - } - - public static void addHerbalism(Player player, Collection blocks) { - if (player == null || blocks == null || blocks.isEmpty()) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - addBlockSkillLegacy(player, blocks, "herbalism"); - return; - } - ArrayList blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new)); - ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.HERBALISM); - } - - public static void addWoodcutting(Player player, Collection blocks) { - if (player == null || blocks == null || blocks.isEmpty()) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - addBlockSkillLegacy(player, blocks, "woodcutting"); - return; - } - ArrayList blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new)); - ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.WOODCUTTING); - } - - public static int getAcrobaticsSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "acrobatics"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ACROBATICS); - } - - public static int getAlchemySkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "alchemy"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ALCHEMY); - } - - public static int getArcherySkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "archery"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ARCHERY); - } - - public static int getAxesSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "axes"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.AXES); - } - - public static int getExcavationSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "excavation"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.EXCAVATION); - } - - public static int getFishingSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "fishing"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.FISHING); - } - - public static int getHerbalismSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "herbalism"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.HERBALISM); - } - - public static int getMiningSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "mining"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.MINING); - } - - public static int getRepairSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "repair"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.REPAIR); - } - - public static int getSmeltingSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "smelting"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.SMELTING); - } - - public static int getSwordsSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "swords"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.SWORDS); - } - - public static int getTamingSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "taming"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.TAMING); - } - - public static int getUnarmedSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "unarmed"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.UNARMED); - } - - public static int getWoodcuttingSkill(Player player) { - if (player == null) { - return -1; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - return getSkillLegacy(player, "woodcutting"); - } - return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.WOODCUTTING); - } - - public static void addAcrobatics(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "acrobatics", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ACROBATICS, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addAlchemy(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "alchemy", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ALCHEMY, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addArchery(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "archery", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ARCHERY, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addAxes(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "axes", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.AXES, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addExcavation(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "excavation", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.EXCAVATION, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addFishing(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "fishing", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.FISHING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addHerbalism(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "herbalism", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.HERBALISM, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addMining(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "mining", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.MINING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addRepair(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "repair", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.REPAIR, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addSmelting(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "smelting", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.SMELTING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addSwords(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "swords", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.SWORDS, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addTaming(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "taming", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.TAMING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addUnarmed(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "unarmed", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.UNARMED, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static void addWoodcutting(Player player, int xp) { - if (player == null) { - return; - } else if (legacy_v13 || legacy_v12 || legacy_v8) { - ExperienceAPI.addXP(player, "woodcutting", xp); - } - UserManager.getPlayer(player).beginXpGain(PrimarySkillType.WOODCUTTING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); - } - - public static boolean hasHerbalismDoubleDrops(Player player) { - if (legacy_v13 || legacy_v12 || legacy_v8) { - return hasBlockDoubleLegacy(player, "herbalism"); - } - - if (PrimarySkillType.HERBALISM.getDoubleDropsDisabled()) { - return false; - } - - return Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_DOUBLE_DROPS) - && RankUtils.hasReachedRank(1, player, SubSkillType.HERBALISM_DOUBLE_DROPS) - && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_DOUBLE_DROPS, player); - } - - public static boolean hasMiningDoubleDrops(Player player) { - if (legacy_v13 || legacy_v12 || legacy_v8) { - return hasBlockDoubleLegacy(player, "mining"); - } - - if (PrimarySkillType.MINING.getDoubleDropsDisabled()) { - return false; - } - - return Permissions.isSubSkillEnabled(player, SubSkillType.MINING_DOUBLE_DROPS) - && RankUtils.hasReachedRank(1, player, SubSkillType.MINING_DOUBLE_DROPS) - && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.MINING_DOUBLE_DROPS, player); - } - - public static boolean hasWoodcuttingDoubleDrops(Player player) { - if (legacy_v13 || legacy_v12 || legacy_v8) { - return hasBlockDoubleLegacy(player, "woodcutting"); - } - - if (PrimarySkillType.WOODCUTTING.getDoubleDropsDisabled()) { - return false; - } - - return Permissions.isSubSkillEnabled(player, SubSkillType.WOODCUTTING_HARVEST_LUMBER) - && RankUtils.hasReachedRank(1, player, SubSkillType.WOODCUTTING_HARVEST_LUMBER) - && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.WOODCUTTING_HARVEST_LUMBER, player); - } - - public static boolean isUsingBerserk(Player player) { - return AbilityAPI.berserkEnabled(player); - } - - public static boolean isUsingGigaDrill(Player player) { - return AbilityAPI.gigaDrillBreakerEnabled(player); - } - - public static boolean isUsingGreenTerra(Player player) { - return AbilityAPI.greenTerraEnabled(player); - } - - public static boolean isUsingSerratedStrikes(Player player) { - return AbilityAPI.serratedStrikesEnabled(player); - } - - public static boolean isUsingSkullSplitter(Player player) { - return AbilityAPI.skullSplitterEnabled(player); - } - - public static boolean isUsingSuperBreaker(Player player) { - return AbilityAPI.superBreakerEnabled(player); - } - - public static boolean isUsingTreeFeller(Player player) { - return AbilityAPI.treeFellerEnabled(player); - } - - public static boolean isBleeding(LivingEntity victim) { - return AbilityAPI.isBleeding(victim); - } - - /** - * woodcutting, mining, herbalism - */ - protected static boolean hasBlockDoubleLegacy(Player player, String skill) { - if (player.hasMetadata("mcMMO: Player Data")) { - try { - Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase()); - if ((boolean) mcmmo_SkillType_getDoubleDropsDisabled.invoke(skillType)) { - return false; - } - - int skillLevel = (int) mcmmo_McMMOPlayer_getSkillLevel.invoke(UserManager.getPlayer(player), skillType); - int activationChance = (int) mcmmo_PerksUtils_handleLuckyPerks.invoke(null, player, skillType); - - Object secondaryDouble = mcmmo_SecondaryAbility_valueOf.invoke(null, skill.toUpperCase() + "_DOUBLE_DROPS"); - if (!((boolean) mcmmo_Permissions_secondaryAbilityEnabled.invoke(null, player, secondaryDouble))) { - return false; - } - return (boolean) mcmmo_SkillUtils_activationSuccessful.invoke(null, secondaryDouble, player, skillLevel, activationChance); - - } catch (Exception ex1) { - Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1); - } - } - return false; - } - - protected static void addBlockSkillLegacy(Player player, Collection blocks, String skill) { - try { - Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase()); - - int xp = 0; - for (Block block : blocks) { - xp += (int) mcmmo_ExperienceConfig_getXp.invoke(mcmmo_ExperienceConfig_instance, skillType, legacy_getBlock(block)); - } - - ExperienceAPI.addXP(player, skill, xp); - } catch (Exception ex1) { - Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1); - } - } - - protected static Object legacy_getBlock(Block block) { - if (legacy_v13) { - return block.getBlockData(); - } else if (legacy_v12) { - return block.getState().getData(); - } else { - return block.getType(); - } - } - - protected static int getSkillLegacy(Player player, String skill) { - if (player.hasMetadata("mcMMO: Player Data")) { - try { - Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase()); - return (int) mcmmo_McMMOPlayer_getSkillLevel.invoke(UserManager.getPlayer(player), skillType); - } catch (Exception ex1) { - Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1); - } - } - return 0; - } - -} +package com.songoda.core.hooks.mcmmo; + +import com.gmail.nossr50.api.AbilityAPI; +import com.gmail.nossr50.api.ExperienceAPI; +import com.gmail.nossr50.config.experience.ExperienceConfig; +import com.gmail.nossr50.datatypes.experience.XPGainReason; +import com.gmail.nossr50.datatypes.experience.XPGainSource; +import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.datatypes.skills.SubSkillType; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.player.UserManager; +import com.gmail.nossr50.util.random.RandomChanceUtil; +import com.gmail.nossr50.util.skills.RankUtils; +import com.gmail.nossr50.util.skills.SkillActivationType; +import com.songoda.core.compatibility.ServerVersion; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +public class McMMOHandler { + + static boolean mcmmo_v2 = false; + static boolean legacy_v13 = false; + static boolean legacy_v12 = false; + static boolean legacy_v8 = false; + + static Class mcmmo_SkillType; + static Method mcmmo_SkillType_valueOf; + static Method mcmmo_SkillType_getDoubleDropsDisabled; + static Object mcmmo_ExperienceConfig_instance; + static Method mcmmo_ExperienceConfig_getXp; + static Method mcmmo_McMMOPlayer_getSkillLevel; + static Class mcmmo_PerksUtils; + static Method mcmmo_PerksUtils_handleLuckyPerks; + static Class mcmmo_SecondaryAbility; + static Method mcmmo_SecondaryAbility_valueOf; + static Method mcmmo_Permissions_secondaryAbilityEnabled; + static Method mcmmo_SkillUtils_activationSuccessful; + + static { + try { + Class.forName("com.gmail.nossr50.datatypes.skills.PrimarySkillType"); + mcmmo_v2 = true; + } catch (ClassNotFoundException ex) { + try { + mcmmo_SkillType = Class.forName("com.gmail.nossr50.datatypes.skills.SkillType"); + mcmmo_SkillType_valueOf = mcmmo_SkillType.getDeclaredMethod("valueOf", String.class); + mcmmo_SkillType_getDoubleDropsDisabled = mcmmo_SkillType.getDeclaredMethod("getDoubleDropsDisabled"); + mcmmo_ExperienceConfig_instance = ExperienceConfig.getInstance(); + mcmmo_McMMOPlayer_getSkillLevel = com.gmail.nossr50.datatypes.player.McMMOPlayer.class.getDeclaredMethod("getSkillLevel", mcmmo_SkillType); + mcmmo_PerksUtils = Class.forName("com.gmail.nossr50.util.skills.PerksUtils"); + mcmmo_PerksUtils_handleLuckyPerks = mcmmo_PerksUtils.getDeclaredMethod("handleLuckyPerks", Player.class, mcmmo_SkillType); + mcmmo_SecondaryAbility = Class.forName("com.gmail.nossr50.datatypes.skills.SecondaryAbility"); + mcmmo_SecondaryAbility_valueOf = mcmmo_SecondaryAbility.getDeclaredMethod("valueOf", String.class); + mcmmo_Permissions_secondaryAbilityEnabled = com.gmail.nossr50.util.Permissions.class.getDeclaredMethod("secondaryAbilityEnabled", Player.class, mcmmo_SecondaryAbility); + mcmmo_SkillUtils_activationSuccessful = com.gmail.nossr50.util.skills.SkillUtils.class.getDeclaredMethod("activationSuccessful", mcmmo_SecondaryAbility, Player.class, int.class, int.class); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { + mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.block.data.BlockData.class); + legacy_v13 = true; + } else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) { + mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.material.MaterialData.class); + legacy_v12 = true; + } else { + mcmmo_ExperienceConfig_getXp = mcmmo_ExperienceConfig_instance.getClass().getDeclaredMethod("getXp", mcmmo_SkillType, org.bukkit.Material.class); + legacy_v8 = true; + } + } catch (Exception ex1) { + Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to register McMMO Legacy Hook", ex1); + } + } + } + + public static void addMining(Player player, Collection blocks) { + if (player == null || blocks == null || blocks.isEmpty()) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + addBlockSkillLegacy(player, blocks, "mining"); + return; + } + ArrayList blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new)); + ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.MINING); + } + + public static void addExcavation(Player player, Collection blocks) { + if (player == null || blocks == null || blocks.isEmpty()) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + addBlockSkillLegacy(player, blocks, "excavation"); + return; + } + ArrayList blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new)); + ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.EXCAVATION); + } + + public static void addHerbalism(Player player, Collection blocks) { + if (player == null || blocks == null || blocks.isEmpty()) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + addBlockSkillLegacy(player, blocks, "herbalism"); + return; + } + ArrayList blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new)); + ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.HERBALISM); + } + + public static void addWoodcutting(Player player, Collection blocks) { + if (player == null || blocks == null || blocks.isEmpty()) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + addBlockSkillLegacy(player, blocks, "woodcutting"); + return; + } + ArrayList blockStates = blocks.stream().map(b -> b.getState()).collect(Collectors.toCollection(ArrayList::new)); + ExperienceAPI.addXpFromBlocksBySkill(blockStates, UserManager.getPlayer(player), PrimarySkillType.WOODCUTTING); + } + + public static int getAcrobaticsSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "acrobatics"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ACROBATICS); + } + + public static int getAlchemySkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "alchemy"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ALCHEMY); + } + + public static int getArcherySkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "archery"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.ARCHERY); + } + + public static int getAxesSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "axes"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.AXES); + } + + public static int getExcavationSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "excavation"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.EXCAVATION); + } + + public static int getFishingSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "fishing"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.FISHING); + } + + public static int getHerbalismSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "herbalism"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.HERBALISM); + } + + public static int getMiningSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "mining"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.MINING); + } + + public static int getRepairSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "repair"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.REPAIR); + } + + public static int getSmeltingSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "smelting"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.SMELTING); + } + + public static int getSwordsSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "swords"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.SWORDS); + } + + public static int getTamingSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "taming"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.TAMING); + } + + public static int getUnarmedSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "unarmed"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.UNARMED); + } + + public static int getWoodcuttingSkill(Player player) { + if (player == null) { + return -1; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + return getSkillLegacy(player, "woodcutting"); + } + return UserManager.getPlayer(player).getSkillLevel(PrimarySkillType.WOODCUTTING); + } + + public static void addAcrobatics(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "acrobatics", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ACROBATICS, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addAlchemy(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "alchemy", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ALCHEMY, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addArchery(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "archery", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.ARCHERY, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addAxes(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "axes", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.AXES, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addExcavation(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "excavation", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.EXCAVATION, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addFishing(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "fishing", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.FISHING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addHerbalism(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "herbalism", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.HERBALISM, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addMining(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "mining", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.MINING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addRepair(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "repair", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.REPAIR, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addSmelting(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "smelting", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.SMELTING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addSwords(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "swords", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.SWORDS, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addTaming(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "taming", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.TAMING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addUnarmed(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "unarmed", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.UNARMED, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static void addWoodcutting(Player player, int xp) { + if (player == null) { + return; + } else if (legacy_v13 || legacy_v12 || legacy_v8) { + ExperienceAPI.addXP(player, "woodcutting", xp); + } + UserManager.getPlayer(player).beginXpGain(PrimarySkillType.WOODCUTTING, xp, XPGainReason.UNKNOWN, XPGainSource.CUSTOM); + } + + public static boolean hasHerbalismDoubleDrops(Player player) { + if (legacy_v13 || legacy_v12 || legacy_v8) { + return hasBlockDoubleLegacy(player, "herbalism"); + } + + if (PrimarySkillType.HERBALISM.getDoubleDropsDisabled()) { + return false; + } + + return Permissions.isSubSkillEnabled(player, SubSkillType.HERBALISM_DOUBLE_DROPS) + && RankUtils.hasReachedRank(1, player, SubSkillType.HERBALISM_DOUBLE_DROPS) + && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_DOUBLE_DROPS, player); + } + + public static boolean hasMiningDoubleDrops(Player player) { + if (legacy_v13 || legacy_v12 || legacy_v8) { + return hasBlockDoubleLegacy(player, "mining"); + } + + if (PrimarySkillType.MINING.getDoubleDropsDisabled()) { + return false; + } + + return Permissions.isSubSkillEnabled(player, SubSkillType.MINING_DOUBLE_DROPS) + && RankUtils.hasReachedRank(1, player, SubSkillType.MINING_DOUBLE_DROPS) + && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.MINING_DOUBLE_DROPS, player); + } + + public static boolean hasWoodcuttingDoubleDrops(Player player) { + if (legacy_v13 || legacy_v12 || legacy_v8) { + return hasBlockDoubleLegacy(player, "woodcutting"); + } + + if (PrimarySkillType.WOODCUTTING.getDoubleDropsDisabled()) { + return false; + } + + return Permissions.isSubSkillEnabled(player, SubSkillType.WOODCUTTING_HARVEST_LUMBER) + && RankUtils.hasReachedRank(1, player, SubSkillType.WOODCUTTING_HARVEST_LUMBER) + && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.WOODCUTTING_HARVEST_LUMBER, player); + } + + public static boolean isUsingBerserk(Player player) { + return AbilityAPI.berserkEnabled(player); + } + + public static boolean isUsingGigaDrill(Player player) { + return AbilityAPI.gigaDrillBreakerEnabled(player); + } + + public static boolean isUsingGreenTerra(Player player) { + return AbilityAPI.greenTerraEnabled(player); + } + + public static boolean isUsingSerratedStrikes(Player player) { + return AbilityAPI.serratedStrikesEnabled(player); + } + + public static boolean isUsingSkullSplitter(Player player) { + return AbilityAPI.skullSplitterEnabled(player); + } + + public static boolean isUsingSuperBreaker(Player player) { + return AbilityAPI.superBreakerEnabled(player); + } + + public static boolean isUsingTreeFeller(Player player) { + return AbilityAPI.treeFellerEnabled(player); + } + + public static boolean isBleeding(LivingEntity victim) { + return AbilityAPI.isBleeding(victim); + } + + /** + * woodcutting, mining, herbalism + */ + protected static boolean hasBlockDoubleLegacy(Player player, String skill) { + if (player.hasMetadata("mcMMO: Player Data")) { + try { + Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase()); + if ((boolean) mcmmo_SkillType_getDoubleDropsDisabled.invoke(skillType)) { + return false; + } + + int skillLevel = (int) mcmmo_McMMOPlayer_getSkillLevel.invoke(UserManager.getPlayer(player), skillType); + int activationChance = (int) mcmmo_PerksUtils_handleLuckyPerks.invoke(null, player, skillType); + + Object secondaryDouble = mcmmo_SecondaryAbility_valueOf.invoke(null, skill.toUpperCase() + "_DOUBLE_DROPS"); + if (!((boolean) mcmmo_Permissions_secondaryAbilityEnabled.invoke(null, player, secondaryDouble))) { + return false; + } + return (boolean) mcmmo_SkillUtils_activationSuccessful.invoke(null, secondaryDouble, player, skillLevel, activationChance); + } catch (Exception ex1) { + Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1); + } + } + return false; + } + + protected static void addBlockSkillLegacy(Player player, Collection blocks, String skill) { + try { + Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase()); + + int xp = 0; + for (Block block : blocks) { + xp += (int) mcmmo_ExperienceConfig_getXp.invoke(mcmmo_ExperienceConfig_instance, skillType, legacy_getBlock(block)); + } + + ExperienceAPI.addXP(player, skill, xp); + } catch (Exception ex1) { + Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1); + } + } + + protected static Object legacy_getBlock(Block block) { + if (legacy_v13) { + return block.getBlockData(); + } else if (legacy_v12) { + return block.getState().getData(); + } else { + return block.getType(); + } + } + + protected static int getSkillLegacy(Player player, String skill) { + if (player.hasMetadata("mcMMO: Player Data")) { + try { + Object skillType = mcmmo_SkillType_valueOf.invoke(null, skill.toUpperCase()); + return (int) mcmmo_McMMOPlayer_getSkillLevel.invoke(UserManager.getPlayer(player), skillType); + } catch (Exception ex1) { + Logger.getLogger(McMMOHandler.class.getName()).log(Level.SEVERE, "Failed to invoke McMMO Legacy Hook", ex1); + } + } + return 0; + } +} diff --git a/Core/src/main/java/com/songoda/core/hooks/protection/Protection.java b/Core/src/main/java/com/songoda/core/hooks/protection/Protection.java index 88e25bd6..12c23126 100644 --- a/Core/src/main/java/com/songoda/core/hooks/protection/Protection.java +++ b/Core/src/main/java/com/songoda/core/hooks/protection/Protection.java @@ -18,5 +18,4 @@ public abstract class Protection implements Hook { public abstract boolean canBreak(Player player, Location location); public abstract boolean canInteract(Player player, Location location); - } diff --git a/Core/src/main/java/com/songoda/core/hooks/stackers/StackMob.java b/Core/src/main/java/com/songoda/core/hooks/stackers/StackMob.java index 9e09ad1f..215f3e6c 100644 --- a/Core/src/main/java/com/songoda/core/hooks/stackers/StackMob.java +++ b/Core/src/main/java/com/songoda/core/hooks/stackers/StackMob.java @@ -78,5 +78,4 @@ public class StackMob extends Stacker { public int getMinStackSize(EntityType type) { return 0; } - } diff --git a/Core/src/main/java/com/songoda/core/hooks/stackers/Stacker.java b/Core/src/main/java/com/songoda/core/hooks/stackers/Stacker.java index e772eb34..5ed03c4c 100644 --- a/Core/src/main/java/com/songoda/core/hooks/stackers/Stacker.java +++ b/Core/src/main/java/com/songoda/core/hooks/stackers/Stacker.java @@ -32,5 +32,4 @@ public abstract class Stacker implements Hook { public abstract void add(LivingEntity entity, int amount); public abstract int getMinStackSize(EntityType type); - } diff --git a/Core/src/main/java/com/songoda/core/hooks/stackers/UltimateStacker.java b/Core/src/main/java/com/songoda/core/hooks/stackers/UltimateStacker.java index 29d8e7f8..aea6ca49 100644 --- a/Core/src/main/java/com/songoda/core/hooks/stackers/UltimateStacker.java +++ b/Core/src/main/java/com/songoda/core/hooks/stackers/UltimateStacker.java @@ -1,7 +1,6 @@ package com.songoda.core.hooks.stackers; import com.songoda.ultimatestacker.stackable.entity.EntityStack; -import com.songoda.ultimatestacker.stackable.entity.EntityStackManager; import com.songoda.ultimatestacker.utils.Methods; import org.bukkit.entity.EntityType; import org.bukkit.entity.Item; diff --git a/Core/src/main/java/com/songoda/core/hooks/stackers/WildStacker.java b/Core/src/main/java/com/songoda/core/hooks/stackers/WildStacker.java index 6fc388f1..01b0fb6b 100644 --- a/Core/src/main/java/com/songoda/core/hooks/stackers/WildStacker.java +++ b/Core/src/main/java/com/songoda/core/hooks/stackers/WildStacker.java @@ -75,5 +75,4 @@ public class WildStacker extends Stacker { } return min == -1 ? 0 : min; } - } diff --git a/Core/src/main/java/com/songoda/core/hooks/worldguard/WorldGuardFlagHandler.java b/Core/src/main/java/com/songoda/core/hooks/worldguard/WorldGuardFlagHandler.java index 3b490b80..f141fd77 100644 --- a/Core/src/main/java/com/songoda/core/hooks/worldguard/WorldGuardFlagHandler.java +++ b/Core/src/main/java/com/songoda/core/hooks/worldguard/WorldGuardFlagHandler.java @@ -1,414 +1,413 @@ -package com.songoda.core.hooks.worldguard; - -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitPlayer; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldguard.LocalPlayer; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.association.RegionAssociable; -import com.sk89q.worldguard.protection.flags.Flag; -import com.sk89q.worldguard.protection.flags.StateFlag; -import com.sk89q.worldguard.protection.flags.StateFlag.State; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; -import com.sk89q.worldguard.protection.regions.RegionQuery; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.stream.Stream; - -/** - * Hooks for adding a custom WorldGuard flag - *

- * Note: Hooks must be added before WG loads! - */ -public class WorldGuardFlagHandler { - - static boolean wgPlugin; - static Object worldGuardPlugin; - static boolean wg_v7 = false; - static boolean legacy_v60 = false; - static boolean legacy_v62 = false; - static boolean legacy_v5 = false; - static boolean hooksInstalled = false; - static Map flags = new HashMap(); - - static { - if ((wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) { - // a number of flags were introduced in 7.x that aren't in 5 or 6 - try { - // if this class exists, we're on 7.x - Class.forName("com.sk89q.worldguard.protection.flags.WeatherTypeFlag"); - wg_v7 = true; - } catch (ClassNotFoundException ex) { - try { - // if this class exists, we're on 6.2 - Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry"); - legacy_v62 = true; - } catch (ClassNotFoundException ex2) { - try { - // if this class exists, we're on 6.0 - Class.forName("com.sk89q.worldguard.protection.flags.BuildFlag"); - legacy_v60 = true; - } catch (ClassNotFoundException ex3) { - try { - // if this class exists, we're on 5.x - Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag"); - legacy_v5 = true; - } catch (ClassNotFoundException ex4) { - // ¯\_(ツ)_/¯ - wgPlugin = false; - } - } - } - } - } - } - - /** - * Attempt to register a worldGuard flag (ALLOW/DENY)
- * Note: This must be called before WorldGuard loads, or it will fail. - * - * @param flag name of the flag to set - * @param state default value of the flag - */ - public static void addHook(String flag, boolean state) { - if (!wgPlugin) { - return; - } - - if (legacy_v62 || legacy_v60 || legacy_v5) { - addLegacyHook(flag, state); - return; - } - - StateFlag addFlag = new StateFlag(flag, state); - try { - WorldGuard.getInstance().getFlagRegistry().register(addFlag); - flags.put(flag, addFlag); - } catch (Exception ex) { - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard", addFlag.getName()); - Object wgFlag = WorldGuard.getInstance().getFlagRegistry().get(addFlag.getName()); - if (wgFlag == null || !(wgFlag instanceof StateFlag)) { - wgPlugin = false; - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not hook WorldGuard"); - } else { - flags.put(flag, wgFlag); - Bukkit.getServer().getLogger().log(Level.WARNING, "Loaded existing {1} {0}", new Object[]{((Flag) wgFlag).getName(), wgFlag.getClass().getSimpleName()}); - } - } - } - - // reflection to add hooks - private static void addLegacyHook(String flag, boolean state) { - try { - // 6.0 has the same classpath for StateFlag as the current version does - // does this flag exist already? - Class defaultFlagClazz = Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag"); - Field flagField = defaultFlagClazz.getField("flagsList"); - Flag[] flagsOld = (Flag[]) flagField.get(null); - Flag wgFlag = Stream.of(flagsOld) - .filter(f -> ((Flag) f).getName().equalsIgnoreCase(flag)) - .findFirst().orElse(null); - if (wgFlag != null) { - // we already have one - flags.put(flag, wgFlag); - Bukkit.getServer().getLogger().log(Level.WARNING, "Loaded existing {1} {0}", new Object[]{wgFlag.getName(), wgFlag.getClass().getSimpleName()}); - return; - } - - // if not, we need to add one - wgFlag = new StateFlag(flag, state); - - // we need to sneak our flag into the array - // make a copy first - Flag[] flagsNew = new Flag[flagsOld.length + 1]; - System.arraycopy(flagsOld, 0, flagsNew, 0, flagsOld.length); - - // add ours - flagsNew[flagsNew.length - 1] = wgFlag; - - // and put the new list into place - setStaticField(flagField, flagsNew); - - if (legacy_v62) { // SimpleFlagRegistry is NOT in 6.0 or 6.1 - // register this flag in the registry - if (legacy_simpleFlagRegistryClazz == null) { - legacy_worldGuardPlugin_flagRegistry = getPrivateField(worldGuardPlugin.getClass(), worldGuardPlugin, "flagRegistry"); - legacy_simpleFlagRegistryClazz = Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry"); - legacy_simpleFlagRegistry_get = legacy_simpleFlagRegistryClazz.getDeclaredMethod("get", String.class); - } - legacy_simpleFlagRegistryClazz.getDeclaredMethod("register", Flag.class).invoke(legacy_worldGuardPlugin_flagRegistry, wgFlag); - } - - // all good! - flags.put(flag, wgFlag); - } catch (Exception ex) { - //Bukkit.getServer().getLogger().log(Level.WARNING, "Failed to set legacy WorldGuard Flags", ex); - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard " + (legacy_v62 ? "6.2" : (legacy_v60 ? "6.0" : "5")), flag); - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not hook WorldGuard"); - wgPlugin = false; - } - } - - private static Object getPrivateField(Class c, Object handle, String fieldName) throws Exception { - Field field = c.getDeclaredField(fieldName); - field.setAccessible(true); // This should be okay since it only runs on older versions. - return field.get(handle); - } - - private static void setStaticField(Field field, Object value) throws Exception { - field.setAccessible(true); // This should be okay since it only runs on older versions. - Field modifier = Field.class.getDeclaredField("modifiers"); - modifier.setAccessible(true); // This should be okay since it only runs on older versions. - modifier.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, value); - } - - public static boolean isEnabled() { - return wgPlugin; - } - - public static Object getFlag(String flag) { - Object flagObj = flags.get(flag); - - // load a flag if we don't know it - if (flagObj == null) { - if (wg_v7) { - flags.put(flag, flagObj = WorldGuard.getInstance().getFlagRegistry().get(flag)); - } else if (legacy_v62) { - try { - if (legacy_simpleFlagRegistryClazz == null) { - legacy_worldGuardPlugin_flagRegistry = getPrivateField(worldGuardPlugin.getClass(), worldGuardPlugin, "flagRegistry"); - legacy_simpleFlagRegistryClazz = Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry"); - legacy_simpleFlagRegistry_get = legacy_simpleFlagRegistryClazz.getDeclaredMethod("get", String.class); - } - flags.put(flag, flagObj = legacy_simpleFlagRegistry_get.invoke(legacy_worldGuardPlugin_flagRegistry, flag)); - } catch (Exception ex) { - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex); - } - } else if (!legacy_loadedFlags && (legacy_v60 || legacy_v5)) { - try { - Class defaultFlagClazz = Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag"); - Field flagField = defaultFlagClazz.getField("flagsList"); - Flag[] flagsOld = (Flag[]) flagField.get(null); - Stream.of(flagsOld).forEach(f -> flags.put(f.getName(), f)); - flagObj = flags.get(flag); - } catch (Exception ex) { - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex); - } - legacy_loadedFlags = true; - } - } - return flagObj; - } - - public static Boolean getBooleanFlag(Location loc, String flag) { - return getBooleanFlag(loc, flag, null); - } - - /** - * Checks this location to see what this flag is set to - * - * @param loc location to check - * @param flag ALLOW/DENY flag to check - * @return flag state, or null if undefined - */ - public static Boolean getBooleanFlag(Location loc, String flag, Player optionalPlayer) { - if (!wgPlugin) { - return null; - } - - LocalPlayer player = optionalPlayer != null ? WorldGuardPlugin.inst().wrapPlayer(optionalPlayer) : null; - - Object flagObj = getFlag(flag); - - // There's a different way to get this in the old version - if (legacy_v62 || legacy_v60 || legacy_v5) { - return flagObj == null ? null : getBooleanFlagLegacy(loc, flagObj); - } - - // so, what's up? - if (flagObj instanceof StateFlag) { - RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); - State result = query.getApplicableRegions(BukkitAdapter.adapt(loc)).queryState(player, (StateFlag) flagObj); - return result != null ? result == State.ALLOW : null; - } - return null; - } - - /** - * Query all regions that are in or intersect this chunk - * - * @param c chunk to check for regions in - * @param flag ALLOW/DENY flag to check - * @return flag state, or null if undefined - */ - public static Boolean getBooleanFlag(Chunk c, String flag) { - if (!wgPlugin) { - return null; - } - Object flagObj = getFlag(flag); - // There's a different way to get this in the old version - if (legacy_v62 || legacy_v60 || legacy_v5) { - return flagObj == null ? null : getBooleanFlagLegacy(c, flagObj); - } - - // so, what's up? - if (flagObj instanceof StateFlag) { - RegionManager worldManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(c.getWorld())); - if (worldManager == null) { - return null; - } - ProtectedCuboidRegion chunkRegion = new ProtectedCuboidRegion("__TEST__", - BlockVector3.at(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4), - BlockVector3.at((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15)); - ApplicableRegionSet set = worldManager.getApplicableRegions(chunkRegion); - State result = set.queryState((RegionAssociable) null, (StateFlag) flagObj); - if (result == null && set.size() == 0) { - return null; - } - return result == State.ALLOW; - } - return null; - } - - static Method legacy_getRegionManager = null; - static Method legacy_getApplicableRegions_Region = null; - static Method legacy_getApplicableRegions_Location = null; - static Method legacy5_applicableRegionSet_getFlag = null; - static Constructor legacy_newProtectedCuboidRegion; - static Class legacy_blockVectorClazz; - static Constructor legacy_newblockVector; - static Class legacy_VectorClazz; - static Constructor legacy_newVectorClazz; - static Method legacy_getApplicableRegions_Vector = null; - static Class legacy_simpleFlagRegistryClazz = null; // only used for 6.2 - static Method legacy_simpleFlagRegistry_get = null; // only used for 6.2 - static Object legacy_worldGuardPlugin_flagRegistry = null; // only used for 6.2 - static boolean legacy_loadedFlags = false; - - private static Boolean getBooleanFlagLegacy(Location l, Object flag) { - try { - // cache reflection methods - if (legacy_getRegionManager == null) { - legacy_getRegionManager = worldGuardPlugin.getClass() - .getDeclaredMethod("getRegionManager", org.bukkit.World.class); - legacy_getApplicableRegions_Region = RegionManager.class.getDeclaredMethod("getApplicableRegions", - Class.forName("com.sk89q.worldguard.protection.regions.ProtectedRegion")); - legacy_getApplicableRegions_Location = RegionManager.class.getDeclaredMethod("getApplicableRegions", - Location.class); - legacy_blockVectorClazz = Class.forName("com.sk89q.worldedit.BlockVector"); - legacy_newblockVector = legacy_blockVectorClazz.getConstructor(int.class, int.class, int.class); - legacy_newProtectedCuboidRegion = Class.forName("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion") - .getConstructor(String.class, legacy_blockVectorClazz, legacy_blockVectorClazz); - legacy_VectorClazz = Class.forName("com.sk89q.worldedit.Vector"); - legacy_newVectorClazz = legacy_VectorClazz.getConstructor(int.class, int.class, int.class); - legacy_getApplicableRegions_Vector = RegionManager.class.getDeclaredMethod("getApplicableRegions", legacy_VectorClazz); - } - - // grab the applicable manager for this world - Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, l.getWorld()); - if (worldManager == null) { - return null; - } - - // create a vector object - Object vec = legacy_newVectorClazz.newInstance(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - // now look for any intersecting regions - Object set = legacy_getApplicableRegions_Vector.invoke(worldManager, legacy_VectorClazz.cast(vec)); - - // so what's the verdict? - State result; - if (legacy_v62 || legacy_v60) { - result = (State) ((ApplicableRegionSet) set).queryState((RegionAssociable) null, (StateFlag) flag); - } else { - // v5 has a different class signature for ApplicableRegionSet - // also doesn't have a "queryState" function - //getFlag(T flag) - if (legacy5_applicableRegionSet_getFlag == null) { - legacy5_applicableRegionSet_getFlag = Class.forName("com.sk89q.worldguard.protection.ApplicableRegionSet").getMethod("getFlag", Flag.class); - } - result = (State) legacy5_applicableRegionSet_getFlag.invoke(set, flag); - } - if (result == null && set != null && ((Iterable) set).iterator().hasNext()) { - return null; - } - return result == State.ALLOW; - - } catch (Exception ex) { - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex); - } - return null; - } - - private static Boolean getBooleanFlagLegacy(Chunk c, Object flag) { - // ApplicableRegionSet and RegionManager have the same classpath as the current version - // ProtectedCuboidRegion uses a different constructor, though - try { - // cache reflection methods - if (legacy_getRegionManager == null) { - legacy_getRegionManager = worldGuardPlugin.getClass() - .getDeclaredMethod("getRegionManager", org.bukkit.World.class); - legacy_getApplicableRegions_Region = RegionManager.class.getDeclaredMethod("getApplicableRegions", - Class.forName("com.sk89q.worldguard.protection.regions.ProtectedRegion")); - legacy_getApplicableRegions_Location = RegionManager.class.getDeclaredMethod("getApplicableRegions", - Location.class); - legacy_blockVectorClazz = Class.forName("com.sk89q.worldedit.BlockVector"); - legacy_newblockVector = legacy_blockVectorClazz.getConstructor(int.class, int.class, int.class); - legacy_newProtectedCuboidRegion = Class.forName("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion") - .getConstructor(String.class, legacy_blockVectorClazz, legacy_blockVectorClazz); - legacy_VectorClazz = Class.forName("com.sk89q.worldedit.Vector"); - legacy_newVectorClazz = legacy_VectorClazz.getConstructor(int.class, int.class, int.class); - legacy_getApplicableRegions_Vector = RegionManager.class.getDeclaredMethod("getApplicableRegions", legacy_VectorClazz); - } - - // grab the applicable manager for this world - Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, c.getWorld()); - if (worldManager == null) { - return null; - } - - // Create a legacy ProtectedCuboidRegion - Object chunkRegion = legacy_newProtectedCuboidRegion.newInstance("__TEST__", - legacy_newblockVector.newInstance(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4), - legacy_newblockVector.newInstance((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15)); - - // now look for any intersecting regions - Object set = legacy_getApplicableRegions_Region.invoke(worldManager, chunkRegion); - - // so what's the verdict? - State result; - if (legacy_v62 || legacy_v60) { - result = (State) ((ApplicableRegionSet) set).queryState((RegionAssociable) null, (StateFlag) flag); - } else { - // v5 has a different class signature for ApplicableRegionSet - // also doesn't have a "queryState" function - //getFlag(T flag) - if (legacy5_applicableRegionSet_getFlag == null) { - legacy5_applicableRegionSet_getFlag = Class.forName("com.sk89q.worldguard.protection.ApplicableRegionSet").getMethod("getFlag", Flag.class); - } - result = (State) legacy5_applicableRegionSet_getFlag.invoke(set, flag); - } - if (result == null && set != null && ((Iterable) set).iterator().hasNext()) { - return null; - } - return result == State.ALLOW; - - } catch (Exception ex) { - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex); - } - return null; - } -} +package com.songoda.core.hooks.worldguard; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.association.RegionAssociable; +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.StateFlag.State; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.RegionQuery; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.stream.Stream; + +/** + * Hooks for adding a custom WorldGuard flag + *

+ * Note: Hooks must be added before WG loads! + */ +public class WorldGuardFlagHandler { + + static boolean wgPlugin; + static Object worldGuardPlugin; + static boolean wg_v7 = false; + static boolean legacy_v60 = false; + static boolean legacy_v62 = false; + static boolean legacy_v5 = false; + static boolean hooksInstalled = false; + static Map flags = new HashMap(); + + static { + if ((wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) { + // a number of flags were introduced in 7.x that aren't in 5 or 6 + try { + // if this class exists, we're on 7.x + Class.forName("com.sk89q.worldguard.protection.flags.WeatherTypeFlag"); + wg_v7 = true; + } catch (ClassNotFoundException ex) { + try { + // if this class exists, we're on 6.2 + Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry"); + legacy_v62 = true; + } catch (ClassNotFoundException ex2) { + try { + // if this class exists, we're on 6.0 + Class.forName("com.sk89q.worldguard.protection.flags.BuildFlag"); + legacy_v60 = true; + } catch (ClassNotFoundException ex3) { + try { + // if this class exists, we're on 5.x + Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag"); + legacy_v5 = true; + } catch (ClassNotFoundException ex4) { + // ¯\_(ツ)_/¯ + wgPlugin = false; + } + } + } + } + } + } + + /** + * Attempt to register a worldGuard flag (ALLOW/DENY)
+ * Note: This must be called before WorldGuard loads, or it will fail. + * + * @param flag name of the flag to set + * @param state default value of the flag + */ + public static void addHook(String flag, boolean state) { + if (!wgPlugin) { + return; + } + + if (legacy_v62 || legacy_v60 || legacy_v5) { + addLegacyHook(flag, state); + return; + } + + StateFlag addFlag = new StateFlag(flag, state); + try { + WorldGuard.getInstance().getFlagRegistry().register(addFlag); + flags.put(flag, addFlag); + } catch (Exception ex) { + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard", addFlag.getName()); + Object wgFlag = WorldGuard.getInstance().getFlagRegistry().get(addFlag.getName()); + if (wgFlag == null || !(wgFlag instanceof StateFlag)) { + wgPlugin = false; + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not hook WorldGuard"); + } else { + flags.put(flag, wgFlag); + Bukkit.getServer().getLogger().log(Level.WARNING, "Loaded existing {1} {0}", new Object[] {((Flag) wgFlag).getName(), wgFlag.getClass().getSimpleName()}); + } + } + } + + // reflection to add hooks + private static void addLegacyHook(String flag, boolean state) { + try { + // 6.0 has the same classpath for StateFlag as the current version does + // does this flag exist already? + Class defaultFlagClazz = Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag"); + Field flagField = defaultFlagClazz.getField("flagsList"); + Flag[] flagsOld = (Flag[]) flagField.get(null); + Flag wgFlag = Stream.of(flagsOld) + .filter(f -> ((Flag) f).getName().equalsIgnoreCase(flag)) + .findFirst().orElse(null); + if (wgFlag != null) { + // we already have one + flags.put(flag, wgFlag); + Bukkit.getServer().getLogger().log(Level.WARNING, "Loaded existing {1} {0}", new Object[] {wgFlag.getName(), wgFlag.getClass().getSimpleName()}); + return; + } + + // if not, we need to add one + wgFlag = new StateFlag(flag, state); + + // we need to sneak our flag into the array + // make a copy first + Flag[] flagsNew = new Flag[flagsOld.length + 1]; + System.arraycopy(flagsOld, 0, flagsNew, 0, flagsOld.length); + + // add ours + flagsNew[flagsNew.length - 1] = wgFlag; + + // and put the new list into place + setStaticField(flagField, flagsNew); + + if (legacy_v62) { // SimpleFlagRegistry is NOT in 6.0 or 6.1 + // register this flag in the registry + if (legacy_simpleFlagRegistryClazz == null) { + legacy_worldGuardPlugin_flagRegistry = getPrivateField(worldGuardPlugin.getClass(), worldGuardPlugin, "flagRegistry"); + legacy_simpleFlagRegistryClazz = Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry"); + legacy_simpleFlagRegistry_get = legacy_simpleFlagRegistryClazz.getDeclaredMethod("get", String.class); + } + legacy_simpleFlagRegistryClazz.getDeclaredMethod("register", Flag.class).invoke(legacy_worldGuardPlugin_flagRegistry, wgFlag); + } + + // all good! + flags.put(flag, wgFlag); + } catch (Exception ex) { + //Bukkit.getServer().getLogger().log(Level.WARNING, "Failed to set legacy WorldGuard Flags", ex); + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add flag {0} to WorldGuard " + (legacy_v62 ? "6.2" : (legacy_v60 ? "6.0" : "5")), flag); + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not hook WorldGuard"); + wgPlugin = false; + } + } + + private static Object getPrivateField(Class c, Object handle, String fieldName) throws Exception { + Field field = c.getDeclaredField(fieldName); + field.setAccessible(true); // This should be okay since it only runs on older versions. + return field.get(handle); + } + + private static void setStaticField(Field field, Object value) throws Exception { + field.setAccessible(true); // This should be okay since it only runs on older versions. + Field modifier = Field.class.getDeclaredField("modifiers"); + modifier.setAccessible(true); // This should be okay since it only runs on older versions. + modifier.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(null, value); + } + + public static boolean isEnabled() { + return wgPlugin; + } + + public static Object getFlag(String flag) { + Object flagObj = flags.get(flag); + + // load a flag if we don't know it + if (flagObj == null) { + if (wg_v7) { + flags.put(flag, flagObj = WorldGuard.getInstance().getFlagRegistry().get(flag)); + } else if (legacy_v62) { + try { + if (legacy_simpleFlagRegistryClazz == null) { + legacy_worldGuardPlugin_flagRegistry = getPrivateField(worldGuardPlugin.getClass(), worldGuardPlugin, "flagRegistry"); + legacy_simpleFlagRegistryClazz = Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry"); + legacy_simpleFlagRegistry_get = legacy_simpleFlagRegistryClazz.getDeclaredMethod("get", String.class); + } + flags.put(flag, flagObj = legacy_simpleFlagRegistry_get.invoke(legacy_worldGuardPlugin_flagRegistry, flag)); + } catch (Exception ex) { + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex); + } + } else if (!legacy_loadedFlags && (legacy_v60 || legacy_v5)) { + try { + Class defaultFlagClazz = Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag"); + Field flagField = defaultFlagClazz.getField("flagsList"); + Flag[] flagsOld = (Flag[]) flagField.get(null); + Stream.of(flagsOld).forEach(f -> flags.put(f.getName(), f)); + flagObj = flags.get(flag); + } catch (Exception ex) { + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex); + } + legacy_loadedFlags = true; + } + } + return flagObj; + } + + public static Boolean getBooleanFlag(Location loc, String flag) { + return getBooleanFlag(loc, flag, null); + } + + /** + * Checks this location to see what this flag is set to + * + * @param loc location to check + * @param flag ALLOW/DENY flag to check + * + * @return flag state, or null if undefined + */ + public static Boolean getBooleanFlag(Location loc, String flag, Player optionalPlayer) { + if (!wgPlugin) { + return null; + } + + LocalPlayer player = optionalPlayer != null ? WorldGuardPlugin.inst().wrapPlayer(optionalPlayer) : null; + + Object flagObj = getFlag(flag); + + // There's a different way to get this in the old version + if (legacy_v62 || legacy_v60 || legacy_v5) { + return flagObj == null ? null : getBooleanFlagLegacy(loc, flagObj); + } + + // so, what's up? + if (flagObj instanceof StateFlag) { + RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery(); + State result = query.getApplicableRegions(BukkitAdapter.adapt(loc)).queryState(player, (StateFlag) flagObj); + return result != null ? result == State.ALLOW : null; + } + return null; + } + + /** + * Query all regions that are in or intersect this chunk + * + * @param c chunk to check for regions in + * @param flag ALLOW/DENY flag to check + * + * @return flag state, or null if undefined + */ + public static Boolean getBooleanFlag(Chunk c, String flag) { + if (!wgPlugin) { + return null; + } + Object flagObj = getFlag(flag); + // There's a different way to get this in the old version + if (legacy_v62 || legacy_v60 || legacy_v5) { + return flagObj == null ? null : getBooleanFlagLegacy(c, flagObj); + } + + // so, what's up? + if (flagObj instanceof StateFlag) { + RegionManager worldManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(c.getWorld())); + if (worldManager == null) { + return null; + } + ProtectedCuboidRegion chunkRegion = new ProtectedCuboidRegion("__TEST__", + BlockVector3.at(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4), + BlockVector3.at((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15)); + ApplicableRegionSet set = worldManager.getApplicableRegions(chunkRegion); + State result = set.queryState((RegionAssociable) null, (StateFlag) flagObj); + if (result == null && set.size() == 0) { + return null; + } + return result == State.ALLOW; + } + return null; + } + + static Method legacy_getRegionManager = null; + static Method legacy_getApplicableRegions_Region = null; + static Method legacy_getApplicableRegions_Location = null; + static Method legacy5_applicableRegionSet_getFlag = null; + static Constructor legacy_newProtectedCuboidRegion; + static Class legacy_blockVectorClazz; + static Constructor legacy_newblockVector; + static Class legacy_VectorClazz; + static Constructor legacy_newVectorClazz; + static Method legacy_getApplicableRegions_Vector = null; + static Class legacy_simpleFlagRegistryClazz = null; // only used for 6.2 + static Method legacy_simpleFlagRegistry_get = null; // only used for 6.2 + static Object legacy_worldGuardPlugin_flagRegistry = null; // only used for 6.2 + static boolean legacy_loadedFlags = false; + + private static Boolean getBooleanFlagLegacy(Location l, Object flag) { + try { + // cache reflection methods + if (legacy_getRegionManager == null) { + legacy_getRegionManager = worldGuardPlugin.getClass() + .getDeclaredMethod("getRegionManager", org.bukkit.World.class); + legacy_getApplicableRegions_Region = RegionManager.class.getDeclaredMethod("getApplicableRegions", + Class.forName("com.sk89q.worldguard.protection.regions.ProtectedRegion")); + legacy_getApplicableRegions_Location = RegionManager.class.getDeclaredMethod("getApplicableRegions", + Location.class); + legacy_blockVectorClazz = Class.forName("com.sk89q.worldedit.BlockVector"); + legacy_newblockVector = legacy_blockVectorClazz.getConstructor(int.class, int.class, int.class); + legacy_newProtectedCuboidRegion = Class.forName("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion") + .getConstructor(String.class, legacy_blockVectorClazz, legacy_blockVectorClazz); + legacy_VectorClazz = Class.forName("com.sk89q.worldedit.Vector"); + legacy_newVectorClazz = legacy_VectorClazz.getConstructor(int.class, int.class, int.class); + legacy_getApplicableRegions_Vector = RegionManager.class.getDeclaredMethod("getApplicableRegions", legacy_VectorClazz); + } + + // grab the applicable manager for this world + Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, l.getWorld()); + if (worldManager == null) { + return null; + } + + // create a vector object + Object vec = legacy_newVectorClazz.newInstance(l.getBlockX(), l.getBlockY(), l.getBlockZ()); + // now look for any intersecting regions + Object set = legacy_getApplicableRegions_Vector.invoke(worldManager, legacy_VectorClazz.cast(vec)); + + // so what's the verdict? + State result; + if (legacy_v62 || legacy_v60) { + result = (State) ((ApplicableRegionSet) set).queryState((RegionAssociable) null, (StateFlag) flag); + } else { + // v5 has a different class signature for ApplicableRegionSet + // also doesn't have a "queryState" function + //getFlag(T flag) + if (legacy5_applicableRegionSet_getFlag == null) { + legacy5_applicableRegionSet_getFlag = Class.forName("com.sk89q.worldguard.protection.ApplicableRegionSet").getMethod("getFlag", Flag.class); + } + result = (State) legacy5_applicableRegionSet_getFlag.invoke(set, flag); + } + if (result == null && set != null && ((Iterable) set).iterator().hasNext()) { + return null; + } + return result == State.ALLOW; + } catch (Exception ex) { + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex); + } + return null; + } + + private static Boolean getBooleanFlagLegacy(Chunk c, Object flag) { + // ApplicableRegionSet and RegionManager have the same classpath as the current version + // ProtectedCuboidRegion uses a different constructor, though + try { + // cache reflection methods + if (legacy_getRegionManager == null) { + legacy_getRegionManager = worldGuardPlugin.getClass() + .getDeclaredMethod("getRegionManager", org.bukkit.World.class); + legacy_getApplicableRegions_Region = RegionManager.class.getDeclaredMethod("getApplicableRegions", + Class.forName("com.sk89q.worldguard.protection.regions.ProtectedRegion")); + legacy_getApplicableRegions_Location = RegionManager.class.getDeclaredMethod("getApplicableRegions", + Location.class); + legacy_blockVectorClazz = Class.forName("com.sk89q.worldedit.BlockVector"); + legacy_newblockVector = legacy_blockVectorClazz.getConstructor(int.class, int.class, int.class); + legacy_newProtectedCuboidRegion = Class.forName("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion") + .getConstructor(String.class, legacy_blockVectorClazz, legacy_blockVectorClazz); + legacy_VectorClazz = Class.forName("com.sk89q.worldedit.Vector"); + legacy_newVectorClazz = legacy_VectorClazz.getConstructor(int.class, int.class, int.class); + legacy_getApplicableRegions_Vector = RegionManager.class.getDeclaredMethod("getApplicableRegions", legacy_VectorClazz); + } + + // grab the applicable manager for this world + Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, c.getWorld()); + if (worldManager == null) { + return null; + } + + // Create a legacy ProtectedCuboidRegion + Object chunkRegion = legacy_newProtectedCuboidRegion.newInstance("__TEST__", + legacy_newblockVector.newInstance(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4), + legacy_newblockVector.newInstance((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15)); + + // now look for any intersecting regions + Object set = legacy_getApplicableRegions_Region.invoke(worldManager, chunkRegion); + + // so what's the verdict? + State result; + if (legacy_v62 || legacy_v60) { + result = (State) ((ApplicableRegionSet) set).queryState((RegionAssociable) null, (StateFlag) flag); + } else { + // v5 has a different class signature for ApplicableRegionSet + // also doesn't have a "queryState" function + //getFlag(T flag) + if (legacy5_applicableRegionSet_getFlag == null) { + legacy5_applicableRegionSet_getFlag = Class.forName("com.sk89q.worldguard.protection.ApplicableRegionSet").getMethod("getFlag", Flag.class); + } + result = (State) legacy5_applicableRegionSet_getFlag.invoke(set, flag); + } + if (result == null && set != null && ((Iterable) set).iterator().hasNext()) { + return null; + } + return result == State.ALLOW; + } catch (Exception ex) { + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab flags from WorldGuard", ex); + } + return null; + } +} diff --git a/Core/src/main/java/com/songoda/core/hooks/worldguard/WorldGuardRegionHandler.java b/Core/src/main/java/com/songoda/core/hooks/worldguard/WorldGuardRegionHandler.java index 3aa47119..b9528494 100644 --- a/Core/src/main/java/com/songoda/core/hooks/worldguard/WorldGuardRegionHandler.java +++ b/Core/src/main/java/com/songoda/core/hooks/worldguard/WorldGuardRegionHandler.java @@ -1,249 +1,248 @@ -package com.songoda.core.hooks.worldguard; - -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; -import org.bukkit.Location; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; - -public class WorldGuardRegionHandler { - - static boolean wgPlugin; - static Object worldGuardPlugin; - static boolean wg_v7 = false; - static boolean legacy_v60 = false; - static boolean legacy_v62 = false; - static boolean legacy_v5 = false; - static Method legacy_getRegionManager = null; - static Method legacy_getApplicableRegions_Region = null; - static Method legacy_getApplicableRegions_Location = null; - static Constructor legacy_newProtectedCuboidRegion; - static Class legacy_blockVectorClazz; - static Constructor legacy_newblockVector; - static Class legacy_VectorClazz; - static Constructor legacy_newVectorClazz; - static Method legacy_getApplicableRegions_Vector = null; - - static void init() { - if ((wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) { - // a number of flags were introduced in 7.x that aren't in 5 or 6 - try { - // if this class exists, we're on 7.x - Class.forName("com.sk89q.worldguard.protection.flags.WeatherTypeFlag"); - wg_v7 = true; - } catch (ClassNotFoundException ex) { - try { - // if this class exists, we're on 6.2 - Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry"); - legacy_v62 = true; - } catch (ClassNotFoundException ex2) { - try { - // if this class exists, we're on 6.0 - Class.forName("com.sk89q.worldguard.protection.flags.BuildFlag"); - legacy_v60 = true; - } catch (ClassNotFoundException ex3) { - try { - // if this class exists, we're on 5.x - Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag"); - legacy_v5 = true; - } catch (ClassNotFoundException ex4) { - // ¯\_(ツ)_/¯ - wgPlugin = false; - } - } - } - } - } - if (wgPlugin && (legacy_v62 || legacy_v60 || legacy_v5)) { - try { - // cache reflection methods - if (legacy_getRegionManager == null) { - legacy_getRegionManager = worldGuardPlugin.getClass() - .getDeclaredMethod("getRegionManager", org.bukkit.World.class); - legacy_getApplicableRegions_Region = RegionManager.class.getDeclaredMethod("getApplicableRegions", - Class.forName("com.sk89q.worldguard.protection.regions.ProtectedRegion")); - legacy_getApplicableRegions_Location = RegionManager.class.getDeclaredMethod("getApplicableRegions", - Location.class); - legacy_blockVectorClazz = Class.forName("com.sk89q.worldedit.BlockVector"); - legacy_newblockVector = legacy_blockVectorClazz.getConstructor(int.class, int.class, int.class); - legacy_newProtectedCuboidRegion = Class.forName("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion") - .getConstructor(String.class, legacy_blockVectorClazz, legacy_blockVectorClazz); - legacy_VectorClazz = Class.forName("com.sk89q.worldedit.Vector"); - legacy_newVectorClazz = legacy_VectorClazz.getConstructor(int.class, int.class, int.class); - legacy_getApplicableRegions_Vector = RegionManager.class.getDeclaredMethod("getApplicableRegions", legacy_VectorClazz); - } - } catch (Exception ex) { - //Bukkit.getServer().getLogger().log(Level.WARNING, "Failed to set legacy WorldGuard Flags", ex); - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not load WorldGuard methods for " + (legacy_v62 ? "6.2" : (legacy_v60 ? "6.0" : "5"))); - wgPlugin = false; - } - } - } - - public static List getRegionNames(Chunk c) { - if (worldGuardPlugin == null) { - init(); - } - if (!wgPlugin || c == null) { - return Collections.EMPTY_LIST; - } else if (legacy_v62 || legacy_v60 || legacy_v5) { - return getRegionNamesLegacy(c); - } - - RegionManager worldManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(c.getWorld())); - if (worldManager == null) { - return Collections.EMPTY_LIST; - } - ProtectedCuboidRegion chunkRegion = new ProtectedCuboidRegion("__TEST__", - BlockVector3.at(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4), - BlockVector3.at((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15)); - ApplicableRegionSet set = worldManager.getApplicableRegions(chunkRegion); - - List regions = new ArrayList<>(); - List parentNames = new ArrayList<>(); - - for (ProtectedRegion region : set) { - String id = region.getId(); - - regions.add(id); - - ProtectedRegion parent = region.getParent(); - - while (parent != null) { - parentNames.add(parent.getId()); - parent = parent.getParent(); - } - } - regions.removeAll(parentNames); - - return regions; - } - - private static List getRegionNamesLegacy(Chunk c) { - try { - // grab the applicable manager for this world - Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, c.getWorld()); - if (worldManager == null) { - return null; - } - // Create a legacy ProtectedCuboidRegion - Object chunkRegion = legacy_newProtectedCuboidRegion.newInstance("__TEST__", - legacy_newblockVector.newInstance(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4), - legacy_newblockVector.newInstance((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15)); - - // now look for any intersecting regions - // ApplicableRegionSet's prototype is different from v5 to v6, but they're both Iterable - Iterable set = (Iterable) legacy_getApplicableRegions_Region.invoke(worldManager, chunkRegion); - - List regions = new ArrayList<>(); - List parentNames = new ArrayList<>(); - - for (ProtectedRegion region : set) { - String id = region.getId(); - - regions.add(id); - - ProtectedRegion parent = region.getParent(); - - while (parent != null) { - parentNames.add(parent.getId()); - parent = parent.getParent(); - } - } - regions.removeAll(parentNames); - - return regions; - } catch (Exception ex) { - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab regions from WorldGuard", ex); - } - return Collections.EMPTY_LIST; - } - - public static List getRegionNames(Location loc) { - if (worldGuardPlugin == null) { - init(); - } - if (!wgPlugin || loc == null) { - return Collections.EMPTY_LIST; - } else if (legacy_v62 || legacy_v60 || legacy_v5) { - return getRegionNamesLegacy(loc); - } - - RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld())); - - if (regionManager == null) { - return Collections.EMPTY_LIST; - } - - List regions = new ArrayList<>(); - List parentNames = new ArrayList<>(); - ApplicableRegionSet set = regionManager.getApplicableRegions(BukkitAdapter.asBlockVector(loc)); - - for (ProtectedRegion region : set) { - String id = region.getId(); - - regions.add(id); - - ProtectedRegion parent = region.getParent(); - - while (parent != null) { - parentNames.add(parent.getId()); - parent = parent.getParent(); - } - } - regions.removeAll(parentNames); - - return regions; - - } - - private static List getRegionNamesLegacy(Location loc) { - try { - // grab the applicable manager for this world - Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, loc.getWorld()); - if (worldManager == null) { - return Collections.EMPTY_LIST; - } - - // create a vector object - Object vec = legacy_newVectorClazz.newInstance(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - // now look for any intersecting regions - // ApplicableRegionSet's prototype is different from v5 to v6, but they're both Iterable - Iterable set = (Iterable) legacy_getApplicableRegions_Vector.invoke(worldManager, legacy_VectorClazz.cast(vec)); - - List regions = new ArrayList<>(); - List parentNames = new ArrayList<>(); - - for (ProtectedRegion region : set) { - String id = region.getId(); - - regions.add(id); - - ProtectedRegion parent = region.getParent(); - - while (parent != null) { - parentNames.add(parent.getId()); - parent = parent.getParent(); - } - } - regions.removeAll(parentNames); - - return regions; - } catch (Exception ex) { - Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab regions from WorldGuard", ex); - } - return Collections.EMPTY_LIST; - } -} +package com.songoda.core.hooks.worldguard; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; + +public class WorldGuardRegionHandler { + + static boolean wgPlugin; + static Object worldGuardPlugin; + static boolean wg_v7 = false; + static boolean legacy_v60 = false; + static boolean legacy_v62 = false; + static boolean legacy_v5 = false; + static Method legacy_getRegionManager = null; + static Method legacy_getApplicableRegions_Region = null; + static Method legacy_getApplicableRegions_Location = null; + static Constructor legacy_newProtectedCuboidRegion; + static Class legacy_blockVectorClazz; + static Constructor legacy_newblockVector; + static Class legacy_VectorClazz; + static Constructor legacy_newVectorClazz; + static Method legacy_getApplicableRegions_Vector = null; + + static void init() { + if ((wgPlugin = (worldGuardPlugin = Bukkit.getPluginManager().getPlugin("WorldGuard")) != null)) { + // a number of flags were introduced in 7.x that aren't in 5 or 6 + try { + // if this class exists, we're on 7.x + Class.forName("com.sk89q.worldguard.protection.flags.WeatherTypeFlag"); + wg_v7 = true; + } catch (ClassNotFoundException ex) { + try { + // if this class exists, we're on 6.2 + Class.forName("com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry"); + legacy_v62 = true; + } catch (ClassNotFoundException ex2) { + try { + // if this class exists, we're on 6.0 + Class.forName("com.sk89q.worldguard.protection.flags.BuildFlag"); + legacy_v60 = true; + } catch (ClassNotFoundException ex3) { + try { + // if this class exists, we're on 5.x + Class.forName("com.sk89q.worldguard.protection.flags.DefaultFlag"); + legacy_v5 = true; + } catch (ClassNotFoundException ex4) { + // ¯\_(ツ)_/¯ + wgPlugin = false; + } + } + } + } + } + if (wgPlugin && (legacy_v62 || legacy_v60 || legacy_v5)) { + try { + // cache reflection methods + if (legacy_getRegionManager == null) { + legacy_getRegionManager = worldGuardPlugin.getClass() + .getDeclaredMethod("getRegionManager", org.bukkit.World.class); + legacy_getApplicableRegions_Region = RegionManager.class.getDeclaredMethod("getApplicableRegions", + Class.forName("com.sk89q.worldguard.protection.regions.ProtectedRegion")); + legacy_getApplicableRegions_Location = RegionManager.class.getDeclaredMethod("getApplicableRegions", + Location.class); + legacy_blockVectorClazz = Class.forName("com.sk89q.worldedit.BlockVector"); + legacy_newblockVector = legacy_blockVectorClazz.getConstructor(int.class, int.class, int.class); + legacy_newProtectedCuboidRegion = Class.forName("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion") + .getConstructor(String.class, legacy_blockVectorClazz, legacy_blockVectorClazz); + legacy_VectorClazz = Class.forName("com.sk89q.worldedit.Vector"); + legacy_newVectorClazz = legacy_VectorClazz.getConstructor(int.class, int.class, int.class); + legacy_getApplicableRegions_Vector = RegionManager.class.getDeclaredMethod("getApplicableRegions", legacy_VectorClazz); + } + } catch (Exception ex) { + //Bukkit.getServer().getLogger().log(Level.WARNING, "Failed to set legacy WorldGuard Flags", ex); + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not load WorldGuard methods for " + (legacy_v62 ? "6.2" : (legacy_v60 ? "6.0" : "5"))); + wgPlugin = false; + } + } + } + + public static List getRegionNames(Chunk c) { + if (worldGuardPlugin == null) { + init(); + } + if (!wgPlugin || c == null) { + return Collections.EMPTY_LIST; + } else if (legacy_v62 || legacy_v60 || legacy_v5) { + return getRegionNamesLegacy(c); + } + + RegionManager worldManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(c.getWorld())); + if (worldManager == null) { + return Collections.EMPTY_LIST; + } + ProtectedCuboidRegion chunkRegion = new ProtectedCuboidRegion("__TEST__", + BlockVector3.at(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4), + BlockVector3.at((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15)); + ApplicableRegionSet set = worldManager.getApplicableRegions(chunkRegion); + + List regions = new ArrayList<>(); + List parentNames = new ArrayList<>(); + + for (ProtectedRegion region : set) { + String id = region.getId(); + + regions.add(id); + + ProtectedRegion parent = region.getParent(); + + while (parent != null) { + parentNames.add(parent.getId()); + parent = parent.getParent(); + } + } + regions.removeAll(parentNames); + + return regions; + } + + private static List getRegionNamesLegacy(Chunk c) { + try { + // grab the applicable manager for this world + Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, c.getWorld()); + if (worldManager == null) { + return null; + } + // Create a legacy ProtectedCuboidRegion + Object chunkRegion = legacy_newProtectedCuboidRegion.newInstance("__TEST__", + legacy_newblockVector.newInstance(c.getX() << 4, c.getWorld().getMaxHeight(), c.getZ() << 4), + legacy_newblockVector.newInstance((c.getX() << 4) + 15, 0, (c.getZ() << 4) + 15)); + + // now look for any intersecting regions + // ApplicableRegionSet's prototype is different from v5 to v6, but they're both Iterable + Iterable set = (Iterable) legacy_getApplicableRegions_Region.invoke(worldManager, chunkRegion); + + List regions = new ArrayList<>(); + List parentNames = new ArrayList<>(); + + for (ProtectedRegion region : set) { + String id = region.getId(); + + regions.add(id); + + ProtectedRegion parent = region.getParent(); + + while (parent != null) { + parentNames.add(parent.getId()); + parent = parent.getParent(); + } + } + regions.removeAll(parentNames); + + return regions; + } catch (Exception ex) { + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab regions from WorldGuard", ex); + } + return Collections.EMPTY_LIST; + } + + public static List getRegionNames(Location loc) { + if (worldGuardPlugin == null) { + init(); + } + if (!wgPlugin || loc == null) { + return Collections.EMPTY_LIST; + } else if (legacy_v62 || legacy_v60 || legacy_v5) { + return getRegionNamesLegacy(loc); + } + + RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld())); + + if (regionManager == null) { + return Collections.EMPTY_LIST; + } + + List regions = new ArrayList<>(); + List parentNames = new ArrayList<>(); + ApplicableRegionSet set = regionManager.getApplicableRegions(BukkitAdapter.asBlockVector(loc)); + + for (ProtectedRegion region : set) { + String id = region.getId(); + + regions.add(id); + + ProtectedRegion parent = region.getParent(); + + while (parent != null) { + parentNames.add(parent.getId()); + parent = parent.getParent(); + } + } + regions.removeAll(parentNames); + + return regions; + } + + private static List getRegionNamesLegacy(Location loc) { + try { + // grab the applicable manager for this world + Object worldManager = (RegionManager) legacy_getRegionManager.invoke(worldGuardPlugin, loc.getWorld()); + if (worldManager == null) { + return Collections.EMPTY_LIST; + } + + // create a vector object + Object vec = legacy_newVectorClazz.newInstance(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + // now look for any intersecting regions + // ApplicableRegionSet's prototype is different from v5 to v6, but they're both Iterable + Iterable set = (Iterable) legacy_getApplicableRegions_Vector.invoke(worldManager, legacy_VectorClazz.cast(vec)); + + List regions = new ArrayList<>(); + List parentNames = new ArrayList<>(); + + for (ProtectedRegion region : set) { + String id = region.getId(); + + regions.add(id); + + ProtectedRegion parent = region.getParent(); + + while (parent != null) { + parentNames.add(parent.getId()); + parent = parent.getParent(); + } + } + regions.removeAll(parentNames); + + return regions; + } catch (Exception ex) { + Bukkit.getServer().getLogger().log(Level.WARNING, "Could not grab regions from WorldGuard", ex); + } + return Collections.EMPTY_LIST; + } +} diff --git a/Core/src/main/java/com/songoda/core/input/ChatPrompt.java b/Core/src/main/java/com/songoda/core/input/ChatPrompt.java index 5da9d921..325b82e4 100644 --- a/Core/src/main/java/com/songoda/core/input/ChatPrompt.java +++ b/Core/src/main/java/com/songoda/core/input/ChatPrompt.java @@ -157,5 +157,4 @@ public class ChatPrompt implements Listener { return message; } } - } diff --git a/Core/src/main/java/com/songoda/core/locale/Locale.java b/Core/src/main/java/com/songoda/core/locale/Locale.java index d501d993..4c29238b 100644 --- a/Core/src/main/java/com/songoda/core/locale/Locale.java +++ b/Core/src/main/java/com/songoda/core/locale/Locale.java @@ -7,7 +7,16 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -55,6 +64,7 @@ public class Locale { * * @param plugin plugin to load from * @param name name of the default locale, eg "en_US" + * * @return returns the loaded Locale, or null if there was an error */ public static Locale loadDefaultLocale(JavaPlugin plugin, String name) { @@ -67,6 +77,7 @@ public class Locale { * * @param plugin plugin to load from * @param name name of the locale, eg "en_US" + * * @return returns the loaded Locale, or null if there was an error */ public static Locale loadLocale(JavaPlugin plugin, String name) { @@ -85,6 +96,7 @@ public class Locale { * Load all locales from this plugin's locale directory * * @param plugin plugin to load from + * * @return returns the loaded Locales */ public static List loadAllLocales(JavaPlugin plugin) { @@ -130,6 +142,7 @@ public class Locale { * @param plugin plugin owning the locale file * @param locale the specific locale file to save * @param fileName where to save the file + * * @return true if the operation was successful, false otherwise */ public static boolean saveDefaultLocale(JavaPlugin plugin, String locale, String fileName) { @@ -142,6 +155,7 @@ public class Locale { * @param plugin plugin owning the locale file * @param in file to save * @param fileName the name of the file to save + * * @return true if the operation was successful, false otherwise */ public static boolean saveLocale(Plugin plugin, InputStream in, String fileName) { @@ -369,6 +383,7 @@ public class Locale { * Supply the Message object with the plugins prefix. * * @param message message to be applied + * * @return applied message */ private Message supplyPrefix(Message message) { @@ -379,6 +394,7 @@ public class Locale { * Create a new unsaved Message * * @param message the message to create + * * @return the created message */ public Message newMessage(String message) { @@ -389,6 +405,7 @@ public class Locale { * Get a message set for a specific node. * * @param node the node to get + * * @return the message for the specified node */ public Message getMessage(String node) { @@ -403,6 +420,7 @@ public class Locale { * * @param node the node to get * @param defaultValue the default value given that a value for the node was not found + * * @return the message for the specified node. Default if none found */ public Message getMessageOrDefault(String node, String defaultValue) { diff --git a/Core/src/main/java/com/songoda/core/locale/Message.java b/Core/src/main/java/com/songoda/core/locale/Message.java index cc5b8cae..ddfb804f 100644 --- a/Core/src/main/java/com/songoda/core/locale/Message.java +++ b/Core/src/main/java/com/songoda/core/locale/Message.java @@ -157,6 +157,7 @@ public class Message { * * @param placeholder the placeholder to replace * @param replacement the replacement object + * * @return the modified Message */ public Message processPlaceholder(String placeholder, Object replacement) { @@ -179,4 +180,4 @@ public class Message { public String toText() { return this.message.toText(); } -} \ No newline at end of file +} diff --git a/Core/src/main/java/com/songoda/core/lootables/gui/AbstractGuiListEditor.java b/Core/src/main/java/com/songoda/core/lootables/gui/AbstractGuiListEditor.java index 23b61d21..3f42e085 100644 --- a/Core/src/main/java/com/songoda/core/lootables/gui/AbstractGuiListEditor.java +++ b/Core/src/main/java/com/songoda/core/lootables/gui/AbstractGuiListEditor.java @@ -4,8 +4,8 @@ import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.gui.AnvilGui; import com.songoda.core.gui.Gui; import com.songoda.core.gui.GuiUtils; -import com.songoda.core.utils.TextUtils; import com.songoda.core.lootables.loot.Loot; +import com.songoda.core.utils.TextUtils; import java.util.ArrayList; import java.util.Collections; @@ -16,7 +16,7 @@ public abstract class AbstractGuiListEditor extends Gui { protected final Loot loot; private final Gui returnGui; - public AbstractGuiListEditor(Loot loot ,Gui returnGui) { + public AbstractGuiListEditor(Loot loot, Gui returnGui) { super(1, returnGui); this.returnGui = returnGui; this.loot = loot; @@ -27,19 +27,19 @@ public abstract class AbstractGuiListEditor extends Gui { public void paint() { List lore = getData() == null ? new ArrayList<>() : getData(); setButton(2, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, - TextUtils.formatText("&cBack")), + TextUtils.formatText("&cBack")), (event) -> { guiManager.showGUI(event.player, returnGui); ((GuiLootEditor) returnGui).paint(); }); setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, - TextUtils.formatText("&cBack")), + TextUtils.formatText("&cBack")), (event) -> { guiManager.showGUI(event.player, returnGui); ((GuiLootEditor) returnGui).paint(); }); setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, - TextUtils.formatText("&aAdd new line")), + TextUtils.formatText("&aAdd new line")), (event -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e -> { @@ -62,7 +62,7 @@ public abstract class AbstractGuiListEditor extends Gui { : TextUtils.formatText(lore))); setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, - TextUtils.formatText("&cRemove the last line")), + TextUtils.formatText("&cRemove the last line")), (event -> { lore.remove(lore.size() - 1); updateData(lore); diff --git a/Core/src/main/java/com/songoda/core/lootables/gui/GuiEnchantEditor.java b/Core/src/main/java/com/songoda/core/lootables/gui/GuiEnchantEditor.java index aaae930b..63ca6543 100644 --- a/Core/src/main/java/com/songoda/core/lootables/gui/GuiEnchantEditor.java +++ b/Core/src/main/java/com/songoda/core/lootables/gui/GuiEnchantEditor.java @@ -6,7 +6,6 @@ import com.songoda.core.gui.Gui; import com.songoda.core.gui.GuiUtils; import com.songoda.core.lootables.loot.Loot; import com.songoda.core.utils.TextUtils; -import com.songoda.core.lootables.loot.Loot; import org.bukkit.enchantments.Enchantment; import java.util.ArrayList; @@ -32,19 +31,19 @@ public class GuiEnchantEditor extends Gui { public void paint() { Map lore = loot.getEnchants() == null ? new HashMap<>() : new HashMap<>(loot.getEnchants()); setButton(2, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, - TextUtils.formatText("&cBack")), + TextUtils.formatText("&cBack")), (event) -> { guiManager.showGUI(event.player, returnGui); ((GuiLootEditor) returnGui).paint(); }); setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE, - TextUtils.formatText("&cBack")), + TextUtils.formatText("&cBack")), (event) -> { guiManager.showGUI(event.player, returnGui); ((GuiLootEditor) returnGui).paint(); }); setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, - TextUtils.formatText("&aAdd new line")), + TextUtils.formatText("&aAdd new line")), (event -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e -> { @@ -84,9 +83,9 @@ public class GuiEnchantEditor extends Gui { ? TextUtils.formatText(Collections.singletonList("&cNo enchantments set...")) : TextUtils.formatText(enchantments))); - String lastFinal = last; + String lastFinal = last; setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, - TextUtils.formatText("&cRemove the last line")), + TextUtils.formatText("&cRemove the last line")), (event -> { lore.remove(lastFinal); loot.setEnchants(lore); diff --git a/Core/src/main/java/com/songoda/core/lootables/gui/GuiLootEditor.java b/Core/src/main/java/com/songoda/core/lootables/gui/GuiLootEditor.java index 8e2d0228..f10fe666 100644 --- a/Core/src/main/java/com/songoda/core/lootables/gui/GuiLootEditor.java +++ b/Core/src/main/java/com/songoda/core/lootables/gui/GuiLootEditor.java @@ -4,10 +4,10 @@ import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.gui.AnvilGui; import com.songoda.core.gui.Gui; import com.songoda.core.gui.GuiUtils; -import com.songoda.core.utils.TextUtils; import com.songoda.core.lootables.loot.Loot; import com.songoda.core.lootables.loot.LootBuilder; import com.songoda.core.lootables.loot.LootManager; +import com.songoda.core.utils.TextUtils; import org.bukkit.entity.EntityType; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; @@ -42,7 +42,7 @@ public class GuiLootEditor extends Gui { setActionForRange(0, 0, 5, 9, null); setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, - TextUtils.formatText("&cBack")), + TextUtils.formatText("&cBack")), (event) -> { guiManager.showGUI(event.player, returnGui); }); @@ -60,7 +60,7 @@ public class GuiLootEditor extends Gui { }); setButton(10, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, - TextUtils.formatText("&7Name Override: &6" + (loot.getName() == null ? "None set" : loot.getName()))), + TextUtils.formatText("&7Name Override: &6" + (loot.getName() == null ? "None set" : loot.getName()))), (event) -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e -> { @@ -73,8 +73,8 @@ public class GuiLootEditor extends Gui { }); setButton(11, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK, - TextUtils.formatText("&7Lore Override:"), - TextUtils.formatText(loot.getLore() == null ? Collections.singletonList("&6None set") : loot.getLore())), + TextUtils.formatText("&7Lore Override:"), + TextUtils.formatText(loot.getLore() == null ? Collections.singletonList("&6None set") : loot.getLore())), (event) -> guiManager.showGUI(event.player, new GuiLoreEditor(loot, this))); List enchantments = new ArrayList<>(); @@ -84,22 +84,22 @@ public class GuiLootEditor extends Gui { enchantments.add("&6" + entry.getKey() + " " + entry.getValue()); setButton(12, GuiUtils.createButtonItem(CompatibleMaterial.ENCHANTED_BOOK, - TextUtils.formatText("&7Enchantments:"), - TextUtils.formatText(enchantments.isEmpty() ? Collections.singletonList("&6None set") : enchantments)), + TextUtils.formatText("&7Enchantments:"), + TextUtils.formatText(enchantments.isEmpty() ? Collections.singletonList("&6None set") : enchantments)), (event) -> guiManager.showGUI(event.player, new GuiEnchantEditor(loot, this))); setButton(13, GuiUtils.createButtonItem( - loot.getBurnedMaterial() == null - ? CompatibleMaterial.FIRE_CHARGE - : loot.getBurnedMaterial(), - TextUtils.formatText("&7Current Burned Material: &6" - + (loot.getBurnedMaterial() == null - ? "None" - : loot.getBurnedMaterial().name())), TextUtils.formatText( - Arrays.asList("", - "&8Click to set the burned material to", - "&8the material in your hand.") - )), + loot.getBurnedMaterial() == null + ? CompatibleMaterial.FIRE_CHARGE + : loot.getBurnedMaterial(), + TextUtils.formatText("&7Current Burned Material: &6" + + (loot.getBurnedMaterial() == null + ? "None" + : loot.getBurnedMaterial().name())), TextUtils.formatText( + Arrays.asList("", + "&8Click to set the burned material to", + "&8the material in your hand.") + )), (event) -> { ItemStack stack = event.player.getInventory().getItemInMainHand(); loot.setBurnedMaterial(CompatibleMaterial.getMaterial(stack)); @@ -107,12 +107,12 @@ public class GuiLootEditor extends Gui { }); setButton(14, GuiUtils.createButtonItem(CompatibleMaterial.CLOCK, - TextUtils.formatText("&7Chance: &6" + loot.getChance()), - TextUtils.formatText( - Arrays.asList("", - "&8Click to edit this loots", - "&8drop chance.") - )), + TextUtils.formatText("&7Chance: &6" + loot.getChance()), + TextUtils.formatText( + Arrays.asList("", + "&8Click to edit this loots", + "&8drop chance.") + )), (event) -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e) -> { @@ -126,7 +126,7 @@ public class GuiLootEditor extends Gui { }); setButton(15, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, - TextUtils.formatText("&7Min Drop Amount: &6" + loot.getMin())), + TextUtils.formatText("&7Min Drop Amount: &6" + loot.getMin())), (event) -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e) -> { @@ -140,7 +140,7 @@ public class GuiLootEditor extends Gui { }); setButton(16, GuiUtils.createButtonItem(CompatibleMaterial.GLOWSTONE_DUST, - TextUtils.formatText("&7Max Drop Amount: &6" + loot.getMax())), + TextUtils.formatText("&7Max Drop Amount: &6" + loot.getMax())), (event) -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e) -> { @@ -154,7 +154,7 @@ public class GuiLootEditor extends Gui { }); setButton(17, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, - TextUtils.formatText("&7Min Item Damage: &6" + loot.getDamageMin())), + TextUtils.formatText("&7Min Item Damage: &6" + loot.getDamageMin())), (event) -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e) -> { @@ -168,7 +168,7 @@ public class GuiLootEditor extends Gui { }); setButton(18, GuiUtils.createButtonItem(CompatibleMaterial.GLOWSTONE_DUST, - TextUtils.formatText("&7Max Item Damage: &6" + loot.getDamageMax())), + TextUtils.formatText("&7Max Item Damage: &6" + loot.getDamageMax())), (event) -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e) -> { @@ -182,7 +182,7 @@ public class GuiLootEditor extends Gui { }); setButton(19, GuiUtils.createButtonItem(CompatibleMaterial.CHEST, - TextUtils.formatText("&7Allow Looting Enchantment?: &6" + loot.isAllowLootingEnchant())), + TextUtils.formatText("&7Allow Looting Enchantment?: &6" + loot.isAllowLootingEnchant())), (event) -> { loot.setAllowLootingEnchant(!loot.isAllowLootingEnchant()); paint(); @@ -190,7 +190,7 @@ public class GuiLootEditor extends Gui { }); setButton(20, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, - TextUtils.formatText("&7Min Child Loot Min: &6" + loot.getChildDropCountMin())), + TextUtils.formatText("&7Min Child Loot Min: &6" + loot.getChildDropCountMin())), (event) -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e) -> { @@ -204,7 +204,7 @@ public class GuiLootEditor extends Gui { }); setButton(21, GuiUtils.createButtonItem(CompatibleMaterial.GLOWSTONE_DUST, - TextUtils.formatText("&7Min Child Loot Max: &6" + loot.getChildDropCountMax())), + TextUtils.formatText("&7Min Child Loot Max: &6" + loot.getChildDropCountMax())), (event) -> { AnvilGui gui = new AnvilGui(event.player, this); gui.setAction((e) -> { @@ -224,8 +224,8 @@ public class GuiLootEditor extends Gui { entities.add("&6" + entity.name()); setButton(22, GuiUtils.createButtonItem(CompatibleMaterial.ENCHANTED_BOOK, - TextUtils.formatText("&7Only Drop For:"), - TextUtils.formatText(entities)), + TextUtils.formatText("&7Only Drop For:"), + TextUtils.formatText(entities)), (event) -> guiManager.showGUI(event.player, new GuiEntityEditor(loot, this))); setButton(4, 0, GuiUtils.createButtonItem(CompatibleMaterial.LIME_DYE, TextUtils.formatText("&aCreate new Child Loot")), diff --git a/Core/src/main/java/com/songoda/core/lootables/gui/GuiLootableEditor.java b/Core/src/main/java/com/songoda/core/lootables/gui/GuiLootableEditor.java index 69f44010..fb1a0bd9 100644 --- a/Core/src/main/java/com/songoda/core/lootables/gui/GuiLootableEditor.java +++ b/Core/src/main/java/com/songoda/core/lootables/gui/GuiLootableEditor.java @@ -4,11 +4,11 @@ import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.gui.AnvilGui; import com.songoda.core.gui.Gui; import com.songoda.core.gui.GuiUtils; -import com.songoda.core.utils.TextUtils; import com.songoda.core.lootables.loot.Loot; import com.songoda.core.lootables.loot.LootBuilder; import com.songoda.core.lootables.loot.LootManager; import com.songoda.core.lootables.loot.Lootable; +import com.songoda.core.utils.TextUtils; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; diff --git a/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java b/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java index 7bda0ccd..ffbb14d0 100644 --- a/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java +++ b/Core/src/main/java/com/songoda/core/lootables/loot/DropUtils.java @@ -37,7 +37,7 @@ public class DropUtils { commands.add(drop.getCommand()); if (drop.getXp() != 0) - xp.add(drop.getXp()); + xp.add(drop.getXp()); } event.getDrops().clear(); @@ -65,5 +65,4 @@ public class DropUtils { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); } } - } diff --git a/Core/src/main/java/com/songoda/core/lootables/loot/Loot.java b/Core/src/main/java/com/songoda/core/lootables/loot/Loot.java index 21232cbc..107d89c9 100644 --- a/Core/src/main/java/com/songoda/core/lootables/loot/Loot.java +++ b/Core/src/main/java/com/songoda/core/lootables/loot/Loot.java @@ -161,7 +161,6 @@ public class Loot { this.enchants = enchants; } - public void setEnchantChances(Map enchants) { this.enchantChances = enchants; } diff --git a/Core/src/main/java/com/songoda/core/lootables/loot/LootBuilder.java b/Core/src/main/java/com/songoda/core/lootables/loot/LootBuilder.java index bfaf5053..797bbafd 100644 --- a/Core/src/main/java/com/songoda/core/lootables/loot/LootBuilder.java +++ b/Core/src/main/java/com/songoda/core/lootables/loot/LootBuilder.java @@ -1,6 +1,5 @@ package com.songoda.core.lootables.loot; - import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.lootables.loot.objects.EnchantChance; import org.bukkit.entity.EntityType; @@ -35,7 +34,7 @@ public final class LootBuilder { public LootBuilder addEnchants(Tuple... tuples) { Map enchants = new HashMap<>(); for (Tuple tuple : tuples) - enchants.put((String)tuple.getKey(), (int)tuple.getValue()); + enchants.put((String) tuple.getKey(), (int) tuple.getValue()); this.loot.setEnchants(enchants); return this; } @@ -118,7 +117,7 @@ public final class LootBuilder { this.loot.setRequireCharged(require); return this; } - + public Loot build() { return this.loot; } @@ -140,4 +139,4 @@ public final class LootBuilder { return this.y; } } -} \ No newline at end of file +} diff --git a/Core/src/main/java/com/songoda/core/lootables/loot/LootManager.java b/Core/src/main/java/com/songoda/core/lootables/loot/LootManager.java index eb5451a6..d701874b 100644 --- a/Core/src/main/java/com/songoda/core/lootables/loot/LootManager.java +++ b/Core/src/main/java/com/songoda/core/lootables/loot/LootManager.java @@ -140,7 +140,6 @@ public class LootManager { addLootable(lootable); reader.close(); - } catch (IOException e) { e.printStackTrace(); } @@ -164,7 +163,6 @@ public class LootManager { Gson gson = new GsonBuilder().setPrettyPrinting().create(); gson.toJson(lootable, writer); } - } catch (IOException e) { e.printStackTrace(); } diff --git a/Core/src/main/java/com/songoda/core/math/Eval.java b/Core/src/main/java/com/songoda/core/math/Eval.java index d290da9d..a68b51c8 100644 --- a/Core/src/main/java/com/songoda/core/math/Eval.java +++ b/Core/src/main/java/com/songoda/core/math/Eval.java @@ -27,7 +27,7 @@ public class Eval { public double parse() { nextChar(); double x = parseExpression(); - if (pos < toParse.length()) throw new RuntimeException(warningMessage + "Unexpected: " + (char)ch); + if (pos < toParse.length()) throw new RuntimeException(warningMessage + "Unexpected: " + (char) ch); return x; } @@ -39,8 +39,8 @@ public class Eval { private double parseExpression() { double x = parseTerm(); - for (;;) { - if (eat('+')) x += parseTerm(); // addition + for (; ; ) { + if (eat('+')) x += parseTerm(); // addition else if (eat('-')) x -= parseTerm(); // subtraction else return x; } @@ -48,8 +48,8 @@ public class Eval { private double parseTerm() { double x = parseFactor(); - for (;;) { - if (eat('*')) x *= parseFactor(); // multiplication + for (; ; ) { + if (eat('*')) x *= parseFactor(); // multiplication else if (eat('/')) x /= parseFactor(); // division else return x; } @@ -77,7 +77,7 @@ public class Eval { else if (func.equals("tan")) x = Math.tan(Math.toRadians(x)); else throw new RuntimeException(warningMessage + "Unknown function: " + func); } else { - throw new RuntimeException(warningMessage + "Unexpected: " + (char)ch); + throw new RuntimeException(warningMessage + "Unexpected: " + (char) ch); } if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation diff --git a/Core/src/main/java/com/songoda/core/utils/BlockUtils.java b/Core/src/main/java/com/songoda/core/utils/BlockUtils.java index 93321e50..7c5221b7 100644 --- a/Core/src/main/java/com/songoda/core/utils/BlockUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/BlockUtils.java @@ -1,1064 +1,1069 @@ -package com.songoda.core.utils; - -import com.songoda.core.compatibility.ClassMapping; -import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.compatibility.ServerVersion; -import org.bukkit.Bukkit; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.EnumSet; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class BlockUtils { - - protected static final Set DOORS; - protected static final Set PRESSURE_PLATES; - protected static final Set FENCE_GATES; - protected static final Set TRAP_DOORS; - protected static final boolean useLegacy = Material.getMaterial("OAK_LOG") == null; - protected static Method legacySetBlockData = null; - protected static Method legacyUpdateBlockData = null; - - static { - DOORS = EnumSet.noneOf(Material.class); - PRESSURE_PLATES = EnumSet.noneOf(Material.class); - FENCE_GATES = EnumSet.noneOf(Material.class); - TRAP_DOORS = EnumSet.noneOf(Material.class); - - for (Material material : Material.values()) { - String name = material.name(); - if (name.contains("DOOR") && !name.contains("ITEM")) { - if (name.contains("TRAP")) { - TRAP_DOORS.add(material); - } else { - DOORS.add(material); - } - } else if (name.contains("GATE") && !name.contains("END")) { - FENCE_GATES.add(material); - } else if (name.contains("_PLATE")) { - PRESSURE_PLATES.add(material); - } - } - - if (useLegacy) { - try { - //legacyUpdateBlockData = Block.class.getDeclaredMethod("update"); - legacySetBlockData = Block.class.getDeclaredMethod("setData", byte.class); - } catch (NoSuchMethodException ex) { - } - } - } - - /** - * Interact with this block to either update redstone or open doors - * - * @param b block to update - * @return if this block's state was updated - */ - public static boolean tryInteract(Block b) { - final Material bType = b.getType(); - if (isOpenable(bType)) { - toggleDoorStates(true, b); - return true; - } else if (bType == Material.LEVER) { - toggleLever(b); - return true; - } else if (bType.name().endsWith("_BUTTON")) { - pressButton(b); - return true; - } - - return false; - } - - /** - * Change a pressure plate's redstone state - * - * @param plate plate to update - * @param power power to set to 0-15 (wood plates are active if greater than 0) - */ - public static void updatePressurePlate(Block plate, int power) { - if (useLegacy && legacySetBlockData != null) { - _updatePressurePlateLegacy(plate, power); - } else { - BlockUtilsModern._updatePressurePlateModern(plate, power); - } - } - - private static void _updatePressurePlateLegacy(Block plate, int power) { - final Material m = plate.getType(); - try { - if (m.name().equals("GOLD_PLATE") || m.name().equals("IRON_PLATE")) { - legacySetBlockData.invoke(plate, (byte) (power & 0x15)); - } else if (m.name().endsWith("_PLATE")) { - legacySetBlockData.invoke(plate, (byte) (power == 0 ? 0 : 1)); - } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); - } - } - - public static void pressButton(Block button) { - if (useLegacy && legacySetBlockData != null) { - _pressButtonLegacy(button); - } else { - BlockUtilsModern._pressButtonModern(button); - } - } - - public static void releaseButton(Block button) { - if (useLegacy && legacySetBlockData != null) { - _releaseButtonLegacy(button); - } else { - BlockUtilsModern._releaseButtonModern(button); - } - } - - private static void _pressButtonLegacy(Block button) { - final Material m = button.getType(); - if (!m.name().endsWith("_BUTTON")) return; - try { - legacySetBlockData.invoke(button, (byte) (button.getData() | (31 & 0x8))); - button.getState().update(); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); - } - } - - private static void _releaseButtonLegacy(Block button) { - final Material m = button.getType(); - if (!m.name().endsWith("_BUTTON")) return; - try { - legacySetBlockData.invoke(button, (byte) (button.getData() & ~0x8)); - button.getState().update(); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); - } - } - - public static void toggleLever(Block lever) { - if (useLegacy && legacySetBlockData != null) { - _toggleLeverLegacy(lever); - } else { - BlockUtilsModern._toggleLeverModern(lever); - } - } - - private static void _toggleLeverLegacy(Block lever) { - final Material m = lever.getType(); - if (m != Material.LEVER) return; - try { - legacySetBlockData.invoke(lever, (byte) (lever.getData() ^ 0x8)); - lever.getState().update(); - //lever.getWorld().playEffect(lever.getLocation(), Effect.CLICK1, 0); - // now we need to update the redstone around it.. -// int data = lever.getData() & ~0x8; -// Block attached; -// switch(data) { -// case 0: -// attached = lever.getRelative(BlockFace.UP); -// break; -// case 1: -// attached = lever.getRelative(BlockFace.WEST); -// break; -// case 2: -// attached = lever.getRelative(BlockFace.EAST); -// break; -// case 3: -// attached = lever.getRelative(BlockFace.NORTH); -// break; -// case 4: -// attached = lever.getRelative(BlockFace.SOUTH); -// break; -// case 5: -// attached = lever.getRelative(BlockFace.DOWN); -// break; -// default: -// return; -// } -// - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); - } - } - - /** - * Change all of the given door states to be inverse; that is, if a door is - * open, it will be closed afterwards. If the door is closed, it will become - * open. - *

- * Note that the blocks given must be the bottom block of the door. - * - * @param allowDoorToOpen If FALSE, and the door is currently CLOSED, it - * will NOT be opened! - * @param doors Blocks given must be the bottom block of the door - */ - public static void toggleDoorStates(boolean allowDoorToOpen, Block... doors) { - if (useLegacy && legacySetBlockData != null) { - _toggleDoorStatesLegacy(allowDoorToOpen, doors); - } else { - BlockUtilsModern._toggleDoorStatesModern(allowDoorToOpen, doors); - } - } - - private static void _toggleDoorStatesLegacy(boolean allowDoorToOpen, Block... doors) { - try { - for (Block door : doors) { - if (door == null) { - continue; - } - - boolean isTop = (door.getData() & 0x8) != 0; - if (isTop) { - // The lower half of the door contains the direction & open/close state - door = door.getRelative(BlockFace.DOWN); - } - - // If we aren't allowing the door to open, check if it's already closed - if (!allowDoorToOpen && (door.getData() & 0x4) == 0) { - // The door is already closed and we don't want to open it - // the bit 0x4 is set when the door is open - continue; - } - - // Now xor both data values with 0x4, the flag that states if the door is open - legacySetBlockData.invoke(door, (byte) (door.getData() ^ 0x4)); - - // Play the door open/close sound - door.getWorld().playEffect(door.getLocation(), Effect.DOOR_TOGGLE, 0); - } - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); - } - } - - /** - * Get the double door for the given block - * - * @param block - * @return - */ - public static Block getDoubleDoor(Block block) { - // TODO? if legacy, just search N/S/E/W to see if there's another door nearby - if (!isOpenable(block.getType())) { - return null; - } - - return BlockUtilsModern._getDoubleDoorModern(block); - } - - public static boolean isOpenable(Material m) { - return DOORS.contains(m) - || FENCE_GATES.contains(m) - || TRAP_DOORS.contains(m); - } - - public static BlockFace getDoorClosedDirection(Block door) { - return useLegacy ? _getDoorClosedDirectionLegacy(door) : BlockUtilsModern._getDoorClosedDirectionModern(door); - } - - private static BlockFace _getDoorClosedDirectionLegacy(Block door) { - final Material type = door.getType(); - if (DOORS.contains(type)) { - boolean isTop = (door.getData() & 0x8) != 0; - if (isTop) { - // The lower half of the door contains the direction & open/close state - door = door.getRelative(BlockFace.DOWN); - if (door.getType() != type) { - return null; - } - } - boolean isOpen = (door.getData() & 0x4) != 0; - //int facing = (door.getData() & 0x3); - // [east, south, west, north] - boolean facingNS = (door.getData() & 0x1) != 0; - if (facingNS) { - return isOpen ? BlockFace.EAST : BlockFace.SOUTH; - } else { - return isOpen ? BlockFace.SOUTH : BlockFace.EAST; - } - } else if (FENCE_GATES.contains(door.getType())) { - boolean isOpen = (door.getData() & 0x4) != 0; - //int facing = (door.getData() & 0x3); - // so fence gate orientations are [south, west, north, east] - boolean facingNS = (door.getData() & 0x1) == 0; - if (facingNS) { - return isOpen ? BlockFace.EAST : BlockFace.SOUTH; - } else { - return isOpen ? BlockFace.SOUTH : BlockFace.EAST; - } - } else if (TRAP_DOORS.contains(door.getType())) { - boolean isOpen = (door.getData() & 0x4) != 0; - // [south, north, east, west] - boolean facingNS = (door.getData() & 0x3) <= 1; - if (facingNS) { - return isOpen ? BlockFace.EAST : BlockFace.SOUTH; - } else { - return isOpen ? BlockFace.SOUTH : BlockFace.EAST; - } - } - return null; - } - - private static Class clazzCraftWorld, clazzCraftBlock, clazzBlockPosition; - private static Method getHandle, updateAdjacentComparators, craftBlock_getNMS, nmsBlockData_getBlock; - - /** - * Manually trigger the updateAdjacentComparators method for containers - * - * @param location location of the container - */ - public static void updateAdjacentComparators(Location location) { - if (location == null || location.getWorld() == null) return; - try { - // Cache reflection. - if (clazzCraftWorld == null) { - clazzCraftWorld = ClassMapping.CRAFT_WORLD.getClazz(); - clazzCraftBlock = ClassMapping.CRAFT_BLOCK.getClazz(); - clazzBlockPosition = ClassMapping.BLOCK_POSITION.getClazz(); - Class clazzWorld = ClassMapping.WORLD.getClazz(); - Class clazzBlock = ClassMapping.BLOCK.getClazz(); - - getHandle = clazzCraftWorld.getMethod("getHandle"); - updateAdjacentComparators = clazzWorld.getMethod("updateAdjacentComparators", clazzBlockPosition, clazzBlock); - - craftBlock_getNMS = clazzCraftBlock.getDeclaredMethod("getNMS"); - Class clazzBlockData = ClassMapping.BLOCK_BASE.getClazz("BlockData"); - nmsBlockData_getBlock = clazzBlockData.getDeclaredMethod("getBlock"); - } - - // invoke and cast objects. - Object craftWorld = clazzCraftWorld.cast(location.getWorld()); - Object world = getHandle.invoke(craftWorld); - Object craftBlock = clazzCraftBlock.cast(location.getBlock()); - - // Invoke final method. - updateAdjacentComparators - .invoke(world, clazzBlockPosition.getConstructor(double.class, double.class, double.class) - .newInstance(location.getX(), location.getY(), location.getZ()), - nmsBlockData_getBlock.invoke(craftBlock_getNMS.invoke(craftBlock))); - - } catch (ReflectiveOperationException e) { - e.printStackTrace(); - } - } - - private static Class clazzIBlockData, clazzBlocks; - private static Method getByCombinedId, setType, getChunkAt, getBlockData; - - /** - * Set a block to a certain type by updating the block directly in the - * NMS chunk. - *

- * The chunk must be loaded and players must relog if they have the - * chunk loaded in order to use this method. - * - * @param world - * @param x - * @param y - * @param z - * @param material - * @param data - */ - public static void setBlockFast(World world, int x, int y, int z, Material material, byte data) { - try { - // Cache reflection - if (clazzIBlockData == null) { - clazzIBlockData = ClassMapping.I_BLOCK_DATA.getClazz(); - clazzBlockPosition = ClassMapping.BLOCK_POSITION.getClazz(); - clazzCraftWorld = ClassMapping.CRAFT_WORLD.getClazz(); - clazzBlocks = ClassMapping.BLOCKS.getClazz(); - Class clazzBlock = ClassMapping.BLOCK.getClazz(); - Class clazzWorld = ClassMapping.WORLD.getClazz(); - Class clazzChunk = ClassMapping.CHUNK.getClazz(); - - getHandle = clazzCraftWorld.getMethod("getHandle"); - getChunkAt = clazzWorld.getMethod("getChunkAt", int.class, int.class); - - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - getBlockData = clazzBlock.getMethod("getBlockData"); - setType = clazzChunk.getMethod("setType", clazzBlockPosition, clazzIBlockData, boolean.class); - } else { - getByCombinedId = clazzBlock.getMethod("getByCombinedId", int.class); - setType = clazzChunk.getMethod("a", clazzBlockPosition, clazzIBlockData); - } - } - - // invoke and cast objects. - Object craftWorld = clazzCraftWorld.cast(world); - Object nmsWorld = getHandle.invoke(craftWorld); - Object chunk = getChunkAt.invoke(nmsWorld, x >> 4, z >> 4); - Object blockPosition = clazzBlockPosition.getConstructor(int.class, int.class, int.class).newInstance(x & 0xF, y, z & 0xF); - - // Invoke final method. - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - Object block = clazzBlocks.getField(material.name()).get(null); - Object IBlockData = getBlockData.invoke(block); - setType.invoke(chunk, blockPosition, IBlockData, true); - } else { - Object IBlockData = getByCombinedId.invoke(null, material.getId() + (data << 12)); - setType.invoke(chunk, blockPosition, IBlockData); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static void setBlockFast(World world, int x, int y, int z, CompatibleMaterial material, byte data) { - setBlockFast(world, x, y, z, material.getBlockMaterial(), data); - } - - /** - * Checks if a crop is at its max growth stage - * - * @param block The crop block to check - * @return true if the block is a crop and at its max growth stage - */ - public static boolean isCropFullyGrown(Block block) { - if (block == null) { - return false; - } else if (!useLegacy) { - return BlockUtilsModern._isCropFullyGrown(block); - } - CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); - if (mat == null || !mat.isCrop()) { - return false; - } else { - return block.getData() >= (mat == CompatibleMaterial.BEETROOTS - || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); - } - } - - /** - * Gets the max growth stage for the given block - * - * @param block The crop block to check - * @return The max growth stage of the given crop type, or -1 if not a crop - */ - public static int getMaxGrowthStage(Block block) { - if (block == null) { - return -1; - } else if (!useLegacy) { - return BlockUtilsModern._getMaxGrowthStage(block); - } - CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); - if (mat == null || !mat.isCrop()) { - return -1; - } else { - return (mat == CompatibleMaterial.BEETROOTS - || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); - } - } - - /** - * Gets the max growth stage for the given material - * - * @param material The material of the crop - * @return The max growth stage of the given crop type - */ - public static int getMaxGrowthStage(Material material) { - if (material == null) { - return -1; - } else if (!useLegacy) { - return BlockUtilsModern._getMaxGrowthStage(material); - } - CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(material); - if (mat == null || !mat.isCrop()) { - return -1; - } else { - return (mat == CompatibleMaterial.BEETROOTS - || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); - } - } - - /** - * Sets the max growth stage for the given block - * - * @param block The crop block to change - * @param stage new growth stage to use - */ - public static void setGrowthStage(Block block, int stage) { - if (block == null) { - } else if (!useLegacy) { - BlockUtilsModern._setGrowthStage(block, stage); - } else { - CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); - if (mat != null && mat.isCrop()) { - try { - legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, (mat == CompatibleMaterial.BEETROOTS - || mat == CompatibleMaterial.NETHER_WART ? 3 : 7)))); - } catch (Exception ex) { - Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); - } - } - } - } - - /** - * Increments the growth stage for the given block - * - * @param block The crop block to grow - */ - public static void incrementGrowthStage(Block block) { - if (block == null) { - } else if (!useLegacy) { - BlockUtilsModern._incrementGrowthStage(block); - } else { - CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); - if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS - || mat == CompatibleMaterial.NETHER_WART ? 3 : 7)) { - try { - legacySetBlockData.invoke(block, (byte) (block.getData() + 1)); - } catch (Exception ex) { - Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); - } - } - } - } - - /** - * Sets a crop's growth back to stage 0 - * - * @param block The crop block to set - */ - public static void resetGrowthStage(Block block) { - if (block == null) { - } else if (!useLegacy) { - BlockUtilsModern._resetGrowthStage(block); - } else { - CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); - if (mat != null && mat.isCrop()) { - try { - legacySetBlockData.invoke(block, (byte) 0); - } catch (Exception ex) { - Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); - } - } - } - } - - /** - * Check to see if this material does not impede player/mob movement at all. - * - * @param m material to check - * @return true if this material doesn't have a solid hitbox - */ - public static boolean canPassThrough(Material m) { - - switch (m.name()) { - case "ACACIA_BUTTON": - case "ACACIA_PRESSURE_PLATE": - case "ACACIA_SAPLING": - case "ACACIA_SIGN": - case "ACACIA_WALL_SIGN": - case "ACTIVATOR_RAIL": - case "AIR": - case "ATTACHED_MELON_STEM": - case "ATTACHED_PUMPKIN_STEM": - case "AZURE_BLUET": - case "BEETROOTS": - case "BIRCH_BUTTON": - case "BIRCH_PRESSURE_PLATE": - case "BIRCH_SAPLING": - case "BIRCH_SIGN": - case "BIRCH_WALL_SIGN": - case "BLACK_WALL_BANNER": - case "BLUE_BANNER": - case "BLUE_ORCHID": - case "BLUE_WALL_BANNER": - case "BRAIN_CORAL_FAN": - case "BRAIN_CORAL_WALL_FAN": - case "BROWN_BANNER": - case "BROWN_MUSHROOM": - case "BROWN_WALL_BANNER": - case "BUBBLE_CORAL_FAN": - case "BUBBLE_CORAL_WALL_FAN": - case "CARROTS": - case "CAVE_AIR": - case "COBWEB": - case "CORNFLOWER": - case "CYAN_BANNER": - case "CYAN_WALL_BANNER": - case "DANDELION": - case "DARK_OAK_BUTTON": - case "DARK_OAK_PRESSURE_PLATE": - case "DARK_OAK_SAPLING": - case "DARK_OAK_SIGN": - case "DARK_OAK_WALL_SIGN": - case "DEAD_BRAIN_CORAL_FAN": - case "DEAD_BRAIN_CORAL_WALL_FAN": - case "DEAD_BUBBLE_CORAL_FAN": - case "DEAD_BUBBLE_CORAL_WALL_FAN": - case "DEAD_BUSH": - case "DEAD_FIRE_CORAL_FAN": - case "DEAD_FIRE_CORAL_WALL_FAN": - case "DEAD_HORN_CORAL_FAN": - case "DEAD_HORN_CORAL_WALL_FAN": - case "DEAD_TUBE_CORAL_FAN": - case "DEAD_TUBE_CORAL_WALL_FAN": - case "DETECTOR_RAIL": - case "END_PORTAL": - case "FERN": - case "FIRE": - case "FIRE_CORAL_FAN": - case "FIRE_CORAL_WALL_FAN": - case "GRASS": - case "GRAY_BANNER": - case "GRAY_WALL_BANNER": - case "GREEN_BANNER": - case "GREEN_WALL_BANNER": - case "HEAVY_WEIGHTED_PRESSURE_PLATE": - case "HORN_CORAL_FAN": - case "HORN_CORAL_WALL_FAN": - case "JUNGLE_BUTTON": - case "JUNGLE_PRESSURE_PLATE": - case "JUNGLE_SAPLING": - case "JUNGLE_SIGN": - case "JUNGLE_WALL_SIGN": - case "KELP": - case "LADDER": - case "LARGE_FERN": - case "LAVA": - case "LEVER": - case "LIGHT_BLUE_BANNER": - case "LIGHT_BLUE_WALL_BANNER": - case "LIGHT_GRAY_BANNER": - case "LIGHT_GRAY_WALL_BANNER": - case "LIGHT_WEIGHTED_PRESSURE_PLATE": - case "LILAC": - case "LILY_OF_THE_VALLEY": - case "LIME_BANNER": - case "MAGENTA_BANNER": - case "MAGENTA_WALL_BANNER": - case "MELON_STEM": - case "NETHER_PORTAL": - case "NETHER_WART": - case "OAK_BUTTON": - case "OAK_PRESSURE_PLATE": - case "OAK_SAPLING": - case "OAK_SIGN": - case "OAK_WALL_SIGN": - case "ORANGE_BANNER": - case "ORANGE_TULIP": - case "ORANGE_WALL_BANNER": - case "OXEYE_DAISY": - case "PEONY": - case "PINK_BANNER": - case "PINK_TULIP": - case "PINK_WALL_BANNER": - case "POTATOES": - case "POWERED_RAIL": - case "PUMPKIN_STEM": - case "PURPLE_BANNER": - case "PURPLE_WALL_BANNER": - case "RAIL": - case "REDSTONE_TORCH": - case "REDSTONE_WALL_TORCH": - case "REDSTONE_WIRE": - case "RED_BANNER": - case "RED_MUSHROOM": - case "RED_TULIP": - case "RED_WALL_BANNER": - case "ROSE_BUSH": - case "SCAFFOLDING": - case "SEAGRASS": - case "SPRUCE_BUTTON": - case "SPRUCE_PRESSURE_PLATE": - case "SPRUCE_SAPLING": - case "SPRUCE_SIGN": - case "SPRUCE_WALL_SIGN": - case "STONE_BUTTON": - case "STONE_PRESSURE_PLATE": - case "STRUCTURE_VOID": - case "SUGAR_CANE": - case "SUNFLOWER": - case "SWEET_BERRY_BUSH": - case "TALL_GRASS": - case "TALL_SEAGRASS": - case "TORCH": - case "TRIPWIRE": - case "TRIPWIRE_HOOK": - case "TUBE_CORAL_FAN": - case "TUBE_CORAL_WALL_FAN": - case "VINE": - case "VOID_AIR": - case "WALL_TORCH": - case "WATER": - case "WHEAT": - case "WHITE_BANNER": - case "WHITE_TULIP": - case "WHITE_WALL_BANNER": - case "WITHER_ROSE": - case "YELLOW_BANNER": - case "YELLOW_WALL_BANNER": - // Legacy values: - case "WEB": - case "LONG_GRASS": - case "YELLOW_FLOWER": - case "RED_ROSE": - case "CROPS": - case "SIGN_POST": - case "RAILS": - case "WALL_SIGN": - case "STONE_PLATE": - case "WOOD_PLATE": - case "REDSTONE_TORCH_OFF": - case "REDSTONE_TORCH_ON": - case "SUGAR_CANE_BLOCK": - case "PORTAL": - case "ENDER_PORTAL": - case "CARROT": - case "POTATO": - case "WOOD_BUTTON": - case "GOLD_PLATE": - case "IRON_PLATE": - case "DOUBLE_PLANT": - case "STANDING_BANNER": - case "WALL_BANNER": - case "BEETROOT_BLOCK": - return true; - } - return false; - } - - /** - * Check to see if a player can walk into this material
- * This includes blocks like slabs and stairs - * - * @param m material to check - * @return true if this is a block that can be walked though or up - */ - public static boolean canWalkTo(Material m) { - switch (m.name()) { - case "ACACIA_BUTTON": - case "ACACIA_PRESSURE_PLATE": - case "ACACIA_SAPLING": - case "ACACIA_SIGN": - case "ACACIA_SLAB": - case "ACACIA_STAIRS": - case "ACACIA_TRAPDOOR": - case "ACACIA_WALL_SIGN": - case "ACTIVATOR_RAIL": - case "AIR": - case "ANDESITE_SLAB": - case "ANDESITE_STAIRS": - case "ATTACHED_MELON_STEM": - case "ATTACHED_PUMPKIN_STEM": - case "AZURE_BLUET": - case "BEETROOTS": - case "BIRCH_BUTTON": - case "BIRCH_DOOR": - case "BIRCH_FENCE_GATE": - case "BIRCH_PRESSURE_PLATE": - case "BIRCH_SAPLING": - case "BIRCH_SIGN": - case "BIRCH_SLAB": - case "BIRCH_STAIRS": - case "BIRCH_TRAPDOOR": - case "BIRCH_WALL_SIGN": - case "BLACK_CARPET": - case "BLACK_WALL_BANNER": - case "BLUE_BANNER": - case "BLUE_CARPET": - case "BLUE_ORCHID": - case "BLUE_WALL_BANNER": - case "BRAIN_CORAL_FAN": - case "BRAIN_CORAL_WALL_FAN": - case "BRICK_SLAB": - case "BRICK_STAIRS": - case "BROWN_BANNER": - case "BROWN_CARPET": - case "BROWN_MUSHROOM": - case "BROWN_WALL_BANNER": - case "BUBBLE_CORAL_FAN": - case "BUBBLE_CORAL_WALL_FAN": - case "CAKE": - case "CAMPFIRE": - case "CARROTS": - case "CAVE_AIR": - case "COBBLESTONE_SLAB": - case "COBBLESTONE_STAIRS": - case "COBWEB": - case "COMPARATOR": - case "CORNFLOWER": - case "CUT_RED_SANDSTONE_SLAB": - case "CUT_SANDSTONE_SLAB": - case "CYAN_BANNER": - case "CYAN_CARPET": - case "CYAN_WALL_BANNER": - case "DANDELION": - case "DARK_OAK_BUTTON": - case "DARK_OAK_DOOR": - case "DARK_OAK_FENCE_GATE": - case "DARK_OAK_PRESSURE_PLATE": - case "DARK_OAK_SAPLING": - case "DARK_OAK_SIGN": - case "DARK_OAK_SLAB": - case "DARK_OAK_STAIRS": - case "DARK_OAK_TRAPDOOR": - case "DARK_OAK_WALL_SIGN": - case "DARK_PRISMARINE_SLAB": - case "DARK_PRISMARINE_STAIRS": - case "DAYLIGHT_DETECTOR": - case "DEAD_BRAIN_CORAL_FAN": - case "DEAD_BRAIN_CORAL_WALL_FAN": - case "DEAD_BUBBLE_CORAL_FAN": - case "DEAD_BUBBLE_CORAL_WALL_FAN": - case "DEAD_BUSH": - case "DEAD_FIRE_CORAL_FAN": - case "DEAD_FIRE_CORAL_WALL_FAN": - case "DEAD_HORN_CORAL_FAN": - case "DEAD_HORN_CORAL_WALL_FAN": - case "DEAD_TUBE_CORAL_FAN": - case "DEAD_TUBE_CORAL_WALL_FAN": - case "DETECTOR_RAIL": - case "DIORITE_SLAB": - case "DIORITE_STAIRS": - case "END_PORTAL": - case "END_STONE_BRICK_SLAB": - case "END_STONE_BRICK_STAIRS": - case "FERN": - case "FIRE": - case "FIRE_CORAL_FAN": - case "FIRE_CORAL_WALL_FAN": - case "FLOWER_POT": - case "GRANITE_SLAB": - case "GRANITE_STAIRS": - case "GRASS": - case "GRAY_BANNER": - case "GRAY_CARPET": - case "GRAY_WALL_BANNER": - case "GREEN_BANNER": - case "GREEN_WALL_BANNER": - case "HEAVY_WEIGHTED_PRESSURE_PLATE": - case "HORN_CORAL_FAN": - case "HORN_CORAL_WALL_FAN": - case "IRON_DOOR": - case "JUNGLE_BUTTON": - case "JUNGLE_DOOR": - case "JUNGLE_FENCE_GATE": - case "JUNGLE_PRESSURE_PLATE": - case "JUNGLE_SAPLING": - case "JUNGLE_SIGN": - case "JUNGLE_SLAB": - case "JUNGLE_STAIRS": - case "JUNGLE_TRAPDOOR": - case "JUNGLE_WALL_SIGN": - case "KELP": - case "LADDER": - case "LARGE_FERN": - case "LAVA": - case "LEVER": - case "LIGHT_BLUE_BANNER": - case "LIGHT_BLUE_CARPET": - case "LIGHT_BLUE_WALL_BANNER": - case "LIGHT_GRAY_BANNER": - case "LIGHT_GRAY_CARPET": - case "LIGHT_GRAY_WALL_BANNER": - case "LIGHT_WEIGHTED_PRESSURE_PLATE": - case "LILAC": - case "LILY_OF_THE_VALLEY": - case "LILY_PAD": - case "LIME_BANNER": - case "LIME_CARPET": - case "MAGENTA_BANNER": - case "MAGENTA_CARPET": - case "MAGENTA_WALL_BANNER": - case "MELON_STEM": - case "MOSSY_COBBLESTONE_SLAB": - case "MOSSY_COBBLESTONE_STAIRS": - case "MOSSY_STONE_BRICK_SLAB": - case "MOSSY_STONE_BRICK_STAIRS": - case "NETHER_BRICK_SLAB": - case "NETHER_BRICK_STAIRS": - case "NETHER_PORTAL": - case "NETHER_WART": - case "OAK_BUTTON": - case "OAK_DOOR": - case "OAK_FENCE_GATE": - case "OAK_PRESSURE_PLATE": - case "OAK_SAPLING": - case "OAK_SIGN": - case "OAK_SLAB": - case "OAK_STAIRS": - case "OAK_TRAPDOOR": - case "OAK_WALL_SIGN": - case "ORANGE_BANNER": - case "ORANGE_CARPET": - case "ORANGE_TULIP": - case "ORANGE_WALL_BANNER": - case "OXEYE_DAISY": - case "PEONY": - case "PETRIFIED_OAK_SLAB": - case "PINK_BANNER": - case "PINK_CARPET": - case "PINK_TULIP": - case "PINK_WALL_BANNER": - case "POLISHED_ANDESITE_SLAB": - case "POLISHED_ANDESITE_STAIRS": - case "POLISHED_DIORITE_SLAB": - case "POLISHED_DIORITE_STAIRS": - case "POLISHED_GRANITE_SLAB": - case "POLISHED_GRANITE_STAIRS": - case "POTATOES": - case "POTTED_ACACIA_SAPLING": - case "POTTED_ALLIUM": - case "POTTED_AZURE_BLUET": - case "POTTED_BAMBOO": - case "POTTED_BIRCH_SAPLING": - case "POTTED_BLUE_ORCHID": - case "POTTED_BROWN_MUSHROOM": - case "POTTED_CACTUS": - case "POTTED_CORNFLOWER": - case "POTTED_DANDELION": - case "POTTED_DARK_OAK_SAPLING": - case "POTTED_DEAD_BUSH": - case "POTTED_FERN": - case "POTTED_JUNGLE_SAPLING": - case "POTTED_LILY_OF_THE_VALLEY": - case "POTTED_OAK_SAPLING": - case "POTTED_ORANGE_TULIP": - case "POTTED_OXEYE_DAISY": - case "POTTED_PINK_TULIP": - case "POTTED_POPPY": - case "POTTED_RED_MUSHROOM": - case "POTTED_RED_TULIP": - case "POTTED_SPRUCE_SAPLING": - case "POTTED_WHITE_TULIP": - case "POTTED_WITHER_ROSE": - case "POWERED_RAIL": - case "PRISMARINE_BRICK_SLAB": - case "PRISMARINE_BRICK_STAIRS": - case "PRISMARINE_SLAB": - case "PRISMARINE_STAIRS": - case "PUMPKIN_STEM": - case "PURPLE_BANNER": - case "PURPLE_CARPET": - case "PURPLE_WALL_BANNER": - case "PURPUR_SLAB": - case "PURPUR_STAIRS": - case "RAIL": - case "REDSTONE_TORCH": - case "REDSTONE_WALL_TORCH": - case "REDSTONE_WIRE": - case "RED_BANNER": - case "RED_CARPET": - case "RED_MUSHROOM": - case "RED_SANDSTONE_SLAB": - case "RED_SANDSTONE_STAIRS": - case "RED_TULIP": - case "RED_WALL_BANNER": - case "REPEATER": - case "ROSE_BUSH": - case "SANDSTONE_SLAB": - case "SANDSTONE_STAIRS": - case "SCAFFOLDING": - case "SEAGRASS": - case "SMOOTH_QUARTZ_SLAB": - case "SMOOTH_QUARTZ_STAIRS": - case "SMOOTH_RED_SANDSTONE_SLAB": - case "SMOOTH_RED_SANDSTONE_STAIRS": - case "SMOOTH_SANDSTONE_SLAB": - case "SMOOTH_SANDSTONE_STAIRS": - case "SMOOTH_STONE_SLAB": - case "SPRUCE_BUTTON": - case "SPRUCE_DOOR": - case "SPRUCE_FENCE_GATE": - case "SPRUCE_PRESSURE_PLATE": - case "SPRUCE_SAPLING": - case "SPRUCE_SIGN": - case "SPRUCE_SLAB": - case "SPRUCE_STAIRS": - case "SPRUCE_TRAPDOOR": - case "SPRUCE_WALL_SIGN": - case "STONECUTTER": - case "STONE_BRICK_SLAB": - case "STONE_BRICK_STAIRS": - case "STONE_BUTTON": - case "STONE_PRESSURE_PLATE": - case "STONE_SLAB": - case "STONE_STAIRS": - case "STRUCTURE_VOID": - case "SUGAR_CANE": - case "SUNFLOWER": - case "SWEET_BERRY_BUSH": - case "TALL_GRASS": - case "TALL_SEAGRASS": - case "TORCH": - case "TRIPWIRE": - case "TRIPWIRE_HOOK": - case "TUBE_CORAL_FAN": - case "TUBE_CORAL_WALL_FAN": - case "VINE": - case "VOID_AIR": - case "WALL_TORCH": - case "WATER": - case "WHEAT": - case "WHITE_BANNER": - case "WHITE_CARPET": - case "WHITE_TULIP": - case "WHITE_WALL_BANNER": - case "WITHER_ROSE": - case "YELLOW_BANNER": - case "YELLOW_CARPET": - case "YELLOW_WALL_BANNER": - // Legacy values: - case "WEB": - case "LONG_GRASS": - case "YELLOW_FLOWER": - case "RED_ROSE": - case "STEP": - case "WOOD_STAIRS": - case "CROPS": - case "SIGN_POST": - case "RAILS": - case "WOODEN_DOOR": - case "WALL_SIGN": - case "STONE_PLATE": - case "IRON_DOOR_BLOCK": - case "WOOD_PLATE": - case "REDSTONE_TORCH_OFF": - case "REDSTONE_TORCH_ON": - case "SNOW": - case "SUGAR_CANE_BLOCK": - case "PORTAL": - case "CAKE_BLOCK": - case "DIODE_BLOCK_OFF": - case "DIODE_BLOCK_ON": - case "TRAP_DOOR": - case "FENCE_GATE": - case "SMOOTH_STAIRS": - case "ENDER_PORTAL": - case "WOOD_STEP": - case "SPRUCE_WOOD_STAIRS": - case "BIRCH_WOOD_STAIRS": - case "JUNGLE_WOOD_STAIRS": - case "CARROT": - case "POTATO": - case "WOOD_BUTTON": - case "GOLD_PLATE": - case "IRON_PLATE": - case "REDSTONE_COMPARATOR_OFF": - case "REDSTONE_COMPARATOR_ON": - case "QUARTZ_STAIRS": - case "DOUBLE_PLANT": - case "STANDING_BANNER": - case "WALL_BANNER": - case "DAYLIGHT_DETECTOR_INVERTED": - case "DOUBLE_STONE_SLAB2": - case "STONE_SLAB2": - case "BEETROOT_BLOCK": - return true; - } - return false; - } -} +package com.songoda.core.utils; + +import com.songoda.core.compatibility.ClassMapping; +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.ServerVersion; +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.EnumSet; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class BlockUtils { + + protected static final Set DOORS; + protected static final Set PRESSURE_PLATES; + protected static final Set FENCE_GATES; + protected static final Set TRAP_DOORS; + protected static final boolean useLegacy = Material.getMaterial("OAK_LOG") == null; + protected static Method legacySetBlockData = null; + protected static Method legacyUpdateBlockData = null; + + static { + DOORS = EnumSet.noneOf(Material.class); + PRESSURE_PLATES = EnumSet.noneOf(Material.class); + FENCE_GATES = EnumSet.noneOf(Material.class); + TRAP_DOORS = EnumSet.noneOf(Material.class); + + for (Material material : Material.values()) { + String name = material.name(); + if (name.contains("DOOR") && !name.contains("ITEM")) { + if (name.contains("TRAP")) { + TRAP_DOORS.add(material); + } else { + DOORS.add(material); + } + } else if (name.contains("GATE") && !name.contains("END")) { + FENCE_GATES.add(material); + } else if (name.contains("_PLATE")) { + PRESSURE_PLATES.add(material); + } + } + + if (useLegacy) { + try { + //legacyUpdateBlockData = Block.class.getDeclaredMethod("update"); + legacySetBlockData = Block.class.getDeclaredMethod("setData", byte.class); + } catch (NoSuchMethodException ex) { + } + } + } + + /** + * Interact with this block to either update redstone or open doors + * + * @param b block to update + * + * @return if this block's state was updated + */ + public static boolean tryInteract(Block b) { + final Material bType = b.getType(); + if (isOpenable(bType)) { + toggleDoorStates(true, b); + return true; + } else if (bType == Material.LEVER) { + toggleLever(b); + return true; + } else if (bType.name().endsWith("_BUTTON")) { + pressButton(b); + return true; + } + + return false; + } + + /** + * Change a pressure plate's redstone state + * + * @param plate plate to update + * @param power power to set to 0-15 (wood plates are active if greater than 0) + */ + public static void updatePressurePlate(Block plate, int power) { + if (useLegacy && legacySetBlockData != null) { + _updatePressurePlateLegacy(plate, power); + } else { + BlockUtilsModern._updatePressurePlateModern(plate, power); + } + } + + private static void _updatePressurePlateLegacy(Block plate, int power) { + final Material m = plate.getType(); + try { + if (m.name().equals("GOLD_PLATE") || m.name().equals("IRON_PLATE")) { + legacySetBlockData.invoke(plate, (byte) (power & 0x15)); + } else if (m.name().endsWith("_PLATE")) { + legacySetBlockData.invoke(plate, (byte) (power == 0 ? 0 : 1)); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); + } + } + + public static void pressButton(Block button) { + if (useLegacy && legacySetBlockData != null) { + _pressButtonLegacy(button); + } else { + BlockUtilsModern._pressButtonModern(button); + } + } + + public static void releaseButton(Block button) { + if (useLegacy && legacySetBlockData != null) { + _releaseButtonLegacy(button); + } else { + BlockUtilsModern._releaseButtonModern(button); + } + } + + private static void _pressButtonLegacy(Block button) { + final Material m = button.getType(); + if (!m.name().endsWith("_BUTTON")) return; + try { + legacySetBlockData.invoke(button, (byte) (button.getData() | (31 & 0x8))); + button.getState().update(); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); + } + } + + private static void _releaseButtonLegacy(Block button) { + final Material m = button.getType(); + if (!m.name().endsWith("_BUTTON")) return; + try { + legacySetBlockData.invoke(button, (byte) (button.getData() & ~0x8)); + button.getState().update(); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); + } + } + + public static void toggleLever(Block lever) { + if (useLegacy && legacySetBlockData != null) { + _toggleLeverLegacy(lever); + } else { + BlockUtilsModern._toggleLeverModern(lever); + } + } + + private static void _toggleLeverLegacy(Block lever) { + final Material m = lever.getType(); + if (m != Material.LEVER) return; + try { + legacySetBlockData.invoke(lever, (byte) (lever.getData() ^ 0x8)); + lever.getState().update(); + //lever.getWorld().playEffect(lever.getLocation(), Effect.CLICK1, 0); + // now we need to update the redstone around it.. +// int data = lever.getData() & ~0x8; +// Block attached; +// switch(data) { +// case 0: +// attached = lever.getRelative(BlockFace.UP); +// break; +// case 1: +// attached = lever.getRelative(BlockFace.WEST); +// break; +// case 2: +// attached = lever.getRelative(BlockFace.EAST); +// break; +// case 3: +// attached = lever.getRelative(BlockFace.NORTH); +// break; +// case 4: +// attached = lever.getRelative(BlockFace.SOUTH); +// break; +// case 5: +// attached = lever.getRelative(BlockFace.DOWN); +// break; +// default: +// return; +// } +// + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); + } + } + + /** + * Change all of the given door states to be inverse; that is, if a door is + * open, it will be closed afterwards. If the door is closed, it will become + * open. + *

+ * Note that the blocks given must be the bottom block of the door. + * + * @param allowDoorToOpen If FALSE, and the door is currently CLOSED, it + * will NOT be opened! + * @param doors Blocks given must be the bottom block of the door + */ + public static void toggleDoorStates(boolean allowDoorToOpen, Block... doors) { + if (useLegacy && legacySetBlockData != null) { + _toggleDoorStatesLegacy(allowDoorToOpen, doors); + } else { + BlockUtilsModern._toggleDoorStatesModern(allowDoorToOpen, doors); + } + } + + private static void _toggleDoorStatesLegacy(boolean allowDoorToOpen, Block... doors) { + try { + for (Block door : doors) { + if (door == null) { + continue; + } + + boolean isTop = (door.getData() & 0x8) != 0; + if (isTop) { + // The lower half of the door contains the direction & open/close state + door = door.getRelative(BlockFace.DOWN); + } + + // If we aren't allowing the door to open, check if it's already closed + if (!allowDoorToOpen && (door.getData() & 0x4) == 0) { + // The door is already closed and we don't want to open it + // the bit 0x4 is set when the door is open + continue; + } + + // Now xor both data values with 0x4, the flag that states if the door is open + legacySetBlockData.invoke(door, (byte) (door.getData() ^ 0x4)); + + // Play the door open/close sound + door.getWorld().playEffect(door.getLocation(), Effect.DOOR_TOGGLE, 0); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); + } + } + + /** + * Get the double door for the given block + * + * @param block + * + * @return + */ + public static Block getDoubleDoor(Block block) { + // TODO? if legacy, just search N/S/E/W to see if there's another door nearby + if (!isOpenable(block.getType())) { + return null; + } + + return BlockUtilsModern._getDoubleDoorModern(block); + } + + public static boolean isOpenable(Material m) { + return DOORS.contains(m) + || FENCE_GATES.contains(m) + || TRAP_DOORS.contains(m); + } + + public static BlockFace getDoorClosedDirection(Block door) { + return useLegacy ? _getDoorClosedDirectionLegacy(door) : BlockUtilsModern._getDoorClosedDirectionModern(door); + } + + private static BlockFace _getDoorClosedDirectionLegacy(Block door) { + final Material type = door.getType(); + if (DOORS.contains(type)) { + boolean isTop = (door.getData() & 0x8) != 0; + if (isTop) { + // The lower half of the door contains the direction & open/close state + door = door.getRelative(BlockFace.DOWN); + if (door.getType() != type) { + return null; + } + } + boolean isOpen = (door.getData() & 0x4) != 0; + //int facing = (door.getData() & 0x3); + // [east, south, west, north] + boolean facingNS = (door.getData() & 0x1) != 0; + if (facingNS) { + return isOpen ? BlockFace.EAST : BlockFace.SOUTH; + } else { + return isOpen ? BlockFace.SOUTH : BlockFace.EAST; + } + } else if (FENCE_GATES.contains(door.getType())) { + boolean isOpen = (door.getData() & 0x4) != 0; + //int facing = (door.getData() & 0x3); + // so fence gate orientations are [south, west, north, east] + boolean facingNS = (door.getData() & 0x1) == 0; + if (facingNS) { + return isOpen ? BlockFace.EAST : BlockFace.SOUTH; + } else { + return isOpen ? BlockFace.SOUTH : BlockFace.EAST; + } + } else if (TRAP_DOORS.contains(door.getType())) { + boolean isOpen = (door.getData() & 0x4) != 0; + // [south, north, east, west] + boolean facingNS = (door.getData() & 0x3) <= 1; + if (facingNS) { + return isOpen ? BlockFace.EAST : BlockFace.SOUTH; + } else { + return isOpen ? BlockFace.SOUTH : BlockFace.EAST; + } + } + return null; + } + + private static Class clazzCraftWorld, clazzCraftBlock, clazzBlockPosition; + private static Method getHandle, updateAdjacentComparators, craftBlock_getNMS, nmsBlockData_getBlock; + + /** + * Manually trigger the updateAdjacentComparators method for containers + * + * @param location location of the container + */ + public static void updateAdjacentComparators(Location location) { + if (location == null || location.getWorld() == null) return; + try { + // Cache reflection. + if (clazzCraftWorld == null) { + clazzCraftWorld = ClassMapping.CRAFT_WORLD.getClazz(); + clazzCraftBlock = ClassMapping.CRAFT_BLOCK.getClazz(); + clazzBlockPosition = ClassMapping.BLOCK_POSITION.getClazz(); + Class clazzWorld = ClassMapping.WORLD.getClazz(); + Class clazzBlock = ClassMapping.BLOCK.getClazz(); + + getHandle = clazzCraftWorld.getMethod("getHandle"); + updateAdjacentComparators = clazzWorld.getMethod("updateAdjacentComparators", clazzBlockPosition, clazzBlock); + + craftBlock_getNMS = clazzCraftBlock.getDeclaredMethod("getNMS"); + Class clazzBlockData = ClassMapping.BLOCK_BASE.getClazz("BlockData"); + nmsBlockData_getBlock = clazzBlockData.getDeclaredMethod("getBlock"); + } + + // invoke and cast objects. + Object craftWorld = clazzCraftWorld.cast(location.getWorld()); + Object world = getHandle.invoke(craftWorld); + Object craftBlock = clazzCraftBlock.cast(location.getBlock()); + + // Invoke final method. + updateAdjacentComparators + .invoke(world, clazzBlockPosition.getConstructor(double.class, double.class, double.class) + .newInstance(location.getX(), location.getY(), location.getZ()), + nmsBlockData_getBlock.invoke(craftBlock_getNMS.invoke(craftBlock))); + } catch (ReflectiveOperationException e) { + e.printStackTrace(); + } + } + + private static Class clazzIBlockData, clazzBlocks; + private static Method getByCombinedId, setType, getChunkAt, getBlockData; + + /** + * Set a block to a certain type by updating the block directly in the + * NMS chunk. + *

+ * The chunk must be loaded and players must relog if they have the + * chunk loaded in order to use this method. + * + * @param world + * @param x + * @param y + * @param z + * @param material + * @param data + */ + public static void setBlockFast(World world, int x, int y, int z, Material material, byte data) { + try { + // Cache reflection + if (clazzIBlockData == null) { + clazzIBlockData = ClassMapping.I_BLOCK_DATA.getClazz(); + clazzBlockPosition = ClassMapping.BLOCK_POSITION.getClazz(); + clazzCraftWorld = ClassMapping.CRAFT_WORLD.getClazz(); + clazzBlocks = ClassMapping.BLOCKS.getClazz(); + Class clazzBlock = ClassMapping.BLOCK.getClazz(); + Class clazzWorld = ClassMapping.WORLD.getClazz(); + Class clazzChunk = ClassMapping.CHUNK.getClazz(); + + getHandle = clazzCraftWorld.getMethod("getHandle"); + getChunkAt = clazzWorld.getMethod("getChunkAt", int.class, int.class); + + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { + getBlockData = clazzBlock.getMethod("getBlockData"); + setType = clazzChunk.getMethod("setType", clazzBlockPosition, clazzIBlockData, boolean.class); + } else { + getByCombinedId = clazzBlock.getMethod("getByCombinedId", int.class); + setType = clazzChunk.getMethod("a", clazzBlockPosition, clazzIBlockData); + } + } + + // invoke and cast objects. + Object craftWorld = clazzCraftWorld.cast(world); + Object nmsWorld = getHandle.invoke(craftWorld); + Object chunk = getChunkAt.invoke(nmsWorld, x >> 4, z >> 4); + Object blockPosition = clazzBlockPosition.getConstructor(int.class, int.class, int.class).newInstance(x & 0xF, y, z & 0xF); + + // Invoke final method. + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { + Object block = clazzBlocks.getField(material.name()).get(null); + Object IBlockData = getBlockData.invoke(block); + setType.invoke(chunk, blockPosition, IBlockData, true); + } else { + Object IBlockData = getByCombinedId.invoke(null, material.getId() + (data << 12)); + setType.invoke(chunk, blockPosition, IBlockData); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void setBlockFast(World world, int x, int y, int z, CompatibleMaterial material, byte data) { + setBlockFast(world, x, y, z, material.getBlockMaterial(), data); + } + + /** + * Checks if a crop is at its max growth stage + * + * @param block The crop block to check + * + * @return true if the block is a crop and at its max growth stage + */ + public static boolean isCropFullyGrown(Block block) { + if (block == null) { + return false; + } else if (!useLegacy) { + return BlockUtilsModern._isCropFullyGrown(block); + } + CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); + if (mat == null || !mat.isCrop()) { + return false; + } else { + return block.getData() >= (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); + } + } + + /** + * Gets the max growth stage for the given block + * + * @param block The crop block to check + * + * @return The max growth stage of the given crop type, or -1 if not a crop + */ + public static int getMaxGrowthStage(Block block) { + if (block == null) { + return -1; + } else if (!useLegacy) { + return BlockUtilsModern._getMaxGrowthStage(block); + } + CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); + if (mat == null || !mat.isCrop()) { + return -1; + } else { + return (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); + } + } + + /** + * Gets the max growth stage for the given material + * + * @param material The material of the crop + * + * @return The max growth stage of the given crop type + */ + public static int getMaxGrowthStage(Material material) { + if (material == null) { + return -1; + } else if (!useLegacy) { + return BlockUtilsModern._getMaxGrowthStage(material); + } + CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(material); + if (mat == null || !mat.isCrop()) { + return -1; + } else { + return (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7); + } + } + + /** + * Sets the max growth stage for the given block + * + * @param block The crop block to change + * @param stage new growth stage to use + */ + public static void setGrowthStage(Block block, int stage) { + if (block == null) { + } else if (!useLegacy) { + BlockUtilsModern._setGrowthStage(block, stage); + } else { + CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); + if (mat != null && mat.isCrop()) { + try { + legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7)))); + } catch (Exception ex) { + Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); + } + } + } + } + + /** + * Increments the growth stage for the given block + * + * @param block The crop block to grow + */ + public static void incrementGrowthStage(Block block) { + if (block == null) { + } else if (!useLegacy) { + BlockUtilsModern._incrementGrowthStage(block); + } else { + CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); + if (mat != null && mat.isCrop() && block.getData() < (mat == CompatibleMaterial.BEETROOTS + || mat == CompatibleMaterial.NETHER_WART ? 3 : 7)) { + try { + legacySetBlockData.invoke(block, (byte) (block.getData() + 1)); + } catch (Exception ex) { + Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); + } + } + } + } + + /** + * Sets a crop's growth back to stage 0 + * + * @param block The crop block to set + */ + public static void resetGrowthStage(Block block) { + if (block == null) { + } else if (!useLegacy) { + BlockUtilsModern._resetGrowthStage(block); + } else { + CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType()); + if (mat != null && mat.isCrop()) { + try { + legacySetBlockData.invoke(block, (byte) 0); + } catch (Exception ex) { + Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex); + } + } + } + } + + /** + * Check to see if this material does not impede player/mob movement at all. + * + * @param m material to check + * + * @return true if this material doesn't have a solid hitbox + */ + public static boolean canPassThrough(Material m) { + + switch (m.name()) { + case "ACACIA_BUTTON": + case "ACACIA_PRESSURE_PLATE": + case "ACACIA_SAPLING": + case "ACACIA_SIGN": + case "ACACIA_WALL_SIGN": + case "ACTIVATOR_RAIL": + case "AIR": + case "ATTACHED_MELON_STEM": + case "ATTACHED_PUMPKIN_STEM": + case "AZURE_BLUET": + case "BEETROOTS": + case "BIRCH_BUTTON": + case "BIRCH_PRESSURE_PLATE": + case "BIRCH_SAPLING": + case "BIRCH_SIGN": + case "BIRCH_WALL_SIGN": + case "BLACK_WALL_BANNER": + case "BLUE_BANNER": + case "BLUE_ORCHID": + case "BLUE_WALL_BANNER": + case "BRAIN_CORAL_FAN": + case "BRAIN_CORAL_WALL_FAN": + case "BROWN_BANNER": + case "BROWN_MUSHROOM": + case "BROWN_WALL_BANNER": + case "BUBBLE_CORAL_FAN": + case "BUBBLE_CORAL_WALL_FAN": + case "CARROTS": + case "CAVE_AIR": + case "COBWEB": + case "CORNFLOWER": + case "CYAN_BANNER": + case "CYAN_WALL_BANNER": + case "DANDELION": + case "DARK_OAK_BUTTON": + case "DARK_OAK_PRESSURE_PLATE": + case "DARK_OAK_SAPLING": + case "DARK_OAK_SIGN": + case "DARK_OAK_WALL_SIGN": + case "DEAD_BRAIN_CORAL_FAN": + case "DEAD_BRAIN_CORAL_WALL_FAN": + case "DEAD_BUBBLE_CORAL_FAN": + case "DEAD_BUBBLE_CORAL_WALL_FAN": + case "DEAD_BUSH": + case "DEAD_FIRE_CORAL_FAN": + case "DEAD_FIRE_CORAL_WALL_FAN": + case "DEAD_HORN_CORAL_FAN": + case "DEAD_HORN_CORAL_WALL_FAN": + case "DEAD_TUBE_CORAL_FAN": + case "DEAD_TUBE_CORAL_WALL_FAN": + case "DETECTOR_RAIL": + case "END_PORTAL": + case "FERN": + case "FIRE": + case "FIRE_CORAL_FAN": + case "FIRE_CORAL_WALL_FAN": + case "GRASS": + case "GRAY_BANNER": + case "GRAY_WALL_BANNER": + case "GREEN_BANNER": + case "GREEN_WALL_BANNER": + case "HEAVY_WEIGHTED_PRESSURE_PLATE": + case "HORN_CORAL_FAN": + case "HORN_CORAL_WALL_FAN": + case "JUNGLE_BUTTON": + case "JUNGLE_PRESSURE_PLATE": + case "JUNGLE_SAPLING": + case "JUNGLE_SIGN": + case "JUNGLE_WALL_SIGN": + case "KELP": + case "LADDER": + case "LARGE_FERN": + case "LAVA": + case "LEVER": + case "LIGHT_BLUE_BANNER": + case "LIGHT_BLUE_WALL_BANNER": + case "LIGHT_GRAY_BANNER": + case "LIGHT_GRAY_WALL_BANNER": + case "LIGHT_WEIGHTED_PRESSURE_PLATE": + case "LILAC": + case "LILY_OF_THE_VALLEY": + case "LIME_BANNER": + case "MAGENTA_BANNER": + case "MAGENTA_WALL_BANNER": + case "MELON_STEM": + case "NETHER_PORTAL": + case "NETHER_WART": + case "OAK_BUTTON": + case "OAK_PRESSURE_PLATE": + case "OAK_SAPLING": + case "OAK_SIGN": + case "OAK_WALL_SIGN": + case "ORANGE_BANNER": + case "ORANGE_TULIP": + case "ORANGE_WALL_BANNER": + case "OXEYE_DAISY": + case "PEONY": + case "PINK_BANNER": + case "PINK_TULIP": + case "PINK_WALL_BANNER": + case "POTATOES": + case "POWERED_RAIL": + case "PUMPKIN_STEM": + case "PURPLE_BANNER": + case "PURPLE_WALL_BANNER": + case "RAIL": + case "REDSTONE_TORCH": + case "REDSTONE_WALL_TORCH": + case "REDSTONE_WIRE": + case "RED_BANNER": + case "RED_MUSHROOM": + case "RED_TULIP": + case "RED_WALL_BANNER": + case "ROSE_BUSH": + case "SCAFFOLDING": + case "SEAGRASS": + case "SPRUCE_BUTTON": + case "SPRUCE_PRESSURE_PLATE": + case "SPRUCE_SAPLING": + case "SPRUCE_SIGN": + case "SPRUCE_WALL_SIGN": + case "STONE_BUTTON": + case "STONE_PRESSURE_PLATE": + case "STRUCTURE_VOID": + case "SUGAR_CANE": + case "SUNFLOWER": + case "SWEET_BERRY_BUSH": + case "TALL_GRASS": + case "TALL_SEAGRASS": + case "TORCH": + case "TRIPWIRE": + case "TRIPWIRE_HOOK": + case "TUBE_CORAL_FAN": + case "TUBE_CORAL_WALL_FAN": + case "VINE": + case "VOID_AIR": + case "WALL_TORCH": + case "WATER": + case "WHEAT": + case "WHITE_BANNER": + case "WHITE_TULIP": + case "WHITE_WALL_BANNER": + case "WITHER_ROSE": + case "YELLOW_BANNER": + case "YELLOW_WALL_BANNER": + // Legacy values: + case "WEB": + case "LONG_GRASS": + case "YELLOW_FLOWER": + case "RED_ROSE": + case "CROPS": + case "SIGN_POST": + case "RAILS": + case "WALL_SIGN": + case "STONE_PLATE": + case "WOOD_PLATE": + case "REDSTONE_TORCH_OFF": + case "REDSTONE_TORCH_ON": + case "SUGAR_CANE_BLOCK": + case "PORTAL": + case "ENDER_PORTAL": + case "CARROT": + case "POTATO": + case "WOOD_BUTTON": + case "GOLD_PLATE": + case "IRON_PLATE": + case "DOUBLE_PLANT": + case "STANDING_BANNER": + case "WALL_BANNER": + case "BEETROOT_BLOCK": + return true; + } + return false; + } + + /** + * Check to see if a player can walk into this material
+ * This includes blocks like slabs and stairs + * + * @param m material to check + * + * @return true if this is a block that can be walked though or up + */ + public static boolean canWalkTo(Material m) { + switch (m.name()) { + case "ACACIA_BUTTON": + case "ACACIA_PRESSURE_PLATE": + case "ACACIA_SAPLING": + case "ACACIA_SIGN": + case "ACACIA_SLAB": + case "ACACIA_STAIRS": + case "ACACIA_TRAPDOOR": + case "ACACIA_WALL_SIGN": + case "ACTIVATOR_RAIL": + case "AIR": + case "ANDESITE_SLAB": + case "ANDESITE_STAIRS": + case "ATTACHED_MELON_STEM": + case "ATTACHED_PUMPKIN_STEM": + case "AZURE_BLUET": + case "BEETROOTS": + case "BIRCH_BUTTON": + case "BIRCH_DOOR": + case "BIRCH_FENCE_GATE": + case "BIRCH_PRESSURE_PLATE": + case "BIRCH_SAPLING": + case "BIRCH_SIGN": + case "BIRCH_SLAB": + case "BIRCH_STAIRS": + case "BIRCH_TRAPDOOR": + case "BIRCH_WALL_SIGN": + case "BLACK_CARPET": + case "BLACK_WALL_BANNER": + case "BLUE_BANNER": + case "BLUE_CARPET": + case "BLUE_ORCHID": + case "BLUE_WALL_BANNER": + case "BRAIN_CORAL_FAN": + case "BRAIN_CORAL_WALL_FAN": + case "BRICK_SLAB": + case "BRICK_STAIRS": + case "BROWN_BANNER": + case "BROWN_CARPET": + case "BROWN_MUSHROOM": + case "BROWN_WALL_BANNER": + case "BUBBLE_CORAL_FAN": + case "BUBBLE_CORAL_WALL_FAN": + case "CAKE": + case "CAMPFIRE": + case "CARROTS": + case "CAVE_AIR": + case "COBBLESTONE_SLAB": + case "COBBLESTONE_STAIRS": + case "COBWEB": + case "COMPARATOR": + case "CORNFLOWER": + case "CUT_RED_SANDSTONE_SLAB": + case "CUT_SANDSTONE_SLAB": + case "CYAN_BANNER": + case "CYAN_CARPET": + case "CYAN_WALL_BANNER": + case "DANDELION": + case "DARK_OAK_BUTTON": + case "DARK_OAK_DOOR": + case "DARK_OAK_FENCE_GATE": + case "DARK_OAK_PRESSURE_PLATE": + case "DARK_OAK_SAPLING": + case "DARK_OAK_SIGN": + case "DARK_OAK_SLAB": + case "DARK_OAK_STAIRS": + case "DARK_OAK_TRAPDOOR": + case "DARK_OAK_WALL_SIGN": + case "DARK_PRISMARINE_SLAB": + case "DARK_PRISMARINE_STAIRS": + case "DAYLIGHT_DETECTOR": + case "DEAD_BRAIN_CORAL_FAN": + case "DEAD_BRAIN_CORAL_WALL_FAN": + case "DEAD_BUBBLE_CORAL_FAN": + case "DEAD_BUBBLE_CORAL_WALL_FAN": + case "DEAD_BUSH": + case "DEAD_FIRE_CORAL_FAN": + case "DEAD_FIRE_CORAL_WALL_FAN": + case "DEAD_HORN_CORAL_FAN": + case "DEAD_HORN_CORAL_WALL_FAN": + case "DEAD_TUBE_CORAL_FAN": + case "DEAD_TUBE_CORAL_WALL_FAN": + case "DETECTOR_RAIL": + case "DIORITE_SLAB": + case "DIORITE_STAIRS": + case "END_PORTAL": + case "END_STONE_BRICK_SLAB": + case "END_STONE_BRICK_STAIRS": + case "FERN": + case "FIRE": + case "FIRE_CORAL_FAN": + case "FIRE_CORAL_WALL_FAN": + case "FLOWER_POT": + case "GRANITE_SLAB": + case "GRANITE_STAIRS": + case "GRASS": + case "GRAY_BANNER": + case "GRAY_CARPET": + case "GRAY_WALL_BANNER": + case "GREEN_BANNER": + case "GREEN_WALL_BANNER": + case "HEAVY_WEIGHTED_PRESSURE_PLATE": + case "HORN_CORAL_FAN": + case "HORN_CORAL_WALL_FAN": + case "IRON_DOOR": + case "JUNGLE_BUTTON": + case "JUNGLE_DOOR": + case "JUNGLE_FENCE_GATE": + case "JUNGLE_PRESSURE_PLATE": + case "JUNGLE_SAPLING": + case "JUNGLE_SIGN": + case "JUNGLE_SLAB": + case "JUNGLE_STAIRS": + case "JUNGLE_TRAPDOOR": + case "JUNGLE_WALL_SIGN": + case "KELP": + case "LADDER": + case "LARGE_FERN": + case "LAVA": + case "LEVER": + case "LIGHT_BLUE_BANNER": + case "LIGHT_BLUE_CARPET": + case "LIGHT_BLUE_WALL_BANNER": + case "LIGHT_GRAY_BANNER": + case "LIGHT_GRAY_CARPET": + case "LIGHT_GRAY_WALL_BANNER": + case "LIGHT_WEIGHTED_PRESSURE_PLATE": + case "LILAC": + case "LILY_OF_THE_VALLEY": + case "LILY_PAD": + case "LIME_BANNER": + case "LIME_CARPET": + case "MAGENTA_BANNER": + case "MAGENTA_CARPET": + case "MAGENTA_WALL_BANNER": + case "MELON_STEM": + case "MOSSY_COBBLESTONE_SLAB": + case "MOSSY_COBBLESTONE_STAIRS": + case "MOSSY_STONE_BRICK_SLAB": + case "MOSSY_STONE_BRICK_STAIRS": + case "NETHER_BRICK_SLAB": + case "NETHER_BRICK_STAIRS": + case "NETHER_PORTAL": + case "NETHER_WART": + case "OAK_BUTTON": + case "OAK_DOOR": + case "OAK_FENCE_GATE": + case "OAK_PRESSURE_PLATE": + case "OAK_SAPLING": + case "OAK_SIGN": + case "OAK_SLAB": + case "OAK_STAIRS": + case "OAK_TRAPDOOR": + case "OAK_WALL_SIGN": + case "ORANGE_BANNER": + case "ORANGE_CARPET": + case "ORANGE_TULIP": + case "ORANGE_WALL_BANNER": + case "OXEYE_DAISY": + case "PEONY": + case "PETRIFIED_OAK_SLAB": + case "PINK_BANNER": + case "PINK_CARPET": + case "PINK_TULIP": + case "PINK_WALL_BANNER": + case "POLISHED_ANDESITE_SLAB": + case "POLISHED_ANDESITE_STAIRS": + case "POLISHED_DIORITE_SLAB": + case "POLISHED_DIORITE_STAIRS": + case "POLISHED_GRANITE_SLAB": + case "POLISHED_GRANITE_STAIRS": + case "POTATOES": + case "POTTED_ACACIA_SAPLING": + case "POTTED_ALLIUM": + case "POTTED_AZURE_BLUET": + case "POTTED_BAMBOO": + case "POTTED_BIRCH_SAPLING": + case "POTTED_BLUE_ORCHID": + case "POTTED_BROWN_MUSHROOM": + case "POTTED_CACTUS": + case "POTTED_CORNFLOWER": + case "POTTED_DANDELION": + case "POTTED_DARK_OAK_SAPLING": + case "POTTED_DEAD_BUSH": + case "POTTED_FERN": + case "POTTED_JUNGLE_SAPLING": + case "POTTED_LILY_OF_THE_VALLEY": + case "POTTED_OAK_SAPLING": + case "POTTED_ORANGE_TULIP": + case "POTTED_OXEYE_DAISY": + case "POTTED_PINK_TULIP": + case "POTTED_POPPY": + case "POTTED_RED_MUSHROOM": + case "POTTED_RED_TULIP": + case "POTTED_SPRUCE_SAPLING": + case "POTTED_WHITE_TULIP": + case "POTTED_WITHER_ROSE": + case "POWERED_RAIL": + case "PRISMARINE_BRICK_SLAB": + case "PRISMARINE_BRICK_STAIRS": + case "PRISMARINE_SLAB": + case "PRISMARINE_STAIRS": + case "PUMPKIN_STEM": + case "PURPLE_BANNER": + case "PURPLE_CARPET": + case "PURPLE_WALL_BANNER": + case "PURPUR_SLAB": + case "PURPUR_STAIRS": + case "RAIL": + case "REDSTONE_TORCH": + case "REDSTONE_WALL_TORCH": + case "REDSTONE_WIRE": + case "RED_BANNER": + case "RED_CARPET": + case "RED_MUSHROOM": + case "RED_SANDSTONE_SLAB": + case "RED_SANDSTONE_STAIRS": + case "RED_TULIP": + case "RED_WALL_BANNER": + case "REPEATER": + case "ROSE_BUSH": + case "SANDSTONE_SLAB": + case "SANDSTONE_STAIRS": + case "SCAFFOLDING": + case "SEAGRASS": + case "SMOOTH_QUARTZ_SLAB": + case "SMOOTH_QUARTZ_STAIRS": + case "SMOOTH_RED_SANDSTONE_SLAB": + case "SMOOTH_RED_SANDSTONE_STAIRS": + case "SMOOTH_SANDSTONE_SLAB": + case "SMOOTH_SANDSTONE_STAIRS": + case "SMOOTH_STONE_SLAB": + case "SPRUCE_BUTTON": + case "SPRUCE_DOOR": + case "SPRUCE_FENCE_GATE": + case "SPRUCE_PRESSURE_PLATE": + case "SPRUCE_SAPLING": + case "SPRUCE_SIGN": + case "SPRUCE_SLAB": + case "SPRUCE_STAIRS": + case "SPRUCE_TRAPDOOR": + case "SPRUCE_WALL_SIGN": + case "STONECUTTER": + case "STONE_BRICK_SLAB": + case "STONE_BRICK_STAIRS": + case "STONE_BUTTON": + case "STONE_PRESSURE_PLATE": + case "STONE_SLAB": + case "STONE_STAIRS": + case "STRUCTURE_VOID": + case "SUGAR_CANE": + case "SUNFLOWER": + case "SWEET_BERRY_BUSH": + case "TALL_GRASS": + case "TALL_SEAGRASS": + case "TORCH": + case "TRIPWIRE": + case "TRIPWIRE_HOOK": + case "TUBE_CORAL_FAN": + case "TUBE_CORAL_WALL_FAN": + case "VINE": + case "VOID_AIR": + case "WALL_TORCH": + case "WATER": + case "WHEAT": + case "WHITE_BANNER": + case "WHITE_CARPET": + case "WHITE_TULIP": + case "WHITE_WALL_BANNER": + case "WITHER_ROSE": + case "YELLOW_BANNER": + case "YELLOW_CARPET": + case "YELLOW_WALL_BANNER": + // Legacy values: + case "WEB": + case "LONG_GRASS": + case "YELLOW_FLOWER": + case "RED_ROSE": + case "STEP": + case "WOOD_STAIRS": + case "CROPS": + case "SIGN_POST": + case "RAILS": + case "WOODEN_DOOR": + case "WALL_SIGN": + case "STONE_PLATE": + case "IRON_DOOR_BLOCK": + case "WOOD_PLATE": + case "REDSTONE_TORCH_OFF": + case "REDSTONE_TORCH_ON": + case "SNOW": + case "SUGAR_CANE_BLOCK": + case "PORTAL": + case "CAKE_BLOCK": + case "DIODE_BLOCK_OFF": + case "DIODE_BLOCK_ON": + case "TRAP_DOOR": + case "FENCE_GATE": + case "SMOOTH_STAIRS": + case "ENDER_PORTAL": + case "WOOD_STEP": + case "SPRUCE_WOOD_STAIRS": + case "BIRCH_WOOD_STAIRS": + case "JUNGLE_WOOD_STAIRS": + case "CARROT": + case "POTATO": + case "WOOD_BUTTON": + case "GOLD_PLATE": + case "IRON_PLATE": + case "REDSTONE_COMPARATOR_OFF": + case "REDSTONE_COMPARATOR_ON": + case "QUARTZ_STAIRS": + case "DOUBLE_PLANT": + case "STANDING_BANNER": + case "WALL_BANNER": + case "DAYLIGHT_DETECTOR_INVERTED": + case "DOUBLE_STONE_SLAB2": + case "STONE_SLAB2": + case "BEETROOT_BLOCK": + return true; + } + return false; + } +} diff --git a/Core/src/main/java/com/songoda/core/utils/BlockUtilsModern.java b/Core/src/main/java/com/songoda/core/utils/BlockUtilsModern.java index a67d960b..284d0029 100644 --- a/Core/src/main/java/com/songoda/core/utils/BlockUtilsModern.java +++ b/Core/src/main/java/com/songoda/core/utils/BlockUtilsModern.java @@ -1,341 +1,340 @@ -package com.songoda.core.utils; - -import com.songoda.core.compatibility.ClassMapping; -import com.songoda.core.compatibility.ServerVersion; -import org.bukkit.Bukkit; -import org.bukkit.Effect; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Ageable; -import org.bukkit.block.data.AnaloguePowerable; -import org.bukkit.block.data.Bisected; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Powerable; -import org.bukkit.block.data.type.Door; -import org.bukkit.block.data.type.Gate; -import org.bukkit.block.data.type.Switch; -import org.bukkit.block.data.type.TrapDoor; - -import java.lang.reflect.Method; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class BlockUtilsModern { - - protected static void _updatePressurePlateModern(Block plate, int power) { - BlockData blockData = plate.getBlockData(); - boolean update = false; - if (blockData instanceof AnaloguePowerable) { - AnaloguePowerable a = (AnaloguePowerable) blockData; - int toPower = Math.min(a.getMaximumPower(), power); - if ((update = toPower != a.getPower())) { - a.setPower(toPower); - plate.setBlockData(a); - } - } else if (blockData instanceof Powerable) { - Powerable p = (Powerable) blockData; - if ((update = p.isPowered() != (power != 0))) { - p.setPowered(power != 0); - plate.setBlockData(p); - } - } - if (update) { - _updateRedstoneNeighbours(plate); - } - } - - protected static void _toggleLeverModern(Block lever) { - BlockData blockData = lever.getBlockData(); - if (blockData instanceof Switch) { - Switch s = (Switch) blockData; - s.setPowered(!s.isPowered()); - lever.setBlockData(s); - _updateRedstoneNeighbours(lever); - } - } - - protected static void _pressButtonModern(Block button) { - BlockData blockData = button.getBlockData(); - if (blockData instanceof Switch) { - Switch s = (Switch) blockData; - s.setPowered(true); - button.setBlockData(s); - _updateRedstoneNeighbours(button); - } - } - - static void _releaseButtonModern(Block button) { - BlockData blockData = button.getBlockData(); - if (blockData instanceof Switch) { - Switch s = (Switch) blockData; - s.setPowered(false); - button.setBlockData(s); - _updateRedstoneNeighbours(button); - } - } - - private static Class clazzCraftWorld; - private static Class clazzCraftBlock; - private static Class clazzLeverBlock; - private static Class clazzButtonBlock; - private static Class clazzPressurePlateBlock; - private static Method craftWorld_getHandle, craftBlock_getNMS, craftBlock_getPostition, craftBlockData_getState, - nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours, nmsBlockData_getBlock; - - static { - try { - // Cache reflection. - - clazzCraftWorld = ClassMapping.CRAFT_WORLD.getClazz(); - clazzCraftBlock = ClassMapping.CRAFT_BLOCK.getClazz(); - - craftWorld_getHandle = clazzCraftWorld.getMethod("getHandle"); - craftBlock_getPostition = clazzCraftBlock.getDeclaredMethod("getPosition"); - - craftBlock_getNMS = clazzCraftBlock.getDeclaredMethod("getNMS"); - Class clazzBlockData = ClassMapping.BLOCK_BASE.getClazz("BlockData"); - nmsBlockData_getBlock = clazzBlockData.getDeclaredMethod("getBlock"); - - Class clazzCraftBlockData = ClassMapping.CRAFT_BLOCK_DATA.getClazz(); - craftBlockData_getState = clazzCraftBlockData.getDeclaredMethod("getState"); - - Class clazzWorld = ClassMapping.WORLD.getClazz(); - Class clazzBlockState = ClassMapping.I_BLOCK_DATA.getClazz(); - Class clazzBlockPos = ClassMapping.BLOCK_POSITION.getClazz(); - clazzLeverBlock = ClassMapping.BLOCK_LEVER.getClazz(); - clazzButtonBlock = ClassMapping.BLOCK_BUTTON_ABSTRACT.getClazz(); - clazzPressurePlateBlock = ClassMapping.BLOCK_PRESSURE_PLATE_ABSTRACT.getClazz(); - - // nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours - nmsLever_updateNeighbours = clazzLeverBlock.getDeclaredMethod(ServerVersion.isServerVersionAbove(ServerVersion.V1_13) - ? "e" : "b", clazzBlockState, clazzWorld, clazzBlockPos); - nmsLever_updateNeighbours.setAccessible(true); - - nmsButton_updateNeighbours = clazzButtonBlock.getDeclaredMethod(ServerVersion.isServerVersionAbove(ServerVersion.V1_13) - ? "f" : "c", clazzBlockState, clazzWorld, clazzBlockPos); - nmsButton_updateNeighbours.setAccessible(true); - - nmsPlate_updateNeighbours = clazzPressurePlateBlock.getDeclaredMethod("a", clazzWorld, clazzBlockPos); - nmsPlate_updateNeighbours.setAccessible(true); - } catch (Throwable ex) { - Logger.getLogger(BlockUtilsModern.class.getName()).log(Level.SEVERE, null, ex); - } - } - - static void _updateRedstoneNeighbours(Block block) { - try { - // spigot made some changes to how data updates work in 1.13+ - // updating the data value of a redstone power source - // does NOT update attatched block power, - // even if you update the block state. (Still broken last I checked in 1.15.2) - // so now we're going to manually call the updateNeighbours block method - - // invoke and cast objects. - Object cworld = clazzCraftWorld.cast(block.getWorld()); - Object mworld = craftWorld_getHandle.invoke(cworld); - Object cblock = clazzCraftBlock.cast(block); - Object mblock = nmsBlockData_getBlock.invoke(craftBlock_getNMS.invoke(cblock)); - Object mpos = craftBlock_getPostition.invoke(cblock); - - //System.out.println(mblock.getClass()); - // now for testing stuff - if (clazzLeverBlock.isAssignableFrom(mblock.getClass())) { - final Object mstate = craftBlockData_getState.invoke(block.getBlockData()); - nmsLever_updateNeighbours.invoke(mblock, mstate, mworld, mpos); - } else if (clazzButtonBlock.isAssignableFrom(mblock.getClass())) { - final Object mstate = craftBlockData_getState.invoke(block.getBlockData()); - nmsButton_updateNeighbours.invoke(mblock, mstate, mworld, mpos); - } else if (clazzPressurePlateBlock.isAssignableFrom(mblock.getClass())) { - nmsPlate_updateNeighbours.invoke(mblock, mworld, mpos); - } else { - System.out.println("Unknown redstone: " + mblock.getClass().getName()); - } -// -// if(mblock instanceof net.minecraft.server.v1_15_R1.BlockLever) { -// Method updateNeighbours = net.minecraft.server.v1_15_R1.BlockLever.class.getDeclaredMethod("e", net.minecraft.server.v1_15_R1.IBlockData.class, net.minecraft.server.v1_15_R1.World.class, net.minecraft.server.v1_15_R1.BlockPosition.class); -// updateNeighbours.setAccessible(true); -// // IBlockData = block state after being powered -// -// updateNeighbours.invoke(mblock, -// ((org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) block.getBlockData()).getState(), -// mworld, -// mpos); -// } else if(mblock instanceof net.minecraft.server.v1_15_R1.BlockButtonAbstract) { -// Method updateNeighbours = net.minecraft.server.v1_15_R1.BlockButtonAbstract.class.getDeclaredMethod("f", net.minecraft.server.v1_15_R1.IBlockData.class, net.minecraft.server.v1_15_R1.World.class, net.minecraft.server.v1_15_R1.BlockPosition.class); -// updateNeighbours.setAccessible(true); -// // IBlockData = block state after being powered -// -// updateNeighbours.invoke(mblock, -// ((org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) block.getBlockData()).getState(), -// mworld, -// mpos); -// } else if(mblock instanceof net.minecraft.server.v1_15_R1.BlockPressurePlateAbstract) { -// Method updateNeighbours = net.minecraft.server.v1_15_R1.BlockPressurePlateAbstract.class.getDeclaredMethod("a", net.minecraft.server.v1_15_R1.World.class, net.minecraft.server.v1_15_R1.BlockPosition.class); -// updateNeighbours.setAccessible(true); -// // IBlockData = block state after being powered -// -// updateNeighbours.invoke(mblock, -// mworld, -// mpos); -// } - } catch (Throwable ex) { - Logger.getLogger(BlockUtilsModern.class.getName()).log(Level.SEVERE, null, ex); - } - } - - protected static void _toggleDoorStatesModern(boolean allowDoorToOpen, Block... doors) { - for (Block door : doors) { - BlockData blockData; - if (door == null || !((blockData = door.getBlockData()) instanceof Door)) { - continue; - } - - Door data = (Door) blockData; - if (!allowDoorToOpen && !data.isOpen()) { - continue; - } - - // The lower half of the door contains the open/close state - if (data.getHalf() == Bisected.Half.TOP) { - Block lowerHalf = door.getRelative(BlockFace.DOWN); - if (lowerHalf.getBlockData() instanceof Door) { - Door lowerData = (Door) lowerHalf.getBlockData(); - lowerData.setOpen(!data.isOpen()); - lowerHalf.setBlockData(lowerData); - } - } else { - data.setOpen(!data.isOpen()); - door.setBlockData(data); - } - - // Play the door open/close sound - door.getWorld().playEffect(door.getLocation(), Effect.DOOR_TOGGLE, 0); - } - } - - protected static Block _getDoubleDoorModern(Block block) { - BlockData bd = block.getBlockData(); - Block door = null; - if (bd instanceof Door) { - final Door d = (Door) bd; - final BlockFace face = d.getFacing(); - if (face.getModX() == 0) { - if (d.getHinge() == Door.Hinge.RIGHT) { - door = block.getRelative(face.getModZ(), 0, 0); - } else { - door = block.getRelative(-face.getModZ(), 0, 0); - } - } else { - if (d.getHinge() == Door.Hinge.RIGHT) { - door = block.getRelative(0, 0, -face.getModX()); - } else { - door = block.getRelative(0, 0, face.getModX()); - } - } - } - return door != null && door.getBlockData() instanceof Door - && ((Door) door.getBlockData()).getHinge() != ((Door) bd).getHinge() ? door : null; - } - - protected static BlockFace _getDoorClosedDirectionModern(Block door) { - if (BlockUtils.DOORS.contains(door.getType())) { - BlockData bd = door.getBlockData(); - if (bd instanceof Door) { - Door d = (Door) bd; - - // The lower half of the door contains the open/close state - if (d.getHalf() == Bisected.Half.TOP) { - door = door.getRelative(BlockFace.DOWN); - if (door.getBlockData() instanceof Door) { - d = (Door) door.getBlockData(); - } else { - return null; - } - } - - final BlockFace face = d.getFacing(); - // now we /could/ also correct for the hinge (top block), it's not needed information - if (face.getModX() == 0) { - return d.isOpen() ? BlockFace.EAST : BlockFace.SOUTH; - } else { - return d.isOpen() ? BlockFace.SOUTH : BlockFace.EAST; - } - } - } else if (BlockUtils.FENCE_GATES.contains(door.getType())) { - BlockData bd = door.getBlockData(); - if (bd instanceof Gate) { - Gate g = (Gate) bd; - final BlockFace face = g.getFacing(); - if (face.getModX() == 0) { - return g.isOpen() ? BlockFace.EAST : BlockFace.SOUTH; - } else { - return g.isOpen() ? BlockFace.SOUTH : BlockFace.EAST; - } - } - } else if (BlockUtils.TRAP_DOORS.contains(door.getType())) { - BlockData bd = door.getBlockData(); - if (bd instanceof TrapDoor) { - TrapDoor t = (TrapDoor) bd; - if (!t.isOpen()) { - return BlockFace.UP; - } else { - return t.getFacing(); - } - } - } - return null; - } - - protected static boolean _isCropFullyGrown(Block block) { - BlockData data = block.getBlockData(); - if (data instanceof Ageable) { - return ((Ageable) data).getAge() == ((Ageable) data).getMaximumAge(); - } - return false; - } - - protected static int _getMaxGrowthStage(Block block) { - BlockData data = block.getBlockData(); - if (data instanceof Ageable) { - return ((Ageable) data).getMaximumAge(); - } - return -1; - } - - protected static int _getMaxGrowthStage(Material material) { - BlockData data = material.createBlockData(); - if (data instanceof Ageable) { - return ((Ageable) data).getMaximumAge(); - } - return -1; - } - - public static void _setGrowthStage(Block block, int stage) { - BlockData data = block.getBlockData(); - if (data instanceof Ageable) { - ((Ageable) data).setAge(Math.max(0, Math.min(stage, ((Ageable) data).getMaximumAge()))); - block.setBlockData(data); - } - } - - public static void _incrementGrowthStage(Block block) { - BlockData data = block.getBlockData(); - if (data instanceof Ageable) { - final int max = ((Ageable) data).getMaximumAge(); - final int age = ((Ageable) data).getAge(); - if (age < max) { - ((Ageable) data).setAge(age + 1); - block.setBlockData(data); - } - } - } - - public static void _resetGrowthStage(Block block) { - BlockData data = block.getBlockData(); - if (data instanceof Ageable) { - ((Ageable) data).setAge(0); - block.setBlockData(data); - } - } -} +package com.songoda.core.utils; + +import com.songoda.core.compatibility.ClassMapping; +import com.songoda.core.compatibility.ServerVersion; +import org.bukkit.Effect; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Ageable; +import org.bukkit.block.data.AnaloguePowerable; +import org.bukkit.block.data.Bisected; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Powerable; +import org.bukkit.block.data.type.Door; +import org.bukkit.block.data.type.Gate; +import org.bukkit.block.data.type.Switch; +import org.bukkit.block.data.type.TrapDoor; + +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class BlockUtilsModern { + + protected static void _updatePressurePlateModern(Block plate, int power) { + BlockData blockData = plate.getBlockData(); + boolean update = false; + if (blockData instanceof AnaloguePowerable) { + AnaloguePowerable a = (AnaloguePowerable) blockData; + int toPower = Math.min(a.getMaximumPower(), power); + if ((update = toPower != a.getPower())) { + a.setPower(toPower); + plate.setBlockData(a); + } + } else if (blockData instanceof Powerable) { + Powerable p = (Powerable) blockData; + if ((update = p.isPowered() != (power != 0))) { + p.setPowered(power != 0); + plate.setBlockData(p); + } + } + if (update) { + _updateRedstoneNeighbours(plate); + } + } + + protected static void _toggleLeverModern(Block lever) { + BlockData blockData = lever.getBlockData(); + if (blockData instanceof Switch) { + Switch s = (Switch) blockData; + s.setPowered(!s.isPowered()); + lever.setBlockData(s); + _updateRedstoneNeighbours(lever); + } + } + + protected static void _pressButtonModern(Block button) { + BlockData blockData = button.getBlockData(); + if (blockData instanceof Switch) { + Switch s = (Switch) blockData; + s.setPowered(true); + button.setBlockData(s); + _updateRedstoneNeighbours(button); + } + } + + static void _releaseButtonModern(Block button) { + BlockData blockData = button.getBlockData(); + if (blockData instanceof Switch) { + Switch s = (Switch) blockData; + s.setPowered(false); + button.setBlockData(s); + _updateRedstoneNeighbours(button); + } + } + + private static Class clazzCraftWorld; + private static Class clazzCraftBlock; + private static Class clazzLeverBlock; + private static Class clazzButtonBlock; + private static Class clazzPressurePlateBlock; + private static Method craftWorld_getHandle, craftBlock_getNMS, craftBlock_getPostition, craftBlockData_getState, + nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours, nmsBlockData_getBlock; + + static { + try { + // Cache reflection. + + clazzCraftWorld = ClassMapping.CRAFT_WORLD.getClazz(); + clazzCraftBlock = ClassMapping.CRAFT_BLOCK.getClazz(); + + craftWorld_getHandle = clazzCraftWorld.getMethod("getHandle"); + craftBlock_getPostition = clazzCraftBlock.getDeclaredMethod("getPosition"); + + craftBlock_getNMS = clazzCraftBlock.getDeclaredMethod("getNMS"); + Class clazzBlockData = ClassMapping.BLOCK_BASE.getClazz("BlockData"); + nmsBlockData_getBlock = clazzBlockData.getDeclaredMethod("getBlock"); + + Class clazzCraftBlockData = ClassMapping.CRAFT_BLOCK_DATA.getClazz(); + craftBlockData_getState = clazzCraftBlockData.getDeclaredMethod("getState"); + + Class clazzWorld = ClassMapping.WORLD.getClazz(); + Class clazzBlockState = ClassMapping.I_BLOCK_DATA.getClazz(); + Class clazzBlockPos = ClassMapping.BLOCK_POSITION.getClazz(); + clazzLeverBlock = ClassMapping.BLOCK_LEVER.getClazz(); + clazzButtonBlock = ClassMapping.BLOCK_BUTTON_ABSTRACT.getClazz(); + clazzPressurePlateBlock = ClassMapping.BLOCK_PRESSURE_PLATE_ABSTRACT.getClazz(); + + // nmsLever_updateNeighbours, nmsButton_updateNeighbours, nmsPlate_updateNeighbours + nmsLever_updateNeighbours = clazzLeverBlock.getDeclaredMethod(ServerVersion.isServerVersionAbove(ServerVersion.V1_13) + ? "e" : "b", clazzBlockState, clazzWorld, clazzBlockPos); + nmsLever_updateNeighbours.setAccessible(true); + + nmsButton_updateNeighbours = clazzButtonBlock.getDeclaredMethod(ServerVersion.isServerVersionAbove(ServerVersion.V1_13) + ? "f" : "c", clazzBlockState, clazzWorld, clazzBlockPos); + nmsButton_updateNeighbours.setAccessible(true); + + nmsPlate_updateNeighbours = clazzPressurePlateBlock.getDeclaredMethod("a", clazzWorld, clazzBlockPos); + nmsPlate_updateNeighbours.setAccessible(true); + } catch (Throwable ex) { + Logger.getLogger(BlockUtilsModern.class.getName()).log(Level.SEVERE, null, ex); + } + } + + static void _updateRedstoneNeighbours(Block block) { + try { + // spigot made some changes to how data updates work in 1.13+ + // updating the data value of a redstone power source + // does NOT update attatched block power, + // even if you update the block state. (Still broken last I checked in 1.15.2) + // so now we're going to manually call the updateNeighbours block method + + // invoke and cast objects. + Object cworld = clazzCraftWorld.cast(block.getWorld()); + Object mworld = craftWorld_getHandle.invoke(cworld); + Object cblock = clazzCraftBlock.cast(block); + Object mblock = nmsBlockData_getBlock.invoke(craftBlock_getNMS.invoke(cblock)); + Object mpos = craftBlock_getPostition.invoke(cblock); + + //System.out.println(mblock.getClass()); + // now for testing stuff + if (clazzLeverBlock.isAssignableFrom(mblock.getClass())) { + final Object mstate = craftBlockData_getState.invoke(block.getBlockData()); + nmsLever_updateNeighbours.invoke(mblock, mstate, mworld, mpos); + } else if (clazzButtonBlock.isAssignableFrom(mblock.getClass())) { + final Object mstate = craftBlockData_getState.invoke(block.getBlockData()); + nmsButton_updateNeighbours.invoke(mblock, mstate, mworld, mpos); + } else if (clazzPressurePlateBlock.isAssignableFrom(mblock.getClass())) { + nmsPlate_updateNeighbours.invoke(mblock, mworld, mpos); + } else { + System.out.println("Unknown redstone: " + mblock.getClass().getName()); + } +// +// if(mblock instanceof net.minecraft.server.v1_15_R1.BlockLever) { +// Method updateNeighbours = net.minecraft.server.v1_15_R1.BlockLever.class.getDeclaredMethod("e", net.minecraft.server.v1_15_R1.IBlockData.class, net.minecraft.server.v1_15_R1.World.class, net.minecraft.server.v1_15_R1.BlockPosition.class); +// updateNeighbours.setAccessible(true); +// // IBlockData = block state after being powered +// +// updateNeighbours.invoke(mblock, +// ((org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) block.getBlockData()).getState(), +// mworld, +// mpos); +// } else if(mblock instanceof net.minecraft.server.v1_15_R1.BlockButtonAbstract) { +// Method updateNeighbours = net.minecraft.server.v1_15_R1.BlockButtonAbstract.class.getDeclaredMethod("f", net.minecraft.server.v1_15_R1.IBlockData.class, net.minecraft.server.v1_15_R1.World.class, net.minecraft.server.v1_15_R1.BlockPosition.class); +// updateNeighbours.setAccessible(true); +// // IBlockData = block state after being powered +// +// updateNeighbours.invoke(mblock, +// ((org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData) block.getBlockData()).getState(), +// mworld, +// mpos); +// } else if(mblock instanceof net.minecraft.server.v1_15_R1.BlockPressurePlateAbstract) { +// Method updateNeighbours = net.minecraft.server.v1_15_R1.BlockPressurePlateAbstract.class.getDeclaredMethod("a", net.minecraft.server.v1_15_R1.World.class, net.minecraft.server.v1_15_R1.BlockPosition.class); +// updateNeighbours.setAccessible(true); +// // IBlockData = block state after being powered +// +// updateNeighbours.invoke(mblock, +// mworld, +// mpos); +// } + } catch (Throwable ex) { + Logger.getLogger(BlockUtilsModern.class.getName()).log(Level.SEVERE, null, ex); + } + } + + protected static void _toggleDoorStatesModern(boolean allowDoorToOpen, Block... doors) { + for (Block door : doors) { + BlockData blockData; + if (door == null || !((blockData = door.getBlockData()) instanceof Door)) { + continue; + } + + Door data = (Door) blockData; + if (!allowDoorToOpen && !data.isOpen()) { + continue; + } + + // The lower half of the door contains the open/close state + if (data.getHalf() == Bisected.Half.TOP) { + Block lowerHalf = door.getRelative(BlockFace.DOWN); + if (lowerHalf.getBlockData() instanceof Door) { + Door lowerData = (Door) lowerHalf.getBlockData(); + lowerData.setOpen(!data.isOpen()); + lowerHalf.setBlockData(lowerData); + } + } else { + data.setOpen(!data.isOpen()); + door.setBlockData(data); + } + + // Play the door open/close sound + door.getWorld().playEffect(door.getLocation(), Effect.DOOR_TOGGLE, 0); + } + } + + protected static Block _getDoubleDoorModern(Block block) { + BlockData bd = block.getBlockData(); + Block door = null; + if (bd instanceof Door) { + final Door d = (Door) bd; + final BlockFace face = d.getFacing(); + if (face.getModX() == 0) { + if (d.getHinge() == Door.Hinge.RIGHT) { + door = block.getRelative(face.getModZ(), 0, 0); + } else { + door = block.getRelative(-face.getModZ(), 0, 0); + } + } else { + if (d.getHinge() == Door.Hinge.RIGHT) { + door = block.getRelative(0, 0, -face.getModX()); + } else { + door = block.getRelative(0, 0, face.getModX()); + } + } + } + return door != null && door.getBlockData() instanceof Door + && ((Door) door.getBlockData()).getHinge() != ((Door) bd).getHinge() ? door : null; + } + + protected static BlockFace _getDoorClosedDirectionModern(Block door) { + if (BlockUtils.DOORS.contains(door.getType())) { + BlockData bd = door.getBlockData(); + if (bd instanceof Door) { + Door d = (Door) bd; + + // The lower half of the door contains the open/close state + if (d.getHalf() == Bisected.Half.TOP) { + door = door.getRelative(BlockFace.DOWN); + if (door.getBlockData() instanceof Door) { + d = (Door) door.getBlockData(); + } else { + return null; + } + } + + final BlockFace face = d.getFacing(); + // now we /could/ also correct for the hinge (top block), it's not needed information + if (face.getModX() == 0) { + return d.isOpen() ? BlockFace.EAST : BlockFace.SOUTH; + } else { + return d.isOpen() ? BlockFace.SOUTH : BlockFace.EAST; + } + } + } else if (BlockUtils.FENCE_GATES.contains(door.getType())) { + BlockData bd = door.getBlockData(); + if (bd instanceof Gate) { + Gate g = (Gate) bd; + final BlockFace face = g.getFacing(); + if (face.getModX() == 0) { + return g.isOpen() ? BlockFace.EAST : BlockFace.SOUTH; + } else { + return g.isOpen() ? BlockFace.SOUTH : BlockFace.EAST; + } + } + } else if (BlockUtils.TRAP_DOORS.contains(door.getType())) { + BlockData bd = door.getBlockData(); + if (bd instanceof TrapDoor) { + TrapDoor t = (TrapDoor) bd; + if (!t.isOpen()) { + return BlockFace.UP; + } else { + return t.getFacing(); + } + } + } + return null; + } + + protected static boolean _isCropFullyGrown(Block block) { + BlockData data = block.getBlockData(); + if (data instanceof Ageable) { + return ((Ageable) data).getAge() == ((Ageable) data).getMaximumAge(); + } + return false; + } + + protected static int _getMaxGrowthStage(Block block) { + BlockData data = block.getBlockData(); + if (data instanceof Ageable) { + return ((Ageable) data).getMaximumAge(); + } + return -1; + } + + protected static int _getMaxGrowthStage(Material material) { + BlockData data = material.createBlockData(); + if (data instanceof Ageable) { + return ((Ageable) data).getMaximumAge(); + } + return -1; + } + + public static void _setGrowthStage(Block block, int stage) { + BlockData data = block.getBlockData(); + if (data instanceof Ageable) { + ((Ageable) data).setAge(Math.max(0, Math.min(stage, ((Ageable) data).getMaximumAge()))); + block.setBlockData(data); + } + } + + public static void _incrementGrowthStage(Block block) { + BlockData data = block.getBlockData(); + if (data instanceof Ageable) { + final int max = ((Ageable) data).getMaximumAge(); + final int age = ((Ageable) data).getAge(); + if (age < max) { + ((Ageable) data).setAge(age + 1); + block.setBlockData(data); + } + } + } + + public static void _resetGrowthStage(Block block) { + BlockData data = block.getBlockData(); + if (data instanceof Ageable) { + ((Ageable) data).setAge(0); + block.setBlockData(data); + } + } +} diff --git a/Core/src/main/java/com/songoda/core/utils/ColorUtils.java b/Core/src/main/java/com/songoda/core/utils/ColorUtils.java index a802d7bc..8c7455f1 100644 --- a/Core/src/main/java/com/songoda/core/utils/ColorUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/ColorUtils.java @@ -51,7 +51,6 @@ public class ColorUtils { public B getBlue() { return blue; } - } public static ColorCode fromRGB(int r, int g, int b) { @@ -64,5 +63,4 @@ public class ColorUtils { }); return closest.firstEntry().getValue(); } - -} \ No newline at end of file +} diff --git a/Core/src/main/java/com/songoda/core/utils/EntityUtils.java b/Core/src/main/java/com/songoda/core/utils/EntityUtils.java index 7da89bb2..904de5ec 100644 --- a/Core/src/main/java/com/songoda/core/utils/EntityUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/EntityUtils.java @@ -1,7 +1,7 @@ package com.songoda.core.utils; -import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.ClassMapping; +import com.songoda.core.compatibility.CompatibleMaterial; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; diff --git a/Core/src/main/java/com/songoda/core/utils/ItemSerializer.java b/Core/src/main/java/com/songoda/core/utils/ItemSerializer.java index 095a9344..5384a465 100644 --- a/Core/src/main/java/com/songoda/core/utils/ItemSerializer.java +++ b/Core/src/main/java/com/songoda/core/utils/ItemSerializer.java @@ -20,6 +20,7 @@ public class ItemSerializer { * A method to serialize an {@link ItemStack} list to Base64 String. * * @param items to turn into a Base64 String. + * * @return Base64 string of the items. */ public static String toBase64(List items) { @@ -48,6 +49,7 @@ public class ItemSerializer { * Gets a list of ItemStacks from Base64 string. * * @param data Base64 string to convert to ItemStack list. + * * @return ItemStack array created from the Base64 string. */ public static List fromBase64(String data) { @@ -72,7 +74,9 @@ public class ItemSerializer { /** * Deserialize a byte array into an ItemStack. + * * @param data Data to deserialize. + * * @return Deserialized ItemStack. */ public static ItemStack deserializeItem(byte[] data) { @@ -88,7 +92,9 @@ public class ItemSerializer { /** * Serialize an ItemStack into a byte array. + * * @param item Item to serialize. + * * @return Serialized data. */ public static byte[] serializeItem(ItemStack item) { diff --git a/Core/src/main/java/com/songoda/core/utils/ItemUtils.java b/Core/src/main/java/com/songoda/core/utils/ItemUtils.java index abde1616..f0c48bba 100644 --- a/Core/src/main/java/com/songoda/core/utils/ItemUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/ItemUtils.java @@ -1,1115 +1,1128 @@ -/** - * This class uses some Minecraft code and also Paper API - */ -package com.songoda.core.utils; - -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; -import com.songoda.core.compatibility.CompatibleHand; -import com.songoda.core.compatibility.CompatibleMaterial; -import com.songoda.core.compatibility.ServerVersion; -import com.songoda.core.compatibility.ClassMapping; -import org.apache.commons.lang.StringUtils; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; -import org.bukkit.util.io.BukkitObjectInputStream; -import org.bukkit.util.io.BukkitObjectOutputStream; -import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Base64; -import java.util.Iterator; -import java.util.List; -import java.util.Random; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.Stream; - -public class ItemUtils { - - static boolean can_getI18NDisplayName = true; - - static { - try { - ItemStack.class.getMethod("getI18NDisplayName"); - } catch (NoSuchMethodException | SecurityException ex) { - can_getI18NDisplayName = false; - } - } - - public static String getItemName(ItemStack it) { - if (it == null) { - return null; - } else { - return itemName(it.getType()); - } - } - - static String itemName(Material mat) { - String matName = mat.name().replace("_", " "); - StringBuilder titleCase = new StringBuilder(matName.length()); - - Stream.of(matName.split(" ")).forEach(s -> { - s = s.toLowerCase(); - if (s.equals("of")) { - titleCase.append(s).append(" "); - } else { - char[] str = s.toCharArray(); - str[0] = Character.toUpperCase(str[0]); - titleCase.append(new String(str)).append(" "); - } - }); - - return titleCase.toString().trim(); - } - - private static Method methodAsBukkitCopy, methodAsNMSCopy, methodA; - - static { - try { - Class clazzEnchantmentManager = ClassMapping.ENCHANTMENT_MANAGER.getClazz(); - Class clazzItemStack = ClassMapping.ITEM_STACK.getClazz(); - Class clazzCraftItemStack = ClassMapping.CRAFT_ITEM_STACK.getClazz(); - - methodAsBukkitCopy = clazzCraftItemStack.getMethod("asBukkitCopy", clazzItemStack); - methodAsNMSCopy = clazzCraftItemStack.getMethod("asNMSCopy", ItemStack.class); - - if (ServerVersion.isServerVersion(ServerVersion.V1_8)) - methodA = clazzEnchantmentManager.getMethod("a", Random.class, clazzItemStack, int.class); - else - methodA = clazzEnchantmentManager.getMethod("a", Random.class, clazzItemStack, int.class, boolean.class); - - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } - } - - public static ItemStack applyRandomEnchants(ItemStack item, int level) { - try { - Object nmsItemStack = methodAsNMSCopy.invoke(null, item); - - if (ServerVersion.isServerVersion(ServerVersion.V1_8)) - nmsItemStack = methodA.invoke(null, new Random(), nmsItemStack, level); - else - nmsItemStack = methodA.invoke(null, new Random(), nmsItemStack, level, false); - - item = (ItemStack) methodAsBukkitCopy.invoke(null, nmsItemStack); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - return item; - } - - public static String itemStackArrayToBase64(ItemStack[] items) { - try { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); - dataOutput.writeInt(items.length); - for (ItemStack item : items) dataOutput.writeObject(item); - dataOutput.close(); - return Base64Coder.encodeLines(outputStream.toByteArray()); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static ItemStack[] itemStackArrayFromBase64(String data) { - try { - ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); - BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); - ItemStack[] items = new ItemStack[dataInput.readInt()]; - for (int i = 0; i < items.length; i++) - items[i] = (ItemStack) dataInput.readObject(); - dataInput.close(); - return items; - } catch (ClassNotFoundException | IOException e) { - e.printStackTrace(); - } - return null; - } - - /** - * Clone of org.bukkit.inventory.ItemStack.asQuantity, since it is a paper-only function - * - * @param item item to copy - * @param qty amount the new ItemStack should have - * @return a copy of the original item - */ - public static ItemStack getAsCopy(ItemStack item, int qty) { - ItemStack clone = item.clone(); - clone.setAmount(qty); - return clone; - } - - public static boolean hasEnoughDurability(ItemStack tool, int requiredAmount) { - if (tool.getType().getMaxDurability() <= 1) - return true; - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - if (!tool.hasItemMeta() || !(tool.getItemMeta() instanceof Damageable)) - return true; - - Damageable damageable = (Damageable) tool.getItemMeta(); - int durabilityRemaining = tool.getType().getMaxDurability() - damageable.getDamage(); - return durabilityRemaining > requiredAmount; - } else { - return tool.getDurability() + requiredAmount <= tool.getType().getMaxDurability(); - } - } - - static Class cb_ItemStack = NMSUtils.getCraftClass("inventory.CraftItemStack"); - static Class mc_ItemStack = ClassMapping.ITEM_STACK.getClazz(); - static Class mc_NBTTagCompound = ClassMapping.NBT_TAG_COMPOUND.getClazz(); - static Class mc_NBTTagList = ClassMapping.NBT_TAG_LIST.getClazz(); - static Class mc_NBTBase = ClassMapping.NBT_BASE.getClazz(); - static Method mc_ItemStack_getTag; - static Method mc_ItemStack_setTag; - static Method mc_NBTTagCompound_set; - static Method mc_NBTTagCompound_remove; - static Method mc_NBTTagCompound_setShort; - static Method mc_NBTTagCompound_setString; - static Method mc_NBTTagList_add; - static Method cb_CraftItemStack_asNMSCopy; - static Method cb_CraftItemStack_asCraftMirror; - - static { - if (cb_ItemStack != null) { - try { - mc_ItemStack_getTag = mc_ItemStack.getDeclaredMethod("getTag"); - mc_ItemStack_setTag = mc_ItemStack.getDeclaredMethod("setTag", mc_NBTTagCompound); - mc_NBTTagCompound_set = mc_NBTTagCompound.getDeclaredMethod("set", String.class, mc_NBTBase); - mc_NBTTagCompound_remove = mc_NBTTagCompound.getDeclaredMethod("remove", String.class); - mc_NBTTagCompound_setShort = mc_NBTTagCompound.getDeclaredMethod("setShort", String.class, short.class); - mc_NBTTagCompound_setString = mc_NBTTagCompound.getDeclaredMethod("setString", String.class, String.class); - cb_CraftItemStack_asNMSCopy = cb_ItemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); - cb_CraftItemStack_asCraftMirror = cb_ItemStack.getDeclaredMethod("asCraftMirror", mc_ItemStack); - mc_NBTTagList_add = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14) - ? NMSUtils.getPrivateMethod(mc_NBTTagList, "a", mc_NBTBase) - : mc_NBTTagList.getDeclaredMethod("add", mc_NBTBase); - } catch (Exception ex) { - Logger.getLogger(ItemUtils.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - - /** - * Make an item glow as if it contained an enchantment.
- * Tested working 1.8-1.14 - * - * @param item itemstack to create a glowing copy of - * @return copy of item with a blank enchantment nbt tag - */ - public static ItemStack addGlow(ItemStack item) { - // from 1.11 up, fake enchantments don't work without more steps - // creating a new Enchantment involves some very involved reflection, - // as the namespace is the same but until 1.12 requires an int, but versions after require a String - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) { - item.addUnsafeEnchantment(Enchantment.DURABILITY, 1); - // you can at least hide the enchantment, though - ItemMeta m = item.getItemMeta(); - m.addItemFlags(ItemFlag.HIDE_ENCHANTS); - item.setItemMeta(m); - return item; - } else { - // hack a fake enchant onto the item - // Confirmed works on 1.8, 1.9, 1.10 - // Does not work 1.11+ (minecraft ignores the glitched enchantment) - if (item != null && item.getType() != Material.AIR && cb_CraftItemStack_asCraftMirror != null) { - try { - Object nmsStack = cb_CraftItemStack_asNMSCopy.invoke(null, item); - Object tag = mc_ItemStack_getTag.invoke(nmsStack); - if (tag == null) { - tag = mc_NBTTagCompound.newInstance(); - } - // set to have a fake enchantment - Object enchantmentList = mc_NBTTagList.newInstance(); - /* - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - // Servers from 1.13 and up change the id to a string - Object fakeEnchantment = mc_NBTTagCompound.newInstance(); - mc_NBTTagCompound_setString.invoke(fakeEnchantment, "id", "glow:glow"); - mc_NBTTagCompound_setShort.invoke(fakeEnchantment, "lvl", (short) 0); - mc_NBTTagList_add.invoke(enchantmentList, fakeEnchantment); - } else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) { - // Servers from 1.11 and up require *something* in the enchantment field - Object fakeEnchantment = mc_NBTTagCompound.newInstance(); - mc_NBTTagCompound_setShort.invoke(fakeEnchantment, "id", (short) 245); - mc_NBTTagCompound_setShort.invoke(fakeEnchantment, "lvl", (short) 1); - mc_NBTTagList_add.invoke(enchantmentList, fakeEnchantment); - }//*/ - mc_NBTTagCompound_set.invoke(tag, "ench", enchantmentList); - mc_ItemStack_setTag.invoke(nmsStack, tag); - item = (ItemStack) cb_CraftItemStack_asCraftMirror.invoke(null, nmsStack); - } catch (Exception ex) { - Bukkit.getLogger().log(Level.SEVERE, "Failed to set glow enchantment on item: " + item, ex); - } - } - } - return item; - } - - /** - * Remove all enchantments, including hidden enchantments - * - * @param item item to clear enchants from - * @return copy of the item without any enchantment tag - */ - public static ItemStack removeGlow(ItemStack item) { - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) { - item.removeEnchantment(Enchantment.DURABILITY); - return item; - } else { - if (item != null && item.getType() != Material.AIR && cb_CraftItemStack_asCraftMirror != null) { - try { - Object nmsStack = cb_CraftItemStack_asNMSCopy.invoke(null, item); - Object tag = mc_ItemStack_getTag.invoke(nmsStack); - if (tag != null) { - // remove enchantment list - mc_NBTTagCompound_remove.invoke(tag, "ench"); - mc_ItemStack_setTag.invoke(nmsStack, tag); - item = (ItemStack) cb_CraftItemStack_asCraftMirror.invoke(null, nmsStack); - } - } catch (Exception ex) { - Bukkit.getLogger().log(Level.SEVERE, "Failed to set glow enchantment on item: " + item, ex); - } - } - } - return item; - } - - private static Class mc_Item = ClassMapping.ITEM.getClazz(); - private static Method mc_Item_getItem; - private static Field mc_Item_maxStackSize; - - static { - if (mc_ItemStack != null) { - try { - mc_Item_getItem = mc_ItemStack.getDeclaredMethod("getItem"); - mc_Item_maxStackSize = mc_Item.getDeclaredField("maxStackSize"); - mc_Item_maxStackSize.setAccessible(true); - } catch (Exception ex) { - } - } - } - - public static ItemStack setMaxStack(ItemStack item, int max) { - if (item != null && mc_Item_maxStackSize != null) { - try { - Object objItemStack = mc_Item_getItem.invoke(cb_CraftItemStack_asNMSCopy.invoke(null, item)); - mc_Item_maxStackSize.set(objItemStack, max); - } catch (ReflectiveOperationException e) { - Bukkit.getLogger().log(Level.SEVERE, "Failed to set max stack size on item " + item, e); - } - } - return item; - } - - public static ItemStack getPlayerSkull(OfflinePlayer player) { - ItemStack head = CompatibleMaterial.PLAYER_HEAD.getItem(); - if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) { - return head; - } - - SkullMeta meta = (SkullMeta) head.getItemMeta(); - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - meta.setOwningPlayer(player); - } else { - meta.setOwner(player.getName()); - } - head.setItemMeta(meta); - return head; - } - - public static void setHeadOwner(ItemStack head, OfflinePlayer player) { - if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8) || head == null || !CompatibleMaterial.PLAYER_HEAD.matches(head)) { - return; - } - SkullMeta meta = (SkullMeta) head.getItemMeta(); - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - meta.setOwningPlayer(player); - } else { - meta.setOwner(player.getName()); - } - } - - public static ItemStack getCustomHead(String texture) { - return getCustomHead(null, texture); - } - - public static ItemStack getCustomHead(String signature, String texture) { - ItemStack skullItem = CompatibleMaterial.PLAYER_HEAD.getItem(); - if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) - return skullItem; - - SkullMeta sm = (SkullMeta) skullItem.getItemMeta(); - GameProfile gm; - if (texture.endsWith("=")) { - gm = new GameProfile(UUID.nameUUIDFromBytes(texture.getBytes()), "CustomHead"); - if (signature == null) - gm.getProperties().put("textures", new Property("texture", texture.replaceAll("=", ""))); - else - gm.getProperties().put("textures", new Property("textures", texture, signature)); - } else { - gm = new GameProfile(UUID.nameUUIDFromBytes(texture.getBytes()), "CustomHead"); - byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"http://textures.minecraft.net/texture/%s\"}}}", texture).getBytes()); - gm.getProperties().put("textures", new Property("textures", new String(encodedData))); - } - - try { - Field profileField; - profileField = sm.getClass().getDeclaredField("profile"); - profileField.setAccessible(true); - profileField.set(sm, gm); - skullItem.setItemMeta(sm); - return skullItem; - } catch (NoSuchFieldException | IllegalAccessException | SecurityException ex) { - throw new RuntimeException("Reflection error while setting head texture", ex); - } - } - - static Class cb_CraftPlayer = NMSUtils.getCraftClass("entity.CraftPlayer"); - static Method cb_CraftPlayer_getProfile; - - static { - try { - cb_CraftPlayer_getProfile = cb_CraftPlayer.getMethod("getProfile"); - } catch (Exception ex) { - } - } - - public static String getSkullTexture(Player player) { - if (player == null || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) { - return null; - } - try { - - Object craftPlayer = cb_CraftPlayer.cast(player); - - Iterator iterator = ((GameProfile) cb_CraftPlayer_getProfile.invoke(craftPlayer)).getProperties().get("textures").iterator(); - - return iterator.hasNext() ? iterator.next().getValue() : null; - - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - return null; - } - } - - public static String getSkullTexture(ItemStack item) { - if (!CompatibleMaterial.PLAYER_HEAD.matches(item) || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) { - return null; - } - try { - SkullMeta localSkullMeta = (SkullMeta) item.getItemMeta(); - Field cb_SkullMeta_profile = localSkullMeta.getClass().getDeclaredField("profile"); - if (cb_SkullMeta_profile == null) return null; - cb_SkullMeta_profile.setAccessible(true); - - GameProfile profile = (GameProfile) cb_SkullMeta_profile.get(localSkullMeta); - Iterator iterator = profile.getProperties().get("textures").iterator(); - - return iterator.hasNext() ? iterator.next().getValue() : null; - } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) { - } - return null; - } - - public static String getDecodedTexture(String encoded) { - return encoded != null ? StringUtils.substringBetween(new String(Base64.getDecoder().decode(encoded)), "texture/", "\"") : null; - } - - /** - * Use up whatever item the player is holding in their main hand - * - * @param player player to grab item from - * @param hand the hand to take the item from. - */ - @Deprecated - public static void takeActiveItem(Player player, CompatibleHand hand) { - takeActiveItem(player, hand, 1); - } - - /** - * Use up whatever item the player is holding in their main hand - * - * @param player player to grab item from - * @param hand the hand to take the item from. - * @param amount number of items to use up - */ - @Deprecated - public static void takeActiveItem(Player player, CompatibleHand hand, int amount) { - hand.takeItem(player, amount); - } - - /** - * Quickly check to see if the two items use the same material.
- * NOTE: Does not check meta data; only checks the item material. - * - * @param is1 first item to compare - * @param is2 item to compare against - * @return true if both items are of the same material - */ - public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) { - CompatibleMaterial mat1 = CompatibleMaterial.getMaterial(is1); - return mat1 != null && mat1 == CompatibleMaterial.getMaterial(is2); - } - - /** - * Check to see if this item can be moved into a single slot in this - * inventory.
- * This returns true if there is a free slot or a slot with a matching item - * where adding this item's amount to that item's amount will not violate - * the maximum stack size for that item. - * - * @param inventory inventory to check - * @param item item to check against - * @return true if a free slot or single receiver slot is available - */ - public static boolean canMove(Inventory inventory, ItemStack item) { - if (inventory.firstEmpty() != -1) { - return true; - } - - final ItemMeta itemMeta = item.getItemMeta(); - for (ItemStack stack : inventory) { - final ItemMeta stackMeta; - if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() - && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) - && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { - return true; - } - } - return false; - } - - /** - * Check to see if this item can be moved into a single slot in this - * inventory.
- * This returns true if there is a free slot or a slot with a matching item - * where adding this item's amount to that item's amount will not violate - * the maximum stack size for that item. - * - * @param contents inventory to check - * @param item item to check against - * @return true if a free slot or single receiver slot is available - */ - public static boolean canMove(ItemStack[] contents, ItemStack item) { - final ItemMeta itemMeta = item.getItemMeta(); - for (int i = 0; i < contents.length; i++) { - final ItemStack stack = contents[i]; - if (stack == null || stack.getAmount() == 0) { - return true; - } - final ItemMeta stackMeta; - if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() - && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) - && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { - return true; - } - } - return false; - } - - /** - * Check to see if this item can be moved into a single slot in this - * inventory while also reserving one of the slots.
- * This returns true if there is a free slot or a slot with a matching item - * where adding this item's amount to that item's amount will not violate - * the maximum stack size for that item. - * - * @param inventory inventory to check - * @param item item to check against - * @param reserved which slot should be reserved - * @return true if a free slot or single receiver slot is available - */ - public static boolean canMoveReserved(Inventory inventory, ItemStack item, int reserved) { - final ItemMeta itemMeta = item.getItemMeta(); - final ItemStack[] contents = inventory.getContents(); - for (int i = 0; i < contents.length; i++) { - if (i == reserved) { - continue; - } - final ItemStack stack = contents[i]; - final ItemMeta stackMeta; - if (stack == null || stack.getAmount() == 0 - || (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() - && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) - && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta)))) { - return true; - } - } - return false; - } - - /** - * Check to see if this item can be moved into a single slot in this - * inventory while also reserving one of the slots.
- * This returns true if there is a free slot or a slot with a matching item - * where adding this item's amount to that item's amount will not violate - * the maximum stack size for that item. - * - * @param contents inventory to check - * @param item item to check against - * @param reserved which slot should be reserved - * @return true if a free slot or single receiver slot is available - */ - public static boolean canMoveReserved(ItemStack[] contents, ItemStack item, int reserved) { - final ItemMeta itemMeta = item.getItemMeta(); - for (int i = 0; i < contents.length; i++) { - if (i == reserved) { - continue; - } - final ItemStack stack = contents[i]; - if (stack == null || stack.getAmount() == 0) { - return true; - } - final ItemMeta stackMeta; - if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() - && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) - && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { - return true; - } - } - return false; - } - - /** - * Add up to a number of items to this inventory. - * - * @param item item to add - * @param amountToAdd how many of this item to attempt to add - * @param inventory a list that represents the inventory - * @param maxSize maximum number of different items this container can hold - * @return how many items were added - */ - public static int addAny(ItemStack item, int amountToAdd, List inventory, int maxSize) { - return addAny(item, amountToAdd, inventory, maxSize, -1); - } - - /** - * Add up to a number of items to this inventory. - * - * @param item item to add - * @param amountToAdd how many of this item to attempt to add - * @param inventory a list that represents the inventory - * @param maxSize maximum number of different items this container can hold - * @param reserved slot to reserve - will not fill this slot - * @return how many items were added - */ - public static int addAny(ItemStack item, int amountToAdd, List inventory, int maxSize, int reserved) { - int totalAdded = 0; - if (inventory != null && item != null && amountToAdd > 0) { - final int maxStack = item.getMaxStackSize(); - for (int i = 0; amountToAdd > 0 && i < maxSize; i++) { - if (i == reserved) { - continue; - } - final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); - if (cacheItem == null || cacheItem.getAmount() == 0) { - // free slot! - int toAdd = Math.min(maxStack, amountToAdd); - ItemStack item2 = item.clone(); - item2.setAmount(toAdd); - if (i >= inventory.size()) { - inventory.add(item2); - } else { - inventory.set(i, item2); - } - totalAdded += toAdd; - amountToAdd -= toAdd; - } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { - // free space! - int toAdd = Math.min(maxStack - cacheItem.getAmount(), amountToAdd); - inventory.get(i).setAmount(toAdd + cacheItem.getAmount()); - totalAdded += toAdd; - amountToAdd -= toAdd; - } - } - } - return totalAdded; - } - - /** - * Add an item to this inventory, but only if it can be added completely. - * - * @param item item to add - * @param inventory a list that represents the inventory - * @param containerSize maximum number of different items this container can - * hold - * @return true if the item was added - */ - public static boolean addItem(ItemStack item, List inventory, int containerSize) { - if (inventory == null || item == null || item.getAmount() <= 0 || containerSize <= 0) { - return false; - } - return addItem(item, item.getAmount(), inventory, containerSize); - } - - /** - * Add an item to this inventory, but only if it can be added completely. - * - * @param item item to add - * @param inventory a list that represents the inventory - * @param containerSize maximum number of different items this container can - * hold - * @param reserved slot to reserve - will not fill this slot - * @return true if the item was added - */ - public static boolean addItem(ItemStack item, List inventory, int containerSize, int reserved) { - if (inventory == null || item == null || item.getAmount() <= 0 || containerSize <= 0) { - return false; - } - return addItem(item, item.getAmount(), inventory, containerSize, reserved); - } - - /** - * Add an item to this inventory. - * - * @param item item to add - * @param amount how many of this item should be added - * @param inventory a list that represents the inventory - * @param containerSize maximum number of different items this container can - * @param reserved slot to reserve - will not fill this slot hold - * @return true if the item was added - */ - public static boolean addItem(ItemStack item, int amount, List inventory, int containerSize, int reserved) { - return addItem(item, amount, inventory, containerSize, reserved, null); - } - - /** - * Add an item to this inventory, but only if it can be added completely. - * - * @param item item to add - * @param amount how many of this item should be added - * @param inventory a list that represents the inventory - * @param containerSize maximum number of different items this container can - * hold - * @param reserved slot to reserve - will not fill this slot - * @param inventorySource Material of the container - * @return true if the item was added - */ - public static boolean addItem(ItemStack item, int amount, List inventory, int containerSize, int reserved, Material inventorySource) { - if (inventory == null || item == null || amount <= 0 || inventorySource == null) { - return false; - } - boolean[] check = null; - - if (inventorySource != null && inventorySource != Material.AIR) { - // Don't transfer shulker boxes into other shulker boxes, that's a bad idea. - if (inventorySource.name().contains("SHULKER_BOX") && item.getType().name().contains("SHULKER_BOX")) { - return false; - } - - // some destination containers have special conditions - switch (inventorySource.name()) { - case "BREWING_STAND": { - - // first compile a list of what slots to check - check = new boolean[5]; - String typeStr = item.getType().name().toUpperCase(); - if (typeStr.contains("POTION") || typeStr.contains("BOTTLE")) { - // potion bottles are the first three slots - check[0] = check[1] = check[2] = true; - } - // fuel in 5th position, input in 4th - if (item.getType() == Material.BLAZE_POWDER) { - check[4] = true; - } else { - check[3] = true; - } - - } - case "SMOKER": - case "BLAST_FURNACE": - case "BURNING_FURNACE": - case "FURNACE": { - - check = new boolean[3]; - - boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel(); - // fuel is 2nd slot, input is first - if (isFuel) { - - check[1] = true; - } else { - check[0] = true; - } - - } - } - } - - // grab the amount to move and the max item stack size - int toAdd = item.getAmount(); - final int maxStack = item.getMaxStackSize(); - - // we can reduce calls to ItemStack.isSimilar() by caching what cells to look at - if (check == null) { - check = new boolean[containerSize]; - for (int i = 0; toAdd > 0 && i < check.length; i++) { - check[i] = true; - } - } - if (reserved >= 0 && check.length < reserved) { - check[reserved] = false; - } - - // first verify that we can add this item - for (int i = 0; toAdd > 0 && i < containerSize; i++) { - if (check[i]) { - final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); - if (cacheItem == null || cacheItem.getAmount() == 0) { - // free slot! - toAdd -= Math.min(maxStack, toAdd); - check[i] = true; - } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { - // free space! - toAdd -= Math.min(maxStack - cacheItem.getAmount(), toAdd); - check[i] = true; - } else { - check[i] = false; - } - } - } - if (toAdd <= 0) { - // all good to add! - toAdd = item.getAmount(); - for (int i = 0; toAdd > 0 && i < containerSize; i++) { - if (!check[i]) { - continue; - } - final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); - if (cacheItem == null || cacheItem.getAmount() == 0) { - // free slot! - int adding = Math.min(maxStack, toAdd); - ItemStack item2 = item.clone(); - item2.setAmount(adding); - if (i >= inventory.size()) { - inventory.add(item2); - } else { - inventory.set(i, item2); - } - toAdd -= adding; - } else if (maxStack > cacheItem.getAmount()) { - // free space! - // (no need to check item.isSimilar(cacheItem), since we have that cached in check[]) - int adding = Math.min(maxStack - cacheItem.getAmount(), toAdd); - inventory.get(i).setAmount(adding + cacheItem.getAmount()); - toAdd -= adding; - } - } - return true; - } - return false; - } - - /** - * Add up to a number of items to this inventory. - * - * @param item item to add - * @param amountToAdd how many of this item to attempt to add - * @param inventory a list that represents the inventory - * @return how many items were added - */ - public static int addAny(ItemStack item, int amountToAdd, Inventory inventory) { - int totalAdded = 0; - if (inventory != null && item != null && amountToAdd > 0) { - final int containerSize = inventory.getSize(); - final int maxStack = item.getMaxStackSize(); - for (int i = 0; amountToAdd > 0 && i < containerSize; i++) { - final ItemStack cacheItem = inventory.getItem(i); - if (cacheItem == null || cacheItem.getAmount() == 0) { - // free slot! - int toAdd = Math.min(maxStack, amountToAdd); - ItemStack item2 = item.clone(); - item2.setAmount(toAdd); - inventory.setItem(i, item2); - totalAdded += toAdd; - amountToAdd -= toAdd; - } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { - // free space! - int toAdd = Math.min(maxStack - cacheItem.getAmount(), amountToAdd); - cacheItem.setAmount(toAdd + cacheItem.getAmount()); - totalAdded += toAdd; - amountToAdd -= toAdd; - } - } - } - return totalAdded; - } - - /** - * Add an item to this inventory, but only if it can be added completely. - * - * @param item item to add - * @param inventory a list that represents the inventory hold - * @return true if the item was added - */ - public static boolean addItem(ItemStack item, Inventory inventory) { - if (inventory == null || item == null || item.getAmount() <= 0) { - return false; - } - return addItem(item, item.getAmount(), inventory, -1, null); - } - - /** - * Add an item to this inventory. - * - * @param item item to add - * @param amount how many of this item should be added - * @param inventory a list that represents the inventory - * @param reserved slot to reserve - will not fill this slot - * @return true if the item was added - */ - public static boolean addItem(ItemStack item, int amount, Inventory inventory, int reserved) { - return addItem(item, amount, inventory, reserved, null); - } - - /** - * Add an item to this inventory, but only if it can be added completely. - * - * @param item item to add - * @param amount how many of this item should be added - * @param inventory a list that represents the inventory - * @param reserved slot to reserve - will not fill this slot - * @param inventorySource Material of the container - * @return true if the item was added - */ - public static boolean addItem(ItemStack item, int amount, Inventory inventory, int reserved, Material inventorySource) { - if (inventory == null || item == null || amount <= 0 || inventorySource == null) { - return false; - } - boolean[] check = null; - - if (inventorySource != null && inventorySource != Material.AIR) { - - // Don't transfer shulker boxes into other shulker boxes, that's a bad idea. - if (inventorySource.name().contains("SHULKER_BOX") && item.getType().name().contains("SHULKER_BOX")) { - return false; - } - - // some destination containers have special conditions - switch (inventorySource.name()) { - case "BREWING_STAND": { - - // first compile a list of what slots to check - check = new boolean[5]; - String typeStr = item.getType().name().toUpperCase(); - if (typeStr.contains("POTION") || typeStr.contains("BOTTLE")) { - // potion bottles are the first three slots - check[0] = check[1] = check[2] = true; - } - // fuel in 5th position, input in 4th - if (item.getType() == Material.BLAZE_POWDER) { - check[4] = true; - } else { - check[3] = true; - } - - } - case "SMOKER": - case "BLAST_FURNACE": - case "BURNING_FURNACE": - case "FURNACE": { - - check = new boolean[3]; - - boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel(); - // fuel is 2nd slot, input is first - if (isFuel) { - - check[1] = true; - } else { - check[0] = true; - } - - } - } - } - // grab the amount to move and the max item stack size - int toAdd = item.getAmount(); - final int maxStack = item.getMaxStackSize(); - final int containerSize = inventory.getSize(); - - // we can reduce calls to ItemStack.isSimilar() by caching what cells to look at - if (check == null) { - check = new boolean[containerSize]; - for (int i = 0; toAdd > 0 && i < check.length; i++) { - check[i] = true; - } - } - - // first verify that we can add this item - for (int i = 0; toAdd > 0 && i < containerSize; i++) { - if (check[i]) { - final ItemStack cacheItem = inventory.getItem(i); - if (cacheItem == null || cacheItem.getAmount() == 0) { - // free slot! - toAdd -= Math.min(maxStack, toAdd); - check[i] = true; - } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { - // free space! - toAdd -= Math.min(maxStack - cacheItem.getAmount(), toAdd); - check[i] = true; - } else { - check[i] = false; - } - } - } - if (toAdd <= 0) { - // all good to add! - toAdd = item.getAmount(); - for (int i = 0; toAdd > 0 && i < containerSize; i++) { - if (!check[i]) { - continue; - } - final ItemStack cacheItem = inventory.getItem(i); - if (cacheItem == null || cacheItem.getAmount() == 0) { - // free slot! - int adding = Math.min(maxStack, toAdd); - ItemStack item2 = item.clone(); - item2.setAmount(adding); - inventory.setItem(i, item2); - toAdd -= adding; - } else if (maxStack > cacheItem.getAmount()) { - // free space! - // (no need to check item.isSimilar(cacheItem), since we have that cached in check[]) - int adding = Math.min(maxStack - cacheItem.getAmount(), toAdd); - cacheItem.setAmount(adding + cacheItem.getAmount()); - toAdd -= adding; - } - } - return true; - } - return false; - } - - public static CompatibleMaterial getDyeColor(char color) { - switch (color) { - case '0': - return CompatibleMaterial.BLACK_DYE; - case '1': - return CompatibleMaterial.BLUE_DYE; - case '2': - return CompatibleMaterial.GREEN_DYE; - case '3': - return CompatibleMaterial.CYAN_DYE; - case '4': - return CompatibleMaterial.BROWN_DYE; - case '5': - return CompatibleMaterial.PURPLE_DYE; - case '6': - return CompatibleMaterial.ORANGE_DYE; - case '7': - return CompatibleMaterial.LIGHT_GRAY_DYE; - case '8': - return CompatibleMaterial.GREEN_DYE; - case 'a': - return CompatibleMaterial.LIME_DYE; - case 'b': - return CompatibleMaterial.LIGHT_BLUE_DYE; - case 'c': - return CompatibleMaterial.RED_DYE; - case 'd': - return CompatibleMaterial.MAGENTA_DYE; - case 'e': - return CompatibleMaterial.YELLOW_DYE; - case 'f': - return CompatibleMaterial.WHITE_DYE; - } - return CompatibleMaterial.STONE; - } - - /** - * Add an item to this inventory. - * - * @param item item to add - * @param amount how many of this item should be added - * @param inventory a list that represents the inventory - * @param containerSize maximum number of different items this container can - * hold - * @return true if the item was added - */ - public static boolean addItem(ItemStack item, int amount, List inventory, int containerSize) { - if (inventory == null || item == null || amount <= 0 || containerSize <= 0) { - return false; - } - - // grab the amount to move and the max item stack size - int toAdd = amount; - final int maxStack = item.getMaxStackSize(); - boolean[] check = null; - - // we can reduce calls to ItemStack.isSimilar() by caching what cells to look at - if (check == null) { - check = new boolean[containerSize]; - for (int i = 0; toAdd > 0 && i < check.length; i++) { - check[i] = true; - } - } - - // first verify that we can add this item - for (int i = 0; toAdd > 0 && i < containerSize; i++) { - if (check[i]) { - final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); - if (cacheItem == null || cacheItem.getAmount() == 0) { - // free slot! - toAdd -= Math.min(maxStack, toAdd); - check[i] = true; - } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { - // free space! - toAdd -= Math.min(maxStack - cacheItem.getAmount(), toAdd); - check[i] = true; - } else { - check[i] = false; - } - } - } - - if (toAdd <= 0) { - // all good to add! - toAdd = item.getAmount(); - for (int i = 0; toAdd > 0 && i < containerSize; i++) { - if (!check[i]) { - continue; - } - final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); - if (cacheItem == null || cacheItem.getAmount() == 0) { - // free slot! - int adding = Math.min(maxStack, toAdd); - ItemStack item2 = item.clone(); - item2.setAmount(adding); - if (i >= inventory.size()) { - inventory.add(item2); - } else { - inventory.set(i, item2); - } - toAdd -= adding; - } else if (maxStack > cacheItem.getAmount()) { - // free space! - // (no need to check item.isSimilar(cacheItem), since we have that cached in check[]) - int adding = Math.min(maxStack - cacheItem.getAmount(), toAdd); - inventory.get(i).setAmount(adding + cacheItem.getAmount()); - toAdd -= adding; - } - } - return true; - } - return false; - } -} +/** + * This class uses some Minecraft code and also Paper API + */ +package com.songoda.core.utils; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.songoda.core.compatibility.ClassMapping; +import com.songoda.core.compatibility.CompatibleHand; +import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.ServerVersion; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.util.io.BukkitObjectInputStream; +import org.bukkit.util.io.BukkitObjectOutputStream; +import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Base64; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Stream; + +public class ItemUtils { + + static boolean can_getI18NDisplayName = true; + + static { + try { + ItemStack.class.getMethod("getI18NDisplayName"); + } catch (NoSuchMethodException | SecurityException ex) { + can_getI18NDisplayName = false; + } + } + + public static String getItemName(ItemStack it) { + if (it == null) { + return null; + } else { + return itemName(it.getType()); + } + } + + static String itemName(Material mat) { + String matName = mat.name().replace("_", " "); + StringBuilder titleCase = new StringBuilder(matName.length()); + + Stream.of(matName.split(" ")).forEach(s -> { + s = s.toLowerCase(); + if (s.equals("of")) { + titleCase.append(s).append(" "); + } else { + char[] str = s.toCharArray(); + str[0] = Character.toUpperCase(str[0]); + titleCase.append(new String(str)).append(" "); + } + }); + + return titleCase.toString().trim(); + } + + private static Method methodAsBukkitCopy, methodAsNMSCopy, methodA; + + static { + try { + Class clazzEnchantmentManager = ClassMapping.ENCHANTMENT_MANAGER.getClazz(); + Class clazzItemStack = ClassMapping.ITEM_STACK.getClazz(); + Class clazzCraftItemStack = ClassMapping.CRAFT_ITEM_STACK.getClazz(); + + methodAsBukkitCopy = clazzCraftItemStack.getMethod("asBukkitCopy", clazzItemStack); + methodAsNMSCopy = clazzCraftItemStack.getMethod("asNMSCopy", ItemStack.class); + + if (ServerVersion.isServerVersion(ServerVersion.V1_8)) + methodA = clazzEnchantmentManager.getMethod("a", Random.class, clazzItemStack, int.class); + else + methodA = clazzEnchantmentManager.getMethod("a", Random.class, clazzItemStack, int.class, boolean.class); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + + public static ItemStack applyRandomEnchants(ItemStack item, int level) { + try { + Object nmsItemStack = methodAsNMSCopy.invoke(null, item); + + if (ServerVersion.isServerVersion(ServerVersion.V1_8)) + nmsItemStack = methodA.invoke(null, new Random(), nmsItemStack, level); + else + nmsItemStack = methodA.invoke(null, new Random(), nmsItemStack, level, false); + + item = (ItemStack) methodAsBukkitCopy.invoke(null, nmsItemStack); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + return item; + } + + public static String itemStackArrayToBase64(ItemStack[] items) { + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); + dataOutput.writeInt(items.length); + for (ItemStack item : items) dataOutput.writeObject(item); + dataOutput.close(); + return Base64Coder.encodeLines(outputStream.toByteArray()); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static ItemStack[] itemStackArrayFromBase64(String data) { + try { + ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); + BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); + ItemStack[] items = new ItemStack[dataInput.readInt()]; + for (int i = 0; i < items.length; i++) + items[i] = (ItemStack) dataInput.readObject(); + dataInput.close(); + return items; + } catch (ClassNotFoundException | IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * Clone of org.bukkit.inventory.ItemStack.asQuantity, since it is a paper-only function + * + * @param item item to copy + * @param qty amount the new ItemStack should have + * + * @return a copy of the original item + */ + public static ItemStack getAsCopy(ItemStack item, int qty) { + ItemStack clone = item.clone(); + clone.setAmount(qty); + return clone; + } + + public static boolean hasEnoughDurability(ItemStack tool, int requiredAmount) { + if (tool.getType().getMaxDurability() <= 1) + return true; + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { + if (!tool.hasItemMeta() || !(tool.getItemMeta() instanceof Damageable)) + return true; + + Damageable damageable = (Damageable) tool.getItemMeta(); + int durabilityRemaining = tool.getType().getMaxDurability() - damageable.getDamage(); + return durabilityRemaining > requiredAmount; + } else { + return tool.getDurability() + requiredAmount <= tool.getType().getMaxDurability(); + } + } + + static Class cb_ItemStack = NMSUtils.getCraftClass("inventory.CraftItemStack"); + static Class mc_ItemStack = ClassMapping.ITEM_STACK.getClazz(); + static Class mc_NBTTagCompound = ClassMapping.NBT_TAG_COMPOUND.getClazz(); + static Class mc_NBTTagList = ClassMapping.NBT_TAG_LIST.getClazz(); + static Class mc_NBTBase = ClassMapping.NBT_BASE.getClazz(); + static Method mc_ItemStack_getTag; + static Method mc_ItemStack_setTag; + static Method mc_NBTTagCompound_set; + static Method mc_NBTTagCompound_remove; + static Method mc_NBTTagCompound_setShort; + static Method mc_NBTTagCompound_setString; + static Method mc_NBTTagList_add; + static Method cb_CraftItemStack_asNMSCopy; + static Method cb_CraftItemStack_asCraftMirror; + + static { + if (cb_ItemStack != null) { + try { + mc_ItemStack_getTag = mc_ItemStack.getDeclaredMethod("getTag"); + mc_ItemStack_setTag = mc_ItemStack.getDeclaredMethod("setTag", mc_NBTTagCompound); + mc_NBTTagCompound_set = mc_NBTTagCompound.getDeclaredMethod("set", String.class, mc_NBTBase); + mc_NBTTagCompound_remove = mc_NBTTagCompound.getDeclaredMethod("remove", String.class); + mc_NBTTagCompound_setShort = mc_NBTTagCompound.getDeclaredMethod("setShort", String.class, short.class); + mc_NBTTagCompound_setString = mc_NBTTagCompound.getDeclaredMethod("setString", String.class, String.class); + cb_CraftItemStack_asNMSCopy = cb_ItemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); + cb_CraftItemStack_asCraftMirror = cb_ItemStack.getDeclaredMethod("asCraftMirror", mc_ItemStack); + mc_NBTTagList_add = ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14) + ? NMSUtils.getPrivateMethod(mc_NBTTagList, "a", mc_NBTBase) + : mc_NBTTagList.getDeclaredMethod("add", mc_NBTBase); + } catch (Exception ex) { + Logger.getLogger(ItemUtils.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + /** + * Make an item glow as if it contained an enchantment.
+ * Tested working 1.8-1.14 + * + * @param item itemstack to create a glowing copy of + * + * @return copy of item with a blank enchantment nbt tag + */ + public static ItemStack addGlow(ItemStack item) { + // from 1.11 up, fake enchantments don't work without more steps + // creating a new Enchantment involves some very involved reflection, + // as the namespace is the same but until 1.12 requires an int, but versions after require a String + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) { + item.addUnsafeEnchantment(Enchantment.DURABILITY, 1); + // you can at least hide the enchantment, though + ItemMeta m = item.getItemMeta(); + m.addItemFlags(ItemFlag.HIDE_ENCHANTS); + item.setItemMeta(m); + return item; + } else { + // hack a fake enchant onto the item + // Confirmed works on 1.8, 1.9, 1.10 + // Does not work 1.11+ (minecraft ignores the glitched enchantment) + if (item != null && item.getType() != Material.AIR && cb_CraftItemStack_asCraftMirror != null) { + try { + Object nmsStack = cb_CraftItemStack_asNMSCopy.invoke(null, item); + Object tag = mc_ItemStack_getTag.invoke(nmsStack); + if (tag == null) { + tag = mc_NBTTagCompound.newInstance(); + } + // set to have a fake enchantment + Object enchantmentList = mc_NBTTagList.newInstance(); + /* + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { + // Servers from 1.13 and up change the id to a string + Object fakeEnchantment = mc_NBTTagCompound.newInstance(); + mc_NBTTagCompound_setString.invoke(fakeEnchantment, "id", "glow:glow"); + mc_NBTTagCompound_setShort.invoke(fakeEnchantment, "lvl", (short) 0); + mc_NBTTagList_add.invoke(enchantmentList, fakeEnchantment); + } else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) { + // Servers from 1.11 and up require *something* in the enchantment field + Object fakeEnchantment = mc_NBTTagCompound.newInstance(); + mc_NBTTagCompound_setShort.invoke(fakeEnchantment, "id", (short) 245); + mc_NBTTagCompound_setShort.invoke(fakeEnchantment, "lvl", (short) 1); + mc_NBTTagList_add.invoke(enchantmentList, fakeEnchantment); + }//*/ + mc_NBTTagCompound_set.invoke(tag, "ench", enchantmentList); + mc_ItemStack_setTag.invoke(nmsStack, tag); + item = (ItemStack) cb_CraftItemStack_asCraftMirror.invoke(null, nmsStack); + } catch (Exception ex) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to set glow enchantment on item: " + item, ex); + } + } + } + return item; + } + + /** + * Remove all enchantments, including hidden enchantments + * + * @param item item to clear enchants from + * + * @return copy of the item without any enchantment tag + */ + public static ItemStack removeGlow(ItemStack item) { + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) { + item.removeEnchantment(Enchantment.DURABILITY); + return item; + } else { + if (item != null && item.getType() != Material.AIR && cb_CraftItemStack_asCraftMirror != null) { + try { + Object nmsStack = cb_CraftItemStack_asNMSCopy.invoke(null, item); + Object tag = mc_ItemStack_getTag.invoke(nmsStack); + if (tag != null) { + // remove enchantment list + mc_NBTTagCompound_remove.invoke(tag, "ench"); + mc_ItemStack_setTag.invoke(nmsStack, tag); + item = (ItemStack) cb_CraftItemStack_asCraftMirror.invoke(null, nmsStack); + } + } catch (Exception ex) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to set glow enchantment on item: " + item, ex); + } + } + } + return item; + } + + private static Class mc_Item = ClassMapping.ITEM.getClazz(); + private static Method mc_Item_getItem; + private static Field mc_Item_maxStackSize; + + static { + if (mc_ItemStack != null) { + try { + mc_Item_getItem = mc_ItemStack.getDeclaredMethod("getItem"); + mc_Item_maxStackSize = mc_Item.getDeclaredField("maxStackSize"); + mc_Item_maxStackSize.setAccessible(true); + } catch (Exception ex) { + } + } + } + + public static ItemStack setMaxStack(ItemStack item, int max) { + if (item != null && mc_Item_maxStackSize != null) { + try { + Object objItemStack = mc_Item_getItem.invoke(cb_CraftItemStack_asNMSCopy.invoke(null, item)); + mc_Item_maxStackSize.set(objItemStack, max); + } catch (ReflectiveOperationException e) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to set max stack size on item " + item, e); + } + } + return item; + } + + public static ItemStack getPlayerSkull(OfflinePlayer player) { + ItemStack head = CompatibleMaterial.PLAYER_HEAD.getItem(); + if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) { + return head; + } + + SkullMeta meta = (SkullMeta) head.getItemMeta(); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { + meta.setOwningPlayer(player); + } else { + meta.setOwner(player.getName()); + } + head.setItemMeta(meta); + return head; + } + + public static void setHeadOwner(ItemStack head, OfflinePlayer player) { + if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8) || head == null || !CompatibleMaterial.PLAYER_HEAD.matches(head)) { + return; + } + SkullMeta meta = (SkullMeta) head.getItemMeta(); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { + meta.setOwningPlayer(player); + } else { + meta.setOwner(player.getName()); + } + } + + public static ItemStack getCustomHead(String texture) { + return getCustomHead(null, texture); + } + + public static ItemStack getCustomHead(String signature, String texture) { + ItemStack skullItem = CompatibleMaterial.PLAYER_HEAD.getItem(); + if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) + return skullItem; + + SkullMeta sm = (SkullMeta) skullItem.getItemMeta(); + GameProfile gm; + if (texture.endsWith("=")) { + gm = new GameProfile(UUID.nameUUIDFromBytes(texture.getBytes()), "CustomHead"); + if (signature == null) + gm.getProperties().put("textures", new Property("texture", texture.replaceAll("=", ""))); + else + gm.getProperties().put("textures", new Property("textures", texture, signature)); + } else { + gm = new GameProfile(UUID.nameUUIDFromBytes(texture.getBytes()), "CustomHead"); + byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"http://textures.minecraft.net/texture/%s\"}}}", texture).getBytes()); + gm.getProperties().put("textures", new Property("textures", new String(encodedData))); + } + + try { + Field profileField; + profileField = sm.getClass().getDeclaredField("profile"); + profileField.setAccessible(true); + profileField.set(sm, gm); + skullItem.setItemMeta(sm); + return skullItem; + } catch (NoSuchFieldException | IllegalAccessException | SecurityException ex) { + throw new RuntimeException("Reflection error while setting head texture", ex); + } + } + + static Class cb_CraftPlayer = NMSUtils.getCraftClass("entity.CraftPlayer"); + static Method cb_CraftPlayer_getProfile; + + static { + try { + cb_CraftPlayer_getProfile = cb_CraftPlayer.getMethod("getProfile"); + } catch (Exception ex) { + } + } + + public static String getSkullTexture(Player player) { + if (player == null || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) { + return null; + } + try { + + Object craftPlayer = cb_CraftPlayer.cast(player); + + Iterator iterator = ((GameProfile) cb_CraftPlayer_getProfile.invoke(craftPlayer)).getProperties().get("textures").iterator(); + + return iterator.hasNext() ? iterator.next().getValue() : null; + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + return null; + } + } + + public static String getSkullTexture(ItemStack item) { + if (!CompatibleMaterial.PLAYER_HEAD.matches(item) || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) { + return null; + } + try { + SkullMeta localSkullMeta = (SkullMeta) item.getItemMeta(); + Field cb_SkullMeta_profile = localSkullMeta.getClass().getDeclaredField("profile"); + if (cb_SkullMeta_profile == null) return null; + cb_SkullMeta_profile.setAccessible(true); + + GameProfile profile = (GameProfile) cb_SkullMeta_profile.get(localSkullMeta); + Iterator iterator = profile.getProperties().get("textures").iterator(); + + return iterator.hasNext() ? iterator.next().getValue() : null; + } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) { + } + return null; + } + + public static String getDecodedTexture(String encoded) { + return encoded != null ? StringUtils.substringBetween(new String(Base64.getDecoder().decode(encoded)), "texture/", "\"") : null; + } + + /** + * Use up whatever item the player is holding in their main hand + * + * @param player player to grab item from + * @param hand the hand to take the item from. + */ + @Deprecated + public static void takeActiveItem(Player player, CompatibleHand hand) { + takeActiveItem(player, hand, 1); + } + + /** + * Use up whatever item the player is holding in their main hand + * + * @param player player to grab item from + * @param hand the hand to take the item from. + * @param amount number of items to use up + */ + @Deprecated + public static void takeActiveItem(Player player, CompatibleHand hand, int amount) { + hand.takeItem(player, amount); + } + + /** + * Quickly check to see if the two items use the same material.
+ * NOTE: Does not check meta data; only checks the item material. + * + * @param is1 first item to compare + * @param is2 item to compare against + * + * @return true if both items are of the same material + */ + public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) { + CompatibleMaterial mat1 = CompatibleMaterial.getMaterial(is1); + return mat1 != null && mat1 == CompatibleMaterial.getMaterial(is2); + } + + /** + * Check to see if this item can be moved into a single slot in this + * inventory.
+ * This returns true if there is a free slot or a slot with a matching item + * where adding this item's amount to that item's amount will not violate + * the maximum stack size for that item. + * + * @param inventory inventory to check + * @param item item to check against + * + * @return true if a free slot or single receiver slot is available + */ + public static boolean canMove(Inventory inventory, ItemStack item) { + if (inventory.firstEmpty() != -1) { + return true; + } + + final ItemMeta itemMeta = item.getItemMeta(); + for (ItemStack stack : inventory) { + final ItemMeta stackMeta; + if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() + && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) + && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { + return true; + } + } + return false; + } + + /** + * Check to see if this item can be moved into a single slot in this + * inventory.
+ * This returns true if there is a free slot or a slot with a matching item + * where adding this item's amount to that item's amount will not violate + * the maximum stack size for that item. + * + * @param contents inventory to check + * @param item item to check against + * + * @return true if a free slot or single receiver slot is available + */ + public static boolean canMove(ItemStack[] contents, ItemStack item) { + final ItemMeta itemMeta = item.getItemMeta(); + for (int i = 0; i < contents.length; i++) { + final ItemStack stack = contents[i]; + if (stack == null || stack.getAmount() == 0) { + return true; + } + final ItemMeta stackMeta; + if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() + && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) + && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { + return true; + } + } + return false; + } + + /** + * Check to see if this item can be moved into a single slot in this + * inventory while also reserving one of the slots.
+ * This returns true if there is a free slot or a slot with a matching item + * where adding this item's amount to that item's amount will not violate + * the maximum stack size for that item. + * + * @param inventory inventory to check + * @param item item to check against + * @param reserved which slot should be reserved + * + * @return true if a free slot or single receiver slot is available + */ + public static boolean canMoveReserved(Inventory inventory, ItemStack item, int reserved) { + final ItemMeta itemMeta = item.getItemMeta(); + final ItemStack[] contents = inventory.getContents(); + for (int i = 0; i < contents.length; i++) { + if (i == reserved) { + continue; + } + final ItemStack stack = contents[i]; + final ItemMeta stackMeta; + if (stack == null || stack.getAmount() == 0 + || (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() + && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) + && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta)))) { + return true; + } + } + return false; + } + + /** + * Check to see if this item can be moved into a single slot in this + * inventory while also reserving one of the slots.
+ * This returns true if there is a free slot or a slot with a matching item + * where adding this item's amount to that item's amount will not violate + * the maximum stack size for that item. + * + * @param contents inventory to check + * @param item item to check against + * @param reserved which slot should be reserved + * + * @return true if a free slot or single receiver slot is available + */ + public static boolean canMoveReserved(ItemStack[] contents, ItemStack item, int reserved) { + final ItemMeta itemMeta = item.getItemMeta(); + for (int i = 0; i < contents.length; i++) { + if (i == reserved) { + continue; + } + final ItemStack stack = contents[i]; + if (stack == null || stack.getAmount() == 0) { + return true; + } + final ItemMeta stackMeta; + if (isSimilarMaterial(stack, item) && (stack.getAmount() + item.getAmount()) < stack.getMaxStackSize() + && ((itemMeta == null) == ((stackMeta = stack.getItemMeta()) == null)) + && (itemMeta == null || Bukkit.getItemFactory().equals(itemMeta, stackMeta))) { + return true; + } + } + return false; + } + + /** + * Add up to a number of items to this inventory. + * + * @param item item to add + * @param amountToAdd how many of this item to attempt to add + * @param inventory a list that represents the inventory + * @param maxSize maximum number of different items this container can hold + * + * @return how many items were added + */ + public static int addAny(ItemStack item, int amountToAdd, List inventory, int maxSize) { + return addAny(item, amountToAdd, inventory, maxSize, -1); + } + + /** + * Add up to a number of items to this inventory. + * + * @param item item to add + * @param amountToAdd how many of this item to attempt to add + * @param inventory a list that represents the inventory + * @param maxSize maximum number of different items this container can hold + * @param reserved slot to reserve - will not fill this slot + * + * @return how many items were added + */ + public static int addAny(ItemStack item, int amountToAdd, List inventory, int maxSize, int reserved) { + int totalAdded = 0; + if (inventory != null && item != null && amountToAdd > 0) { + final int maxStack = item.getMaxStackSize(); + for (int i = 0; amountToAdd > 0 && i < maxSize; i++) { + if (i == reserved) { + continue; + } + final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); + if (cacheItem == null || cacheItem.getAmount() == 0) { + // free slot! + int toAdd = Math.min(maxStack, amountToAdd); + ItemStack item2 = item.clone(); + item2.setAmount(toAdd); + if (i >= inventory.size()) { + inventory.add(item2); + } else { + inventory.set(i, item2); + } + totalAdded += toAdd; + amountToAdd -= toAdd; + } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { + // free space! + int toAdd = Math.min(maxStack - cacheItem.getAmount(), amountToAdd); + inventory.get(i).setAmount(toAdd + cacheItem.getAmount()); + totalAdded += toAdd; + amountToAdd -= toAdd; + } + } + } + return totalAdded; + } + + /** + * Add an item to this inventory, but only if it can be added completely. + * + * @param item item to add + * @param inventory a list that represents the inventory + * @param containerSize maximum number of different items this container can + * hold + * + * @return true if the item was added + */ + public static boolean addItem(ItemStack item, List inventory, int containerSize) { + if (inventory == null || item == null || item.getAmount() <= 0 || containerSize <= 0) { + return false; + } + return addItem(item, item.getAmount(), inventory, containerSize); + } + + /** + * Add an item to this inventory, but only if it can be added completely. + * + * @param item item to add + * @param inventory a list that represents the inventory + * @param containerSize maximum number of different items this container can + * hold + * @param reserved slot to reserve - will not fill this slot + * + * @return true if the item was added + */ + public static boolean addItem(ItemStack item, List inventory, int containerSize, int reserved) { + if (inventory == null || item == null || item.getAmount() <= 0 || containerSize <= 0) { + return false; + } + return addItem(item, item.getAmount(), inventory, containerSize, reserved); + } + + /** + * Add an item to this inventory. + * + * @param item item to add + * @param amount how many of this item should be added + * @param inventory a list that represents the inventory + * @param containerSize maximum number of different items this container can + * @param reserved slot to reserve - will not fill this slot hold + * + * @return true if the item was added + */ + public static boolean addItem(ItemStack item, int amount, List inventory, int containerSize, int reserved) { + return addItem(item, amount, inventory, containerSize, reserved, null); + } + + /** + * Add an item to this inventory, but only if it can be added completely. + * + * @param item item to add + * @param amount how many of this item should be added + * @param inventory a list that represents the inventory + * @param containerSize maximum number of different items this container can + * hold + * @param reserved slot to reserve - will not fill this slot + * @param inventorySource Material of the container + * + * @return true if the item was added + */ + public static boolean addItem(ItemStack item, int amount, List inventory, int containerSize, int reserved, Material inventorySource) { + if (inventory == null || item == null || amount <= 0 || inventorySource == null) { + return false; + } + boolean[] check = null; + + if (inventorySource != null && inventorySource != Material.AIR) { + // Don't transfer shulker boxes into other shulker boxes, that's a bad idea. + if (inventorySource.name().contains("SHULKER_BOX") && item.getType().name().contains("SHULKER_BOX")) { + return false; + } + + // some destination containers have special conditions + switch (inventorySource.name()) { + case "BREWING_STAND": { + + // first compile a list of what slots to check + check = new boolean[5]; + String typeStr = item.getType().name().toUpperCase(); + if (typeStr.contains("POTION") || typeStr.contains("BOTTLE")) { + // potion bottles are the first three slots + check[0] = check[1] = check[2] = true; + } + // fuel in 5th position, input in 4th + if (item.getType() == Material.BLAZE_POWDER) { + check[4] = true; + } else { + check[3] = true; + } + } + case "SMOKER": + case "BLAST_FURNACE": + case "BURNING_FURNACE": + case "FURNACE": { + + check = new boolean[3]; + + boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel(); + // fuel is 2nd slot, input is first + if (isFuel) { + + check[1] = true; + } else { + check[0] = true; + } + } + } + } + + // grab the amount to move and the max item stack size + int toAdd = item.getAmount(); + final int maxStack = item.getMaxStackSize(); + + // we can reduce calls to ItemStack.isSimilar() by caching what cells to look at + if (check == null) { + check = new boolean[containerSize]; + for (int i = 0; toAdd > 0 && i < check.length; i++) { + check[i] = true; + } + } + if (reserved >= 0 && check.length < reserved) { + check[reserved] = false; + } + + // first verify that we can add this item + for (int i = 0; toAdd > 0 && i < containerSize; i++) { + if (check[i]) { + final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); + if (cacheItem == null || cacheItem.getAmount() == 0) { + // free slot! + toAdd -= Math.min(maxStack, toAdd); + check[i] = true; + } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { + // free space! + toAdd -= Math.min(maxStack - cacheItem.getAmount(), toAdd); + check[i] = true; + } else { + check[i] = false; + } + } + } + if (toAdd <= 0) { + // all good to add! + toAdd = item.getAmount(); + for (int i = 0; toAdd > 0 && i < containerSize; i++) { + if (!check[i]) { + continue; + } + final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); + if (cacheItem == null || cacheItem.getAmount() == 0) { + // free slot! + int adding = Math.min(maxStack, toAdd); + ItemStack item2 = item.clone(); + item2.setAmount(adding); + if (i >= inventory.size()) { + inventory.add(item2); + } else { + inventory.set(i, item2); + } + toAdd -= adding; + } else if (maxStack > cacheItem.getAmount()) { + // free space! + // (no need to check item.isSimilar(cacheItem), since we have that cached in check[]) + int adding = Math.min(maxStack - cacheItem.getAmount(), toAdd); + inventory.get(i).setAmount(adding + cacheItem.getAmount()); + toAdd -= adding; + } + } + return true; + } + return false; + } + + /** + * Add up to a number of items to this inventory. + * + * @param item item to add + * @param amountToAdd how many of this item to attempt to add + * @param inventory a list that represents the inventory + * + * @return how many items were added + */ + public static int addAny(ItemStack item, int amountToAdd, Inventory inventory) { + int totalAdded = 0; + if (inventory != null && item != null && amountToAdd > 0) { + final int containerSize = inventory.getSize(); + final int maxStack = item.getMaxStackSize(); + for (int i = 0; amountToAdd > 0 && i < containerSize; i++) { + final ItemStack cacheItem = inventory.getItem(i); + if (cacheItem == null || cacheItem.getAmount() == 0) { + // free slot! + int toAdd = Math.min(maxStack, amountToAdd); + ItemStack item2 = item.clone(); + item2.setAmount(toAdd); + inventory.setItem(i, item2); + totalAdded += toAdd; + amountToAdd -= toAdd; + } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { + // free space! + int toAdd = Math.min(maxStack - cacheItem.getAmount(), amountToAdd); + cacheItem.setAmount(toAdd + cacheItem.getAmount()); + totalAdded += toAdd; + amountToAdd -= toAdd; + } + } + } + return totalAdded; + } + + /** + * Add an item to this inventory, but only if it can be added completely. + * + * @param item item to add + * @param inventory a list that represents the inventory hold + * + * @return true if the item was added + */ + public static boolean addItem(ItemStack item, Inventory inventory) { + if (inventory == null || item == null || item.getAmount() <= 0) { + return false; + } + return addItem(item, item.getAmount(), inventory, -1, null); + } + + /** + * Add an item to this inventory. + * + * @param item item to add + * @param amount how many of this item should be added + * @param inventory a list that represents the inventory + * @param reserved slot to reserve - will not fill this slot + * + * @return true if the item was added + */ + public static boolean addItem(ItemStack item, int amount, Inventory inventory, int reserved) { + return addItem(item, amount, inventory, reserved, null); + } + + /** + * Add an item to this inventory, but only if it can be added completely. + * + * @param item item to add + * @param amount how many of this item should be added + * @param inventory a list that represents the inventory + * @param reserved slot to reserve - will not fill this slot + * @param inventorySource Material of the container + * + * @return true if the item was added + */ + public static boolean addItem(ItemStack item, int amount, Inventory inventory, int reserved, Material inventorySource) { + if (inventory == null || item == null || amount <= 0 || inventorySource == null) { + return false; + } + boolean[] check = null; + + if (inventorySource != null && inventorySource != Material.AIR) { + + // Don't transfer shulker boxes into other shulker boxes, that's a bad idea. + if (inventorySource.name().contains("SHULKER_BOX") && item.getType().name().contains("SHULKER_BOX")) { + return false; + } + + // some destination containers have special conditions + switch (inventorySource.name()) { + case "BREWING_STAND": { + + // first compile a list of what slots to check + check = new boolean[5]; + String typeStr = item.getType().name().toUpperCase(); + if (typeStr.contains("POTION") || typeStr.contains("BOTTLE")) { + // potion bottles are the first three slots + check[0] = check[1] = check[2] = true; + } + // fuel in 5th position, input in 4th + if (item.getType() == Material.BLAZE_POWDER) { + check[4] = true; + } else { + check[3] = true; + } + } + case "SMOKER": + case "BLAST_FURNACE": + case "BURNING_FURNACE": + case "FURNACE": { + + check = new boolean[3]; + + boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel(); + // fuel is 2nd slot, input is first + if (isFuel) { + + check[1] = true; + } else { + check[0] = true; + } + } + } + } + // grab the amount to move and the max item stack size + int toAdd = item.getAmount(); + final int maxStack = item.getMaxStackSize(); + final int containerSize = inventory.getSize(); + + // we can reduce calls to ItemStack.isSimilar() by caching what cells to look at + if (check == null) { + check = new boolean[containerSize]; + for (int i = 0; toAdd > 0 && i < check.length; i++) { + check[i] = true; + } + } + + // first verify that we can add this item + for (int i = 0; toAdd > 0 && i < containerSize; i++) { + if (check[i]) { + final ItemStack cacheItem = inventory.getItem(i); + if (cacheItem == null || cacheItem.getAmount() == 0) { + // free slot! + toAdd -= Math.min(maxStack, toAdd); + check[i] = true; + } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { + // free space! + toAdd -= Math.min(maxStack - cacheItem.getAmount(), toAdd); + check[i] = true; + } else { + check[i] = false; + } + } + } + if (toAdd <= 0) { + // all good to add! + toAdd = item.getAmount(); + for (int i = 0; toAdd > 0 && i < containerSize; i++) { + if (!check[i]) { + continue; + } + final ItemStack cacheItem = inventory.getItem(i); + if (cacheItem == null || cacheItem.getAmount() == 0) { + // free slot! + int adding = Math.min(maxStack, toAdd); + ItemStack item2 = item.clone(); + item2.setAmount(adding); + inventory.setItem(i, item2); + toAdd -= adding; + } else if (maxStack > cacheItem.getAmount()) { + // free space! + // (no need to check item.isSimilar(cacheItem), since we have that cached in check[]) + int adding = Math.min(maxStack - cacheItem.getAmount(), toAdd); + cacheItem.setAmount(adding + cacheItem.getAmount()); + toAdd -= adding; + } + } + return true; + } + return false; + } + + public static CompatibleMaterial getDyeColor(char color) { + switch (color) { + case '0': + return CompatibleMaterial.BLACK_DYE; + case '1': + return CompatibleMaterial.BLUE_DYE; + case '2': + return CompatibleMaterial.GREEN_DYE; + case '3': + return CompatibleMaterial.CYAN_DYE; + case '4': + return CompatibleMaterial.BROWN_DYE; + case '5': + return CompatibleMaterial.PURPLE_DYE; + case '6': + return CompatibleMaterial.ORANGE_DYE; + case '7': + return CompatibleMaterial.LIGHT_GRAY_DYE; + case '8': + return CompatibleMaterial.GREEN_DYE; + case 'a': + return CompatibleMaterial.LIME_DYE; + case 'b': + return CompatibleMaterial.LIGHT_BLUE_DYE; + case 'c': + return CompatibleMaterial.RED_DYE; + case 'd': + return CompatibleMaterial.MAGENTA_DYE; + case 'e': + return CompatibleMaterial.YELLOW_DYE; + case 'f': + return CompatibleMaterial.WHITE_DYE; + } + return CompatibleMaterial.STONE; + } + + /** + * Add an item to this inventory. + * + * @param item item to add + * @param amount how many of this item should be added + * @param inventory a list that represents the inventory + * @param containerSize maximum number of different items this container can + * hold + * + * @return true if the item was added + */ + public static boolean addItem(ItemStack item, int amount, List inventory, int containerSize) { + if (inventory == null || item == null || amount <= 0 || containerSize <= 0) { + return false; + } + + // grab the amount to move and the max item stack size + int toAdd = amount; + final int maxStack = item.getMaxStackSize(); + boolean[] check = null; + + // we can reduce calls to ItemStack.isSimilar() by caching what cells to look at + if (check == null) { + check = new boolean[containerSize]; + for (int i = 0; toAdd > 0 && i < check.length; i++) { + check[i] = true; + } + } + + // first verify that we can add this item + for (int i = 0; toAdd > 0 && i < containerSize; i++) { + if (check[i]) { + final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); + if (cacheItem == null || cacheItem.getAmount() == 0) { + // free slot! + toAdd -= Math.min(maxStack, toAdd); + check[i] = true; + } else if (maxStack > cacheItem.getAmount() && item.isSimilar(cacheItem)) { + // free space! + toAdd -= Math.min(maxStack - cacheItem.getAmount(), toAdd); + check[i] = true; + } else { + check[i] = false; + } + } + } + + if (toAdd <= 0) { + // all good to add! + toAdd = item.getAmount(); + for (int i = 0; toAdd > 0 && i < containerSize; i++) { + if (!check[i]) { + continue; + } + final ItemStack cacheItem = i >= inventory.size() ? null : inventory.get(i); + if (cacheItem == null || cacheItem.getAmount() == 0) { + // free slot! + int adding = Math.min(maxStack, toAdd); + ItemStack item2 = item.clone(); + item2.setAmount(adding); + if (i >= inventory.size()) { + inventory.add(item2); + } else { + inventory.set(i, item2); + } + toAdd -= adding; + } else if (maxStack > cacheItem.getAmount()) { + // free space! + // (no need to check item.isSimilar(cacheItem), since we have that cached in check[]) + int adding = Math.min(maxStack - cacheItem.getAmount(), toAdd); + inventory.get(i).setAmount(adding + cacheItem.getAmount()); + toAdd -= adding; + } + } + return true; + } + return false; + } +} diff --git a/Core/src/main/java/com/songoda/core/utils/LocationUtils.java b/Core/src/main/java/com/songoda/core/utils/LocationUtils.java index c87305b1..e80d0428 100644 --- a/Core/src/main/java/com/songoda/core/utils/LocationUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/LocationUtils.java @@ -21,5 +21,4 @@ public class LocationUtils { l.getY() >= y1 && l.getY() <= y2 && l.getZ() >= z1 && l.getZ() <= z2; } - } diff --git a/Core/src/main/java/com/songoda/core/utils/Metrics.java b/Core/src/main/java/com/songoda/core/utils/Metrics.java index 78312e1d..c403db19 100644 --- a/Core/src/main/java/com/songoda/core/utils/Metrics.java +++ b/Core/src/main/java/com/songoda/core/utils/Metrics.java @@ -45,8 +45,8 @@ public class Metrics { if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D final String defaultPackage = new String( - new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'}); - final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); + new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'}); + final String examplePackage = new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); // We want to make sure nobody just copy & pastes the example and use the wrong package names if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) { throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); @@ -316,6 +316,7 @@ public class Metrics { * * @param plugin Any plugin. It's just used to get a logger instance. * @param data The data to send. + * * @throws Exception If the request failed. */ private static void sendData(Plugin plugin, JSONObject data) throws Exception { @@ -367,7 +368,9 @@ public class Metrics { * Gzips the given String. * * @param str The string to gzip. + * * @return The gzipped String. + * * @throws IOException If the compression failed. */ private static byte[] compress(final String str) throws IOException { @@ -421,7 +424,6 @@ public class Metrics { } protected abstract JSONObject getChartData() throws Exception; - } /** @@ -577,7 +579,6 @@ public class Metrics { data.put("value", value); return data; } - } /** @@ -622,7 +623,6 @@ public class Metrics { data.put("values", values); return data; } - } /** @@ -660,7 +660,6 @@ public class Metrics { data.put("values", values); return data; } - } /** @@ -710,5 +709,4 @@ public class Metrics { return data; } } - -} \ No newline at end of file +} diff --git a/Core/src/main/java/com/songoda/core/utils/NumberUtils.java b/Core/src/main/java/com/songoda/core/utils/NumberUtils.java index 6b308055..afaa636c 100644 --- a/Core/src/main/java/com/songoda/core/utils/NumberUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/NumberUtils.java @@ -24,7 +24,7 @@ public class NumberUtils { if (count < 1000) return String.valueOf(count); int exp = (int) (Math.log(count) / Math.log(1000)); return String.format("%.1f%c", count / Math.pow(1000, exp), - "kMGTPE".charAt(exp-1)).replace(".0", ""); + "kMGTPE".charAt(exp - 1)).replace(".0", ""); } public static boolean isInt(String number) { @@ -43,5 +43,4 @@ public class NumberUtils { return false; return s.matches("[-+]?\\d*\\.?\\d+"); } - } diff --git a/Core/src/main/java/com/songoda/core/utils/PlayerUtils.java b/Core/src/main/java/com/songoda/core/utils/PlayerUtils.java index 0c68c687..17c9b397 100644 --- a/Core/src/main/java/com/songoda/core/utils/PlayerUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/PlayerUtils.java @@ -1,230 +1,236 @@ -package com.songoda.core.utils; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.PermissionAttachmentInfo; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.stream.Collectors; - -public class PlayerUtils { - - static Random random = new Random(); - - public static void sendMessages(Player player, String... messages) { - for (String message : messages) - player.sendMessage(message); - } - - public static void sendMessages(Player player, List messages) { - for (String message : messages) - player.sendMessage(message); - } - - /** - * Get a list of all of the players that this player can "see" - * - * @param sender user to check against, or null for all players - * @param startingWith optional query to test: only players whose game names - * start with this - * @return list of player names that are "visible" to the player - */ - public static List getVisiblePlayerNames(CommandSender sender, String startingWith) { - Player player = sender instanceof Player ? (Player) sender : null; - final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase(); - return Bukkit.getOnlinePlayers().stream() - .filter(p -> p != player) - .filter(p -> startsWith == null || p.getName().toLowerCase().startsWith(startsWith)) - .filter(p -> player == null || (player.canSee(p) && p.getMetadata("vanished").isEmpty())) - .map(Player::getName) - .collect(Collectors.toList()); - } - - /** - * Get a list of all of the players that this player can "see" - * - * @param sender user to check against, or null for all players - * @param startingWith optional query to test: only players whose game names - * start with this - * @return list of player names that are "visible" to the player - */ - public static List getVisiblePlayerDisplayNames(CommandSender sender, String startingWith) { - Player player = sender instanceof Player ? (Player) sender : null; - final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.replaceAll("[^a-zA-Z]", "").toLowerCase(); - return Bukkit.getOnlinePlayers().stream() - .filter(p -> p != player) - .filter(p -> startsWith == null || p.getDisplayName().replaceAll("[^a-zA-Z]", "").toLowerCase().startsWith(startsWith)) - .filter(p -> player == null || (player.canSee(p) && p.getMetadata("vanished").isEmpty())) - .map(Player::getDisplayName) - .collect(Collectors.toList()); - } - - /** - * Get a list of all of the players that this player can "see" - * - * @param sender user to check against, or null for all players - * @param startingWith optional query to test: only players whose game names - * start with this - * @return list of players that are "visible" to the player - */ - public static List getVisiblePlayers(CommandSender sender, String startingWith) { - Player player = sender instanceof Player ? (Player) sender : null; - final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase(); - return Bukkit.getOnlinePlayers().stream() - .filter(p -> p != player) - .filter(p -> startsWith == null || p.getName().toLowerCase().startsWith(startsWith)) - .filter(p -> player == null || (player.canSee(p) && p.getMetadata("vanished").isEmpty())) - .map(p -> (Player) p) - .collect(Collectors.toList()); - } - - /** - * Get a list of all online player names that start with a string. - * - * @param us Ourselves / who is requesting the list. Will not return this player. - * @param startsWith All names returned must start with this input string - * @return List of matching player IGN - */ - public static List getAllPlayers(CommandSender us, String startsWith) { - final String arg = startsWith.toLowerCase(); - return Bukkit.getOnlinePlayers().stream() - .filter(p -> us != p && p.getName().startsWith(arg)) - .map(Player::getName) - .collect(Collectors.toList()); - } - - /** - * Get a list of all online player names that start with a string. - * - * @param us Ourselves / who is requesting the list. Will not return this player. - * @param startsWith All names returned must start with this input string - * @return List of matching player display names - */ - public static List getAllPlayersDisplay(CommandSender us, String startsWith) { - final String arg = startsWith.replaceAll("[^a-zA-Z]", "").toLowerCase(); - return Bukkit.getOnlinePlayers().stream() - .filter(p -> us != p && p.getDisplayName().replaceAll("[^a-zA-Z]", "").startsWith(arg)) - .map(Player::getDisplayName) - .collect(Collectors.toList()); - } - - /** - * Search for and grab the closest match for a provided player name.
- * Also checks player display names if there is not an exact match. - * - * @param player player to search for - * @return Player that closest matches the input name, or null if none found - */ - public static Player findPlayer(String player) { - Player found = Bukkit.getServer().getPlayer(player); - if (found == null) { - final String searchName = player.toLowerCase(); - final String searchDisplayName = player.replaceAll("[^a-zA-Z]", "").toLowerCase(); - int d = 999; - for (Player p2 : Bukkit.getOnlinePlayers()) { - final String test; - if (p2.getName().toLowerCase().startsWith(searchName)) { - int d2 = p2.getName().length() - searchName.length(); - if (d2 < d) { - found = p2; - d = d2; - } else if (d2 == d) { - found = null; - } - } else if ((test = p2.getDisplayName().replaceAll("[^a-zA-Z]", "")).toLowerCase().startsWith(searchDisplayName)) { - int d2 = test.length() - searchDisplayName.length(); - if (d2 < d) { - found = p2; - d = d2; - } else if (d2 == d) { - found = null; - } - } - } - } - return found; - } - - public static Player getRandomPlayer() { - final Collection all = Bukkit.getOnlinePlayers(); - final Iterator alli = all.iterator(); - int pick = random.nextInt(all.size()); - for (; pick > 0; --pick) { - alli.next(); - } - return alli.hasNext() ? alli.next() : null; - } - - public static void giveItem(Player player, ItemStack item) { - if (player == null || !player.isOnline() || item == null) { - return; - } - Map leftover = player.getInventory().addItem(item); - if (!leftover.isEmpty()) { - leftover.values().stream().forEach(it -> player.getWorld().dropItemNaturally(player.getLocation(), it)); - } - } - - public static void giveItem(Player player, ItemStack... items) { - if (player == null || !player.isOnline() || items == null || items.length == 0) { - return; - } - Map leftover = player.getInventory().addItem(items); - if (!leftover.isEmpty()) { - final World world = player.getWorld(); - final Location location = player.getLocation(); - leftover.values().stream().forEach(it -> world.dropItemNaturally(location, it)); - } - } - - public static void giveItem(Player player, Collection items) { - if (player == null || !player.isOnline() || items == null || items.isEmpty()) { - return; - } - Map leftover = player.getInventory().addItem(items.toArray(new ItemStack[items.size()])); - if (!leftover.isEmpty()) { - final World world = player.getWorld(); - final Location location = player.getLocation(); - leftover.values().stream().forEach(it -> world.dropItemNaturally(location, it)); - } - } - - public static int getNumberFromPermission(Player player, String permission, int def) { - final Set permissions = player.getEffectivePermissions(); - - boolean set = false; - int highest = 0; - - for (PermissionAttachmentInfo info : permissions) { - - final String perm = info.getPermission(); - - if (!perm.startsWith(permission)) continue; - - final int index = perm.lastIndexOf('.'); - - if (index == -1 || index == perm.length()) continue; - - String numStr = perm.substring(perm.lastIndexOf('.') + 1); - if (numStr.equals("*")) return def; - - final int number = Integer.parseInt(numStr); - - if (number >= highest) { - highest = number; - set = true; - } - } - - return set ? highest : def; - } -} +package com.songoda.core.utils; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.permissions.PermissionAttachmentInfo; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.stream.Collectors; + +public class PlayerUtils { + + static Random random = new Random(); + + public static void sendMessages(Player player, String... messages) { + for (String message : messages) + player.sendMessage(message); + } + + public static void sendMessages(Player player, List messages) { + for (String message : messages) + player.sendMessage(message); + } + + /** + * Get a list of all of the players that this player can "see" + * + * @param sender user to check against, or null for all players + * @param startingWith optional query to test: only players whose game names + * start with this + * + * @return list of player names that are "visible" to the player + */ + public static List getVisiblePlayerNames(CommandSender sender, String startingWith) { + Player player = sender instanceof Player ? (Player) sender : null; + final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase(); + return Bukkit.getOnlinePlayers().stream() + .filter(p -> p != player) + .filter(p -> startsWith == null || p.getName().toLowerCase().startsWith(startsWith)) + .filter(p -> player == null || (player.canSee(p) && p.getMetadata("vanished").isEmpty())) + .map(Player::getName) + .collect(Collectors.toList()); + } + + /** + * Get a list of all of the players that this player can "see" + * + * @param sender user to check against, or null for all players + * @param startingWith optional query to test: only players whose game names + * start with this + * + * @return list of player names that are "visible" to the player + */ + public static List getVisiblePlayerDisplayNames(CommandSender sender, String startingWith) { + Player player = sender instanceof Player ? (Player) sender : null; + final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.replaceAll("[^a-zA-Z]", "").toLowerCase(); + return Bukkit.getOnlinePlayers().stream() + .filter(p -> p != player) + .filter(p -> startsWith == null || p.getDisplayName().replaceAll("[^a-zA-Z]", "").toLowerCase().startsWith(startsWith)) + .filter(p -> player == null || (player.canSee(p) && p.getMetadata("vanished").isEmpty())) + .map(Player::getDisplayName) + .collect(Collectors.toList()); + } + + /** + * Get a list of all of the players that this player can "see" + * + * @param sender user to check against, or null for all players + * @param startingWith optional query to test: only players whose game names + * start with this + * + * @return list of players that are "visible" to the player + */ + public static List getVisiblePlayers(CommandSender sender, String startingWith) { + Player player = sender instanceof Player ? (Player) sender : null; + final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase(); + return Bukkit.getOnlinePlayers().stream() + .filter(p -> p != player) + .filter(p -> startsWith == null || p.getName().toLowerCase().startsWith(startsWith)) + .filter(p -> player == null || (player.canSee(p) && p.getMetadata("vanished").isEmpty())) + .map(p -> (Player) p) + .collect(Collectors.toList()); + } + + /** + * Get a list of all online player names that start with a string. + * + * @param us Ourselves / who is requesting the list. Will not return this player. + * @param startsWith All names returned must start with this input string + * + * @return List of matching player IGN + */ + public static List getAllPlayers(CommandSender us, String startsWith) { + final String arg = startsWith.toLowerCase(); + return Bukkit.getOnlinePlayers().stream() + .filter(p -> us != p && p.getName().startsWith(arg)) + .map(Player::getName) + .collect(Collectors.toList()); + } + + /** + * Get a list of all online player names that start with a string. + * + * @param us Ourselves / who is requesting the list. Will not return this player. + * @param startsWith All names returned must start with this input string + * + * @return List of matching player display names + */ + public static List getAllPlayersDisplay(CommandSender us, String startsWith) { + final String arg = startsWith.replaceAll("[^a-zA-Z]", "").toLowerCase(); + return Bukkit.getOnlinePlayers().stream() + .filter(p -> us != p && p.getDisplayName().replaceAll("[^a-zA-Z]", "").startsWith(arg)) + .map(Player::getDisplayName) + .collect(Collectors.toList()); + } + + /** + * Search for and grab the closest match for a provided player name.
+ * Also checks player display names if there is not an exact match. + * + * @param player player to search for + * + * @return Player that closest matches the input name, or null if none found + */ + public static Player findPlayer(String player) { + Player found = Bukkit.getServer().getPlayer(player); + if (found == null) { + final String searchName = player.toLowerCase(); + final String searchDisplayName = player.replaceAll("[^a-zA-Z]", "").toLowerCase(); + int d = 999; + for (Player p2 : Bukkit.getOnlinePlayers()) { + final String test; + if (p2.getName().toLowerCase().startsWith(searchName)) { + int d2 = p2.getName().length() - searchName.length(); + if (d2 < d) { + found = p2; + d = d2; + } else if (d2 == d) { + found = null; + } + } else if ((test = p2.getDisplayName().replaceAll("[^a-zA-Z]", "")).toLowerCase().startsWith(searchDisplayName)) { + int d2 = test.length() - searchDisplayName.length(); + if (d2 < d) { + found = p2; + d = d2; + } else if (d2 == d) { + found = null; + } + } + } + } + return found; + } + + public static Player getRandomPlayer() { + final Collection all = Bukkit.getOnlinePlayers(); + final Iterator alli = all.iterator(); + int pick = random.nextInt(all.size()); + for (; pick > 0; --pick) { + alli.next(); + } + return alli.hasNext() ? alli.next() : null; + } + + public static void giveItem(Player player, ItemStack item) { + if (player == null || !player.isOnline() || item == null) { + return; + } + Map leftover = player.getInventory().addItem(item); + if (!leftover.isEmpty()) { + leftover.values().stream().forEach(it -> player.getWorld().dropItemNaturally(player.getLocation(), it)); + } + } + + public static void giveItem(Player player, ItemStack... items) { + if (player == null || !player.isOnline() || items == null || items.length == 0) { + return; + } + Map leftover = player.getInventory().addItem(items); + if (!leftover.isEmpty()) { + final World world = player.getWorld(); + final Location location = player.getLocation(); + leftover.values().stream().forEach(it -> world.dropItemNaturally(location, it)); + } + } + + public static void giveItem(Player player, Collection items) { + if (player == null || !player.isOnline() || items == null || items.isEmpty()) { + return; + } + Map leftover = player.getInventory().addItem(items.toArray(new ItemStack[items.size()])); + if (!leftover.isEmpty()) { + final World world = player.getWorld(); + final Location location = player.getLocation(); + leftover.values().stream().forEach(it -> world.dropItemNaturally(location, it)); + } + } + + public static int getNumberFromPermission(Player player, String permission, int def) { + final Set permissions = player.getEffectivePermissions(); + + boolean set = false; + int highest = 0; + + for (PermissionAttachmentInfo info : permissions) { + + final String perm = info.getPermission(); + + if (!perm.startsWith(permission)) continue; + + final int index = perm.lastIndexOf('.'); + + if (index == -1 || index == perm.length()) continue; + + String numStr = perm.substring(perm.lastIndexOf('.') + 1); + if (numStr.equals("*")) return def; + + final int number = Integer.parseInt(numStr); + + if (number >= highest) { + highest = number; + set = true; + } + } + + return set ? highest : def; + } +} diff --git a/Core/src/main/java/com/songoda/core/utils/ReflectionUtils.java b/Core/src/main/java/com/songoda/core/utils/ReflectionUtils.java index 1a77f58c..adc797b3 100644 --- a/Core/src/main/java/com/songoda/core/utils/ReflectionUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/ReflectionUtils.java @@ -1,339 +1,337 @@ -package com.songoda.core.utils; - -import java.io.File; -import java.io.IOException; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLDecoder; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; -import java.security.CodeSource; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class ReflectionUtils { - - public final static double JAVA_VERSION = getVersion(); - private static String system_os = System.getProperty("os.name").toLowerCase(); - - private static double getVersion() { - String version = System.getProperty("java.version"); - int i = version.indexOf('.'); - if (i != -1 && (i = version.indexOf('.', i + 1)) != -1) { - return Double.parseDouble(version.substring(0, i)); - } - return Double.NaN; - } - - public static File getJarFile(Class jarClass) { - return new File(jarClass.getProtectionDomain().getCodeSource().getLocation().getPath(). - replace("%20", " ").replace("%25", "%")); - } - - public static void setPrivateField(Class c, Object handle, String fieldName, Object value) throws Exception { - Field f = c.getDeclaredField(fieldName); - f.setAccessible(true); - f.set(handle, value); - } - - public static Object getPrivateField(Class c, Object handle, String fieldName) throws Exception { - Field field = c.getDeclaredField(fieldName); - field.setAccessible(true); - return field.get(handle); - } - - public static Object invokePrivateMethod(Class c, String methodName, Object handle, Class[] types, Object[] parameters) throws Exception { - Method m = c.getDeclaredMethod(methodName, types); - m.setAccessible(true); - return m.invoke(handle, parameters); - } - - // does not work in JRE 8+ - private static Method j7getStackTraceElementMethod; - private static Method j7getStackTraceDepthMethod; - - // does not work in JRE != 8 - private static Method j8getJavaLangAccess; - private static Method j8getStackTraceElementMethod; - - static { - try { - j7getStackTraceElementMethod = Throwable.class.getDeclaredMethod("getStackTraceElement", int.class); - j7getStackTraceElementMethod.setAccessible(true); - j7getStackTraceDepthMethod = Throwable.class.getDeclaredMethod("getStackTraceDepth"); - j7getStackTraceDepthMethod.setAccessible(true); - } catch (Exception ex) { - j7getStackTraceElementMethod = j7getStackTraceDepthMethod = null; - } - try { - j8getJavaLangAccess = Class.forName("sun.misc.SharedSecrets").getDeclaredMethod("getStackTraceElement"); - j8getJavaLangAccess.setAccessible(true); - j8getStackTraceElementMethod = Class.forName("sun.misc.JavaLangAccess").getDeclaredMethod("getStackTraceDepth", Throwable.class, int.class); - j8getStackTraceElementMethod.setAccessible(true); - } catch (Exception ex) { - j8getJavaLangAccess = j8getStackTraceElementMethod = null; - } - } - - /** - * If you only need one stack trace element this is faster than - * Throwable.getStackTrace()[element], it doesn't generate the full stack - * trace. - */ - public static StackTraceElement getStackTraceElement(int index) { - try { - Throwable dummy = new Throwable(); - - if (j8getStackTraceElementMethod != null) { - return (StackTraceElement) j8getStackTraceElementMethod.invoke(j8getJavaLangAccess.invoke(null), dummy, index); -// } else if (JAVA_VERSION >= 9) { -// return StackWalker.getInstance(Collections.emptySet(), index + 1) -// .walk(s -> s.skip(index).findFirst()) -// .orElse(null); - } else if (j7getStackTraceElementMethod == null) { - // better than nothing, right? :/ - return (new Throwable()).getStackTrace()[index]; - } else { - if (index < (Integer) j7getStackTraceDepthMethod.invoke(dummy)) { - return (StackTraceElement) j7getStackTraceElementMethod.invoke(new Throwable(), index); - } else { - return null; - } - } - } catch (Throwable t) { - } - return null; - } - - public static Map, T> getClassesInClassPackageByAnnotation(Class clazz, Class annotation) throws IOException { - final Map, T> foundClasses = new HashMap<>(); - for (Class c : getAllClassesInClassPackage(clazz, false)) { - T t = c.getAnnotation(annotation); - if (t != null) { - foundClasses.put(c, t); - } - } - return foundClasses; - } - - public static List> getAllClassesInClassPackage(Class clazz, boolean recursive) throws IOException { - final List> packageClasses = new ArrayList<>(); - - final String clazzPackageName = clazz.getPackage().getName(); - URL dot = clazz.getResource("."); - if (dot == null) { - // jar file - String packagePath = clazzPackageName.replace('.', '/'); - CodeSource src = clazz.getProtectionDomain().getCodeSource(); - if (src != null) { - URL jar = src.getLocation(); - ZipInputStream zip = new ZipInputStream(jar.openStream()); - ZipEntry e; - while ((e = zip.getNextEntry()) != null) { - String name = e.getName(); - if (!name.endsWith("/") && name.startsWith(packagePath + "/")) { - if (recursive || name.indexOf('/', packagePath.length() + 1) == -1) { - try { - Class loadedClazz = Class.forName(name.substring(0, name.lastIndexOf('.')).replace('/', '.')); - packageClasses.add(loadedClazz); - } catch (ClassNotFoundException e1) { - System.err.println("class not found: " + e1.getMessage()); - } - } - } - } - } - } else { - String clazzPath = clazz.getResource(".").getPath(); - if (clazzPath.startsWith("/") && system_os.contains("win")) { - clazzPath = clazzPath.substring(1); - } - Path packagePath = Paths.get(clazzPath); - - Files.walkFileTree(packagePath, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - String filename = file.getName(file.getNameCount() - 1).toString(); - - if (filename.endsWith(".class")) { - String className = filename.replace(".class", ""); - - try { - Class loadedClazz = Class.forName( - clazzPackageName + "." + className); - - packageClasses.add(loadedClazz); - } catch (ClassNotFoundException e) { - System.err.println("class not found: " + e.getMessage()); - } - } - return super.visitFile(file, attrs); - } - }); - - } - - return packageClasses; - } - - public static enum ITERATION { - - NONE, CLASS, PACKAGE, FULL - } - - public static List getClassNamesFromPackage(Class classInPackage) throws IOException, URISyntaxException, ClassNotFoundException { - String classPath = classInPackage.getName(); - int packageDelim = classPath.lastIndexOf('.'); - return getClassNamesFromPackage(getJarFile(classInPackage), classPath.substring(0, packageDelim), ITERATION.NONE); - } - - public static List getClassNamesFromPackage(String packageName) throws IOException, URISyntaxException, ClassNotFoundException { - return getClassNamesFromPackage(packageName, ITERATION.NONE); - } - - public static List getClassNamesFromPackage(String packageName, ITERATION iterate) throws IOException, URISyntaxException, ClassNotFoundException { - return getClassNamesFromPackage(null, packageName, iterate); - } - - public static List getClassNamesFromPackage(File sourceJar, String packageName, ITERATION iterate) throws IOException, URISyntaxException, ClassNotFoundException { - // http://stackoverflow.com/questions/1456930/how-do-i-read-all-classes-from-a-java-package-in-the-classpath - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - URL packageURL; - ArrayList names = new ArrayList(); - - if (packageName.contains("/")) { - // load as a file - packageURL = classLoader.getResource(packageName); - - // todo - if there is an error, step backwards to find the first avaliable package - if (packageURL == null && packageName.contains("/")) { - // added - check to see if maybe trying to load a file? - final int i = packageName.lastIndexOf('/'); - packageName = packageName.substring(0, i) + "." + packageName.substring(i + 1); - packageURL = classLoader.getResource(packageName); - } - } else { - packageName = packageName.replace(".", "/"); - packageURL = classLoader.getResource(packageName); - - if (sourceJar == null && packageURL == null) { - throw new IOException("Cannot open resource '" + packageName + "'"); - } - - } - - if (sourceJar == null && packageURL == null) { - throw new IOException("Cannot open resource '" + packageName + "'"); - //} else if (packageURL.getProtocol().equals("file") || ) { - // cannot do this.. - } else if (sourceJar != null || packageURL.getProtocol().equals("jar")) { - // this can also be used to load jar from resources - String jarFileName; - JarFile jf; - Enumeration jarEntries; - String entryName; - - // build jar file name, then loop through zipped entries - jarFileName = sourceJar != null ? sourceJar.getAbsolutePath() : URLDecoder.decode(packageURL.getFile(), "UTF-8"); - // changed - support for resource jar files, too - if (jarFileName.startsWith("file:/")) { - jarFileName = jarFileName.substring(system_os.contains("win") ? 5 : 4); - } - if (jarFileName.startsWith("/") && system_os.contains("win")) { - jarFileName = jarFileName.substring(1); - } - if (jarFileName.contains("!")) { - jarFileName = jarFileName.substring(0, jarFileName.indexOf("!")); - } - - jf = new JarFile(jarFileName); - jarEntries = jf.entries(); - // in case of multiple sub-classes, keep track of what classes have been searched - ArrayList loaded = new ArrayList(); - while (jarEntries.hasMoreElements()) { - entryName = jarEntries.nextElement().getName(); - if (entryName.startsWith(packageName) && entryName.length() > packageName.length() && entryName.toLowerCase().endsWith(".class")) { - if (entryName.contains(".")) { - entryName = entryName.substring(packageName.length() + 1, entryName.lastIndexOf('.')); - } - // iteration test - if (!entryName.contains("/") || (iterate == ITERATION.PACKAGE || iterate == ITERATION.FULL)) { - - if (entryName.contains("$")) { // added - sub-package test - // added - iteration - if (iterate == ITERATION.CLASS || iterate == ITERATION.FULL) { - entryName = entryName.substring(0, entryName.indexOf('$')).replace('/', '.'); - if (!loaded.contains(entryName)) { - loaded.add(entryName); - try { - Class c = Class.forName(packageName.replace('/', '.') + "." + entryName); - for (Class c2 : c.getDeclaredClasses()) { - names.add(entryName + "." + c2.getSimpleName()); - } - } catch (Throwable t) { - } - } - } - } else { - names.add(entryName.replace('/', '.')); - } - } - } - } - } else { - // hits here if running in IDE - - // loop through files in classpath - URI uri = new URI(packageURL.toString()); - File folder = new File(uri.getPath()); - // won't work with path which contains blank (%20) - // File folder = new File(packageURL.getFile()); - File[] contenuti = folder.listFiles(); - // in case of multiple sub-classes, keep track of what classes have been searched - ArrayList loaded = new ArrayList(); - String entryName; - for (File actual : contenuti) { - entryName = actual.getName(); - if (entryName.contains(".")) { // added - folder check - entryName = entryName.substring(0, entryName.lastIndexOf('.')); - if (entryName.contains("$")) { // added - sub-package test - // added - iteration - if (iterate == ITERATION.CLASS || iterate == ITERATION.FULL) { - entryName = entryName.substring(0, entryName.indexOf('$')); - if (!loaded.contains(entryName)) { - loaded.add(entryName); - Class c = Class.forName(packageName.replace('/', '.') + "." + entryName); - for (Class c2 : c.getDeclaredClasses()) { - names.add(entryName + "." + c2.getSimpleName()); - } - } - } - } else { - names.add(entryName); - } - } else if (iterate == ITERATION.PACKAGE || iterate == ITERATION.FULL) { - // added - iteration - for (String sub : getClassNamesFromPackage(packageName + "/" + entryName, iterate)) { - names.add(entryName + "." + sub); - } - } - } - } - return names; - } -} +package com.songoda.core.utils; + +import java.io.File; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLDecoder; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.security.CodeSource; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class ReflectionUtils { + + public final static double JAVA_VERSION = getVersion(); + private static String system_os = System.getProperty("os.name").toLowerCase(); + + private static double getVersion() { + String version = System.getProperty("java.version"); + int i = version.indexOf('.'); + if (i != -1 && (i = version.indexOf('.', i + 1)) != -1) { + return Double.parseDouble(version.substring(0, i)); + } + return Double.NaN; + } + + public static File getJarFile(Class jarClass) { + return new File(jarClass.getProtectionDomain().getCodeSource().getLocation().getPath(). + replace("%20", " ").replace("%25", "%")); + } + + public static void setPrivateField(Class c, Object handle, String fieldName, Object value) throws Exception { + Field f = c.getDeclaredField(fieldName); + f.setAccessible(true); + f.set(handle, value); + } + + public static Object getPrivateField(Class c, Object handle, String fieldName) throws Exception { + Field field = c.getDeclaredField(fieldName); + field.setAccessible(true); + return field.get(handle); + } + + public static Object invokePrivateMethod(Class c, String methodName, Object handle, Class[] types, Object[] parameters) throws Exception { + Method m = c.getDeclaredMethod(methodName, types); + m.setAccessible(true); + return m.invoke(handle, parameters); + } + + // does not work in JRE 8+ + private static Method j7getStackTraceElementMethod; + private static Method j7getStackTraceDepthMethod; + + // does not work in JRE != 8 + private static Method j8getJavaLangAccess; + private static Method j8getStackTraceElementMethod; + + static { + try { + j7getStackTraceElementMethod = Throwable.class.getDeclaredMethod("getStackTraceElement", int.class); + j7getStackTraceElementMethod.setAccessible(true); + j7getStackTraceDepthMethod = Throwable.class.getDeclaredMethod("getStackTraceDepth"); + j7getStackTraceDepthMethod.setAccessible(true); + } catch (Exception ex) { + j7getStackTraceElementMethod = j7getStackTraceDepthMethod = null; + } + try { + j8getJavaLangAccess = Class.forName("sun.misc.SharedSecrets").getDeclaredMethod("getStackTraceElement"); + j8getJavaLangAccess.setAccessible(true); + j8getStackTraceElementMethod = Class.forName("sun.misc.JavaLangAccess").getDeclaredMethod("getStackTraceDepth", Throwable.class, int.class); + j8getStackTraceElementMethod.setAccessible(true); + } catch (Exception ex) { + j8getJavaLangAccess = j8getStackTraceElementMethod = null; + } + } + + /** + * If you only need one stack trace element this is faster than + * Throwable.getStackTrace()[element], it doesn't generate the full stack + * trace. + */ + public static StackTraceElement getStackTraceElement(int index) { + try { + Throwable dummy = new Throwable(); + + if (j8getStackTraceElementMethod != null) { + return (StackTraceElement) j8getStackTraceElementMethod.invoke(j8getJavaLangAccess.invoke(null), dummy, index); +// } else if (JAVA_VERSION >= 9) { +// return StackWalker.getInstance(Collections.emptySet(), index + 1) +// .walk(s -> s.skip(index).findFirst()) +// .orElse(null); + } else if (j7getStackTraceElementMethod == null) { + // better than nothing, right? :/ + return (new Throwable()).getStackTrace()[index]; + } else { + if (index < (Integer) j7getStackTraceDepthMethod.invoke(dummy)) { + return (StackTraceElement) j7getStackTraceElementMethod.invoke(new Throwable(), index); + } else { + return null; + } + } + } catch (Throwable t) { + } + return null; + } + + public static Map, T> getClassesInClassPackageByAnnotation(Class clazz, Class annotation) throws IOException { + final Map, T> foundClasses = new HashMap<>(); + for (Class c : getAllClassesInClassPackage(clazz, false)) { + T t = c.getAnnotation(annotation); + if (t != null) { + foundClasses.put(c, t); + } + } + return foundClasses; + } + + public static List> getAllClassesInClassPackage(Class clazz, boolean recursive) throws IOException { + final List> packageClasses = new ArrayList<>(); + + final String clazzPackageName = clazz.getPackage().getName(); + URL dot = clazz.getResource("."); + if (dot == null) { + // jar file + String packagePath = clazzPackageName.replace('.', '/'); + CodeSource src = clazz.getProtectionDomain().getCodeSource(); + if (src != null) { + URL jar = src.getLocation(); + ZipInputStream zip = new ZipInputStream(jar.openStream()); + ZipEntry e; + while ((e = zip.getNextEntry()) != null) { + String name = e.getName(); + if (!name.endsWith("/") && name.startsWith(packagePath + "/")) { + if (recursive || name.indexOf('/', packagePath.length() + 1) == -1) { + try { + Class loadedClazz = Class.forName(name.substring(0, name.lastIndexOf('.')).replace('/', '.')); + packageClasses.add(loadedClazz); + } catch (ClassNotFoundException e1) { + System.err.println("class not found: " + e1.getMessage()); + } + } + } + } + } + } else { + String clazzPath = clazz.getResource(".").getPath(); + if (clazzPath.startsWith("/") && system_os.contains("win")) { + clazzPath = clazzPath.substring(1); + } + Path packagePath = Paths.get(clazzPath); + + Files.walkFileTree(packagePath, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + String filename = file.getName(file.getNameCount() - 1).toString(); + + if (filename.endsWith(".class")) { + String className = filename.replace(".class", ""); + + try { + Class loadedClazz = Class.forName( + clazzPackageName + "." + className); + + packageClasses.add(loadedClazz); + } catch (ClassNotFoundException e) { + System.err.println("class not found: " + e.getMessage()); + } + } + return super.visitFile(file, attrs); + } + }); + } + + return packageClasses; + } + + public static enum ITERATION { + + NONE, CLASS, PACKAGE, FULL + } + + public static List getClassNamesFromPackage(Class classInPackage) throws IOException, URISyntaxException, ClassNotFoundException { + String classPath = classInPackage.getName(); + int packageDelim = classPath.lastIndexOf('.'); + return getClassNamesFromPackage(getJarFile(classInPackage), classPath.substring(0, packageDelim), ITERATION.NONE); + } + + public static List getClassNamesFromPackage(String packageName) throws IOException, URISyntaxException, ClassNotFoundException { + return getClassNamesFromPackage(packageName, ITERATION.NONE); + } + + public static List getClassNamesFromPackage(String packageName, ITERATION iterate) throws IOException, URISyntaxException, ClassNotFoundException { + return getClassNamesFromPackage(null, packageName, iterate); + } + + public static List getClassNamesFromPackage(File sourceJar, String packageName, ITERATION iterate) throws IOException, URISyntaxException, ClassNotFoundException { + // http://stackoverflow.com/questions/1456930/how-do-i-read-all-classes-from-a-java-package-in-the-classpath + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + URL packageURL; + ArrayList names = new ArrayList(); + + if (packageName.contains("/")) { + // load as a file + packageURL = classLoader.getResource(packageName); + + // todo - if there is an error, step backwards to find the first avaliable package + if (packageURL == null && packageName.contains("/")) { + // added - check to see if maybe trying to load a file? + final int i = packageName.lastIndexOf('/'); + packageName = packageName.substring(0, i) + "." + packageName.substring(i + 1); + packageURL = classLoader.getResource(packageName); + } + } else { + packageName = packageName.replace(".", "/"); + packageURL = classLoader.getResource(packageName); + + if (sourceJar == null && packageURL == null) { + throw new IOException("Cannot open resource '" + packageName + "'"); + } + } + + if (sourceJar == null && packageURL == null) { + throw new IOException("Cannot open resource '" + packageName + "'"); + //} else if (packageURL.getProtocol().equals("file") || ) { + // cannot do this.. + } else if (sourceJar != null || packageURL.getProtocol().equals("jar")) { + // this can also be used to load jar from resources + String jarFileName; + JarFile jf; + Enumeration jarEntries; + String entryName; + + // build jar file name, then loop through zipped entries + jarFileName = sourceJar != null ? sourceJar.getAbsolutePath() : URLDecoder.decode(packageURL.getFile(), "UTF-8"); + // changed - support for resource jar files, too + if (jarFileName.startsWith("file:/")) { + jarFileName = jarFileName.substring(system_os.contains("win") ? 5 : 4); + } + if (jarFileName.startsWith("/") && system_os.contains("win")) { + jarFileName = jarFileName.substring(1); + } + if (jarFileName.contains("!")) { + jarFileName = jarFileName.substring(0, jarFileName.indexOf("!")); + } + + jf = new JarFile(jarFileName); + jarEntries = jf.entries(); + // in case of multiple sub-classes, keep track of what classes have been searched + ArrayList loaded = new ArrayList(); + while (jarEntries.hasMoreElements()) { + entryName = jarEntries.nextElement().getName(); + if (entryName.startsWith(packageName) && entryName.length() > packageName.length() && entryName.toLowerCase().endsWith(".class")) { + if (entryName.contains(".")) { + entryName = entryName.substring(packageName.length() + 1, entryName.lastIndexOf('.')); + } + // iteration test + if (!entryName.contains("/") || (iterate == ITERATION.PACKAGE || iterate == ITERATION.FULL)) { + + if (entryName.contains("$")) { // added - sub-package test + // added - iteration + if (iterate == ITERATION.CLASS || iterate == ITERATION.FULL) { + entryName = entryName.substring(0, entryName.indexOf('$')).replace('/', '.'); + if (!loaded.contains(entryName)) { + loaded.add(entryName); + try { + Class c = Class.forName(packageName.replace('/', '.') + "." + entryName); + for (Class c2 : c.getDeclaredClasses()) { + names.add(entryName + "." + c2.getSimpleName()); + } + } catch (Throwable t) { + } + } + } + } else { + names.add(entryName.replace('/', '.')); + } + } + } + } + } else { + // hits here if running in IDE + + // loop through files in classpath + URI uri = new URI(packageURL.toString()); + File folder = new File(uri.getPath()); + // won't work with path which contains blank (%20) + // File folder = new File(packageURL.getFile()); + File[] contenuti = folder.listFiles(); + // in case of multiple sub-classes, keep track of what classes have been searched + ArrayList loaded = new ArrayList(); + String entryName; + for (File actual : contenuti) { + entryName = actual.getName(); + if (entryName.contains(".")) { // added - folder check + entryName = entryName.substring(0, entryName.lastIndexOf('.')); + if (entryName.contains("$")) { // added - sub-package test + // added - iteration + if (iterate == ITERATION.CLASS || iterate == ITERATION.FULL) { + entryName = entryName.substring(0, entryName.indexOf('$')); + if (!loaded.contains(entryName)) { + loaded.add(entryName); + Class c = Class.forName(packageName.replace('/', '.') + "." + entryName); + for (Class c2 : c.getDeclaredClasses()) { + names.add(entryName + "." + c2.getSimpleName()); + } + } + } + } else { + names.add(entryName); + } + } else if (iterate == ITERATION.PACKAGE || iterate == ITERATION.FULL) { + // added - iteration + for (String sub : getClassNamesFromPackage(packageName + "/" + entryName, iterate)) { + names.add(entryName + "." + sub); + } + } + } + } + return names; + } +} diff --git a/Core/src/main/java/com/songoda/core/utils/RotationUtils.java b/Core/src/main/java/com/songoda/core/utils/RotationUtils.java index 5db73491..33c80401 100644 --- a/Core/src/main/java/com/songoda/core/utils/RotationUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/RotationUtils.java @@ -1,40 +1,39 @@ -package com.songoda.core.utils; - -import org.bukkit.block.BlockFace; - -public class RotationUtils { - - public static float faceToYaw(BlockFace face) { - switch (face) { - case NORTH: - return 180F; - case SOUTH: - return 0F; - case EAST: - return -90F; - case WEST: - return 90F; - } - return 0F; - } - - public static BlockFace yawToFace(float face) { - switch (Math.round((face + 360) / 90) * 90) { - case 0: - case 360: - return BlockFace.SOUTH; - case 180: - case 540: - return BlockFace.NORTH; - case 270: - case 630: - return BlockFace.EAST; - case 90: - case 450: - return BlockFace.WEST; - } - // idk - return BlockFace.SOUTH; - } - -} +package com.songoda.core.utils; + +import org.bukkit.block.BlockFace; + +public class RotationUtils { + + public static float faceToYaw(BlockFace face) { + switch (face) { + case NORTH: + return 180F; + case SOUTH: + return 0F; + case EAST: + return -90F; + case WEST: + return 90F; + } + return 0F; + } + + public static BlockFace yawToFace(float face) { + switch (Math.round((face + 360) / 90) * 90) { + case 0: + case 360: + return BlockFace.SOUTH; + case 180: + case 540: + return BlockFace.NORTH; + case 270: + case 630: + return BlockFace.EAST; + case 90: + case 450: + return BlockFace.WEST; + } + // idk + return BlockFace.SOUTH; + } +} diff --git a/Core/src/main/java/com/songoda/core/utils/TextUtils.java b/Core/src/main/java/com/songoda/core/utils/TextUtils.java index 71252554..ffabc10c 100644 --- a/Core/src/main/java/com/songoda/core/utils/TextUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/TextUtils.java @@ -88,6 +88,7 @@ public class TextUtils { * Note: Do not use semi-colons in this string, or they will be lost when decoding! * * @param s string to convert + * * @return encoded string */ public static String convertToInvisibleLoreString(String s) { @@ -105,6 +106,7 @@ public class TextUtils { * Note: Do not use semi-colons in this string, or they will be lost when decoding! * * @param s string to convert + * * @return encoded string */ public static String convertToInvisibleString(String s) { @@ -119,6 +121,7 @@ public class TextUtils { * Removes color markers used to encode strings as invisible text * * @param s encoded string + * * @return string with color markers removed */ public static String convertFromInvisibleString(String s) { @@ -202,4 +205,4 @@ public class TextUtils { return decoder.decode(data, CharBuffer.allocate(data.capacity()), true).isUnderflow(); } -} \ No newline at end of file +} diff --git a/Core/src/main/java/com/songoda/core/utils/TimeUtils.java b/Core/src/main/java/com/songoda/core/utils/TimeUtils.java index 22e8ae84..f270e452 100644 --- a/Core/src/main/java/com/songoda/core/utils/TimeUtils.java +++ b/Core/src/main/java/com/songoda/core/utils/TimeUtils.java @@ -26,7 +26,6 @@ public class TimeUtils { return sb.toString().trim(); } - public static long parseTime(String input) { long result = 0; StringBuilder number = new StringBuilder(); diff --git a/Core/src/main/java/com/songoda/core/world/SSpawner.java b/Core/src/main/java/com/songoda/core/world/SSpawner.java index b4f0bd6a..2f892009 100644 --- a/Core/src/main/java/com/songoda/core/world/SSpawner.java +++ b/Core/src/main/java/com/songoda/core/world/SSpawner.java @@ -4,7 +4,6 @@ import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.hooks.EntityStackerManager; import com.songoda.core.nms.NmsManager; import com.songoda.core.nms.world.SpawnedEntity; -import com.songoda.core.nms.world.WorldCore; import com.songoda.core.utils.EntityUtils; import org.bukkit.Location; import org.bukkit.block.CreatureSpawner; @@ -29,15 +28,13 @@ public class SSpawner { this(spawner.getLocation()); } - public int spawn(int amountToSpawn, EntityType... types) { return spawn(amountToSpawn, "EXPLOSION_NORMAL", null, null, types); } - /** * Spawn the spawner. - * + *

* If you want support for stackers you will need to load them * on your plugins enable. * diff --git a/Core/src/main/java/com/songoda/core/world/SWorldBorder.java b/Core/src/main/java/com/songoda/core/world/SWorldBorder.java index b0bd2280..c4d3eebf 100644 --- a/Core/src/main/java/com/songoda/core/world/SWorldBorder.java +++ b/Core/src/main/java/com/songoda/core/world/SWorldBorder.java @@ -3,7 +3,6 @@ package com.songoda.core.world; import com.songoda.core.compatibility.ClassMapping; import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.utils.NMSUtils; -import net.minecraft.world.level.border.WorldBorder; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -98,6 +97,5 @@ public class SWorldBorder { public enum Color { Blue, Green, Red - } } diff --git a/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCompound.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCompound.java index 269dfc2c..90231ae4 100644 --- a/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCompound.java +++ b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCompound.java @@ -60,5 +60,4 @@ public interface NBTCompound { void deSerialize(byte[] serialized); void addExtras(); - } diff --git a/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCore.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCore.java index 87ef0bb3..465d05b8 100644 --- a/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCore.java +++ b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTCore.java @@ -12,5 +12,4 @@ public interface NBTCore { NBTEntity of(Entity entity); NBTEntity newEntity(); - } diff --git a/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTEntity.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTEntity.java index 88a032e9..fdec3a41 100644 --- a/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTEntity.java +++ b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTEntity.java @@ -8,5 +8,4 @@ public interface NBTEntity extends NBTCompound { Entity spawn(Location location); Entity reSpawn(Location location); - } diff --git a/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTItem.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTItem.java index 9df8771b..f45d8edb 100644 --- a/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTItem.java +++ b/NMS/NMS-API/src/main/java/com/songoda/core/nms/nbt/NBTItem.java @@ -5,5 +5,4 @@ import org.bukkit.inventory.ItemStack; public interface NBTItem extends NBTCompound { ItemStack finish(); - } diff --git a/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SItemStack.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SItemStack.java index 380d478d..35cda3b1 100644 --- a/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SItemStack.java +++ b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SItemStack.java @@ -9,5 +9,4 @@ public interface SItemStack { Random random = new Random(); void breakItem(Player player, int amount); - } diff --git a/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SpawnedEntity.java b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SpawnedEntity.java index 2b8288f4..ad6996ed 100644 --- a/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SpawnedEntity.java +++ b/NMS/NMS-API/src/main/java/com/songoda/core/nms/world/SpawnedEntity.java @@ -5,5 +5,4 @@ import org.bukkit.entity.LivingEntity; public interface SpawnedEntity { boolean onSpawn(LivingEntity entity); - } diff --git a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java index 07da98de..d1379dfe 100644 --- a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java index ee278645..55746a3d 100644 --- a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/anvil/AnvilView.java @@ -200,5 +200,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java index c167d743..66444a53 100644 --- a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java index 483bb80d..cf3178ad 100644 --- a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java +++ b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SItemStackImpl.java @@ -30,7 +30,7 @@ public class SItemStackImpl implements SItemStack { vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); - entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[]{Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); + entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[] {Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); } } } diff --git a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java index 40bd0222..c1bbb1c5 100644 --- a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java +++ b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/SSpawnerImpl.java @@ -67,7 +67,7 @@ public class SSpawnerImpl implements SSpawner { if (!canSpawn(entityInsentient, spot, canSpawnOn)) continue; - entityInsentient.prepare(damageScaler,null); + entityInsentient.prepare(damageScaler, null); LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); diff --git a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java index 2630a68a..1304d868 100644 --- a/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_10_R1/src/main/java/com/songoda/core/nms/v1_10_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_10_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_10_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_10_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_10_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java index 25ff6171..3c76bdf0 100644 --- a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java index e412f97b..41793bcf 100644 --- a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/anvil/AnvilView.java @@ -200,5 +200,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java index af2d2bce..0432c755 100644 --- a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java index 2c88aa51..75acfd73 100644 --- a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java +++ b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SItemStackImpl.java @@ -30,7 +30,7 @@ public class SItemStackImpl implements SItemStack { vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); - entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[]{Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); + entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[] {Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); } } } diff --git a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java index 7a376547..566058b7 100644 --- a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java +++ b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/SSpawnerImpl.java @@ -69,7 +69,7 @@ public class SSpawnerImpl implements SSpawner { if (!canSpawn(entityInsentient, spot, canSpawnOn)) continue; - entityInsentient.prepare(damageScaler,null); + entityInsentient.prepare(damageScaler, null); LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); diff --git a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java index 7d45f652..b5f33e75 100644 --- a/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_11_R1/src/main/java/com/songoda/core/nms/v1_11_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_11_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_11_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_11_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_11_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java index 34efd7b5..2ab4b570 100644 --- a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java index 711174c2..20923a19 100644 --- a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/anvil/AnvilView.java @@ -182,5 +182,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java index c38e8727..213d07ca 100644 --- a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java +++ b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCompoundImpl.java @@ -206,5 +206,4 @@ public class NBTCompoundImpl implements NBTCompound { public String toString() { return compound.toString(); } - } diff --git a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java index 18b44729..ec6ac7fd 100644 --- a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java index f5f9d382..76f714b0 100644 --- a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java +++ b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SItemStackImpl.java @@ -30,7 +30,7 @@ public class SItemStackImpl implements SItemStack { vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); - entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[]{Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); + entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[] {Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); } } } diff --git a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java index 097655a2..666b897e 100644 --- a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java +++ b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/SSpawnerImpl.java @@ -69,7 +69,7 @@ public class SSpawnerImpl implements SSpawner { if (!canSpawn(entityInsentient, spot, canSpawnOn)) continue; - entityInsentient.prepare(damageScaler,null); + entityInsentient.prepare(damageScaler, null); LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); diff --git a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java index df653a91..baa8c509 100644 --- a/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_12_R1/src/main/java/com/songoda/core/nms/v1_12_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_12_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_12_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_12_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_12_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java index 7701fd14..f228650a 100644 --- a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java index 1938b056..51391e63 100644 --- a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/anvil/AnvilView.java @@ -183,5 +183,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java index 8b04bf28..9c689459 100644 --- a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java +++ b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCompoundImpl.java @@ -206,5 +206,4 @@ public class NBTCompoundImpl implements NBTCompound { public String toString() { return compound.toString(); } - } diff --git a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java index ccefa036..0e1729bf 100644 --- a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java index d5e78191..8b596578 100644 --- a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java +++ b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SItemStackImpl.java @@ -29,7 +29,7 @@ public class SItemStackImpl implements SItemStack { Vec3D vec3d1 = new Vec3D(((double) this.random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D); vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); - vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double)entityPlayer.getHeadHeight(), entityPlayer.locZ); + vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); entityPlayer.world.addParticle(new ParticleParamItem(Particles.C, CraftItemStack.asNMSCopy(item)), vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z); } } diff --git a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java index 1f8c96c4..957ceb98 100644 --- a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java +++ b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/SSpawnerImpl.java @@ -69,7 +69,7 @@ public class SSpawnerImpl implements SSpawner { if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) continue; - entityInsentient.prepare(damageScaler,null, null); + entityInsentient.prepare(damageScaler, null, null); LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); diff --git a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java index 027c9521..3ccf1900 100644 --- a/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_13_R1/src/main/java/com/songoda/core/nms/v1_13_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_13_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_13_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_13_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_13_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java index ab0a8dec..90991c72 100644 --- a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java +++ b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java index 30fc8925..7e4fa62f 100644 --- a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java +++ b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/anvil/AnvilView.java @@ -183,5 +183,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java index f2a449b1..cd7adc73 100644 --- a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java +++ b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCompoundImpl.java @@ -197,7 +197,7 @@ public class NBTCompoundImpl implements NBTCompound { } } - @Override + @Override public void addExtras() { // None } diff --git a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java index c78b4fc2..fa07f53d 100644 --- a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java index 87fe726a..17e3abc5 100644 --- a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java +++ b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SItemStackImpl.java @@ -29,7 +29,7 @@ public class SItemStackImpl implements SItemStack { Vec3D vec3d1 = new Vec3D(((double) this.random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D); vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); - vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double)entityPlayer.getHeadHeight(), entityPlayer.locZ); + vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); entityPlayer.world.addParticle(new ParticleParamItem(Particles.C, CraftItemStack.asNMSCopy(item)), vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z); } } diff --git a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java index bf172a9f..830f1402 100644 --- a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java +++ b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/SSpawnerImpl.java @@ -69,7 +69,7 @@ public class SSpawnerImpl implements SSpawner { if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) continue; - entityInsentient.prepare(damageScaler,null, null); + entityInsentient.prepare(damageScaler, null, null); LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); diff --git a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java index 6f4e89e9..3b39c887 100644 --- a/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_13_R2/src/main/java/com/songoda/core/nms/v1_13_R2/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_13_R2.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_13_R2.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_13_R2.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_13_R2.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java index b8454093..af14d1e7 100644 --- a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilCore.java @@ -19,5 +19,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { EntityPlayer p = ((CraftPlayer) player).getHandle(); return new AnvilView(p.nextContainerCounter(), p, holder); } - } diff --git a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java index 0b18a49f..573ee281 100644 --- a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/anvil/AnvilView.java @@ -2,7 +2,17 @@ package com.songoda.core.nms.v1_14_R1.anvil; import com.songoda.core.nms.anvil.CustomAnvil; import com.songoda.core.nms.anvil.methods.AnvilTextChange; -import net.minecraft.server.v1_14_R1.*; +import net.minecraft.server.v1_14_R1.BlockPosition; +import net.minecraft.server.v1_14_R1.ChatMessage; +import net.minecraft.server.v1_14_R1.Container; +import net.minecraft.server.v1_14_R1.ContainerAccess; +import net.minecraft.server.v1_14_R1.ContainerAnvil; +import net.minecraft.server.v1_14_R1.ContainerProperty; +import net.minecraft.server.v1_14_R1.Containers; +import net.minecraft.server.v1_14_R1.EntityHuman; +import net.minecraft.server.v1_14_R1.EntityPlayer; +import net.minecraft.server.v1_14_R1.IInventory; +import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView; import org.bukkit.inventory.Inventory; @@ -248,5 +258,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java index 8c123e1f..4d93334b 100644 --- a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java index 0310f3bf..22986684 100644 --- a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java +++ b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/SItemStackImpl.java @@ -29,7 +29,7 @@ public class SItemStackImpl implements SItemStack { Vec3D vec3d1 = new Vec3D(((double) this.random.nextFloat() - 0.5D) * 0.3D, d0, 0.6D); vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); - vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double)entityPlayer.getHeadHeight(), entityPlayer.locZ); + vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); entityPlayer.world.addParticle(new ParticleParamItem(Particles.ITEM, CraftItemStack.asNMSCopy(item)), vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z); } } diff --git a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java index b2ffa2a8..ffae55d7 100644 --- a/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_14_R1/src/main/java/com/songoda/core/nms/v1_14_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_14_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_14_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -19,8 +19,8 @@ import net.minecraft.server.v1_14_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_14_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java index ce6e942f..8ec5ce1f 100644 --- a/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilCore.java @@ -19,5 +19,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { EntityPlayer p = ((CraftPlayer) player).getHandle(); return new AnvilView(p.nextContainerCounter(), p, holder); } - } diff --git a/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java index c753453e..0977eefd 100644 --- a/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/anvil/AnvilView.java @@ -2,7 +2,16 @@ package com.songoda.core.nms.v1_15_R1.anvil; import com.songoda.core.nms.anvil.CustomAnvil; import com.songoda.core.nms.anvil.methods.AnvilTextChange; -import net.minecraft.server.v1_15_R1.*; +import net.minecraft.server.v1_15_R1.BlockPosition; +import net.minecraft.server.v1_15_R1.ChatMessage; +import net.minecraft.server.v1_15_R1.Container; +import net.minecraft.server.v1_15_R1.ContainerAccess; +import net.minecraft.server.v1_15_R1.ContainerAnvil; +import net.minecraft.server.v1_15_R1.Containers; +import net.minecraft.server.v1_15_R1.EntityHuman; +import net.minecraft.server.v1_15_R1.EntityPlayer; +import net.minecraft.server.v1_15_R1.IInventory; +import net.minecraft.server.v1_15_R1.PacketPlayOutOpenWindow; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView; import org.bukkit.inventory.Inventory; @@ -217,5 +226,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - -} \ No newline at end of file +} diff --git a/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java index 1b69a08c..7a338dce 100644 --- a/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java index fa37a0ae..ee51a767 100644 --- a/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_15_R1/src/main/java/com/songoda/core/nms/v1_15_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_15_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_15_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -19,8 +19,8 @@ import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java index b23efc3e..1e35a315 100644 --- a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilCore.java @@ -19,5 +19,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { EntityPlayer p = ((CraftPlayer) player).getHandle(); return new AnvilView(p.nextContainerCounter(), p, holder); } - } diff --git a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java index adf5c182..15e76699 100644 --- a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/anvil/AnvilView.java @@ -2,7 +2,17 @@ package com.songoda.core.nms.v1_16_R1.anvil; import com.songoda.core.nms.anvil.CustomAnvil; import com.songoda.core.nms.anvil.methods.AnvilTextChange; -import net.minecraft.server.v1_16_R1.*; +import net.minecraft.server.v1_16_R1.BlockPosition; +import net.minecraft.server.v1_16_R1.ChatMessage; +import net.minecraft.server.v1_16_R1.Container; +import net.minecraft.server.v1_16_R1.ContainerAccess; +import net.minecraft.server.v1_16_R1.ContainerAnvil; +import net.minecraft.server.v1_16_R1.ContainerAnvilAbstract; +import net.minecraft.server.v1_16_R1.Containers; +import net.minecraft.server.v1_16_R1.EntityHuman; +import net.minecraft.server.v1_16_R1.EntityPlayer; +import net.minecraft.server.v1_16_R1.IInventory; +import net.minecraft.server.v1_16_R1.PacketPlayOutOpenWindow; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView; import org.bukkit.inventory.Inventory; @@ -217,5 +227,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - -} \ No newline at end of file +} diff --git a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java index 24aaa35c..0c647586 100644 --- a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java index 573f20b1..04218147 100644 --- a/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_16_R1/src/main/java/com/songoda/core/nms/v1_16_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_16_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_16_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -19,8 +19,8 @@ import net.minecraft.server.v1_16_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_16_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java index 82b5b27a..70410849 100644 --- a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java +++ b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilCore.java @@ -19,5 +19,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { EntityPlayer p = ((CraftPlayer) player).getHandle(); return new AnvilView(p.nextContainerCounter(), p, holder); } - } diff --git a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java index 2e173751..ada5f32d 100644 --- a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java +++ b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/anvil/AnvilView.java @@ -2,7 +2,17 @@ package com.songoda.core.nms.v1_16_R2.anvil; import com.songoda.core.nms.anvil.CustomAnvil; import com.songoda.core.nms.anvil.methods.AnvilTextChange; -import net.minecraft.server.v1_16_R2.*; +import net.minecraft.server.v1_16_R2.BlockPosition; +import net.minecraft.server.v1_16_R2.ChatMessage; +import net.minecraft.server.v1_16_R2.Container; +import net.minecraft.server.v1_16_R2.ContainerAccess; +import net.minecraft.server.v1_16_R2.ContainerAnvil; +import net.minecraft.server.v1_16_R2.ContainerAnvilAbstract; +import net.minecraft.server.v1_16_R2.Containers; +import net.minecraft.server.v1_16_R2.EntityHuman; +import net.minecraft.server.v1_16_R2.EntityPlayer; +import net.minecraft.server.v1_16_R2.IInventory; +import net.minecraft.server.v1_16_R2.PacketPlayOutOpenWindow; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryView; import org.bukkit.inventory.Inventory; @@ -217,5 +227,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - -} \ No newline at end of file +} diff --git a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java index fe48d942..e291da4f 100644 --- a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java index e35abdbb..1c9c474e 100644 --- a/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_16_R2/src/main/java/com/songoda/core/nms/v1_16_R2/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_16_R2.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_16_R2.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -19,8 +19,8 @@ import net.minecraft.server.v1_16_R2.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_16_R2.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java index 53ea5814..0bf4afa2 100644 --- a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java +++ b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilCore.java @@ -19,5 +19,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { EntityPlayer p = ((CraftPlayer) player).getHandle(); return new AnvilView(p.nextContainerCounter(), p, holder); } - } diff --git a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java index b60763ae..2334edb7 100644 --- a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java +++ b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/anvil/AnvilView.java @@ -2,7 +2,17 @@ package com.songoda.core.nms.v1_16_R3.anvil; import com.songoda.core.nms.anvil.CustomAnvil; import com.songoda.core.nms.anvil.methods.AnvilTextChange; -import net.minecraft.server.v1_16_R3.*; +import net.minecraft.server.v1_16_R3.BlockPosition; +import net.minecraft.server.v1_16_R3.ChatMessage; +import net.minecraft.server.v1_16_R3.Container; +import net.minecraft.server.v1_16_R3.ContainerAccess; +import net.minecraft.server.v1_16_R3.ContainerAnvil; +import net.minecraft.server.v1_16_R3.ContainerAnvilAbstract; +import net.minecraft.server.v1_16_R3.Containers; +import net.minecraft.server.v1_16_R3.EntityHuman; +import net.minecraft.server.v1_16_R3.EntityPlayer; +import net.minecraft.server.v1_16_R3.IInventory; +import net.minecraft.server.v1_16_R3.PacketPlayOutOpenWindow; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView; import org.bukkit.inventory.Inventory; @@ -217,5 +227,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - -} \ No newline at end of file +} diff --git a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java index fcf160a9..cc9c924b 100644 --- a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java index 26089a9d..2915d6fa 100644 --- a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java +++ b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/nbt/NBTItemImpl.java @@ -4,12 +4,6 @@ import com.songoda.core.nms.nbt.NBTItem; import net.minecraft.server.v1_16_R3.NBTTagCompound; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.io.BukkitObjectInputStream; -import org.bukkit.util.io.BukkitObjectOutputStream; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; public class NBTItemImpl extends NBTCompoundImpl implements NBTItem { diff --git a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java index 5b254bb7..2fd2fa98 100644 --- a/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_16_R3/src/main/java/com/songoda/core/nms/v1_16_R3/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_16_R3.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_16_R3.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -19,8 +19,8 @@ import net.minecraft.server.v1_16_R3.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_16_R3.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java index 1456d7af..50c030f7 100644 --- a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilCore.java @@ -19,5 +19,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { EntityPlayer p = ((CraftPlayer) player).getHandle(); return new AnvilView(p.nextContainerCounter(), p, holder); } - } diff --git a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java index 3ef792d7..c19e88e9 100644 --- a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/anvil/AnvilView.java @@ -204,5 +204,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { entity.initMenu(entity.bV); //entity.bV.addSlotListener(entity.cX); } - -} \ No newline at end of file +} diff --git a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java index 367b0fc8..4ea5c8b0 100644 --- a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java index 2191eff5..39e75ebe 100644 --- a/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java +++ b/NMS/NMS-v1_17_R1/src/main/java/com/songoda/core/nms/v1_17_R1/world/SWorldImpl.java @@ -46,7 +46,6 @@ public class SWorldImpl implements SWorld { if (bukkitEntity instanceof LivingEntity && bukkitEntity.isValid()) { list.add((LivingEntity) bukkitEntity); } - }); } catch (IllegalAccessException e) { e.printStackTrace(); diff --git a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java index a5b00d86..22dae5e5 100644 --- a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java index 7b537b3e..51609c93 100644 --- a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/anvil/AnvilView.java @@ -198,5 +198,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java index 165d2d3a..ba94a666 100644 --- a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java +++ b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCompoundImpl.java @@ -207,5 +207,4 @@ public class NBTCompoundImpl implements NBTCompound { public String toString() { return compound.toString(); } - } diff --git a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java index 572c8b2c..d6a8c58d 100644 --- a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java index 10fe1cf6..af58e3ea 100644 --- a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/nbt/NBTEntityImpl.java @@ -30,7 +30,6 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { } catch (NoSuchFieldException e) { e.printStackTrace(); } - } @Override diff --git a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java index c39e27d8..cd3b8640 100644 --- a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java +++ b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/SItemStackImpl.java @@ -30,7 +30,7 @@ public class SItemStackImpl implements SItemStack { vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); - entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c, new int[]{Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); + entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c, new int[] {Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); } } } diff --git a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java index 33364b37..3a7048d7 100644 --- a/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_8_R1/src/main/java/com/songoda/core/nms/v1_8_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_8_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_8_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_8_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_8_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java index e44d1f3f..8b9387ad 100644 --- a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java +++ b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java index ca69a828..dd55b1f8 100644 --- a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java +++ b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/anvil/AnvilView.java @@ -198,5 +198,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java index 644c708c..db563f3d 100644 --- a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java index 4d411052..1d17a0f7 100644 --- a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/nbt/NBTEntityImpl.java @@ -30,7 +30,6 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { } catch (NoSuchFieldException e) { e.printStackTrace(); } - } @Override diff --git a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java index 15d72e94..7e87d059 100644 --- a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java +++ b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/SItemStackImpl.java @@ -30,7 +30,7 @@ public class SItemStackImpl implements SItemStack { vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); - entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c, new int[]{Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); + entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c, new int[] {Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); } } } diff --git a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java index aabaa81f..6e4db821 100644 --- a/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_8_R2/src/main/java/com/songoda/core/nms/v1_8_R2/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_8_R2.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_8_R2.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,10 +17,8 @@ import net.minecraft.server.v1_8_R2.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_8_R2.CraftChunk; - -import java.lang.reflect.Method; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java index 7e3f64a3..47b8399b 100644 --- a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java +++ b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java index f748a8a3..2ff86a6b 100644 --- a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java +++ b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/anvil/AnvilView.java @@ -198,5 +198,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java index d3ab7aae..d9bbb3f9 100644 --- a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java index ab324c78..a087aefb 100644 --- a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java +++ b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/nbt/NBTEntityImpl.java @@ -31,7 +31,6 @@ public class NBTEntityImpl extends NBTCompoundImpl implements NBTEntity { } catch (NoSuchFieldException e) { e.printStackTrace(); } - } @Override diff --git a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java index c5a0d9e9..66a8e299 100644 --- a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java +++ b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/SItemStackImpl.java @@ -30,7 +30,7 @@ public class SItemStackImpl implements SItemStack { vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); - entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c, new int[]{Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); + entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.a, vec3d1.b, vec3d1.c, vec3d.a, vec3d.b + 0.05D, vec3d.c, new int[] {Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); } } } diff --git a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java index fd5a3919..a3388af5 100644 --- a/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_8_R3/src/main/java/com/songoda/core/nms/v1_8_R3/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_8_R3.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_8_R3.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_8_R3.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java index a587a34e..b0b3e7c4 100644 --- a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java +++ b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java index ab34b843..6a11d64a 100644 --- a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java +++ b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/anvil/AnvilView.java @@ -200,5 +200,4 @@ public class AnvilView extends ContainerAnvil implements CustomAnvil { // Add the slot listener entity.activeContainer.addSlotListener(entity); } - } diff --git a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java index 17f85624..01dc2338 100644 --- a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java index c8ad8f56..097cc6d6 100644 --- a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java +++ b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SItemStackImpl.java @@ -30,7 +30,7 @@ public class SItemStackImpl implements SItemStack { vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); - entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[]{Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); + entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[] {Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); } } } diff --git a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java index 1df904d7..9752efe7 100644 --- a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java +++ b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/SSpawnerImpl.java @@ -67,7 +67,7 @@ public class SSpawnerImpl implements SSpawner { if (!canSpawn(entityInsentient, spot, canSpawnOn)) continue; - entityInsentient.prepare(damageScaler,null); + entityInsentient.prepare(damageScaler, null); LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); diff --git a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java index 74d6c9b2..bacf9a37 100644 --- a/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_9_R1/src/main/java/com/songoda/core/nms/v1_9_R1/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_9_R1.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_9_R1.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_9_R1.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_9_R1.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override diff --git a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java index b7a2905b..76ed1882 100644 --- a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java +++ b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/anvil/AnvilCore.java @@ -16,5 +16,4 @@ public class AnvilCore implements com.songoda.core.nms.anvil.AnvilCore { public CustomAnvil createAnvil(Player player, InventoryHolder holder) { return new AnvilView(((CraftPlayer) player).getHandle(), holder); } - } diff --git a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java index 85a0e919..dcf38406 100644 --- a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java +++ b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/nbt/NBTCoreImpl.java @@ -33,5 +33,4 @@ public class NBTCoreImpl implements NBTCore { public NBTEntity newEntity() { return new NBTEntityImpl(new NBTTagCompound(), null); } - } diff --git a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java index e0f16efe..c08d8446 100644 --- a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java +++ b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SItemStackImpl.java @@ -30,7 +30,7 @@ public class SItemStackImpl implements SItemStack { vec3d1 = vec3d1.a(-entityPlayer.pitch * 0.017453292F); vec3d1 = vec3d1.b(-entityPlayer.yaw * 0.017453292F); vec3d1 = vec3d1.add(entityPlayer.locX, entityPlayer.locY + (double) entityPlayer.getHeadHeight(), entityPlayer.locZ); - entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[]{Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); + entityPlayer.world.addParticle(EnumParticle.ITEM_CRACK, vec3d1.x, vec3d1.y, vec3d1.z, vec3d.x, vec3d.y + 0.05D, vec3d.z, new int[] {Item.getId(CraftItemStack.asNMSCopy(item).getItem())}); } } } diff --git a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java index 62e130ec..fab9234b 100644 --- a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java +++ b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/SSpawnerImpl.java @@ -67,7 +67,7 @@ public class SSpawnerImpl implements SSpawner { if (!canSpawn(entityInsentient, spot, canSpawnOn)) continue; - entityInsentient.prepare(damageScaler,null); + entityInsentient.prepare(damageScaler, null); LivingEntity craftEntity = (LivingEntity) entity.getBukkitEntity(); diff --git a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java index 00908f5d..e1645038 100644 --- a/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java +++ b/NMS/NMS-v1_9_R2/src/main/java/com/songoda/core/nms/v1_9_R2/world/WorldCoreImpl.java @@ -1,9 +1,9 @@ package com.songoda.core.nms.v1_9_R2.world; -import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.ReflectionUtils; import com.songoda.core.nms.v1_9_R2.world.spawner.BBaseSpawnerImpl; import com.songoda.core.nms.world.BBaseSpawner; +import com.songoda.core.nms.world.SItemStack; import com.songoda.core.nms.world.SSpawner; import com.songoda.core.nms.world.SWorld; import com.songoda.core.nms.world.WorldCore; @@ -17,8 +17,8 @@ import net.minecraft.server.v1_9_R2.WorldServer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.CreatureSpawner; -import org.bukkit.inventory.ItemStack; import org.bukkit.craftbukkit.v1_9_R2.CraftChunk; +import org.bukkit.inventory.ItemStack; public class WorldCoreImpl implements WorldCore { @Override From e1742385c51062c9f350d78e07eaf00d827b5af9 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 8 Jul 2021 15:47:15 +0200 Subject: [PATCH 6/8] Update GitHub-Actions --- .github/workflows/maven.yml | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a461e4da..40ea85f2 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -5,19 +5,39 @@ name: Build SongodaCore on: push: - branches: [ master ] + branches: [ master, development ] pull_request: types: [ opened, synchronize, reopened ] jobs: build: + name: Build runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 16 - uses: actions/setup-java@v1 + # Setup Java + - uses: actions/setup-java@v2 with: java-version: 16 + distribution: adopt + + # Checkout project files + - uses: actions/checkout@v2 + + # Caches + - name: 'Cache: Maven' + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-maven- + + # Build project - name: Build with Maven - run: mvn -B package --file pom.xml + run: 'mvn -B -Duser.name="GitHub Runner on $GITHUB_REPOSITORY (id=$GITHUB_RUN_ID)" clean package' + + # Upload build artifacts + - name: 'Upload Build Artifact: SongodaCore-*.jar' + uses: actions/upload-artifact@v2 + with: + name: EpicAnchors-artifacts + path: ./Core/target/SongodaCore-*.jar From 8eefbce68d2506d355ad2a9a950254c02ae5f786 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 8 Jul 2021 17:49:41 +0200 Subject: [PATCH 7/8] Change dependency `com.github.Zrips.Jobs` version from LATEST to v4.17.2 --- .github/workflows/maven.yml | 2 +- Core/pom.xml | 8 +------- pom.xml | 8 ++++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 40ea85f2..be433151 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -39,5 +39,5 @@ jobs: - name: 'Upload Build Artifact: SongodaCore-*.jar' uses: actions/upload-artifact@v2 with: - name: EpicAnchors-artifacts + name: SongodaCore-artifacts path: ./Core/target/SongodaCore-*.jar diff --git a/Core/pom.xml b/Core/pom.xml index a486e184..4e9e70ab 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -293,7 +293,7 @@ com.github.Zrips Jobs - LATEST + v4.17.2 provided @@ -360,12 +360,6 @@ 1.1 - - org.jetbrains - annotations - 13.0 - - org.yaml snakeyaml diff --git a/pom.xml b/pom.xml index aae6c9f9..51222819 100644 --- a/pom.xml +++ b/pom.xml @@ -86,13 +86,13 @@ - jitpack.io - https://jitpack.io/ + CodeMC + https://repo.codemc.org/repository/maven-public/ - CodeMC - https://repo.codemc.org/repository/maven-public/ + jitpack.io + https://jitpack.io/ From 60ceac5eb6573d0e8f5bf13037ccb45bf4968b80 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 8 Jul 2021 16:02:08 +0200 Subject: [PATCH 8/8] Version 2.5.8 --- Compatibility/pom.xml | 2 +- Core/pom.xml | 2 +- Core/src/main/java/com/songoda/core/SongodaCore.java | 2 +- NMS/NMS-API/pom.xml | 2 +- NMS/NMS-v1_10_R1/pom.xml | 2 +- NMS/NMS-v1_11_R1/pom.xml | 2 +- NMS/NMS-v1_12_R1/pom.xml | 2 +- NMS/NMS-v1_13_R1/pom.xml | 2 +- NMS/NMS-v1_13_R2/pom.xml | 2 +- NMS/NMS-v1_14_R1/pom.xml | 2 +- NMS/NMS-v1_15_R1/pom.xml | 2 +- NMS/NMS-v1_16_R1/pom.xml | 2 +- NMS/NMS-v1_16_R2/pom.xml | 2 +- NMS/NMS-v1_16_R3/pom.xml | 2 +- NMS/NMS-v1_17_R1/pom.xml | 2 +- NMS/NMS-v1_8_R1/pom.xml | 2 +- NMS/NMS-v1_8_R2/pom.xml | 2 +- NMS/NMS-v1_8_R3/pom.xml | 2 +- NMS/NMS-v1_9_R1/pom.xml | 2 +- NMS/NMS-v1_9_R2/pom.xml | 2 +- pom.xml | 5 ++++- 21 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Compatibility/pom.xml b/Compatibility/pom.xml index f0157783..b2d66096 100644 --- a/Compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../pom.xml diff --git a/Core/pom.xml b/Core/pom.xml index 4e9e70ab..76acd677 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../pom.xml diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index ab913230..e635ec8f 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -53,7 +53,7 @@ public class SongodaCore { /** * This has been added as of Rev 6 */ - private final static String coreVersion = "2.5.7"; + private final static String coreVersion = "2.5.8"; /** * This is specific to the website api diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index c6945aa0..68814803 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index 6dce3d93..16e37be9 100644 --- a/NMS/NMS-v1_10_R1/pom.xml +++ b/NMS/NMS-v1_10_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index 1376f61f..8154024b 100644 --- a/NMS/NMS-v1_11_R1/pom.xml +++ b/NMS/NMS-v1_11_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index 02f1f4a0..022be3cb 100644 --- a/NMS/NMS-v1_12_R1/pom.xml +++ b/NMS/NMS-v1_12_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index 988ad55c..a4ebee39 100644 --- a/NMS/NMS-v1_13_R1/pom.xml +++ b/NMS/NMS-v1_13_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index 01f13c86..a5490084 100644 --- a/NMS/NMS-v1_13_R2/pom.xml +++ b/NMS/NMS-v1_13_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 0759baed..c866bdb1 100644 --- a/NMS/NMS-v1_14_R1/pom.xml +++ b/NMS/NMS-v1_14_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index d80c95bb..8ff76281 100644 --- a/NMS/NMS-v1_15_R1/pom.xml +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index 6f533560..965858c8 100644 --- a/NMS/NMS-v1_16_R1/pom.xml +++ b/NMS/NMS-v1_16_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index 0b2603e0..88f68583 100644 --- a/NMS/NMS-v1_16_R2/pom.xml +++ b/NMS/NMS-v1_16_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index a81966cb..4e1f865e 100644 --- a/NMS/NMS-v1_16_R3/pom.xml +++ b/NMS/NMS-v1_16_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_17_R1/pom.xml b/NMS/NMS-v1_17_R1/pom.xml index d3b29046..3eb8b14b 100644 --- a/NMS/NMS-v1_17_R1/pom.xml +++ b/NMS/NMS-v1_17_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index 51dc12d0..6e159a14 100644 --- a/NMS/NMS-v1_8_R1/pom.xml +++ b/NMS/NMS-v1_8_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index 89430def..9f736ca7 100644 --- a/NMS/NMS-v1_8_R2/pom.xml +++ b/NMS/NMS-v1_8_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index c266e2ca..45b7a751 100644 --- a/NMS/NMS-v1_8_R3/pom.xml +++ b/NMS/NMS-v1_8_R3/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index 26ed3c80..879b40f1 100644 --- a/NMS/NMS-v1_9_R1/pom.xml +++ b/NMS/NMS-v1_9_R1/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index 0422c690..5c9651e2 100644 --- a/NMS/NMS-v1_9_R2/pom.xml +++ b/NMS/NMS-v1_9_R2/pom.xml @@ -7,7 +7,7 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 ../../pom.xml diff --git a/pom.xml b/pom.xml index 51222819..fbad8397 100644 --- a/pom.xml +++ b/pom.xml @@ -6,9 +6,12 @@ com.songoda SongodaCore-Modules - 2.5.7 + 2.5.8 pom + + + 1.8 8