From 43433e4f4313d08e9dea2a68014873635b80dab9 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Mon, 1 Jul 2024 02:29:06 +0800 Subject: [PATCH 01/14] Merge branch 'refs/heads/chore/update-to-1-20-5' into 1-20-5-support # Conflicts: # .github/workflows/auto-approve.yml # .github/workflows/auto-squash.yml # .github/workflows/pr-labels.yml # .github/workflows/pull-request.yml # .github/workflows/release-candidates.yml # pom.xml # src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java # src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java # src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java # src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java # src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/DamageableItem.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RadiationSymptom.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/SlimefunTabCompleter.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/VersionsCommand.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/debug/TestCase.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AutoSavingService.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/services/UpdaterService.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubActivityConnector.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesConnector.java # src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/CropGrowthAccelerator.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/TreeGrowthAccelerator.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/EnchantmentRune.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java # src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java # src/main/java/io/github/thebusybiscuit/slimefun4/storage/backend/legacy/LegacyStorage.java # src/main/java/io/github/thebusybiscuit/slimefun4/utils/FireworkUtils.java # src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ColoredFireworkStar.java # src/main/resources/config.yml # src/test/java/io/github/thebusybiscuit/slimefun4/api/events/TestTalismanActivateEvent.java # src/test/java/io/github/thebusybiscuit/slimefun4/implementation/items/TestDamageableItem.java # src/test/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/TestClimbingPick.java # src/test/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TestCoolerListener.java # src/test/java/io/github/thebusybiscuit/slimefun4/storage/backend/TestLegacyBackend.java # src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestMinecraftVersion.java --- .github/workflows/e2e-testing.yml | 2 +- .gitignore | 1 + CHANGELOG.md | 31 +++- pom.xml | 2 +- .../slimefun4/api/MinecraftVersion.java | 53 +++++- .../api/gps/TeleportationManager.java | 4 +- .../slimefun4/api/items/ItemGroup.java | 11 +- .../api/items/SlimefunItemStack.java | 4 +- .../slimefun4/api/network/Network.java | 3 +- .../api/network/NetworkVisualizer.java | 29 +++- .../core/attributes/DamageableItem.java | 3 +- .../core/attributes/RadiationSymptom.java | 5 +- .../slimefun4/core/debug/TestCase.java | 4 +- .../core/services/AnalyticsService.java | 154 ++++++++++++++++++ .../core/services/MetricsService.java | 141 ++++++++++------ .../core/services/ThreadService.java | 95 +++++++++++ .../github/ContributionsConnector.java | 24 +-- .../github/GitHubActivityConnector.java | 15 +- .../core/services/github/GitHubConnector.java | 57 ++++--- .../github/GitHubIssuesConnector.java | 16 +- .../services/profiler/SlimefunProfiler.java | 32 +++- .../slimefun4/implementation/Slimefun.java | 31 +++- .../implementation/SlimefunItems.java | 45 ++--- .../guide/SurvivalSlimefunGuide.java | 6 +- .../items/androids/MinerAndroid.java | 11 +- .../autocrafters/AbstractAutoCrafter.java | 4 +- .../implementation/items/blocks/Crucible.java | 4 +- .../items/electric/gadgets/MultiTool.java | 17 +- .../items/electric/machines/AutoBrewer.java | 38 ++--- .../items/electric/machines/FluidPump.java | 3 +- .../accelerators/AnimalGrowthAccelerator.java | 9 +- .../accelerators/CropGrowthAccelerator.java | 4 +- .../accelerators/TreeGrowthAccelerator.java | 6 +- .../items/magical/runes/EnchantmentRune.java | 4 +- .../items/magical/runes/VillagerRune.java | 3 +- .../implementation/items/medical/Bandage.java | 4 +- .../items/medical/MedicalSupply.java | 7 +- .../implementation/items/medical/Splint.java | 4 +- .../items/multiblocks/miner/MiningTask.java | 10 +- .../items/tools/ClimbingPick.java | 3 +- .../items/weapons/ExplosiveBow.java | 4 +- .../implementation/items/weapons/IcyBow.java | 6 +- .../listeners/BlockListener.java | 3 +- .../listeners/TalismanListener.java | 7 +- .../setup/SlimefunItemSetup.java | 11 +- .../tasks/AncientAltarTask.java | 21 +-- .../implementation/tasks/ArmorTask.java | 7 +- .../storage/backend/legacy/LegacyStorage.java | 26 ++- .../slimefun4/utils/FireworkUtils.java | 45 ++++- .../slimefun4/utils/SlimefunUtils.java | 2 +- .../compatibility/VersionedEnchantment.java | 63 +++++++ .../compatibility/VersionedEntityType.java | 35 ++++ .../compatibility/VersionedItemFlag.java | 30 ++++ .../compatibility/VersionedParticle.java | 62 +++++++ .../VersionedPotionEffectType.java | 62 +++++++ .../compatibility/VersionedPotionType.java | 41 +++++ .../utils/itemstack/ColoredFireworkStar.java | 4 +- 57 files changed, 1065 insertions(+), 263 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/ThreadService.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedEnchantment.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedEntityType.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedItemFlag.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedParticle.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedPotionEffectType.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedPotionType.java diff --git a/.github/workflows/e2e-testing.yml b/.github/workflows/e2e-testing.yml index 51721413e5..d48a0e1495 100644 --- a/.github/workflows/e2e-testing.yml +++ b/.github/workflows/e2e-testing.yml @@ -62,7 +62,7 @@ jobs: "https://api.papermc.io/v2/projects/paper/versions/$VERSION/builds/$BUILD/downloads/$JAR_FILE" - name: Download Slimefun - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: ${{ inputs.artifact-name }} path: plugins/ diff --git a/.gitignore b/.gitignore index fedd85ebef..66b05d87e2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /.idea/ /.vscode/ /data-storage/ +/javadocs/ .classpath .factorypath diff --git a/CHANGELOG.md b/CHANGELOG.md index fd52f7a3dc..453eb54984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Table of contents -- [Release Candidate 37 (TBD)](#release-candidate-37-tbd) +- [Release Candidate 38 (TBD)](#release-candidate-38-tbd) +- [Release Candidate 37 (25 Feb 2024)](#release-candidate-37-25-feb-2024) - [Release Candidate 36 (20 Dec 2023)](#release-candidate-36-20-dec-2023) - [Release Candidate 35 (07 Jul 2023)](#release-candidate-35-07-jul-2023) - [Release Candidate 34 (20 Jun 2023)](#release-candidate-34-20-jun-2023) @@ -37,7 +38,33 @@ - [Release Candidate 2 (29 Sep 2019)](#release-candidate-2-29-sep-2019) - [Release Candidate 1 (26 Sep 2019)](#release-candidate-1-26-sep-2019) -## Release Candidate 37 (TBD) +## Release Candidate 38 (TBD) + +## Release Candidate 37 (25 Feb 2024) + +#### Additions +* (API) Introduce SlimefunItemRegistryFinalizedEvent (#4099) +* Add update warning to /sf versions (#4096) +* Add new analytics service (#4067) + +#### Changes +* Allow blocks to be dropped while in creative mode (#3934) +* Storage rewrite - Phase 1 (#4065) +* Temporarily disable senstive blocks check (#4077) +* Update MockBukkit to 1.20.4 along with existing tests (#4086) +* Move PlayerProfile saving off the main thread (#4119) + +#### Fixes +* Fix contributor head being pullable (#4072) +* Fix backpack IDs not incrementing (#4081) +* Fix inventory being used when Slimefun block is broken (#4088) +* Fix items not being able to be placed on ancient altar (#4094) +* Update dough to fix item stacking issue (#4100) +* Fix slimefun block turning into a vanilla block if there are viewers (#4101) +* Fixes #4123 - Coal Generator will no longer be locked after researching (#4124) +* Fixes exhaustion when loading large profiles (#4127) +* Fixes guide search when using colored chat (#4125) +* Fix dupe glitch with backpacks (#4134) ## Release Candidate 36 (20 Dec 2023) diff --git a/pom.xml b/pom.xml index 5ce886f565..e3081e8382 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 16 - 1.20 + 1.20.6 https://hub.spigotmc.org/javadocs/spigot/ diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java index 05c2d84347..d50b93199d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java @@ -47,6 +47,12 @@ public enum MinecraftVersion { */ MINECRAFT_1_20(20, "1.20.x"), + /** + * This constant represents Minecraft (Java Edition) Version 1.20.5 + * ("The Armored Paws Update") + */ + MINECRAFT_1_20_5(20, 5, "1.20.5+"), + /** * This constant represents an exceptional state in which we were unable * to identify the Minecraft Version we are using @@ -62,6 +68,7 @@ public enum MinecraftVersion { private final String name; private final boolean virtual; private final int majorVersion; + private final int minorVersion; /** * This constructs a new {@link MinecraftVersion} with the given name. @@ -76,6 +83,26 @@ public enum MinecraftVersion { MinecraftVersion(int majorVersion, @Nonnull String name) { this.name = name; this.majorVersion = majorVersion; + this.minorVersion = -1; + this.virtual = false; + } + + /** + * This constructs a new {@link MinecraftVersion} with the given name. + * This constructor forces the {@link MinecraftVersion} to be real. + * It must be a real version of Minecraft. + * + * @param majorVersion + * The major (minor in semver, major in MC land) version of minecraft as an {@link Integer} + * @param minor + * The minor (patch in semver, minor in MC land) version of minecraft as an {@link Integer} + * @param name + * The display name of this {@link MinecraftVersion} + */ + MinecraftVersion(int majorVersion, int minor, @Nonnull String name) { + this.name = name; + this.majorVersion = majorVersion; + this.minorVersion = minor; this.virtual = false; } @@ -92,6 +119,7 @@ public enum MinecraftVersion { MinecraftVersion(@Nonnull String name, boolean virtual) { this.name = name; this.majorVersion = 0; + this.minorVersion = -1; this.virtual = virtual; } @@ -132,7 +160,30 @@ public boolean isVirtual() { * @return Whether this {@link MinecraftVersion} matches the specified version id */ public boolean isMinecraftVersion(int minecraftVersion) { - return !isVirtual() && this.majorVersion == minecraftVersion; + return this.isMinecraftVersion(minecraftVersion, -1); + } + + /** + * This tests if the given minecraft version matches with this + * {@link MinecraftVersion}. + *

+ * You can obtain the version number by doing {@link PaperLib#getMinecraftVersion()}. + * It is equivalent to the "major" version
+ * You can obtain the patch version by doing {@link PaperLib#getMinecraftPatchVersion()}. + * It is equivalent to the "minor" version + *

+ * Example: {@literal "1.13"} returns {@literal 13}
+ * Exampe: {@literal "1.13.2"} returns {@literal 13_2} + * + * @param minecraftVersion + * The {@link Integer} version to match + * + * @return Whether this {@link MinecraftVersion} matches the specified version id + */ + public boolean isMinecraftVersion(int minecraftVersion, int patchVersion) { + return !isVirtual() + && this.majorVersion == minecraftVersion + && (this.minorVersion == -1 || this.minorVersion >= patchVersion); } /** diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java index afb6dc8977..8dce77d3a2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/TeleportationManager.java @@ -9,6 +9,7 @@ import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import io.papermc.lib.PaperLib; import java.util.HashSet; import java.util.Set; @@ -25,7 +26,6 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; /** * The {@link TeleportationManager} handles the process of teleportation for a {@link Player} @@ -257,7 +257,7 @@ private void onTeleport(Player p, Location destination, boolean success, boolean if (success) { // Apply Resistance Effect, if enabled if (resistance) { - p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 600, 20)); + p.addPotionEffect(new PotionEffect(VersionedPotionEffectType.RESISTANCE, 600, 20)); Slimefun.getLocalization().sendMessage(p, "machines.TELEPORTER.invulnerability"); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java index e543a24ce1..dfb4806282 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/ItemGroup.java @@ -6,6 +6,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.groups.SeasonalItemGroup; import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedItemFlag; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -82,7 +83,7 @@ public ItemGroup(NamespacedKey key, ItemStack item, int tier) { ItemMeta meta = item.getItemMeta(); meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + meta.addItemFlags(VersionedItemFlag.HIDE_ADDITIONAL_TOOLTIP); this.item.setItemMeta(meta); this.tier = tier; } @@ -185,9 +186,7 @@ public void add(@Nonnull SlimefunItem item) { if (isRegistered() && !isCrossAddonItemGroup() && !item.getAddon().getName().equals(this.addon.getName())) { - item.warn("This item does not belong into ItemGroup " - + this - + " as that group belongs to " + item.warn("This item does not belong into ItemGroup " + this + " as that group belongs to " + this.addon.getName()); } @@ -230,9 +229,7 @@ public void remove(@Nonnull SlimefunItem item) { meta.setLore(Arrays.asList( "", - ChatColor.GRAY - + "\u21E8 " - + ChatColor.GREEN + ChatColor.GRAY + "\u21E8 " + ChatColor.GREEN + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup"))); }); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java index bc85e022f7..c760af4441 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java @@ -9,6 +9,7 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.WrongItemStackException; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedItemFlag; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; @@ -22,7 +23,6 @@ import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; -import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; @@ -165,7 +165,7 @@ public SlimefunItemStack( potionMeta.addCustomEffect(effect, true); if (effect.getType().equals(PotionEffectType.SATURATION)) { - im.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + im.addItemFlags(VersionedItemFlag.HIDE_ADDITIONAL_TOOLTIP); } } }); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java index a787c2d628..a237574544 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/Network.java @@ -13,6 +13,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.apache.commons.lang.Validate; +import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle; @@ -226,7 +227,7 @@ private void discoverNeighbors(@Nonnull Location l) { */ public void display() { if (manager.isVisualizerEnabled()) { - Slimefun.runSync(new NetworkVisualizer(this)); + Slimefun.runSync(new NetworkVisualizer(this, Color.BLUE)); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java index 71abce5594..5ba50eef60 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/network/NetworkVisualizer.java @@ -1,22 +1,24 @@ package io.github.thebusybiscuit.slimefun4.api.network; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import javax.annotation.Nonnull; +import org.apache.commons.lang.Validate; import org.bukkit.Color; import org.bukkit.Location; -import org.bukkit.Particle; import org.bukkit.Particle.DustOptions; /** * This class represents the visualizer task of a given {@link Network}. * * @author TheBusyBiscuit + * */ class NetworkVisualizer implements Runnable { /** * The {@link DustOptions} define the {@link Color} and size of our particles. */ - private final DustOptions options = new DustOptions(Color.BLUE, 3.5F); + private final DustOptions particleOptions; /** * This is our {@link Network} instance. @@ -26,10 +28,15 @@ class NetworkVisualizer implements Runnable { /** * This creates a new {@link NetworkVisualizer} for the given {@link Network}. * - * @param network The {@link Network} to visualize + * @param network + * The {@link Network} to visualize */ - NetworkVisualizer(@Nonnull Network network) { + NetworkVisualizer(@Nonnull Network network, @Nonnull Color color) { + Validate.notNull(network, "The network should not be null."); + Validate.notNull(color, "The color cannot be null."); + this.network = network; + this.particleOptions = new DustOptions(color, 3F); } @Override @@ -46,11 +53,21 @@ public void run() { /** * This method will spawn the actual particles. * - * @param l The {@link Location} of our node + * @param l + * The {@link Location} of our node */ private void spawnParticles(@Nonnull Location l) { l.getWorld() .spawnParticle( - Particle.REDSTONE, l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, 1, 0, 0, 0, 1, options); + VersionedParticle.DUST, + l.getX() + 0.5, + l.getY() + 0.5, + l.getZ() + 0.5, + 1, + 0, + 0, + 0, + 1, + particleOptions); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/DamageableItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/DamageableItem.java index 6a4fae9115..1c43c5f653 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/DamageableItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/DamageableItem.java @@ -3,6 +3,7 @@ import io.github.bakedlibs.dough.config.Config; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.utils.UnbreakingAlgorithm; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEnchantment; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.bukkit.Sound; @@ -49,7 +50,7 @@ public interface DamageableItem extends ItemAttribute { */ default void damageItem(@Nonnull Player p, @Nullable ItemStack item) { if (isDamageable() && item != null && !item.getType().isAir() && item.getAmount() > 0) { - int unbreakingLevel = item.getEnchantmentLevel(Enchantment.DURABILITY); + int unbreakingLevel = item.getEnchantmentLevel(VersionedEnchantment.UNBREAKING); if (evaluateUnbreakingEnchantment(unbreakingLevel)) { return; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RadiationSymptom.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RadiationSymptom.java index b8e1c0d6fd..7d20315ce9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RadiationSymptom.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/RadiationSymptom.java @@ -3,6 +3,7 @@ import com.google.common.base.Preconditions; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.utils.RadiationUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import javax.annotation.Nonnull; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; @@ -21,11 +22,11 @@ * @see RadiationUtils */ public enum RadiationSymptom { - SLOW(10, PotionEffectType.SLOW, 3), + SLOW(10, VersionedPotionEffectType.SLOWNESS, 3), WITHER_LOW(25, PotionEffectType.WITHER, 0), BLINDNESS(50, PotionEffectType.BLINDNESS, 4), WITHER_HIGH(75, PotionEffectType.WITHER, 3), - IMMINENT_DEATH(100, PotionEffectType.HARM, 49); + IMMINENT_DEATH(100, VersionedPotionEffectType.INSTANT_DAMAGE, 49); private final int minExposure; private final PotionEffect potionEffect; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/debug/TestCase.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/debug/TestCase.java index 7c413f7b9f..fa9f4aad79 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/debug/TestCase.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/debug/TestCase.java @@ -24,7 +24,9 @@ public enum TestCase { UTILS, - ENERGYNET; + ENERGYNET, + + ANALYTICS; TestCase() {} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java new file mode 100644 index 0000000000..3b0f846c77 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java @@ -0,0 +1,154 @@ +package io.github.thebusybiscuit.slimefun4.core.services; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import io.github.thebusybiscuit.slimefun4.core.debug.Debug; +import io.github.thebusybiscuit.slimefun4.core.debug.TestCase; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.concurrent.TimeUnit; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * This class represents an analytics service that sends data. + * This data is used to analyse performance of this {@link Plugin}. + *

+ * You can find more info in the README file of this Project on GitHub. + * + * @author WalshyDev + */ +public class AnalyticsService { + + private static final int VERSION = 1; + private static final String API_URL = "https://analytics.slimefun.dev/ingest"; + + private final JavaPlugin plugin; + private final HttpClient client = HttpClient.newHttpClient(); + + private boolean enabled; + + public AnalyticsService(JavaPlugin plugin) { + this.plugin = plugin; + } + + public void start() { + this.enabled = Slimefun.getCfg().getBoolean("metrics.analytics"); + + if (enabled) { + plugin.getLogger().info("Enabled Analytics Service"); + + // Send the timings data every minute + Slimefun.getThreadService() + .newScheduledThread( + plugin, "AnalyticsService - Timings", sendTimingsAnalytics(), 1, 1, TimeUnit.MINUTES); + } + } + + // We'll send some timing data every minute. + // To date, we collect the tick interval, the avg timing per tick and avg timing per machine + @Nonnull + private Runnable sendTimingsAnalytics() { + return () -> { + double tickInterval = Slimefun.getTickerTask().getTickRate(); + // This is currently used by bStats in a ranged way, we'll move this + double totalTimings = Slimefun.getProfiler().getAndResetAverageNanosecondTimings(); + double avgPerMachine = Slimefun.getProfiler().getAverageTimingsPerMachine(); + + if (totalTimings == 0 || avgPerMachine == 0) { + Debug.log( + TestCase.ANALYTICS, + "Ignoring analytics data for server_timings as no data was found" + " - total: " + totalTimings + + ", avg: " + avgPerMachine); + // Ignore if no data + return; + } + + send( + "server_timings", + new double[] { + // double1 is schema version + tickInterval, // double2 + totalTimings, // double3 + avgPerMachine // double4 + }, + null); + }; + } + + public void recordPlayerProfileDataTime(@Nonnull String backend, boolean load, long nanoseconds) { + send( + "player_profile_data_load_time", + new double[] { + // double1 is schema version + nanoseconds, // double2 + load ? 1 : 0 // double3 - 1 if load, 0 if save + }, + new String[] { + // blob1 is version + backend // blob2 + }); + } + + // Important: Keep the order of these doubles and blobs the same unless you increment the version number + // If a value is no longer used, just send null or replace it with a new value - don't shift the order + @ParametersAreNonnullByDefault + private void send(String id, double[] doubles, String[] blobs) { + // If not enabled or not official build (e.g. local build) or a unit test, just ignore. + if (!enabled + || !Slimefun.getUpdater().getBranch().isOfficial() + || Slimefun.instance().isUnitTest()) return; + + JsonObject object = new JsonObject(); + // Up to 1 index + JsonArray indexes = new JsonArray(); + indexes.add(id); + object.add("indexes", indexes); + + // Up to 20 doubles (including the version) + JsonArray doublesArray = new JsonArray(); + doublesArray.add(VERSION); + if (doubles != null) { + for (double d : doubles) { + doublesArray.add(d); + } + } + object.add("doubles", doublesArray); + + // Up to 20 blobs (including the version) + JsonArray blobsArray = new JsonArray(); + blobsArray.add(Slimefun.getVersion()); + if (blobs != null) { + for (String s : blobs) { + blobsArray.add(s); + } + } + object.add("blobs", blobsArray); + + Debug.log(TestCase.ANALYTICS, "Sending analytics data for " + id); + Debug.log(TestCase.ANALYTICS, object.toString()); + + // Send async, we do not care about the result. If it fails, that's fine. + client.sendAsync( + HttpRequest.newBuilder() + .uri(URI.create(API_URL)) + .header("User-Agent", "Mozilla/5.0 Slimefun4 AnalyticsService") + .POST(HttpRequest.BodyPublishers.ofString(object.toString())) + .build(), + HttpResponse.BodyHandlers.discarding()) + .thenAcceptAsync((res) -> { + if (res.statusCode() == 200) { + Debug.log(TestCase.ANALYTICS, "Analytics data for " + id + " sent successfully"); + } else { + Debug.log( + TestCase.ANALYTICS, + "Analytics data for " + id + " failed to send - " + res.statusCode()); + } + }); + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java index da1f1e9911..bacf49088c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java @@ -1,24 +1,33 @@ package io.github.thebusybiscuit.slimefun4.core.services; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; import io.github.bakedlibs.dough.common.CommonPatterns; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.net.URI; import java.net.URL; import java.net.URLClassLoader; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandler; +import java.net.http.HttpResponse.BodySubscriber; +import java.nio.ByteBuffer; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.util.concurrent.atomic.AtomicInteger; +import java.time.Duration; +import java.util.List; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow.Subscription; import java.util.logging.Level; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import kong.unirest.GetRequest; -import kong.unirest.HttpResponse; -import kong.unirest.JsonNode; -import kong.unirest.Unirest; -import kong.unirest.UnirestException; import org.bukkit.plugin.Plugin; /** @@ -62,22 +71,12 @@ public class MetricsService { private final Slimefun plugin; private final File parentFolder; private final File metricsModuleFile; + private final HttpClient client = HttpClient.newHttpClient(); private URLClassLoader moduleClassLoader; private String metricVersion = null; private boolean hasDownloadedUpdate = false; - static { - // @formatter:off (We want this to stay this nicely aligned :D ) - Unirest.config() - .concurrency(2, 1) - .setDefaultHeader("User-Agent", "MetricsModule Auto-Updater") - .setDefaultHeader("Accept", "application/vnd.github.v3+json") - .enableCookieManagement(false) - .cookieSpec("ignoreCookies"); - // @formatter:on - } - /** * This constructs a new instance of our {@link MetricsService}. * @@ -203,20 +202,17 @@ public boolean checkForUpdate(@Nullable String currentVersion) { */ private int getLatestVersion() { try { - HttpResponse response = Unirest.get(RELEASES_URL).asJson(); + HttpResponse response = + client.send(buildBaseRequest(URI.create(RELEASES_URL)), HttpResponse.BodyHandlers.ofString()); - if (!response.isSuccess()) { + if (response.statusCode() < 200 || response.statusCode() >= 300) { return -1; } - JsonNode node = response.getBody(); + JsonElement element = JsonParser.parseString(response.body()); - if (node == null) { - return -1; - } - - return node.getObject().getInt("tag_name"); - } catch (UnirestException e) { + return element.getAsJsonObject().get("tag_name").getAsInt(); + } catch (IOException | InterruptedException | JsonParseException e) { plugin.getLogger().log(Level.WARNING, "Failed to fetch latest builds for Metrics: {0}", e.getMessage()); return -1; } @@ -239,28 +235,11 @@ private boolean download(int version) { Files.delete(file.toPath()); } - AtomicInteger lastPercentPosted = new AtomicInteger(); - GetRequest request = Unirest.get(DOWNLOAD_URL + "/" + version + "/" + JAR_NAME + ".jar"); - - HttpResponse response = request.downloadMonitor((b, fileName, bytesWritten, totalBytes) -> { - int percent = (int) (20 * (Math.round((((double) bytesWritten / totalBytes) * 100) / 20))); - - if (percent != 0 && percent != lastPercentPosted.get()) { - plugin.getLogger() - .info("# Downloading... " - + percent - + "% " - + "(" - + bytesWritten - + "/" - + totalBytes - + " bytes)"); - lastPercentPosted.set(percent); - } - }) - .asFile(file.getPath()); - - if (response.isSuccess()) { + HttpResponse response = client.send( + buildBaseRequest(URI.create(DOWNLOAD_URL + "/" + version + "/" + JAR_NAME + ".jar")), + downloadMonitor(HttpResponse.BodyHandlers.ofFile(file.toPath()))); + + if (response.statusCode() >= 200 && response.statusCode() < 300) { plugin.getLogger() .log(Level.INFO, "Successfully downloaded {0} build: #{1}", new Object[] {JAR_NAME, version}); @@ -272,19 +251,17 @@ private boolean download(int version) { hasDownloadedUpdate = true; return true; } - } catch (UnirestException e) { + } catch (InterruptedException | JsonParseException e) { plugin.getLogger() .log( Level.WARNING, - "Failed to fetch the latest jar file from the builds page. Perhaps GitHub is down?" - + " Response: {0}", + "Failed to fetch the latest jar file from the builds page. Perhaps GitHub is down? Response: {0}", e.getMessage()); } catch (IOException e) { plugin.getLogger() .log( Level.WARNING, - "Failed to replace the old metric file with the new one. Please do this manually!" - + " Error: {0}", + "Failed to replace the old metric file with the new one. Please do this manually! Error: {0}", e.getMessage()); } @@ -310,4 +287,62 @@ private boolean download(int version) { public boolean hasAutoUpdates() { return Slimefun.instance().getConfig().getBoolean("metrics.auto-update"); } + + private HttpRequest buildBaseRequest(@Nonnull URI uri) { + return HttpRequest.newBuilder() + .uri(uri) + .timeout(Duration.ofSeconds(5)) + .header("User-Agent", "MetricsModule Auto-Updater") + .header("Accept", "application/vnd.github.v3+json") + .build(); + } + + private BodyHandler downloadMonitor(BodyHandler h) { + return info -> new BodySubscriber() { + + private BodySubscriber delegateSubscriber = h.apply(info); + private int lastPercentPosted = 0; + private long bytesWritten = 0; + + @Override + public void onSubscribe(Subscription subscription) { + delegateSubscriber.onSubscribe(subscription); + } + + @Override + public void onNext(List item) { + bytesWritten += item.stream().mapToLong(ByteBuffer::capacity).sum(); + long totalBytes = info.headers() + .firstValue("Content-Length") + .map(Long::parseLong) + .orElse(-1L); + + int percent = (int) (20 * (Math.round((((double) bytesWritten / totalBytes) * 100) / 20))); + + if (percent != 0 && percent != lastPercentPosted) { + plugin.getLogger() + .info("# Downloading... " + percent + "% " + "(" + bytesWritten + "/" + totalBytes + + " bytes)"); + lastPercentPosted = percent; + } + + delegateSubscriber.onNext(item); + } + + @Override + public void onError(Throwable throwable) { + delegateSubscriber.onError(throwable); + } + + @Override + public void onComplete() { + delegateSubscriber.onComplete(); + } + + @Override + public CompletionStage getBody() { + return delegateSubscriber.getBody(); + } + }; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/ThreadService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/ThreadService.java new file mode 100644 index 0000000000..c99557bef2 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/ThreadService.java @@ -0,0 +1,95 @@ +package io.github.thebusybiscuit.slimefun4.core.services; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import javax.annotation.ParametersAreNonnullByDefault; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitScheduler; + +public final class ThreadService { + + private final ThreadGroup group; + private final ExecutorService cachedPool; + private final ScheduledExecutorService scheduledPool; + + public ThreadService(JavaPlugin plugin) { + this.group = new ThreadGroup(plugin.getName()); + this.cachedPool = Executors.newCachedThreadPool(new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + return new Thread(group, r, plugin.getName() + " - ThreadService"); + } + }); + + this.scheduledPool = Executors.newScheduledThreadPool(1, new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + return new Thread(group, r, plugin.getName() + " - ScheduledThreadService"); + } + }); + } + + /** + * Invoke a new thread from the cached thread pool with the given name. + * This is a much better alternative to using + * {@link BukkitScheduler#runTaskAsynchronously(org.bukkit.plugin.Plugin, Runnable)} + * as this will show not only the plugin but a useful name. + * By default, Bukkit will use "Craft Scheduler Thread - {@literal } - {@literal }" which is nice to show the plugin but + * it's impossible to track exactly what thread that is. + * + * @param plugin The {@link JavaPlugin} that is creating this thread + * @param name The name of this thread, this will be prefixed with the plugin's name + * @param runnable The {@link Runnable} to execute + */ + @ParametersAreNonnullByDefault + public void newThread(JavaPlugin plugin, String name, Runnable runnable) { + cachedPool.submit(() -> { + // This is a bit of a hack, but it's the only way to have the thread name be as desired + Thread.currentThread().setName(plugin.getName() + " - " + name); + runnable.run(); + }); + } + + /** + * Invoke a new scheduled thread from the cached thread pool with the given name. + * This is a much better alternative to using + * {@link BukkitScheduler#runTaskTimerAsynchronously(org.bukkit.plugin.Plugin, Runnable, long, long)} + * as this will show not only the plugin but a useful name. + * By default, Bukkit will use "Craft Scheduler Thread - {@literal } - {@literal }" which is nice to show the plugin but + * it's impossible to track exactly what thread that is. + * + * @param plugin The {@link JavaPlugin} that is creating this thread + * @param name The name of this thread, this will be prefixed with the plugin's name + * @param runnable The {@link Runnable} to execute + */ + @ParametersAreNonnullByDefault + public void newScheduledThread( + JavaPlugin plugin, String name, Runnable runnable, long delay, long period, TimeUnit unit) { + this.scheduledPool.scheduleWithFixedDelay( + () -> { + // This is a bit of a hack, but it's the only way to have the thread name be as desired + Thread.currentThread().setName(plugin.getName() + " - " + name); + runnable.run(); + }, + delay, + delay, + unit); + } + + /** + * Get the caller of a given method, this should only be used for debugging purposes and is not performant. + * + * @return The caller of the method that called this method. + */ + public static String getCaller() { + // First item will be getting the call stack + // Second item will be this call + // Third item will be the func we care about being called + // And finally will be the caller + StackTraceElement element = Thread.currentThread().getStackTrace()[3]; + return element.getClassName() + "." + element.getMethodName() + ":" + element.getLineNumber(); + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java index 6e232dd9bf..b09e58efa4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/ContributionsConnector.java @@ -1,5 +1,8 @@ package io.github.thebusybiscuit.slimefun4.core.services.github; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.util.ArrayList; import java.util.HashMap; @@ -8,9 +11,6 @@ import java.util.logging.Level; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import kong.unirest.JsonNode; -import kong.unirest.json.JSONArray; -import kong.unirest.json.JSONObject; class ContributionsConnector extends GitHubConnector { @@ -87,11 +87,11 @@ public boolean hasFinished() { } @Override - public void onSuccess(@Nonnull JsonNode response) { + public void onSuccess(@Nonnull JsonElement response) { finished = true; - if (response.isArray()) { - computeContributors(response.getArray()); + if (response.isJsonArray()) { + computeContributors(response.getAsJsonArray()); } else { Slimefun.logger() .log(Level.WARNING, "Received an unusual answer from GitHub, possibly a timeout? ({0})", response); @@ -121,13 +121,13 @@ public Map getParameters() { return parameters; } - private void computeContributors(@Nonnull JSONArray array) { - for (int i = 0; i < array.length(); i++) { - JSONObject object = array.getJSONObject(i); + private void computeContributors(@Nonnull JsonArray array) { + for (JsonElement element : array) { + JsonObject object = element.getAsJsonObject(); - String name = object.getString("login"); - int commits = object.getInt("contributions"); - String profile = object.getString("html_url"); + String name = object.get("login").getAsString(); + int commits = object.get("contributions").getAsInt(); + String profile = object.get("html_url").getAsString(); if (!ignoredAccounts.contains(name)) { String username = aliases.getOrDefault(name, name); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubActivityConnector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubActivityConnector.java index df804f41f2..b028bc6af8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubActivityConnector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubActivityConnector.java @@ -1,13 +1,13 @@ package io.github.thebusybiscuit.slimefun4.core.services.github; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import kong.unirest.JsonNode; -import kong.unirest.json.JSONObject; class GitHubActivityConnector extends GitHubConnector { @@ -20,11 +20,12 @@ class GitHubActivityConnector extends GitHubConnector { } @Override - public void onSuccess(@Nonnull JsonNode response) { - JSONObject object = response.getObject(); - int forks = object.getInt("forks"); - int stars = object.getInt("stargazers_count"); - LocalDateTime lastPush = NumberUtils.parseGitHubDate(object.getString("pushed_at")); + public void onSuccess(@Nonnull JsonElement response) { + JsonObject object = response.getAsJsonObject(); + int forks = object.get("forks").getAsInt(); + int stars = object.get("stargazers_count").getAsInt(); + LocalDateTime lastPush = + NumberUtils.parseGitHubDate(object.get("pushed_at").getAsString()); callback.accept(forks, stars, lastPush); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java index 035a13d2f9..ac7d338b8f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubConnector.java @@ -1,5 +1,8 @@ package io.github.thebusybiscuit.slimefun4.core.services.github; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.io.BufferedReader; import java.io.File; @@ -7,17 +10,17 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.logging.Level; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import kong.unirest.HttpResponse; -import kong.unirest.JsonNode; -import kong.unirest.Unirest; -import kong.unirest.UnirestException; -import kong.unirest.json.JSONException; /** * The {@link GitHubConnector} is used to connect to the GitHub API service. @@ -31,6 +34,7 @@ abstract class GitHubConnector { private static final String API_URL = "https://api.github.com/"; private static final String USER_AGENT = "Slimefun4 (https://github.com/Slimefun)"; + private static final HttpClient client = HttpClient.newHttpClient(); protected final GitHubService github; private final String url; @@ -80,7 +84,7 @@ abstract class GitHubConnector { * @param response * The response */ - public abstract void onSuccess(@Nonnull JsonNode response); + public abstract void onSuccess(@Nonnull JsonElement response); /** * This method is called when the connection has failed. @@ -102,40 +106,45 @@ void download() { } try { - // @formatter:off - HttpResponse response = Unirest.get(url) - .queryString(getParameters()) - .header("User-Agent", USER_AGENT) - .asJson(); - // @formatter:on - - if (response.isSuccess()) { - onSuccess(response.getBody()); - writeCacheFile(response.getBody()); + String params = getParameters().entrySet().stream() + .map(p -> p.getKey() + "=" + p.getValue()) + .reduce((p1, p2) -> p1 + "&" + p2) + .map(s -> "?" + s) + .orElse(""); + URI uri = new URI(url + params); + + HttpResponse response = client.send( + HttpRequest.newBuilder(uri).header("User-Agent", USER_AGENT).build(), + HttpResponse.BodyHandlers.ofString()); + JsonElement element = JsonParser.parseString(response.body()); + + if (response.statusCode() >= 200 && response.statusCode() < 300) { + onSuccess(element); + writeCacheFile(element); } else { if (github.isLoggingEnabled()) { Slimefun.logger().log(Level.WARNING, "Failed to fetch {0}: {1} - {2}", new Object[] { - url, response.getStatus(), response.getBody() + url, response.statusCode(), element }); } // It has the cached file, let's just read that then if (file.exists()) { - JsonNode cache = readCacheFile(); + JsonElement cache = readCacheFile(); if (cache != null) { onSuccess(cache); } } } - } catch (UnirestException e) { + } catch (IOException | InterruptedException | JsonParseException | URISyntaxException e) { if (github.isLoggingEnabled()) { Slimefun.logger().log(Level.WARNING, "Could not connect to GitHub in time.", e); } // It has the cached file, let's just read that then if (file.exists()) { - JsonNode cache = readCacheFile(); + JsonElement cache = readCacheFile(); if (cache != null) { onSuccess(cache); @@ -148,11 +157,11 @@ void download() { } } - @Nullable private JsonNode readCacheFile() { + @Nullable private JsonElement readCacheFile() { try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) { - return new JsonNode(reader.readLine()); - } catch (IOException | JSONException e) { + return JsonParser.parseString(reader.readLine()); + } catch (IOException | JsonParseException e) { Slimefun.logger().log(Level.WARNING, "Failed to read Github cache file: {0} - {1}: {2}", new Object[] { file.getName(), e.getClass().getSimpleName(), e.getMessage() }); @@ -160,7 +169,7 @@ void download() { } } - private void writeCacheFile(@Nonnull JsonNode node) { + private void writeCacheFile(@Nonnull JsonElement node) { try (FileOutputStream output = new FileOutputStream(file)) { output.write(node.toString().getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesConnector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesConnector.java index ab2dac5480..63cd5581cb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesConnector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/github/GitHubIssuesConnector.java @@ -1,14 +1,14 @@ package io.github.thebusybiscuit.slimefun4.core.services.github; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import kong.unirest.JsonNode; -import kong.unirest.json.JSONArray; -import kong.unirest.json.JSONObject; class GitHubIssuesConnector extends GitHubConnector { @@ -21,15 +21,15 @@ class GitHubIssuesConnector extends GitHubConnector { } @Override - public void onSuccess(@Nonnull JsonNode response) { - if (response.isArray()) { - JSONArray array = response.getArray(); + public void onSuccess(@Nonnull JsonElement response) { + if (response.isJsonArray()) { + JsonArray array = response.getAsJsonArray(); int issues = 0; int pullRequests = 0; - for (int i = 0; i < array.length(); i++) { - JSONObject obj = array.getJSONObject(i); + for (JsonElement element : array) { + JsonObject obj = element.getAsJsonObject(); if (obj.has("pull_request")) { pullRequests++; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java index 837a8855b9..0b4e547e5b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.core.services.profiler; +import com.google.common.util.concurrent.AtomicDouble; import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; @@ -85,6 +86,8 @@ public class SlimefunProfiler { private final AtomicLong totalMsTicked = new AtomicLong(); private final AtomicInteger ticksPassed = new AtomicInteger(); + private final AtomicLong totalNsTicked = new AtomicLong(); + private final AtomicDouble averageTimingsPerMachine = new AtomicDouble(); /** * This method terminates the {@link SlimefunProfiler}. @@ -203,8 +206,7 @@ private void finishReport() { while (iterator.hasNext()) { iterator.next() .sendMessage("Your timings report has timed out, we were still waiting for " - + queued.get() - + " samples to be collected :/"); + + queued.get() + " samples to be collected :/"); iterator.remove(); } @@ -223,11 +225,15 @@ private void finishReport() { totalElapsedTime = timings.values().stream().mapToLong(Long::longValue).sum(); + averageTimingsPerMachine.getAndSet( + timings.values().stream().mapToLong(Long::longValue).average().orElse(0)); + /* * We log how many milliseconds have been ticked, and how many ticks have passed * This is so when bStats requests the average timings, they're super quick to figure out */ totalMsTicked.addAndGet(TimeUnit.NANOSECONDS.toMillis(totalElapsedTime)); + totalNsTicked.addAndGet(totalElapsedTime); ticksPassed.incrementAndGet(); if (!requests.isEmpty()) { @@ -418,4 +424,26 @@ public long getAndResetAverageTimings() { return l; } + + /** + * Get and reset the average nanosecond timing for this {@link SlimefunProfiler}. + * + * @return The average nanosecond timing for this {@link SlimefunProfiler}. + */ + public double getAndResetAverageNanosecondTimings() { + long l = totalNsTicked.get() / ticksPassed.get(); + totalNsTicked.set(0); + ticksPassed.set(0); + + return l; + } + + /** + * Get and reset the average millisecond timing for each machine. + * + * @return The average millisecond timing for each machine. + */ + public double getAverageTimingsPerMachine() { + return averageTimingsPerMachine.getAndSet(0); + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java index 9b2c39ea6a..668b828c55 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java @@ -21,6 +21,7 @@ import io.github.thebusybiscuit.slimefun4.core.config.SlimefunConfigManager; import io.github.thebusybiscuit.slimefun4.core.config.SlimefunDatabaseManager; import io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager; +import io.github.thebusybiscuit.slimefun4.core.services.AnalyticsService; import io.github.thebusybiscuit.slimefun4.core.services.AutoSavingService; import io.github.thebusybiscuit.slimefun4.core.services.BackupService; import io.github.thebusybiscuit.slimefun4.core.services.BlockDataService; @@ -31,6 +32,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.MinecraftRecipeService; import io.github.thebusybiscuit.slimefun4.core.services.PerWorldSettingsService; import io.github.thebusybiscuit.slimefun4.core.services.PermissionsService; +import io.github.thebusybiscuit.slimefun4.core.services.ThreadService; import io.github.thebusybiscuit.slimefun4.core.services.UpdaterService; import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService; import io.github.thebusybiscuit.slimefun4.core.services.holograms.HologramsService; @@ -189,6 +191,8 @@ public final class Slimefun extends JavaPlugin implements SlimefunAddon, ICompat private final MinecraftRecipeService recipeService = new MinecraftRecipeService(this); private final HologramsService hologramsService = new HologramsService(this); private final SoundService soundService = new SoundService(this); + private final ThreadService threadService = new ThreadService(this); + private final AnalyticsService analyticsService = new AnalyticsService(this); // Some other things we need private final IntegrationsManager integrations = new IntegrationsManager(this); @@ -347,8 +351,9 @@ private void onPluginStart() { config.getBoolean("networks.enable-visualizer"), config.getBoolean("networks.delete-excess-items")); - // Setting up bStats + // Setting up bStats and analytics new Thread(metricsService::start, "Slimefun Metrics").start(); + analyticsService.start(); // Registering all GEO Resources logger.log(Level.INFO, "加载矿物资源..."); @@ -575,11 +580,12 @@ private boolean isVersionUnsupported() { // Now check the actual Version of Minecraft int version = PaperLib.getMinecraftVersion(); + int patchVersion = PaperLib.getMinecraftPatchVersion(); if (version > 0) { // Check all supported versions of Minecraft for (MinecraftVersion supportedVersion : MinecraftVersion.values()) { - if (supportedVersion.isMinecraftVersion(version)) { + if (supportedVersion.isMinecraftVersion(version, patchVersion)) { minecraftVersion = supportedVersion; return false; } @@ -967,6 +973,17 @@ public static SoundService getSoundService() { return instance.metricsService; } + /** + * This method returns the {@link AnalyticsService} of Slimefun. + * It is used to handle sending analytic information. + * + * @return The {@link AnalyticsService} for Slimefun + */ + public static @Nonnull AnalyticsService getAnalyticsService() { + validateInstance(); + return instance.analyticsService; + } + /** * This method returns the {@link GitHubService} of Slimefun. * It is used to retrieve data from GitHub repositories. @@ -1156,4 +1173,14 @@ public File getFile() { validateInstance(); return instance.chatCatcher; } + + /** + * This method returns the {@link ThreadService} of Slimefun. + * Do not use this if you're an addon. Please make your own {@link ThreadService}. + * + * @return The {@link ThreadService} for Slimefun + */ + public static @Nonnull ThreadService getThreadService() { + return instance().threadService; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java index 777bba8ae9..51cdf70103 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/SlimefunItems.java @@ -9,6 +9,7 @@ import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.LoreBuilder; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEnchantment; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ColoredFireworkStar; import java.util.ArrayList; import java.util.HashMap; @@ -674,8 +675,8 @@ private SlimefunItems() {} GRANDPAS_WALKING_STICK.addUnsafeEnchantment(Enchantment.KNOCKBACK, 5); BLADE_OF_VAMPIRES.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 2); - BLADE_OF_VAMPIRES.addUnsafeEnchantment(Enchantment.DURABILITY, 4); - BLADE_OF_VAMPIRES.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 2); + BLADE_OF_VAMPIRES.addUnsafeEnchantment(VersionedEnchantment.UNBREAKING, 4); + BLADE_OF_VAMPIRES.addUnsafeEnchantment(VersionedEnchantment.SHARPNESS, 2); } /* Bows */ @@ -711,8 +712,8 @@ private SlimefunItems() {} "CLIMBING_PICK", Material.IRON_PICKAXE, "&b攀岩镐", "", "&f让你能够在右键后", "&f攀爬到指定平面上.", "&f附魔效率之后攀爬速度将会提升"); static { - COBALT_PICKAXE.addUnsafeEnchantment(Enchantment.DURABILITY, 10); - COBALT_PICKAXE.addUnsafeEnchantment(Enchantment.DIG_SPEED, 6); + COBALT_PICKAXE.addUnsafeEnchantment(VersionedEnchantment.UNBREAKING, 10); + COBALT_PICKAXE.addUnsafeEnchantment(VersionedEnchantment.EFFICIENCY, 6); } /* Armor */ @@ -906,7 +907,7 @@ private SlimefunItems() {} static { Map cactusEnchs = new HashMap<>(); cactusEnchs.put(Enchantment.THORNS, 3); - cactusEnchs.put(Enchantment.DURABILITY, 6); + cactusEnchs.put(VersionedEnchantment.UNBREAKING, 6); CACTUS_HELMET.addUnsafeEnchantments(cactusEnchs); CACTUS_CHESTPLATE.addUnsafeEnchantments(cactusEnchs); @@ -914,8 +915,8 @@ private SlimefunItems() {} CACTUS_BOOTS.addUnsafeEnchantments(cactusEnchs); Map damascusEnchs = new HashMap<>(); - damascusEnchs.put(Enchantment.DURABILITY, 5); - damascusEnchs.put(Enchantment.PROTECTION_ENVIRONMENTAL, 5); + damascusEnchs.put(VersionedEnchantment.UNBREAKING, 5); + damascusEnchs.put(VersionedEnchantment.PROTECTION, 5); DAMASCUS_STEEL_HELMET.addUnsafeEnchantments(damascusEnchs); DAMASCUS_STEEL_CHESTPLATE.addUnsafeEnchantments(damascusEnchs); @@ -923,8 +924,8 @@ private SlimefunItems() {} DAMASCUS_STEEL_BOOTS.addUnsafeEnchantments(damascusEnchs); Map reinforcedEnchs = new HashMap<>(); - reinforcedEnchs.put(Enchantment.DURABILITY, 9); - reinforcedEnchs.put(Enchantment.PROTECTION_ENVIRONMENTAL, 9); + reinforcedEnchs.put(VersionedEnchantment.UNBREAKING, 9); + reinforcedEnchs.put(VersionedEnchantment.PROTECTION, 9); REINFORCED_ALLOY_HELMET.addUnsafeEnchantments(reinforcedEnchs); REINFORCED_ALLOY_CHESTPLATE.addUnsafeEnchantments(reinforcedEnchs); @@ -932,22 +933,22 @@ private SlimefunItems() {} REINFORCED_ALLOY_BOOTS.addUnsafeEnchantments(reinforcedEnchs); Map gildedEnchs = new HashMap<>(); - gildedEnchs.put(Enchantment.DURABILITY, 6); - gildedEnchs.put(Enchantment.PROTECTION_ENVIRONMENTAL, 8); + gildedEnchs.put(VersionedEnchantment.UNBREAKING, 6); + gildedEnchs.put(VersionedEnchantment.PROTECTION, 8); GILDED_IRON_HELMET.addUnsafeEnchantments(gildedEnchs); GILDED_IRON_CHESTPLATE.addUnsafeEnchantments(gildedEnchs); GILDED_IRON_LEGGINGS.addUnsafeEnchantments(gildedEnchs); GILDED_IRON_BOOTS.addUnsafeEnchantments(gildedEnchs); - GOLDEN_HELMET_12K.addUnsafeEnchantment(Enchantment.DURABILITY, 10); - GOLDEN_CHESTPLATE_12K.addUnsafeEnchantment(Enchantment.DURABILITY, 10); - GOLDEN_LEGGINGS_12K.addUnsafeEnchantment(Enchantment.DURABILITY, 10); - GOLDEN_BOOTS_12K.addUnsafeEnchantment(Enchantment.DURABILITY, 10); + GOLDEN_HELMET_12K.addUnsafeEnchantment(VersionedEnchantment.UNBREAKING, 10); + GOLDEN_CHESTPLATE_12K.addUnsafeEnchantment(VersionedEnchantment.UNBREAKING, 10); + GOLDEN_LEGGINGS_12K.addUnsafeEnchantment(VersionedEnchantment.UNBREAKING, 10); + GOLDEN_BOOTS_12K.addUnsafeEnchantment(VersionedEnchantment.UNBREAKING, 10); Map slimeEnchs = new HashMap<>(); - slimeEnchs.put(Enchantment.DURABILITY, 4); - slimeEnchs.put(Enchantment.PROTECTION_ENVIRONMENTAL, 2); + slimeEnchs.put(VersionedEnchantment.UNBREAKING, 4); + slimeEnchs.put(VersionedEnchantment.PROTECTION, 2); SLIME_HELMET_STEEL.addUnsafeEnchantments(slimeEnchs); SLIME_CHESTPLATE_STEEL.addUnsafeEnchantments(slimeEnchs); @@ -955,8 +956,8 @@ private SlimefunItems() {} SLIME_BOOTS_STEEL.addUnsafeEnchantments(slimeEnchs); Map beeEnchs = new HashMap<>(); - beeEnchs.put(Enchantment.DURABILITY, 4); - beeEnchs.put(Enchantment.PROTECTION_ENVIRONMENTAL, 2); + beeEnchs.put(VersionedEnchantment.UNBREAKING, 4); + beeEnchs.put(VersionedEnchantment.PROTECTION, 2); BEE_HELMET.addUnsafeEnchantments(beeEnchs); BEE_WINGS.addUnsafeEnchantments(beeEnchs); @@ -1401,10 +1402,10 @@ private SlimefunItems() {} LoreBuilder.usesLeft(StormStaff.MAX_USES)); static { - STAFF_WIND.addUnsafeEnchantment(Enchantment.LUCK, 1); + STAFF_WIND.addUnsafeEnchantment(VersionedEnchantment.LUCK_OF_THE_SEA, 1); STAFF_FIRE.addUnsafeEnchantment(Enchantment.FIRE_ASPECT, 5); - STAFF_WATER.addUnsafeEnchantment(Enchantment.WATER_WORKER, 1); - STAFF_STORM.addUnsafeEnchantment(Enchantment.DURABILITY, 1); + STAFF_WATER.addUnsafeEnchantment(VersionedEnchantment.AQUA_AFFINITY, 1); + STAFF_STORM.addUnsafeEnchantment(VersionedEnchantment.UNBREAKING, 1); } /* Machines */ diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java index b92bab37ac..595ff54f92 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java @@ -26,6 +26,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedItemFlag; import io.github.thebusybiscuit.slimefun4.utils.itemstack.SlimefunGuideItem; import java.util.ArrayList; import java.util.Arrays; @@ -405,7 +406,10 @@ && isSearchFilterApplicable(slimefunItem, searchTerm)) { ItemGroup itemGroup = slimefunItem.getItemGroup(); meta.setLore(Arrays.asList( "", ChatColor.DARK_GRAY + "\u21E8 " + ChatColor.WHITE + itemGroup.getDisplayName(p))); - meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS); + meta.addItemFlags( + ItemFlag.HIDE_ATTRIBUTES, + ItemFlag.HIDE_ENCHANTS, + VersionedItemFlag.HIDE_ADDITIONAL_TOOLTIP); }); menu.addItem(index, itemstack); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java index cb06c746da..b0319b96b8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java @@ -10,17 +10,18 @@ import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.utils.InfiniteBlockGenerator; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import java.util.Collection; import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Material; import org.bukkit.OfflinePlayer; -import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Container; @@ -75,7 +76,7 @@ protected void dig(Block b, BlockMenu menu, Block block) { if (!SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) && !drops.isEmpty()) { OfflinePlayer owner = - Bukkit.getOfflinePlayer(UUID.fromString(StorageCacheUtils.getData(b.getLocation(), "owner"))); + Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))); if (Slimefun.getProtectionManager().hasPermission(owner, block.getLocation(), Interaction.BREAK_BLOCK)) { AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b)); @@ -100,7 +101,7 @@ protected void moveAndDig(Block b, BlockMenu menu, BlockFace face, Block block) if (!SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) && !drops.isEmpty()) { OfflinePlayer owner = - Bukkit.getOfflinePlayer(UUID.fromString(StorageCacheUtils.getData(b.getLocation(), "owner"))); + Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"))); if (Slimefun.getProtectionManager().hasPermission(owner, block.getLocation(), Interaction.BREAK_BLOCK)) { AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b)); @@ -137,7 +138,7 @@ private void breakBlock(BlockMenu menu, Collection drops, Block block menu.pushItem(drop, getOutputSlots()); if (block instanceof Container container) { - for (ItemStack content : container.getSnapshotInventory().getContents()) { + for (ItemStack content : container.getInventory().getContents()) { block.getWorld().dropItemNaturally(block.getLocation(), content); } } @@ -157,7 +158,7 @@ private void breakBlock(BlockMenu menu, Collection drops, Block block SoundEffect.MINER_ANDROID_BLOCK_GENERATION_SOUND.playAt(block); block.getWorld() .spawnParticle( - Particle.SMOKE_NORMAL, + VersionedParticle.SMOKE, block.getX() + 0.5, block.getY() + 1.25, block.getZ() + 0.5, diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java index 2c38c9e156..abcf514f10 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/autocrafters/AbstractAutoCrafter.java @@ -23,6 +23,7 @@ import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import io.papermc.lib.PaperLib; @@ -45,7 +46,6 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; @@ -242,7 +242,7 @@ protected void tick(@Nonnull Block b, @Nonnull SlimefunBlockData data) { if (craft(interactor, recipe)) { // We are done crafting! Location loc = b.getLocation().add(0.5, 0.8, 0.5); - b.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, loc, 6); + b.getWorld().spawnParticle(VersionedParticle.HAPPY_VILLAGER, loc, 6); removeCharge(b.getLocation(), getEnergyConsumption()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java index bad87638fa..e94b806029 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/Crucible.java @@ -13,6 +13,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import java.util.LinkedList; import java.util.List; @@ -20,7 +21,6 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.Tag; import org.bukkit.World.Environment; import org.bukkit.block.Block; @@ -167,7 +167,7 @@ private void generateLiquid(@Nonnull Block block, boolean isWater) { if (isWater && block.getWorld().getEnvironment() == Environment.NETHER && !allowWaterInNether.getValue()) { // We will still consume the items but won't generate water in the Nether. block.getWorld() - .spawnParticle(Particle.SMOKE_NORMAL, block.getLocation().add(0.5, 0.5, 0.5), 4); + .spawnParticle(VersionedParticle.SMOKE, block.getLocation().add(0.5, 0.5, 0.5), 4); SoundEffect.CRUCIBLE_GENERATE_LIQUID_SOUND.playAt(block); return; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java index 20a45efec9..e982760ffc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/gadgets/MultiTool.java @@ -9,12 +9,14 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEntityType; import java.util.ArrayList; import java.util.List; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.ChatColor; import org.bukkit.NamespacedKey; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; @@ -116,15 +118,12 @@ private ToolUseHandler getToolUseHandler() { private EntityInteractHandler getEntityInteractionHandler() { return (e, item, offhand) -> { // Fixes #2217 - Prevent them from being used to shear entities - switch (e.getRightClicked().getType()) { - case MUSHROOM_COW: - case SHEEP: - case SNOWMAN: - Slimefun.getLocalization().sendMessage(e.getPlayer(), "messages.multi-tool.not-shears"); - e.setCancelled(true); - break; - default: - break; + EntityType type = e.getRightClicked().getType(); + if (type == VersionedEntityType.MOOSHROOM + || type == VersionedEntityType.SNOW_GOLEM + || type == EntityType.SHEEP) { + Slimefun.getLocalization().sendMessage(e.getPlayer(), "messages.multi-tool.not-shears"); + e.setCancelled(true); } }; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java index a8dd16a946..9a2aac1929 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoBrewer.java @@ -5,6 +5,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.attributes.NotHopperable; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionType; import java.util.EnumMap; import java.util.Map; import javax.annotation.Nonnull; @@ -16,7 +17,6 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionType; /** @@ -32,22 +32,22 @@ public class AutoBrewer extends AContainer implements NotHopperable { private static final Map fermentations = new EnumMap<>(PotionType.class); static { - potionRecipes.put(Material.SUGAR, PotionType.SPEED); - potionRecipes.put(Material.RABBIT_FOOT, PotionType.JUMP); + potionRecipes.put(Material.SUGAR, VersionedPotionType.SWIFTNESS); + potionRecipes.put(Material.RABBIT_FOOT, VersionedPotionType.LEAPING); potionRecipes.put(Material.BLAZE_POWDER, PotionType.STRENGTH); - potionRecipes.put(Material.GLISTERING_MELON_SLICE, PotionType.INSTANT_HEAL); + potionRecipes.put(Material.GLISTERING_MELON_SLICE, VersionedPotionType.HEALING); potionRecipes.put(Material.SPIDER_EYE, PotionType.POISON); - potionRecipes.put(Material.GHAST_TEAR, PotionType.REGEN); + potionRecipes.put(Material.GHAST_TEAR, VersionedPotionType.REGENERATION); potionRecipes.put(Material.MAGMA_CREAM, PotionType.FIRE_RESISTANCE); potionRecipes.put(Material.PUFFERFISH, PotionType.WATER_BREATHING); potionRecipes.put(Material.GOLDEN_CARROT, PotionType.NIGHT_VISION); potionRecipes.put(Material.TURTLE_HELMET, PotionType.TURTLE_MASTER); potionRecipes.put(Material.PHANTOM_MEMBRANE, PotionType.SLOW_FALLING); - fermentations.put(PotionType.SPEED, PotionType.SLOWNESS); - fermentations.put(PotionType.JUMP, PotionType.SLOWNESS); - fermentations.put(PotionType.INSTANT_HEAL, PotionType.INSTANT_DAMAGE); - fermentations.put(PotionType.POISON, PotionType.INSTANT_DAMAGE); + fermentations.put(VersionedPotionType.SWIFTNESS, PotionType.SLOWNESS); + fermentations.put(VersionedPotionType.LEAPING, PotionType.SLOWNESS); + fermentations.put(VersionedPotionType.HEALING, VersionedPotionType.HARMING); + fermentations.put(PotionType.POISON, VersionedPotionType.HARMING); fermentations.put(PotionType.NIGHT_VISION, PotionType.INVISIBILITY); } @@ -100,15 +100,13 @@ public AutoBrewer(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipe @ParametersAreNonnullByDefault private @Nullable ItemStack brew(Material input, Material potionType, PotionMeta potion) { - PotionData data = potion.getBasePotionData(); - - PotionType type = data.getType(); + PotionType type = potion.getBasePotionType(); if (type == PotionType.WATER) { if (input == Material.FERMENTED_SPIDER_EYE) { - potion.setBasePotionData(new PotionData(PotionType.WEAKNESS, false, false)); + potion.setBasePotionType(PotionType.WEAKNESS); return new ItemStack(potionType); } else if (input == Material.NETHER_WART) { - potion.setBasePotionData(new PotionData(PotionType.AWKWARD, false, false)); + potion.setBasePotionType(PotionType.AWKWARD); return new ItemStack(potionType); } else if (potionType == Material.POTION && input == Material.GUNPOWDER) { return new ItemStack(Material.SPLASH_POTION); @@ -119,22 +117,22 @@ public AutoBrewer(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipe PotionType fermented = fermentations.get(type); if (fermented != null) { - potion.setBasePotionData(new PotionData(fermented, data.isExtended(), data.isUpgraded())); + potion.setBasePotionType(fermented); return new ItemStack(potionType); } - } else if (input == Material.REDSTONE && type.isExtendable() && !data.isUpgraded()) { + } else if (input == Material.REDSTONE && type.isExtendable() && !type.isUpgradeable()) { // Fixes #3390 - Potions can only be either extended or upgraded. Not both. - potion.setBasePotionData(new PotionData(type, true, false)); + potion.setBasePotionType(type); return new ItemStack(potionType); - } else if (input == Material.GLOWSTONE_DUST && type.isUpgradeable() && !data.isExtended()) { + } else if (input == Material.GLOWSTONE_DUST && type.isUpgradeable() && !type.isExtendable()) { // Fixes #3390 - Potions can only be either extended or upgraded. Not both. - potion.setBasePotionData(new PotionData(type, false, true)); + potion.setBasePotionType(type); return new ItemStack(potionType); } else if (type == PotionType.AWKWARD) { PotionType potionRecipe = potionRecipes.get(input); if (potionRecipe != null) { - potion.setBasePotionData(new PotionData(potionRecipe, false, false)); + potion.setBasePotionType(potionRecipe); return new ItemStack(potionType); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java index 641454af49..b95bdf14ad 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java @@ -36,7 +36,6 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionType; /** @@ -214,7 +213,7 @@ protected void tick(@Nonnull Block b) { case BUBBLE_COLUMN: ItemStack waterBottle = new ItemStack(Material.POTION); PotionMeta meta = (PotionMeta) waterBottle.getItemMeta(); - meta.setBasePotionData(new PotionData(PotionType.WATER)); + meta.setBasePotionType(PotionType.WATER); waterBottle.setItemMeta(meta); return waterBottle; default: diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java index 7b62260ea4..702b410613 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java @@ -6,9 +6,9 @@ import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.entity.Ageable; import org.bukkit.entity.Entity; @@ -55,7 +55,12 @@ protected void tick(Block b) { n.getWorld() .spawnParticle( - Particle.VILLAGER_HAPPY, ((LivingEntity) n).getEyeLocation(), 8, 0.2F, 0.2F, 0.2F); + VersionedParticle.HAPPY_VILLAGER, + ((LivingEntity) n).getEyeLocation(), + 8, + 0.2F, + 0.2F, + 0.2F); return; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/CropGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/CropGrowthAccelerator.java index 881dd8547d..19340f8dc6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/CropGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/CropGrowthAccelerator.java @@ -6,10 +6,10 @@ import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.block.data.Ageable; import org.bukkit.inventory.ItemStack; @@ -66,7 +66,7 @@ private boolean grow(Block machine, BlockMenu inv, Block crop) { crop.getWorld() .spawnParticle( - Particle.VILLAGER_HAPPY, + VersionedParticle.HAPPY_VILLAGER, crop.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/TreeGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/TreeGrowthAccelerator.java index 0c5196fa72..d79a813b14 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/TreeGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/TreeGrowthAccelerator.java @@ -8,12 +8,12 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -import org.bukkit.Particle; import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -94,7 +94,7 @@ private boolean applyBoneMeal(Block machine, Block sapling, BlockMenu inv) { inv.consumeItem(slot); sapling.getWorld() .spawnParticle( - Particle.VILLAGER_HAPPY, + VersionedParticle.HAPPY_VILLAGER, sapling.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, @@ -119,7 +119,7 @@ private boolean updateSaplingData(Block machine, Block block, BlockMenu inv, Sap inv.consumeItem(slot); block.getWorld() .spawnParticle( - Particle.VILLAGER_HAPPY, + VersionedParticle.HAPPY_VILLAGER, block.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/EnchantmentRune.java index 994bfd39b2..7c1a65daa3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/EnchantmentRune.java @@ -8,6 +8,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import java.util.ArrayList; import java.util.Collection; import java.util.EnumMap; @@ -20,7 +21,6 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.SoundCategory; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; @@ -142,7 +142,7 @@ private void addRandomEnchantment(@Nonnull Player p, @Nonnull Item rune) { // Being sure entities are still valid and not picked up or whatsoever. if (rune.isValid() && item.isValid() && itemStack.getAmount() == 1) { - l.getWorld().spawnParticle(Particle.CRIT_MAGIC, l, 1); + l.getWorld().spawnParticle(VersionedParticle.ENCHANTED_HIT, l, 1); SoundEffect.ENCHANTMENT_RUNE_ADD_ENCHANT_SOUND.playAt(l, SoundCategory.PLAYERS); item.remove(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java index 602cd4bb58..e30d45bbef 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/VillagerRune.java @@ -10,6 +10,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; @@ -70,7 +71,7 @@ public VillagerRune( SoundEffect.VILLAGER_RUNE_TRANSFORM_SOUND.playAt(villager.getLocation(), SoundCategory.NEUTRAL); villager.getWorld() .spawnParticle(Particle.CRIMSON_SPORE, villager.getLocation(), 10, 0, offset / 2, 0, 0); - villager.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, villager.getLocation(), 5, 0.04, 1, 0.04); + villager.getWorld().spawnParticle(VersionedParticle.ENCHANT, villager.getLocation(), 5, 0.04, 1, 0.04); } }; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java index f0f708e655..0410d4a27d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Bandage.java @@ -6,6 +6,7 @@ import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Effect; import org.bukkit.GameMode; @@ -14,7 +15,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; /** * A {@link Bandage} or Rag is a medical supply which heals the {@link Player} and extinguishes @@ -57,7 +57,7 @@ public ItemUseHandler getItemHandler() { } p.getWorld().playEffect(p.getLocation(), Effect.STEP_SOUND, Material.WHITE_WOOL); - p.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, healingLevel)); + p.addPotionEffect(new PotionEffect(VersionedPotionEffectType.INSTANT_HEALTH, 1, healingLevel)); p.setFireTicks(0); e.cancel(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java index cef60f7c70..de32523200 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/MedicalSupply.java @@ -5,6 +5,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -30,10 +31,10 @@ protected MedicalSupply( curedEffects.add(PotionEffectType.POISON); curedEffects.add(PotionEffectType.WITHER); - curedEffects.add(PotionEffectType.SLOW); - curedEffects.add(PotionEffectType.SLOW_DIGGING); + curedEffects.add(VersionedPotionEffectType.SLOWNESS); + curedEffects.add(VersionedPotionEffectType.MINING_FATIGUE); curedEffects.add(PotionEffectType.WEAKNESS); - curedEffects.add(PotionEffectType.CONFUSION); + curedEffects.add(VersionedPotionEffectType.NAUSEA); curedEffects.add(PotionEffectType.BLINDNESS); curedEffects.add(PotionEffectType.BAD_OMEN); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java index f61887d194..0e54aa5429 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/medical/Splint.java @@ -7,6 +7,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.GameMode; @@ -14,7 +15,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; public class Splint extends SimpleSlimefunItem { @@ -45,7 +45,7 @@ public Splint( } SoundEffect.SPLINT_CONSUME_SOUND.playFor(p); - p.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 0)); + p.addPotionEffect(new PotionEffect(VersionedPotionEffectType.INSTANT_HEALTH, 1, 0)); e.cancel(); }; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java index fc8643a813..dd9387dcc2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/multiblocks/miner/MiningTask.java @@ -1,6 +1,5 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner; -import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils; import io.github.bakedlibs.dough.blocks.BlockPosition; import io.github.bakedlibs.dough.inventory.InvUtils; import io.github.bakedlibs.dough.items.ItemUtils; @@ -8,6 +7,7 @@ import io.github.bakedlibs.dough.scheduling.TaskQueue; import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import io.papermc.lib.PaperLib; import java.util.UUID; import java.util.logging.Level; @@ -18,7 +18,6 @@ import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.block.Block; @@ -196,9 +195,8 @@ public void run() { return; } - if (!StorageCacheUtils.hasBlock(b.getLocation()) - && miner.canMine(b) - && push(miner.getOutcome(b.getType()))) { + if (miner.canMine(b) && push(miner.getOutcome(b.getType()))) { + // Not changed since this is supposed to be a natural sound. furnace.getWorld().playEffect(furnace.getLocation(), Effect.STEP_SOUND, b.getType()); SoundEffect.MINING_TASK_SOUND.playAt(furnace); @@ -349,7 +347,7 @@ private void setPistonState(@Nonnull Block block, boolean extended) { try { // Smoke Particles around the Chest for dramatic effect Location particleLoc = chest.getLocation().clone().add(0, -1, 0); - block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, particleLoc, 20, 0.7, 0.7, 0.7, 0); + block.getWorld().spawnParticle(VersionedParticle.SMOKE, particleLoc, 20, 0.7, 0.7, 0.7, 0); if (block.getType() == Material.MOVING_PISTON) { // Yeah it isn't really cool when this happens diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java index f905681c00..e338ce9788 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java @@ -12,6 +12,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.settings.ClimbableSurface; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEnchantment; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import java.util.ArrayList; import java.util.Collection; @@ -144,7 +145,7 @@ public double getClimbingSpeed(@Nonnull ItemStack item, @Nonnull Material type) double speed = getClimbingSpeed(type); if (speed > 0) { - int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED); + int efficiencyLevel = item.getEnchantmentLevel(VersionedEnchantment.EFFICIENCY); if (efficiencyLevel > 0) { speed += efficiencyLevel * EFFICIENCY_MODIFIER; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java index 1ab730849f..f0594b8132 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/ExplosiveBow.java @@ -6,11 +6,11 @@ import io.github.thebusybiscuit.slimefun4.api.items.settings.IntRangeSetting; import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import java.util.Collection; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Bukkit; -import org.bukkit.Particle; import org.bukkit.SoundCategory; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; @@ -46,7 +46,7 @@ public ExplosiveBow(ItemGroup itemGroup, SlimefunItemStack item, ItemStack[] rec @Override public BowShootHandler onShoot() { return (e, target) -> { - target.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, target.getLocation(), 1); + target.getWorld().spawnParticle(VersionedParticle.EXPLOSION, target.getLocation(), 1); SoundEffect.EXPLOSIVE_BOW_HIT_SOUND.playAt(target.getLocation(), SoundCategory.PLAYERS); int radius = range.getValue(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java index 579c5c9948..0af9c1a09f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/weapons/IcyBow.java @@ -5,6 +5,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Effect; @@ -13,7 +14,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; /** * The {@link IcyBow} is a special kind of bow which slows down any @@ -46,8 +46,8 @@ public BowShootHandler onShoot() { } n.getWorld().playEffect(n.getLocation(), Effect.STEP_SOUND, Material.ICE); n.getWorld().playEffect(n.getEyeLocation(), Effect.STEP_SOUND, Material.ICE); - n.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20 * 2, 10)); - n.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20 * 2, -10)); + n.addPotionEffect(new PotionEffect(VersionedPotionEffectType.SLOWNESS, 20 * 2, 10)); + n.addPotionEffect(new PotionEffect(VersionedPotionEffectType.JUMP_BOOST, 20 * 2, -10)); }; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index fc3b5dec20..1be8b78169 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -17,6 +17,7 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; import io.github.thebusybiscuit.slimefun4.core.handlers.ToolUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEnchantment; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import java.util.ArrayList; import java.util.List; @@ -419,7 +420,7 @@ private int getBonusDropsWithFortune(@Nullable ItemStack item, @Nonnull Block b) * directly and reuse it. */ ItemMeta meta = item.getItemMeta(); - int fortuneLevel = meta.getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS); + int fortuneLevel = meta.getEnchantLevel(VersionedEnchantment.FORTUNE); if (fortuneLevel > 0 && !meta.hasEnchant(Enchantment.SILK_TOUCH)) { Random random = ThreadLocalRandom.current(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java index 88de8b882c..7063e13668 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java @@ -8,6 +8,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.MagicianTalisman; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman; import io.github.thebusybiscuit.slimefun4.implementation.settings.TalismanEnchantment; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEnchantment; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import java.util.ArrayList; import java.util.Collection; @@ -326,7 +327,7 @@ public void onEnchant(EnchantItemEvent e) { // Wizard Talisman if (!enchantments.containsKey(Enchantment.SILK_TOUCH) - && Enchantment.LOOT_BONUS_BLOCKS.canEnchantItem(e.getItem()) + && VersionedEnchantment.FORTUNE.canEnchantItem(e.getItem()) && Talisman.trigger(e, SlimefunItems.TALISMAN_WIZARD)) { // Randomly lower some enchantments for (Map.Entry entry : enchantments.entrySet()) { @@ -336,7 +337,7 @@ public void onEnchant(EnchantItemEvent e) { } // Give an extra Fortune boost (Lvl 3 - 5) - enchantments.put(Enchantment.LOOT_BONUS_BLOCKS, random.nextInt(3) + 3); + enchantments.put(VersionedEnchantment.FORTUNE, random.nextInt(3) + 3); } } @@ -378,7 +379,7 @@ private void doubleTalismanDrops( Collection drops = e.getItems(); if (Talisman.trigger(e, talismanItemStack, false)) { - int dropAmount = getAmountWithFortune(type, meta.getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS)); + int dropAmount = getAmountWithFortune(type, meta.getEnchantLevel(VersionedEnchantment.FORTUNE)); // Keep track of whether we actually doubled the drops or not boolean doubledDrops = false; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index e279ac287d..1435b4d75c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -202,6 +202,7 @@ import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import java.util.ArrayList; import java.util.List; import javax.annotation.Nonnull; @@ -699,7 +700,7 @@ SlimefunItems.SALT, new ItemStack(Material.COOKED_COD), null, null, null, null, null, new ItemStack(Material.IRON_INGOT) }, - new PotionEffect[] {new PotionEffect(PotionEffectType.JUMP, 300, 5)}, + new PotionEffect[] {new PotionEffect(VersionedPotionEffectType.JUMP_BOOST, 300, 5)}, SoundEffect.SLIME_BOOTS_FALL_SOUND) .register(plugin); @@ -2240,7 +2241,7 @@ SlimefunItems.SALT, new ItemStack(Material.COOKED_COD), null, null, null, null, true, true, "warrior", - new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 3600, 2)) + new PotionEffect(VersionedPotionEffectType.STRENGTH, 3600, 2)) .register(plugin); new Talisman( @@ -2278,7 +2279,7 @@ SlimefunItems.SALT, new ItemStack(Material.COOKED_COD), null, null, null, null, false, "caveman", 50, - new PotionEffect(PotionEffectType.FAST_DIGGING, 800, 2)) + new PotionEffect(VersionedPotionEffectType.HASTE, 800, 2)) .register(plugin); new Talisman( @@ -2824,7 +2825,7 @@ SlimefunItems.SALT, new ItemStack(Material.COOKED_COD), null, null, null, null, SlimefunItems.STEEL_PLATE, new ItemStack(Material.SLIME_BALL) }, - new PotionEffect[] {new PotionEffect(PotionEffectType.JUMP, 300, 5)}, + new PotionEffect[] {new PotionEffect(VersionedPotionEffectType.JUMP_BOOST, 300, 5)}, SoundEffect.SLIME_BOOTS_FALL_SOUND) .register(plugin); @@ -7764,7 +7765,7 @@ public int getCapacity() { null, new ItemStack(Material.HONEY_BLOCK) }, - new PotionEffect[] {new PotionEffect(PotionEffectType.JUMP, 300, 2)}, + new PotionEffect[] {new PotionEffect(VersionedPotionEffectType.JUMP_BOOST, 300, 2)}, SoundEffect.BEE_BOOTS_FALL_SOUND) .register(plugin); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java index da18f75a59..708b618093 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java @@ -7,6 +7,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal; import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedParticle; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; @@ -19,7 +20,6 @@ import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.SoundCategory; import org.bukkit.block.Block; import org.bukkit.entity.Item; @@ -121,12 +121,12 @@ private boolean checkLockedItems() { } private void idle() { - dropLocation.getWorld().spawnParticle(Particle.SPELL_WITCH, dropLocation, 16, 1.2F, 0F, 1.2F); - dropLocation.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, dropLocation, 8, 0.2F, 0F, 0.2F); + dropLocation.getWorld().spawnParticle(VersionedParticle.WITCH, dropLocation, 16, 1.2F, 0F, 1.2F); + dropLocation.getWorld().spawnParticle(VersionedParticle.FIREWORK, dropLocation, 8, 0.2F, 0F, 0.2F); for (Location loc : particleLocations) { - dropLocation.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, loc, 16, 0.3F, 0.2F, 0.3F); - dropLocation.getWorld().spawnParticle(Particle.CRIT_MAGIC, loc, 8, 0.3F, 0.2F, 0.3F); + dropLocation.getWorld().spawnParticle(VersionedParticle.ENCHANT, loc, 16, 0.3F, 0.2F, 0.3F); + dropLocation.getWorld().spawnParticle(VersionedParticle.ENCHANTED_HIT, loc, 8, 0.3F, 0.2F, 0.3F); } } @@ -144,15 +144,16 @@ private void checkPedestal(@Nonnull Block pedestal) { dropLocation .getWorld() .spawnParticle( - Particle.ENCHANTMENT_TABLE, + VersionedParticle.ENCHANT, pedestal.getLocation().add(0.5, 1.5, 0.5), 16, 0.3F, 0.2F, 0.3F); + dropLocation + .getWorld() + .spawnParticle( + VersionedParticle.ENCHANTED_HIT, pedestal.getLocation().add(0.5, 1.5, 0.5), - 16, + 8, 0.3F, 0.2F, 0.3F); - dropLocation - .getWorld() - .spawnParticle(Particle.CRIT_MAGIC, pedestal.getLocation().add(0.5, 1.5, 0.5), 8, 0.3F, 0.2F, 0.3F); positionLock.remove(entity); entity.remove(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java index 79e3b71184..6972158f16 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java @@ -9,6 +9,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.SolarHelmet; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import java.util.Collections; import java.util.HashSet; @@ -50,10 +51,10 @@ public ArmorTask(boolean radioactiveFire) { Set effects = new HashSet<>(); effects.add(new PotionEffect(PotionEffectType.WITHER, 400, 2)); effects.add(new PotionEffect(PotionEffectType.BLINDNESS, 400, 3)); - effects.add(new PotionEffect(PotionEffectType.CONFUSION, 400, 3)); + effects.add(new PotionEffect(VersionedPotionEffectType.NAUSEA, 400, 3)); effects.add(new PotionEffect(PotionEffectType.WEAKNESS, 400, 2)); - effects.add(new PotionEffect(PotionEffectType.SLOW, 400, 1)); - effects.add(new PotionEffect(PotionEffectType.SLOW_DIGGING, 400, 1)); + effects.add(new PotionEffect(VersionedPotionEffectType.SLOWNESS, 400, 1)); + effects.add(new PotionEffect(VersionedPotionEffectType.MINING_FATIGUE, 400, 1)); radiationEffects = Collections.unmodifiableSet(effects); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/storage/backend/legacy/LegacyStorage.java b/src/main/java/io/github/thebusybiscuit/slimefun4/storage/backend/legacy/LegacyStorage.java index ff74af328d..5851acafd1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/storage/backend/legacy/LegacyStorage.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/storage/backend/legacy/LegacyStorage.java @@ -23,6 +23,8 @@ public class LegacyStorage implements Storage { @Override public PlayerData loadPlayerData(@Nonnull UUID uuid) { + long start = System.nanoTime(); + Config playerFile = new Config("data-storage/Slimefun/Players/" + uuid + ".yml"); // Not too sure why this is its own file Config waypointsFile = new Config("data-storage/Slimefun/waypoints/" + uuid + ".yml"); @@ -47,9 +49,11 @@ public PlayerData loadPlayerData(@Nonnull UUID uuid) { items.put(i, playerFile.getItem("backpacks." + key + ".contents." + i)); } - // PlayerBackpack backpack = PlayerBackpack.load(uuid, id, size, items); + /* + PlayerBackpack backpack = PlayerBackpack.load(uuid, id, size, items); - // backpacks.put(id, backpack); + backpacks.put(id, backpack); + */ } catch (Exception x) { Slimefun.logger() .log( @@ -78,12 +82,17 @@ public PlayerData loadPlayerData(@Nonnull UUID uuid) { } } + long end = System.nanoTime(); + Slimefun.getAnalyticsService().recordPlayerProfileDataTime("legacy", true, end - start); + return new PlayerData(researches, backpacks, waypoints); } // The current design of saving all at once isn't great, this will be refined. @Override public void savePlayerData(@Nonnull UUID uuid, @Nonnull PlayerData data) { + long start = System.nanoTime(); + Config playerFile = new Config("data-storage/Slimefun/Players/" + uuid + ".yml"); // Not too sure why this is its own file Config waypointsFile = new Config("data-storage/Slimefun/waypoints/" + uuid + ".yml"); @@ -96,7 +105,15 @@ public void savePlayerData(@Nonnull UUID uuid, @Nonnull PlayerData data) { playerFile.setValue("researches." + research.getID(), true); // Remove the research if it's no longer researched - } else if (playerFile.contains("researches." + research.getID())) { + // ---- + // We have a duplicate ID (173) used for both Coal Gen and Bio Reactor + // If you researched the Goal Gen we would remove it on save if you didn't also have the Bio Reactor + // Due to the fact we would set it as researched (true in the branch above) on Coal Gen + // but then go into this branch and remove it if you didn't have Bio Reactor + // Sooooo we're gonna hack this for now while we move away from the Legacy Storage + // Let's make sure the user doesn't have _any_ research with this ID and _then_ remove it + } else if (playerFile.contains("researches." + research.getID()) + && !data.getResearches().stream().anyMatch((r) -> r.getID() == research.getID())) { playerFile.setValue("researches." + research.getID(), null); } } @@ -128,5 +145,8 @@ public void savePlayerData(@Nonnull UUID uuid, @Nonnull PlayerData data) { // Save files playerFile.save(); waypointsFile.save(); + + long end = System.nanoTime(); + Slimefun.getAnalyticsService().recordPlayerProfileDataTime("legacy", false, end - start); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/FireworkUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/FireworkUtils.java index a0bcf85f79..93cfd94fb1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/FireworkUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/FireworkUtils.java @@ -1,5 +1,7 @@ package io.github.thebusybiscuit.slimefun4.utils; +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nonnull; @@ -14,12 +16,14 @@ import org.bukkit.inventory.meta.FireworkMeta; /** - * This is a simple utility classs for spawning random and colorful {@link Firework} rockets. + * This is a simple utility class for spawning random and colorful {@link Firework} rockets. * * @author TheBusyBiscuit + * */ public final class FireworkUtils { + // @formatter:off private static final Color[] COLORS = { Color.AQUA, Color.BLACK, @@ -39,6 +43,17 @@ public final class FireworkUtils { Color.WHITE, Color.YELLOW }; + // @formatter:on + + private static final EntityType firework; + + static { + if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_20_5)) { + firework = EntityType.FIREWORK_ROCKET; + } else { + firework = EntityType.valueOf("FIREWORK"); + } + } private FireworkUtils() {} @@ -46,9 +61,8 @@ public static void launchFirework(@Nonnull Location l, @Nonnull Color color) { createFirework(l, color); } - @Nonnull - public static Firework createFirework(@Nonnull Location l, @Nonnull Color color) { - Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK); + public static @Nonnull Firework createFirework(@Nonnull Location l, @Nonnull Color color) { + Firework fw = (Firework) l.getWorld().spawnEntity(l, firework); FireworkMeta meta = fw.getFireworkMeta(); meta.setDisplayName(ChatColor.GREEN + "Slimefun Research"); @@ -72,18 +86,33 @@ public static void launchRandom(@Nonnull Entity n, int amount) { } } - @Nonnull - public static FireworkEffect getRandomEffect(@Nonnull Random random, @Nonnull Color color) { + /** + * This returns a randomized {@link FireworkEffect} using the given {@link Color}. + * + * @param random + * The {@link Random} instance to use + * @param color + * The {@link Color} of this {@link FireworkEffect} + * + * @return A randomized {@link FireworkEffect} + */ + public static @Nonnull FireworkEffect getRandomEffect(@Nonnull Random random, @Nonnull Color color) { + // @formatter:off return FireworkEffect.builder() .flicker(random.nextBoolean()) .withColor(color) .with(random.nextBoolean() ? Type.BALL : Type.BALL_LARGE) .trail(random.nextBoolean()) .build(); + // @formatter:on } - @Nonnull - private static Color getRandomColor() { + /** + * This returns a random {@link Color} for our {@link FireworkEffect}. + * + * @return A random {@link Color} + */ + private static @Nonnull Color getRandomColor() { return COLORS[ThreadLocalRandom.current().nextInt(COLORS.length)]; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index 17a1935c69..506ca3193d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -494,7 +494,7 @@ private static boolean equalsItemMeta( } if (itemMeta instanceof PotionMeta && sfitemMeta instanceof PotionMeta) { - return ((PotionMeta) itemMeta).getBasePotionData().equals(((PotionMeta) sfitemMeta).getBasePotionData()); + return ((PotionMeta) itemMeta).getBasePotionType().equals(((PotionMeta) sfitemMeta).getBasePotionType()); } return true; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedEnchantment.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedEnchantment.java new file mode 100644 index 0000000000..cdb127181d --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedEnchantment.java @@ -0,0 +1,63 @@ +package io.github.thebusybiscuit.slimefun4.utils.compatibility; + +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import java.lang.reflect.Field; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.bukkit.enchantments.Enchantment; + +// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java?until=2a6207fe150b6165722fce94c83cc1f206620ab5&untilPath=src%2Fmain%2Fjava%2Forg%2Fbukkit%2Fcraftbukkit%2Flegacy%2FFieldRename.java#86-110 +public class VersionedEnchantment { + + public static final Enchantment EFFICIENCY; + public static final Enchantment UNBREAKING; + public static final Enchantment PROTECTION; + public static final Enchantment SHARPNESS; + public static final Enchantment LUCK_OF_THE_SEA; + public static final Enchantment AQUA_AFFINITY; + public static final Enchantment FORTUNE; + + static { + MinecraftVersion version = Slimefun.getMinecraftVersion(); + + // DIG_SPEED is renamed to EFFICIENCY in 1.20.5 + EFFICIENCY = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Enchantment.EFFICIENCY : getKey("DIG_SPEED"); + + // DURABILITY is renamed to UNBREAKING in 1.20.5 + UNBREAKING = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Enchantment.UNBREAKING : getKey("DURABILITY"); + + // PROTECTION_ENVIRONMENTAL is renamed to PROTECTION in 1.20.5 + PROTECTION = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) + ? Enchantment.PROTECTION + : getKey("PROTECTION_ENVIRONMENTAL"); + + // DAMAGE_ALL is renamed to SHARPNESS in 1.20.5 + SHARPNESS = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Enchantment.SHARPNESS : getKey("DAMAGE_ALL"); + + // LUCK is renamed to LUCK_OF_THE_SEA in 1.20.5 + LUCK_OF_THE_SEA = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Enchantment.LUCK_OF_THE_SEA : getKey("LUCK"); + + // WATER_WORKER is renamed to AQUA_AFFINITY in 1.20.5 + AQUA_AFFINITY = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) + ? Enchantment.AQUA_AFFINITY + : getKey("WATER_WORKER"); + + // LOOT_BONUS_BLOCKS is renamed to FORTUNE in 1.20.5 + FORTUNE = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) + ? Enchantment.FORTUNE + : getKey("LOOT_BONUS_BLOCKS"); + } + + @Nullable private static Enchantment getKey(@Nonnull String key) { + try { + Field field = Enchantment.class.getDeclaredField(key); + return (Enchantment) field.get(null); + } catch (Exception e) { + return null; + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedEntityType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedEntityType.java new file mode 100644 index 0000000000..9fa8f01474 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedEntityType.java @@ -0,0 +1,35 @@ +package io.github.thebusybiscuit.slimefun4.utils.compatibility; + +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import java.lang.reflect.Field; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.bukkit.entity.EntityType; + +// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java?until=2a6207fe150b6165722fce94c83cc1f206620ab5&untilPath=src%2Fmain%2Fjava%2Forg%2Fbukkit%2Fcraftbukkit%2Flegacy%2FFieldRename.java#158-193 +public class VersionedEntityType { + + public static final EntityType MOOSHROOM; + public static final EntityType SNOW_GOLEM; + + static { + MinecraftVersion version = Slimefun.getMinecraftVersion(); + + // MUSHROOM_COW is renamed to MOOSHROOM in 1.20.5 + MOOSHROOM = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? EntityType.MOOSHROOM : getKey("MUSHROOM_COW"); + + // SNOWMAN is renamed to SNOW_GOLEM in 1.20.5 + SNOW_GOLEM = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? EntityType.SNOW_GOLEM : getKey("SNOWMAN"); + } + + @Nullable private static EntityType getKey(@Nonnull String key) { + try { + Field field = EntityType.class.getDeclaredField(key); + return (EntityType) field.get(null); + } catch (Exception e) { + return null; + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedItemFlag.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedItemFlag.java new file mode 100644 index 0000000000..24c5640725 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedItemFlag.java @@ -0,0 +1,30 @@ +package io.github.thebusybiscuit.slimefun4.utils.compatibility; + +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import java.lang.reflect.Field; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.bukkit.inventory.ItemFlag; + +public class VersionedItemFlag { + + public static final ItemFlag HIDE_ADDITIONAL_TOOLTIP; + + static { + MinecraftVersion version = Slimefun.getMinecraftVersion(); + + HIDE_ADDITIONAL_TOOLTIP = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) + ? ItemFlag.HIDE_ADDITIONAL_TOOLTIP + : getKey("HIDE_POTION_EFFECTS"); + } + + @Nullable private static ItemFlag getKey(@Nonnull String key) { + try { + Field field = ItemFlag.class.getDeclaredField(key); + return (ItemFlag) field.get(null); + } catch (Exception e) { + return null; + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedParticle.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedParticle.java new file mode 100644 index 0000000000..c13702fd31 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedParticle.java @@ -0,0 +1,62 @@ +package io.github.thebusybiscuit.slimefun4.utils.compatibility; + +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import java.lang.reflect.Field; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.bukkit.Particle; + +// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java?until=2a6207fe150b6165722fce94c83cc1f206620ab5&untilPath=src%2Fmain%2Fjava%2Forg%2Fbukkit%2Fcraftbukkit%2Flegacy%2FFieldRename.java#281-318 +public class VersionedParticle { + + public static final Particle DUST; + public static final Particle SMOKE; + public static final Particle HAPPY_VILLAGER; + public static final Particle ENCHANTED_HIT; + public static final Particle EXPLOSION; + public static final Particle WITCH; + public static final Particle FIREWORK; + public static final Particle ENCHANT; + + static { + MinecraftVersion version = Slimefun.getMinecraftVersion(); + + // REDSTONE is renamed to DUST in 1.20.5 + DUST = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Particle.DUST : getKey("REDSTONE"); + + // SMOKE_NORMAL is renamed to SMOKE in 1.20.5 + SMOKE = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Particle.SMOKE : getKey("SMOKE_NORMAL"); + + // VILLAGER_HAPPY is renamed to HAPPY_VILLAGER in 1.20.5 + HAPPY_VILLAGER = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) + ? Particle.HAPPY_VILLAGER + : getKey("VILLAGER_HAPPY"); + + // CRIT_MAGIC is renamed to ENCHANTED_HIT in 1.20.5 + ENCHANTED_HIT = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Particle.ENCHANTED_HIT : getKey("CRIT_MAGIC"); + + // EXPLOSION_LARGE is renamed to EXPLOSION in 1.20.5 + EXPLOSION = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Particle.EXPLOSION : getKey("EXPLOSION_LARGE"); + + // SPELL_WITCH is renamed to WITCH in 1.20.5 + WITCH = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Particle.WITCH : getKey("SPELL_WITCH"); + + // FIREWORKS_SPARK is renamed to FIREWORK in 1.20.5 + FIREWORK = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Particle.FIREWORK : getKey("FIREWORKS_SPARK"); + + // ENCHANTMENT_TABLE is renamed to ENCHANT in 1.20.5 + ENCHANT = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? Particle.ENCHANT : getKey("ENCHANTMENT_TABLE"); + } + + @Nullable private static Particle getKey(@Nonnull String key) { + try { + Field field = Particle.class.getDeclaredField(key); + return (Particle) field.get(null); + } catch (Exception e) { + return null; + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedPotionEffectType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedPotionEffectType.java new file mode 100644 index 0000000000..84f03c9a81 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedPotionEffectType.java @@ -0,0 +1,62 @@ +package io.github.thebusybiscuit.slimefun4.utils.compatibility; + +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import java.lang.reflect.Field; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.bukkit.potion.PotionEffectType; + +// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java?until=2a6207fe150b6165722fce94c83cc1f206620ab5&untilPath=src%2Fmain%2Fjava%2Forg%2Fbukkit%2Fcraftbukkit%2Flegacy%2FFieldRename.java#216-228 +public class VersionedPotionEffectType { + + public static final PotionEffectType SLOWNESS; + public static final PotionEffectType HASTE; + public static final PotionEffectType MINING_FATIGUE; + public static final PotionEffectType STRENGTH; + public static final PotionEffectType INSTANT_HEALTH; + public static final PotionEffectType INSTANT_DAMAGE; + public static final PotionEffectType JUMP_BOOST; + public static final PotionEffectType NAUSEA; + public static final PotionEffectType RESISTANCE; + + static { + MinecraftVersion version = Slimefun.getMinecraftVersion(); + + SLOWNESS = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionEffectType.SLOWNESS : getKey("SLOW"); + + HASTE = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionEffectType.HASTE : getKey("FAST_DIGGING"); + + MINING_FATIGUE = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) + ? PotionEffectType.MINING_FATIGUE + : getKey("SLOW_DIGGING"); + + STRENGTH = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) + ? PotionEffectType.STRENGTH + : getKey("INCREASE_DAMAGE"); + + INSTANT_HEALTH = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionEffectType.INSTANT_HEALTH : getKey("HEAL"); + + INSTANT_DAMAGE = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionEffectType.INSTANT_DAMAGE : getKey("HARM"); + + JUMP_BOOST = + version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionEffectType.JUMP_BOOST : getKey("JUMP"); + + NAUSEA = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionEffectType.NAUSEA : getKey("CONFUSION"); + + RESISTANCE = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) + ? PotionEffectType.RESISTANCE + : getKey("DAMAGE_RESISTANCE"); + } + + @Nullable private static PotionEffectType getKey(@Nonnull String key) { + try { + Field field = PotionEffectType.class.getDeclaredField(key); + return (PotionEffectType) field.get(null); + } catch (Exception e) { + return null; + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedPotionType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedPotionType.java new file mode 100644 index 0000000000..52908146f1 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/compatibility/VersionedPotionType.java @@ -0,0 +1,41 @@ +package io.github.thebusybiscuit.slimefun4.utils.compatibility; + +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import java.lang.reflect.Field; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.bukkit.potion.PotionType; + +// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java?until=2a6207fe150b6165722fce94c83cc1f206620ab5&untilPath=src%2Fmain%2Fjava%2Forg%2Fbukkit%2Fcraftbukkit%2Flegacy%2FFieldRename.java#242-250 +public class VersionedPotionType { + + public static final PotionType LEAPING; + public static final PotionType SWIFTNESS; + public static final PotionType HEALING; + public static final PotionType HARMING; + public static final PotionType REGENERATION; + + static { + MinecraftVersion version = Slimefun.getMinecraftVersion(); + + LEAPING = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionType.LEAPING : getKey("JUMP"); + + SWIFTNESS = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionType.SWIFTNESS : getKey("SPEED"); + + HEALING = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionType.HEALING : getKey("INSTANT_HEAL"); + + HARMING = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionType.HARMING : getKey("INSTANT_DAMAGE"); + + REGENERATION = version.isAtLeast(MinecraftVersion.MINECRAFT_1_20_5) ? PotionType.REGENERATION : getKey("REGEN"); + } + + @Nullable private static PotionType getKey(@Nonnull String key) { + try { + Field field = PotionType.class.getDeclaredField(key); + return (PotionType) field.get(null); + } catch (Exception e) { + return null; + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ColoredFireworkStar.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ColoredFireworkStar.java index 55b9731528..65bef8cf16 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ColoredFireworkStar.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/itemstack/ColoredFireworkStar.java @@ -2,6 +2,7 @@ import io.github.bakedlibs.dough.common.ChatColors; import io.github.bakedlibs.dough.items.CustomItemStack; +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedItemFlag; import java.util.ArrayList; import java.util.List; import javax.annotation.ParametersAreNonnullByDefault; @@ -9,7 +10,6 @@ import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Type; import org.bukkit.Material; -import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.FireworkEffectMeta; @@ -45,7 +45,7 @@ public ColoredFireworkStar(Color color, String name, String... lore) { im.setLore(lines); } - im.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + im.addItemFlags(VersionedItemFlag.HIDE_ADDITIONAL_TOOLTIP); }); } } From 5753e69d769c42c2a3d80ed6207fefa0b2194cc1 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Mon, 1 Jul 2024 02:53:52 +0800 Subject: [PATCH 02/14] chore: update dough --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e3081e8382..98ab6c1670 100644 --- a/pom.xml +++ b/pom.xml @@ -277,7 +277,7 @@ com.github.starwishsama.dough dough-api - f266e39d48 + d783252831 compile From c08a04c91de78465c858ae39cdf487c3725c6b35 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 11:39:56 +0800 Subject: [PATCH 03/14] fix: misjudge version code --- .../slimefun4/api/MinecraftVersion.java | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java index d50b93199d..e9aaedad5b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java @@ -11,9 +11,7 @@ * * @author TheBusyBiscuit * @author Walshy - * * @see Slimefun - * */ public enum MinecraftVersion { @@ -75,10 +73,8 @@ public enum MinecraftVersion { * This constructor forces the {@link MinecraftVersion} to be real. * It must be a real version of Minecraft. * - * @param majorVersion - * The major version of minecraft as an {@link Integer} - * @param name - * The display name of this {@link MinecraftVersion} + * @param majorVersion The major version of minecraft as an {@link Integer} + * @param name The display name of this {@link MinecraftVersion} */ MinecraftVersion(int majorVersion, @Nonnull String name) { this.name = name; @@ -92,12 +88,9 @@ public enum MinecraftVersion { * This constructor forces the {@link MinecraftVersion} to be real. * It must be a real version of Minecraft. * - * @param majorVersion - * The major (minor in semver, major in MC land) version of minecraft as an {@link Integer} - * @param minor - * The minor (patch in semver, minor in MC land) version of minecraft as an {@link Integer} - * @param name - * The display name of this {@link MinecraftVersion} + * @param majorVersion The major (minor in semver, major in MC land) version of minecraft as an {@link Integer} + * @param minor The minor (patch in semver, minor in MC land) version of minecraft as an {@link Integer} + * @param name The display name of this {@link MinecraftVersion} */ MinecraftVersion(int majorVersion, int minor, @Nonnull String name) { this.name = name; @@ -111,10 +104,8 @@ public enum MinecraftVersion { * A virtual {@link MinecraftVersion} (unknown or unit test) is not an actual * version of Minecraft but rather a state of the {@link Server} software. * - * @param name - * The display name of this {@link MinecraftVersion} - * @param virtual - * Whether this {@link MinecraftVersion} is virtual + * @param name The display name of this {@link MinecraftVersion} + * @param virtual Whether this {@link MinecraftVersion} is virtual */ MinecraftVersion(@Nonnull String name, boolean virtual) { this.name = name; @@ -154,9 +145,7 @@ public boolean isVirtual() { *

* Example: {@literal "1.13"} returns {@literal 13} * - * @param minecraftVersion - * The {@link Integer} version to match - * + * @param minecraftVersion The {@link Integer} version to match * @return Whether this {@link MinecraftVersion} matches the specified version id */ public boolean isMinecraftVersion(int minecraftVersion) { @@ -175,15 +164,21 @@ public boolean isMinecraftVersion(int minecraftVersion) { * Example: {@literal "1.13"} returns {@literal 13}
* Exampe: {@literal "1.13.2"} returns {@literal 13_2} * - * @param minecraftVersion - * The {@link Integer} version to match - * + * @param minecraftVersion The {@link Integer} version to match * @return Whether this {@link MinecraftVersion} matches the specified version id */ public boolean isMinecraftVersion(int minecraftVersion, int patchVersion) { - return !isVirtual() - && this.majorVersion == minecraftVersion - && (this.minorVersion == -1 || this.minorVersion >= patchVersion); + if (isVirtual()) { + return false; + } + + if (this.majorVersion != 20) { + return this.majorVersion == minecraftVersion && this.minorVersion >= patchVersion; + } else { + return this.majorVersion == minecraftVersion && this.minorVersion == -1 + ? patchVersion < 5 + : patchVersion >= minorVersion; + } } /** @@ -192,9 +187,7 @@ public boolean isMinecraftVersion(int minecraftVersion, int patchVersion) { * * An unknown version will default to {@literal false}. * - * @param version - * The {@link MinecraftVersion} to compare - * + * @param version The {@link MinecraftVersion} to compare * @return Whether this {@link MinecraftVersion} is newer or equal to the given {@link MinecraftVersion} */ public boolean isAtLeast(@Nonnull MinecraftVersion version) { @@ -227,9 +220,7 @@ public boolean isAtLeast(@Nonnull MinecraftVersion version) { * * An unknown version will default to {@literal true}. * - * @param version - * The {@link MinecraftVersion} to compare - * + * @param version The {@link MinecraftVersion} to compare * @return Whether this {@link MinecraftVersion} is older than the given one */ public boolean isBefore(@Nonnull MinecraftVersion version) { From 738d43ad6334caa3d2cf4156848e51dfaef9d454 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 11:52:52 +0800 Subject: [PATCH 04/14] chore: update to java 21 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 98ab6c1670..71d53817d9 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ - 5.0-SNAPSHOT + UNOFFICIAL 2013 jar @@ -113,8 +113,8 @@ **/package-info.java - 16 - 16 + 21 + 21 org.projectlombok From 4e15ba149f6e0dd7e7c722aea08426f916f0d6b8 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 12:03:58 +0800 Subject: [PATCH 05/14] chore: use unified `JAVA_CI_VERSION` variable --- .github/workflows/build-ci.yml | 2 +- .github/workflows/dev-ci.yml | 2 +- .github/workflows/e2e-testing.yml | 2 +- .github/workflows/pr-checker.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 6fe3fbe0b6..a352826077 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/setup-java@v2 with: distribution: 'zulu' - java-version: 17 + java-version: ${{ env.JAVA_CI_VERSION }} java-package: jdk architecture: x64 cache: maven diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index b902674614..5da59dcc24 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 17 + java-version: ${{ env.JAVA_CI_VERSION }} java-package: jdk architecture: x64 cache: maven diff --git a/.github/workflows/e2e-testing.yml b/.github/workflows/e2e-testing.yml index d48a0e1495..b6700ea5f0 100644 --- a/.github/workflows/e2e-testing.yml +++ b/.github/workflows/e2e-testing.yml @@ -26,7 +26,7 @@ jobs: - mcVersion: '1.19.4' javaVersion: '19' - mcVersion: 'latest' - javaVersion: '20' + javaVersion: '21' steps: - name: Checkout repository diff --git a/.github/workflows/pr-checker.yml b/.github/workflows/pr-checker.yml index 64f7c9fdd5..ab7e523e65 100644 --- a/.github/workflows/pr-checker.yml +++ b/.github/workflows/pr-checker.yml @@ -24,11 +24,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Set up JDK uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 17 + java-version: ${{ env.JAVA_CI_VERSION }} java-package: jdk architecture: x64 From 4243404f430444320dde4d82583f2cfb4b83bc25 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 12:12:17 +0800 Subject: [PATCH 06/14] chore: fixing ci --- .github/workflows/build-ci.yml | 2 +- .github/workflows/dev-ci.yml | 2 +- .github/workflows/pr-checker.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index a352826077..4b2c0fabfb 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/setup-java@v2 with: distribution: 'zulu' - java-version: ${{ env.JAVA_CI_VERSION }} + java-version: ${{ vars.JAVA_CI_VERSION }} java-package: jdk architecture: x64 cache: maven diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index 5da59dcc24..054556c0c7 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: ${{ env.JAVA_CI_VERSION }} + java-version: ${{ vars.JAVA_CI_VERSION }} java-package: jdk architecture: x64 cache: maven diff --git a/.github/workflows/pr-checker.yml b/.github/workflows/pr-checker.yml index ab7e523e65..9b09d247d7 100644 --- a/.github/workflows/pr-checker.yml +++ b/.github/workflows/pr-checker.yml @@ -28,7 +28,7 @@ jobs: uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: ${{ env.JAVA_CI_VERSION }} + java-version: ${{ vars.JAVA_CI_VERSION }} java-package: jdk architecture: x64 From 0dde6b2f7ad63a7f4d2082625b7be66d8a69d564 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:17:07 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=F0=9F=94=A7=20bump=20org.projectlombok:l?= =?UTF-8?q?ombok=20from=201.18.30=20to=201.18.34=20(#913)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [org.projectlombok:lombok](https://github.com/projectlombok/lombok) from 1.18.30 to 1.18.34. - [Changelog](https://github.com/projectlombok/lombok/blob/master/doc/changelog.markdown) - [Commits](https://github.com/projectlombok/lombok/compare/v1.18.30...v1.18.34) --- updated-dependencies: - dependency-name: org.projectlombok:lombok dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 71d53817d9..9db9e01dae 100644 --- a/pom.xml +++ b/pom.xml @@ -119,7 +119,7 @@ org.projectlombok lombok - 1.18.30 + 1.18.34 @@ -269,7 +269,7 @@ org.projectlombok lombok - 1.18.30 + 1.18.34 provided From 759e89be14d45510106c1a8116021d75d9422fb6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:17:17 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=F0=9F=94=A7=20bump=20org.apache.maven.pl?= =?UTF-8?q?ugins:maven-compiler-plugin=20(#889)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.12.1 to 3.13.0. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.12.1...maven-compiler-plugin-3.13.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9db9e01dae..856e152453 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.12.1 + 3.13.0 From fe47722031d032b5c090c1de7b922958b54ee39b Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 13:33:16 +0800 Subject: [PATCH 09/14] fix: update online player username --- .../storage/controller/ProfileDataController.java | 15 +++++++++++++++ .../implementation/listeners/JoinListener.java | 13 +++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java b/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java index e6e77bf549..d531782ae6 100644 --- a/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java +++ b/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java @@ -299,6 +299,21 @@ public void getPlayerUuidAsync(String pName, IAsyncReadCallback callback) scheduleReadTask(() -> invokeCallback(callback, getPlayerUuid(pName))); } + public void updateUsername(String uuid, String newName) { + var key = new RecordKey(DataScope.PLAYER_PROFILE); + key.addCondition(FieldKey.PLAYER_UUID, uuid); + + var result = getData(key); + if (result.isEmpty()) { + return; + } + + var data = new RecordSet(); + data.put(FieldKey.PLAYER_NAME, newName); + + scheduleWriteTask(new UUIDKey(DataScope.NONE, uuid), key, data, false); + } + private static RecordSet getRecordSet(PlayerBackpack bp) { var re = new RecordSet(); re.put(FieldKey.PLAYER_UUID, bp.getOwner().getUniqueId().toString()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java index a6339f90e7..51123af2d1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java @@ -7,6 +7,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RadiationTask; import javax.annotation.Nonnull; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -27,8 +28,16 @@ public JoinListener(@Nonnull Slimefun plugin) { @EventHandler public void onJoin(@Nonnull PlayerJoinEvent e) { - PlayerProfile.get(e.getPlayer(), playerProfile -> { - final ItemStack[] armorContents = e.getPlayer().getInventory().getArmorContents(); + final var p = e.getPlayer(); + + PlayerProfile.get(p, playerProfile -> { + if (Bukkit.getOnlineMode()) { + Slimefun.getDatabaseManager() + .getProfileDataController() + .updateUsername(p.getUniqueId().toString(), p.getName()); + } + + final ItemStack[] armorContents = p.getInventory().getArmorContents(); final HashedArmorpiece[] hashedArmorpieces = playerProfile.getArmor(); for (int i = 0; i < 4; i++) { final ItemStack armorPiece = armorContents[i]; From e7c599d8bef7b31f45dbfed0167a9a64213b2441 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 13:52:37 +0800 Subject: [PATCH 10/14] fix: update online player username --- .../slimefun4/storage/controller/ProfileDataController.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java b/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java index d531782ae6..c6200b7769 100644 --- a/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java +++ b/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java @@ -301,13 +301,9 @@ public void getPlayerUuidAsync(String pName, IAsyncReadCallback callback) public void updateUsername(String uuid, String newName) { var key = new RecordKey(DataScope.PLAYER_PROFILE); + key.addField(FieldKey.PLAYER_NAME); key.addCondition(FieldKey.PLAYER_UUID, uuid); - var result = getData(key); - if (result.isEmpty()) { - return; - } - var data = new RecordSet(); data.put(FieldKey.PLAYER_NAME, newName); From 79f8e8dbd1cdfc1e266fd36e2580b85f042bed55 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 14:02:15 +0800 Subject: [PATCH 11/14] fix(util): confused `checkCustomModelData` --- .../github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index 506ca3193d..fca5598c5f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -460,7 +460,7 @@ private static boolean equalsItemMeta( @Nonnull ItemMeta itemMeta, @Nonnull ItemMeta sfitemMeta, boolean checkLore, - boolean bypassCustomModelCheck) { + boolean checkCustomModelCheck) { if (itemMeta.hasDisplayName() != sfitemMeta.hasDisplayName()) { return false; } else if (itemMeta.hasDisplayName() @@ -480,7 +480,7 @@ private static boolean equalsItemMeta( } } - if (!bypassCustomModelCheck) { + if (checkCustomModelCheck) { // Fixes #3133: name and lore are not enough boolean hasItemMetaCustomModelData = itemMeta.hasCustomModelData(); boolean hasSfItemMetaCustomModelData = sfitemMeta.hasCustomModelData(); From 573b66e145d192915cd6fff35501849b04414317 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 14:02:59 +0800 Subject: [PATCH 12/14] fix(util): confused `checkCustomModelData` --- .../thebusybiscuit/slimefun4/utils/SlimefunUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index fca5598c5f..b16e0e8025 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -411,14 +411,14 @@ public static boolean isItemSimilar( private static boolean equalsItemMeta( @Nonnull ItemMeta itemMeta, @Nonnull ItemMetaSnapshot itemMetaSnapshot, boolean checkLore) { - return equalsItemMeta(itemMeta, itemMetaSnapshot, checkLore, true); + return equalsItemMeta(itemMeta, itemMetaSnapshot, checkLore, false); } private static boolean equalsItemMeta( @Nonnull ItemMeta itemMeta, @Nonnull ItemMetaSnapshot itemMetaSnapshot, boolean checkLore, - boolean bypassCustomModelCheck) { + boolean checkCustomModelCheck) { Optional displayName = itemMetaSnapshot.getDisplayName(); if (itemMeta.hasDisplayName() != displayName.isPresent()) { @@ -437,7 +437,7 @@ private static boolean equalsItemMeta( } } - if (bypassCustomModelCheck) { + if (!checkCustomModelCheck) { return true; } From 4390b5eadae1372ef813044a3047e2a58b943f8e Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 4 Jul 2024 14:14:24 +0800 Subject: [PATCH 13/14] fix: try to update username on player login --- .../slimefun4/implementation/listeners/JoinListener.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java index 51123af2d1..1dab165387 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java @@ -7,7 +7,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RadiationTask; import javax.annotation.Nonnull; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -31,11 +30,9 @@ public void onJoin(@Nonnull PlayerJoinEvent e) { final var p = e.getPlayer(); PlayerProfile.get(p, playerProfile -> { - if (Bukkit.getOnlineMode()) { - Slimefun.getDatabaseManager() - .getProfileDataController() - .updateUsername(p.getUniqueId().toString(), p.getName()); - } + Slimefun.getDatabaseManager() + .getProfileDataController() + .updateUsername(p.getUniqueId().toString(), p.getName()); final ItemStack[] armorContents = p.getInventory().getArmorContents(); final HashedArmorpiece[] hashedArmorpieces = playerProfile.getArmor(); From fe1a0c7b29d69e29f2343d20a8b8958b77320b3c Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Fri, 5 Jul 2024 16:29:23 +0800 Subject: [PATCH 14/14] fix(util): force check id when both have id (#912) --- .../slimefun4/utils/SlimefunUtils.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index b16e0e8025..339a22c3c2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -361,9 +361,7 @@ public static boolean isItemSimilar( .getItemData(possibleSfItemMeta) .orElse(null); // Prioritize SlimefunItem id comparison over ItemMeta comparison - if (id != null && id.equals(possibleItemId)) { - Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs matched!"); - + if (id != null && possibleItemId != null) { /* * PR #3417 * @@ -374,14 +372,20 @@ public static boolean isItemSimilar( if (optionalDistinctive.isPresent()) { return optionalDistinctive.get().canStack(possibleSfItemMeta, itemMeta); } - return true; + + var match = id.equals(possibleItemId); + + Debug.log(TestCase.CARGO_INPUT_TESTING, " Use Item ID match: {}", match); + + return match; } else { Debug.log( TestCase.CARGO_INPUT_TESTING, - " Item IDs don't match, checking meta {} == {} (lore: {})", + " one of item have no Slimefun ID, checking meta {} == {} (lore: {})", itemMeta, possibleSfItemMeta, checkLore); + return equalsItemMeta(itemMeta, possibleSfItemMeta, checkLore, checkCustomModelData); } } else if (sfitem.hasItemMeta()) { @@ -462,10 +466,12 @@ private static boolean equalsItemMeta( boolean checkLore, boolean checkCustomModelCheck) { if (itemMeta.hasDisplayName() != sfitemMeta.hasDisplayName()) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing has display name failed"); return false; } else if (itemMeta.hasDisplayName() && sfitemMeta.hasDisplayName() && !itemMeta.getDisplayName().equals(sfitemMeta.getDisplayName())) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing display name failed"); return false; } else if (checkLore) { boolean hasItemMetaLore = itemMeta.hasLore(); @@ -473,9 +479,11 @@ private static boolean equalsItemMeta( if (hasItemMetaLore && hasSfItemMetaLore) { if (!equalsLore(itemMeta.getLore(), sfitemMeta.getLore())) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing lore failed"); return false; } } else if (hasItemMetaLore != hasSfItemMetaLore) { + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing has lore failed"); return false; } } @@ -497,6 +505,8 @@ private static boolean equalsItemMeta( return ((PotionMeta) itemMeta).getBasePotionType().equals(((PotionMeta) sfitemMeta).getBasePotionType()); } + Debug.log(TestCase.CARGO_INPUT_TESTING, " All meta checked."); + return true; }