diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 49fe209a18..a4a76c6b1b 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: ${{ 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 ca1d99d992..d6d53547ae 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: ${{ vars.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 51721413e5..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 @@ -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/.github/workflows/pr-checker.yml b/.github/workflows/pr-checker.yml index 64f7c9fdd5..9b09d247d7 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: ${{ vars.JAVA_CI_VERSION }} java-package: jdk architecture: x64 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/pom.xml b/pom.xml index 5ce886f565..856e152453 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ - 5.0-SNAPSHOT + UNOFFICIAL 2013 jar @@ -26,7 +26,7 @@ 16 - 1.20 + 1.20.6 https://hub.spigotmc.org/javadocs/spigot/ @@ -105,7 +105,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.12.1 + 3.13.0 @@ -113,13 +113,13 @@ **/package-info.java - 16 - 16 + 21 + 21 org.projectlombok lombok - 1.18.30 + 1.18.34 @@ -269,7 +269,7 @@ org.projectlombok lombok - 1.18.30 + 1.18.34 provided @@ -277,7 +277,7 @@ com.github.starwishsama.dough dough-api - f266e39d48 + d783252831 compile 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 26f63a5b8b..0749df397a 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 @@ -316,6 +316,17 @@ 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.addField(FieldKey.PLAYER_NAME); + key.addCondition(FieldKey.PLAYER_UUID, uuid); + + 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/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java index e27daa26d4..e46ce376a8 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 { @@ -47,6 +45,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 @@ -58,20 +62,36 @@ public enum MinecraftVersion { @Getter private final boolean virtual; private final int majorVersion; + private final int minorVersion; /** * 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 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, 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, String name) { + this.name = name; + this.majorVersion = majorVersion; + this.minorVersion = minor; this.virtual = false; } @@ -80,14 +100,13 @@ 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(String name, boolean virtual) { this.name = name; this.majorVersion = 0; + this.minorVersion = -1; this.virtual = virtual; } @@ -100,13 +119,40 @@ public enum MinecraftVersion { *

* 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) { - 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) { + 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; + } } /** @@ -115,9 +161,7 @@ public boolean isMinecraftVersion(int minecraftVersion) { * * 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(MinecraftVersion version) { @@ -135,9 +179,7 @@ public boolean isAtLeast(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(MinecraftVersion version) { 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 4a9a3be67a..33535ec236 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; @@ -24,7 +25,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} @@ -256,7 +256,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 ed48627d0f..2790bdcbd4 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; @@ -86,7 +87,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; } @@ -179,9 +180,7 @@ public void add(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()); } @@ -224,9 +223,7 @@ public ItemStack getItem(Player p) { 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 69857ea431..9bd72c0af5 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 @@ -8,12 +8,13 @@ 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 lombok.Getter; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.serialization.SerializableAs; -import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; @@ -23,11 +24,7 @@ import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Base64; -import java.util.List; -import java.util.Locale; -import java.util.Optional; +import java.util.*; import java.util.function.Consumer; /** @@ -42,6 +39,7 @@ public class SlimefunItemStack extends ItemStack { private final String id; + @Getter private ItemMetaSnapshot itemMetaSnapshot; private boolean locked = false; @@ -166,7 +164,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); } } }); @@ -242,10 +240,6 @@ public final String getItemId() { return type.isInstance(item) ? type.cast(item) : null; } - public ItemMetaSnapshot getItemMetaSnapshot() { - return itemMetaSnapshot; - } - @Override public boolean setItemMeta(ItemMeta meta) { validate(); 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 22e5a6cf74..55922dafd4 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 @@ -6,6 +6,7 @@ import io.github.thebusybiscuit.slimefun4.core.networks.NetworkManager; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.listeners.NetworkListener; + import java.util.ArrayDeque; import java.util.HashSet; import java.util.Queue; @@ -14,6 +15,7 @@ import lombok.Getter; import org.apache.commons.lang.Validate; +import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Particle; @@ -21,10 +23,8 @@ * An abstract Network class to manage networks in a stateful way * * @author meiamsome - * * @see NetworkListener * @see NetworkManager - * */ public abstract class Network { @@ -48,10 +48,8 @@ public abstract class Network { /** * This constructs a new {@link Network} at the given {@link Location}. * - * @param manager - * The {@link NetworkManager} instance - * @param regulator - * The {@link Location} marking the regulator of this {@link Network}. + * @param manager The {@link NetworkManager} instance + * @param regulator The {@link Location} marking the regulator of this {@link Network}. */ protected Network(NetworkManager manager, Location regulator) { Validate.notNull(manager, "A NetworkManager must be provided"); @@ -68,7 +66,7 @@ protected Network(NetworkManager manager, Location regulator) { * This method returns the range of the {@link Network}. * The range determines how far the {@link Network} will search for * nearby nodes from any given node. - * + *

* It basically translates to the maximum distance between nodes. * * @return the range of this {@link Network} @@ -79,23 +77,19 @@ protected Network(NetworkManager manager, Location regulator) { * This method assigns the given {@link Location} a type of {@link NetworkComponent} * for classification. * - * @param l - * The {@link Location} to classify - * + * @param l The {@link Location} to classify * @return The assigned type of {@link NetworkComponent} for this {@link Location} */ - @Nullable public abstract NetworkComponent classifyLocation(Location l); + @Nullable + public abstract NetworkComponent classifyLocation(Location l); /** * This method is called whenever a {@link Location} in this {@link Network} changes * its classification. * - * @param l - * The {@link Location} that is changing its classification - * @param from - * The {@link NetworkComponent} this {@link Location} was previously classified as - * @param to - * The {@link NetworkComponent} this {@link Location} is changing to + * @param l The {@link Location} that is changing its classification + * @param from The {@link NetworkComponent} this {@link Location} was previously classified as + * @param to The {@link NetworkComponent} this {@link Location} is changing to */ public abstract void onClassificationChange(Location l, NetworkComponent from, NetworkComponent to); @@ -112,8 +106,7 @@ public int getSize() { /** * This method adds the given {@link Location} to this {@link Network}. * - * @param l - * The {@link Location} to add + * @param l The {@link Location} to add */ protected void addLocationToNetwork(Location l) { if (connectedLocations.add(l.clone())) { @@ -125,8 +118,7 @@ protected void addLocationToNetwork(Location l) { * This method marks the given {@link Location} as dirty and adds it to a {@link Queue} * to handle this update. * - * @param l - * The {@link Location} to update + * @param l The {@link Location} to update */ public void markDirty(Location l) { Debug.log(TestCase.ENERGYNET, "Mark location " + LocationUtils.locationToString(l) + " as dirty block"); @@ -141,9 +133,7 @@ public void markDirty(Location l) { /** * This method checks whether the given {@link Location} is part of this {@link Network}. * - * @param l - * The {@link Location} to check for - * + * @param l The {@link Location} to check for * @return Whether the given {@link Location} is part of this {@link Network} */ public boolean connectsTo(Location l) { @@ -154,7 +144,8 @@ public boolean connectsTo(Location l) { } } - @Nullable private NetworkComponent getCurrentClassification(Location l) { + @Nullable + private NetworkComponent getCurrentClassification(Location l) { if (regulatorNodes.contains(l)) { return NetworkComponent.REGULATOR; } else if (connectorNodes.contains(l)) { @@ -177,7 +168,7 @@ private void discoverStep() { if (classification != currentAssignment) { if (currentAssignment == NetworkComponent.REGULATOR - || currentAssignment == NetworkComponent.CONNECTOR) { + || currentAssignment == NetworkComponent.CONNECTOR) { // Requires a complete rebuild of the network, so we just throw the current one away. manager.unregisterNetwork(this); return; @@ -228,7 +219,7 @@ private void discoverNeighbors(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 44aa1dbccd..bfc5a95486 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,8 +1,12 @@ 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; /** @@ -15,7 +19,7 @@ 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. @@ -27,8 +31,11 @@ class NetworkVisualizer implements Runnable { * * @param network The {@link Network} to visualize */ - NetworkVisualizer(Network network) { + NetworkVisualizer(Network network, 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 @@ -50,6 +57,15 @@ public void run() { private void spawnParticles(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 b0b045e844..a6bff54ff9 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,7 +3,10 @@ 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.Nullable; + import org.bukkit.Sound; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -14,15 +17,13 @@ /** * This interface, when attached to a {@link SlimefunItem}, provides an easy method for damaging * an {@link ItemStack}, see {@link #damageItem(Player, ItemStack)}. - * + *

* It also provides a simple {@link #isDamageable()} method, in case you wanna add a config * option that decides whether or not this {@link SlimefunItem} shall be damageable. * * @author TheBusyBiscuit * @author RobotHanzo - * * @see UnbreakingAlgorithm - * */ public interface DamageableItem extends ItemAttribute { @@ -38,17 +39,15 @@ public interface DamageableItem extends ItemAttribute { /** * This method will damage the given {@link ItemStack} once. * It also takes into account the {@link Enchantment} {@code Unbreaking}. - * + *

* It will only apply the damage if {@link #isDamageable()} returned true. * - * @param p - * The {@link Player} to which the item belongs - * @param item - * The {@link ItemStack} to damage + * @param p The {@link Player} to which the item belongs + * @param item The {@link ItemStack} to damage */ default void damageItem(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; @@ -77,11 +76,8 @@ default void damageItem(Player p, @Nullable ItemStack item) { * boolean * This function should be overridden when the item type is not a tool which is the default value * - * @param unbreakingLevel - * The {@link Integer} level of the unbreaking {@link Enchantment} - * + * @param unbreakingLevel The {@link Integer} level of the unbreaking {@link Enchantment} * @return Whether to save the item from taking damage - * */ default boolean evaluateUnbreakingEnchantment(int unbreakingLevel) { return UnbreakingAlgorithm.TOOLS.evaluate(unbreakingLevel); 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 213b42a8df..dcbdf039d2 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 org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -20,11 +21,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 0d07711240..736e1ee08a 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 @@ -23,7 +23,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..c46ed69d57 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/AnalyticsService.java @@ -0,0 +1,147 @@ +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 + 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(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) 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); + 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()); + 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/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/profiler/SlimefunProfiler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SlimefunProfiler.java index 91b19dbab7..4ca3a0c81e 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; @@ -84,6 +85,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}. @@ -202,8 +205,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(); } @@ -222,11 +224,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()) { @@ -417,4 +423,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 a1e0771e4f..287f91b71b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java @@ -20,6 +20,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; @@ -29,6 +30,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.holograms.HologramsService; import io.github.thebusybiscuit.slimefun4.core.services.profiler.SlimefunProfiler; import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundService; @@ -178,6 +180,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); @@ -212,7 +216,7 @@ public Slimefun() { public void onEnable() { setInstance(this); - if (isVersionUnsupported()) { + if (isVersionUnsupported()) { // We wanna ensure that the Server uses a compatible version of Minecraft. getServer().getPluginManager().disablePlugin(this); } else if (!SlimefunExtended.checkEnvironment(this)) { @@ -263,7 +267,7 @@ private void onPluginStart() { logger.log(Level.INFO, "正在加载数据库..."); if (PlayerProfileMigrator.getInstance().hasOldData() - || BlockStorageMigrator.getInstance().hasOldData()) { + || BlockStorageMigrator.getInstance().hasOldData()) { Slimefun.logger().warning("===================================================="); Slimefun.logger().warning("\n"); Slimefun.logger().log(Level.WARNING, "!!! 检测到使用文件储存的旧玩家数据 !!!"); @@ -297,7 +301,6 @@ private void onPluginStart() { networkSize, config.getBoolean("networks.enable-visualizer"), config.getBoolean("networks.delete-excess-items")); - // Registering all GEO Resources logger.log(Level.INFO, "加载矿物资源..."); GEOResourcesSetup.setup(); @@ -333,11 +336,11 @@ private void onPluginStart() { Level.SEVERE, x, () -> "An Exception occured while iterating through the Recipe list on Minecraft" - + " Version " - + minecraftVersion.getName() - + " (Slimefun v" - + getVersion() - + ")"); + + " Version " + + minecraftVersion.getName() + + " (Slimefun v" + + getVersion() + + ")"); } }), 0); @@ -513,11 +516,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; } @@ -544,7 +548,7 @@ private boolean isVersionUnsupported() { Level.SEVERE, x, () -> "错误: 无法识别服务器 Minecraft 版本, Slimefun v" - + getDescription().getVersion()); + + getDescription().getVersion()); // We assume "unsupported" if something went wrong. return true; @@ -701,7 +705,7 @@ private void loadResearches() { Level.SEVERE, x, () -> "An Error occurred while initializing Slimefun Researches for Slimefun " - + getVersion()); + + getVersion()); } } @@ -850,7 +854,7 @@ public static ProtectionManager getProtectionManager() { * * @return Our instance of {@link SoundService} */ - + public static SoundService getSoundService() { validateInstance(); return instance.soundService; @@ -883,6 +887,17 @@ private String getStartupTime(long timestamp) { } } + /** + * This method returns the {@link AnalyticsService} of Slimefun. + * It is used to handle sending analytic information. + * + * @return The {@link AnalyticsService} for Slimefun + */ + public static AnalyticsService getAnalyticsService() { + validateInstance(); + return instance.analyticsService; + } + public static SlimefunConfigManager getConfigManager() { validateInstance(); return instance.cfgManager; @@ -986,15 +1001,12 @@ public static Set getInstalledAddons() { /** * This method schedules a delayed synchronous task for Slimefun. * For Slimefun only, not for addons. - * + *

* This method should only be invoked by Slimefun itself. * Addons must schedule their own tasks using their own {@link Plugin} instance. * - * @param runnable - * The {@link Runnable} to run - * @param delay - * The delay for this task - * + * @param runnable The {@link Runnable} to run + * @param delay The delay for this task * @return The resulting {@link BukkitTask} or null if Slimefun was disabled */ public static @Nullable BukkitTask runSync(Runnable runnable, long delay) { @@ -1011,13 +1023,11 @@ public static Set getInstalledAddons() { /** * This method schedules a synchronous task for Slimefun. * For Slimefun only, not for addons. - * + *

* This method should only be invoked by Slimefun itself. * Addons must schedule their own tasks using their own {@link Plugin} instance. * - * @param runnable - * The {@link Runnable} to run - * + * @param runnable The {@link Runnable} to run * @return The resulting {@link BukkitTask} or null if Slimefun was disabled */ public static @Nullable BukkitTask runSync(Runnable runnable) { @@ -1030,7 +1040,7 @@ public static Set getInstalledAddons() { return instance.getServer().getScheduler().runTask(instance, runnable); } - + public File getFile() { return super.getFile(); } @@ -1039,4 +1049,14 @@ public static PlayerChatCatcher getChatCatcher() { 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 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 ef0741c66c..611bff07b1 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; @@ -404,7 +405,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 0fdef706b3..244a290aee 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,16 +10,17 @@ 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.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; @@ -74,7 +75,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)); @@ -99,7 +100,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)); @@ -136,7 +137,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); } } @@ -156,7 +157,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 f9b49855cd..22f621e126 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; @@ -44,7 +45,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; @@ -240,7 +240,7 @@ protected void tick(Block b, 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 15dd020c28..130a100d8b 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,13 +13,13 @@ 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; import java.util.Optional; 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(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 d79b24365c..0ca0734e6d 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,11 +9,13 @@ 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.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; @@ -115,15 +117,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 321b2f1352..36421e0300 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.Nullable; @@ -15,7 +16,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; /** @@ -31,22 +31,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); } @@ -99,15 +99,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); @@ -118,22 +116,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 bddec184bd..12d6064527 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 @@ -35,7 +35,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; /** @@ -213,7 +212,7 @@ private ItemStack getFilledBottle(Block fluid) { 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 a765397dfd..3efcbfb887 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,11 +8,11 @@ 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.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; @@ -93,7 +93,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, @@ -118,7 +118,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 f38da89cca..a475918600 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; @@ -19,7 +20,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(Player p, 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 af7e1e0718..0df656c615 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.ParametersAreNonnullByDefault; import org.bukkit.GameMode; @@ -69,7 +70,7 @@ public EntityInteractHandler getItemHandler() { 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 9d450b1764..f8d6873c99 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 @@ -8,6 +8,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import javax.annotation.ParametersAreNonnullByDefault; + +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import org.bukkit.Effect; import org.bukkit.GameMode; import org.bukkit.Material; @@ -15,14 +17,12 @@ 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 * fire. * * @author TheBusyBiscuit - * */ public class Bandage extends SimpleSlimefunItem { @@ -41,7 +41,7 @@ public Bandage( this.healingLevel = healingLevel; } - + @Override public ItemUseHandler getItemHandler() { return e -> { @@ -49,8 +49,8 @@ public ItemUseHandler getItemHandler() { // Player is neither burning nor injured if (p.getFireTicks() <= 0 - && p.getHealth() - >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { + && p.getHealth() + >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { return; } @@ -59,7 +59,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 592fa4a7e0..1dbd946a24 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; @@ -29,10 +30,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 abc17f861c..0dab6fa4a9 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,13 +7,15 @@ 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 javax.annotation.ParametersAreNonnullByDefault; + +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import org.bukkit.GameMode; import org.bukkit.attribute.Attribute; 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 { @@ -34,8 +36,8 @@ public ItemUseHandler getItemHandler() { // Player is neither burning nor injured if (p.getFireTicks() <= 0 - && p.getHealth() - >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { + && p.getHealth() + >= p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { return; } @@ -44,7 +46,7 @@ public ItemUseHandler getItemHandler() { } 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 55549ecc08..0ded76b0ec 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; @@ -17,7 +17,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; @@ -195,9 +194,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); @@ -348,7 +346,7 @@ private void setPistonState(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 04258e77dc..f04969731c 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 @@ -11,6 +11,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 org.apache.commons.lang.Validate; import org.bukkit.Bukkit; @@ -143,7 +144,7 @@ public double getClimbingSpeed(ItemStack item, 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 d4f58ac162..2a1003a437 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,10 +6,10 @@ 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.ParametersAreNonnullByDefault; import org.bukkit.Bukkit; -import org.bukkit.Particle; import org.bukkit.SoundCategory; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; @@ -45,7 +45,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 3273e5c46c..44c0ebf281 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 @@ -6,13 +6,14 @@ import io.github.thebusybiscuit.slimefun4.core.handlers.BowShootHandler; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import javax.annotation.ParametersAreNonnullByDefault; + +import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedPotionEffectType; import org.bukkit.Effect; import org.bukkit.Material; import org.bukkit.entity.LivingEntity; 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 @@ -45,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 045c7bec37..82462edc5e 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 @@ -16,6 +16,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 org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -405,7 +406,7 @@ private int getBonusDropsWithFortune(@Nullable ItemStack item, 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/JoinListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java index 24267e9616..b00b7bff68 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 @@ -26,8 +26,14 @@ public JoinListener(Slimefun plugin) { @EventHandler public void onJoin(PlayerJoinEvent e) { - PlayerProfile.get(e.getPlayer(), playerProfile -> { - final ItemStack[] armorContents = e.getPlayer().getInventory().getArmorContents(); + final var p = e.getPlayer(); + + PlayerProfile.get(p, playerProfile -> { + 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]; 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 2cf9d51b6e..1008e53814 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; @@ -325,7 +326,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()) { @@ -335,7 +336,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); } } @@ -377,7 +378,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 479b1ee854..1790fe3b42 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.ParametersAreNonnullByDefault; @@ -698,7 +699,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); @@ -2239,7 +2240,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( @@ -2277,7 +2278,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( @@ -2823,7 +2824,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); @@ -7763,7 +7764,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 eb6fdee01d..37ac9ef2f5 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; @@ -18,7 +19,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; @@ -120,12 +120,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); } } @@ -143,15 +143,16 @@ private void checkPedestal(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 4e8c400767..0ff12ed8a9 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; @@ -49,10 +50,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 8587bee831..4b54ae6be5 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 @@ -8,20 +8,22 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.storage.Storage; import io.github.thebusybiscuit.slimefun4.storage.data.PlayerData; + import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.util.UUID; import java.util.logging.Level; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.inventory.ItemStack; @Beta public class LegacyStorage implements Storage { - @Override public PlayerData loadPlayerData(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"); @@ -46,10 +48,6 @@ public PlayerData loadPlayerData(UUID uuid) { for (int i = 0; i < size; i++) { items.put(i, playerFile.getItem("backpacks." + key + ".contents." + i)); } - - PlayerBackpack backpack = PlayerBackpack.load(uuid, id, size, items); - - backpacks.put(id, backpack); } catch (Exception x) { Slimefun.logger() .log( @@ -66,7 +64,7 @@ public PlayerData loadPlayerData(UUID uuid) { for (String key : waypointsFile.getKeys()) { try { if (waypointsFile.contains(key + ".world") - && Bukkit.getWorld(waypointsFile.getString(key + ".world")) != null) { + && Bukkit.getWorld(waypointsFile.getString(key + ".world")) != null) { String waypointName = waypointsFile.getString(key + ".name"); Location loc = waypointsFile.getLocation(key); waypoints.add(new Waypoint(uuid, key, loc, waypointName)); @@ -80,12 +78,16 @@ public PlayerData loadPlayerData(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(UUID uuid, 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"); @@ -98,7 +100,15 @@ public void savePlayerData(UUID uuid, 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); } } @@ -130,5 +140,8 @@ public void savePlayerData(UUID uuid, 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 100af5eeef..a062c2875c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/FireworkUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/FireworkUtils.java @@ -1,7 +1,11 @@ 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 org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.FireworkEffect; @@ -13,12 +17,13 @@ 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, @@ -38,16 +43,27 @@ public final class FireworkUtils { Color.WHITE, Color.YELLOW }; + // @formatter:on - private FireworkUtils() {} + 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() { + } public static void launchFirework(Location l, Color color) { createFirework(l, color); } - public static Firework createFirework(Location l, Color color) { - Firework fw = (Firework) l.getWorld().spawnEntity(l, EntityType.FIREWORK); + Firework fw = (Firework) l.getWorld().spawnEntity(l, firework); FireworkMeta meta = fw.getFireworkMeta(); meta.setDisplayName(ChatColor.GREEN + "Slimefun Research"); @@ -71,17 +87,29 @@ public static void launchRandom(Entity n, int amount) { } } - + /** + * 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 FireworkEffect getRandomEffect(Random random, 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 } - + /** + * This returns a random {@link Color} for our {@link FireworkEffect}. + * + * @return A random {@link Color} + */ private static 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 cb0f0ed847..59ab98ff0e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -118,10 +118,7 @@ public static boolean isSoulbound(@Nullable ItemStack item, @Nullable World worl ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : null; SlimefunItem rune = SlimefunItems.SOULBOUND_RUNE.getItem(); - if (rune != null - && !rune.isDisabled() - && (world == null || !rune.isDisabledIn(world)) - && hasSoulboundFlag(meta)) { + if (rune != null && !rune.isDisabled() && (world == null || !rune.isDisabledIn(world)) && hasSoulboundFlag(meta)) { return true; } @@ -222,11 +219,7 @@ public static ItemStack getCustomHead(String texture) { String base64 = texture; if (CommonPatterns.HEXADECIMAL.matcher(texture).matches()) { - base64 = Base64.getEncoder() - .encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" - + texture - + "\"}}}") - .getBytes(StandardCharsets.UTF_8)); + base64 = Base64.getEncoder().encodeToString(("{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}").getBytes(StandardCharsets.UTF_8)); } PlayerSkin skin = PlayerSkin.fromBase64(base64); @@ -260,17 +253,11 @@ public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStac return isItemSimilar(item, sfitem, checkLore, true, true, true); } - public static boolean isItemSimilar( - @Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount) { + public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount) { return isItemSimilar(item, sfitem, checkLore, checkAmount, true, true); } - public static boolean isItemSimilar( - @Nullable ItemStack item, - @Nullable ItemStack sfitem, - boolean checkLore, - boolean checkAmount, - boolean checkDistinctiveItem) { + public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinctiveItem) { return isItemSimilar(item, sfitem, checkLore, checkAmount, checkDistinctiveItem, true); } @@ -289,22 +276,12 @@ public static boolean isSlimefunItemSimilar(SlimefunItemStack sfItem, ItemStack return false; } - public static boolean isItemSimilar( - @Nullable ItemStack item, - @Nullable ItemStack sfitem, - boolean checkLore, - boolean checkAmount, - boolean checkDistinctiveItem, - boolean checkCustomModelData) { + public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinctiveItem, boolean checkCustomModelData) { if (item == null) { return sfitem == null; - } else if (sfitem == null - || item.getType() != sfitem.getType() - || checkAmount && item.getAmount() < sfitem.getAmount()) { + } else if (sfitem == null || item.getType() != sfitem.getType() || checkAmount && item.getAmount() < sfitem.getAmount()) { return false; - } else if (checkDistinctiveItem - && sfitem instanceof SlimefunItemStack stackOne - && item instanceof SlimefunItemStack stackTwo) { + } else if (checkDistinctiveItem && sfitem instanceof SlimefunItemStack stackOne && item instanceof SlimefunItemStack stackTwo) { return isSlimefunItemSimilar(stackOne, stackTwo); } else if (item.hasItemMeta()) { Debug.log(TestCase.CARGO_INPUT_TESTING, "SlimefunUtils#isItemSimilar - item.hasItemMeta()"); @@ -343,8 +320,7 @@ public static boolean isItemSimilar( ; ItemMeta sfItemMeta = sfitem.getItemMeta(); String possibleItemId = Slimefun.getItemDataService().getItemData(itemMeta).orElse(null); - String sfItemId = Slimefun.getItemDataService() - .getItemData(sfItemMeta).get(); + String sfItemId = Slimefun.getItemDataService().getItemData(sfItemMeta).get(); // Prioritize SlimefunItem id comparison over ItemMeta comparison if (possibleItemId != null && possibleItemId.equals(sfItemId)) { Debug.log(TestCase.CARGO_INPUT_TESTING, " SlimefunItem IDs matched!"); @@ -361,12 +337,7 @@ public static boolean isItemSimilar( return false; } else if (sfitem.hasItemMeta()) { ItemMeta sfItemMeta = sfitem.getItemMeta(); - Debug.log( - TestCase.CARGO_INPUT_TESTING, - " Comparing meta (vanilla items?) - {} == {} (lore: {})", - itemMeta, - sfItemMeta, - checkLore); + Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", itemMeta, sfItemMeta, checkLore); return equalsItemMeta(itemMeta, sfItemMeta, checkLore, !checkCustomModelData); } else { return false; @@ -384,23 +355,16 @@ private static Optional getDistinctiveItem(String id) { return Optional.empty(); } - private static boolean equalsItemMeta( - ItemMeta itemMeta, ItemMetaSnapshot itemMetaSnapshot, boolean checkLore) { + private static boolean equalsItemMeta(ItemMeta itemMeta, ItemMetaSnapshot itemMetaSnapshot, boolean checkLore) { return equalsItemMeta(itemMeta, itemMetaSnapshot, checkLore, true); } - private static boolean equalsItemMeta( - ItemMeta itemMeta, - ItemMetaSnapshot itemMetaSnapshot, - boolean checkLore, - boolean bypassCustomModelCheck) { + private static boolean equalsItemMeta(ItemMeta itemMeta, ItemMetaSnapshot itemMetaSnapshot, boolean checkLore, boolean checkCustomModelCheck) { Optional displayName = itemMetaSnapshot.getDisplayName(); if (itemMeta.hasDisplayName() != displayName.isPresent()) { return false; - } else if (itemMeta.hasDisplayName() - && displayName.isPresent() - && !itemMeta.getDisplayName().equals(displayName.get())) { + } else if (itemMeta.hasDisplayName() && displayName.isPresent() && !itemMeta.getDisplayName().equals(displayName.get())) { return false; } else if (checkLore) { Optional> itemLore = itemMetaSnapshot.getLore(); @@ -412,31 +376,24 @@ private static boolean equalsItemMeta( } } - if (bypassCustomModelCheck) { + if (!checkCustomModelCheck) { return true; } // Fixes #3133: name and lore are not enough OptionalInt itemCustomModelData = itemMetaSnapshot.getCustomModelData(); - if (itemMeta.hasCustomModelData() - && itemCustomModelData.isPresent() - && itemMeta.getCustomModelData() != itemCustomModelData.getAsInt()) { + if (itemMeta.hasCustomModelData() && itemCustomModelData.isPresent() && itemMeta.getCustomModelData() != itemCustomModelData.getAsInt()) { return false; } else { return itemMeta.hasCustomModelData() == itemCustomModelData.isPresent(); } } - private static boolean equalsItemMeta( - ItemMeta itemMeta, - ItemMeta sfitemMeta, - boolean checkLore, - boolean bypassCustomModelCheck) { + private static boolean equalsItemMeta(ItemMeta itemMeta, ItemMeta sfitemMeta, 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())) { + } else if (itemMeta.hasDisplayName() && sfitemMeta.hasDisplayName() && !itemMeta.getDisplayName().equals(sfitemMeta.getDisplayName())) { return false; } else if (checkLore) { boolean hasItemMetaLore = itemMeta.hasLore(); @@ -444,20 +401,20 @@ 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; } } - if (!bypassCustomModelCheck) { + if (checkCustomModelCheck) { // Fixes #3133: name and lore are not enough boolean hasItemMetaCustomModelData = itemMeta.hasCustomModelData(); boolean hasSfItemMetaCustomModelData = sfitemMeta.hasCustomModelData(); - if (hasItemMetaCustomModelData - && hasSfItemMetaCustomModelData - && itemMeta.getCustomModelData() != sfitemMeta.getCustomModelData()) { + if (hasItemMetaCustomModelData && hasSfItemMetaCustomModelData && itemMeta.getCustomModelData() != sfitemMeta.getCustomModelData()) { return false; } else if (hasItemMetaCustomModelData != hasSfItemMetaCustomModelData) { return false; @@ -466,9 +423,11 @@ 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()); } + Debug.log(TestCase.CARGO_INPUT_TESTING, " All meta checked."); + return true; } @@ -562,8 +521,7 @@ public static boolean canPlayerUseItem(Player p, @Nullable ItemStack item, boole * @return The dropped {@link Item} (or null if the {@link SlimefunItemSpawnEvent} was cancelled) */ @ParametersAreNonnullByDefault - public static @Nullable Item spawnItem( - Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, @Nullable Player player) { + public static @Nullable Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, @Nullable Player player) { SlimefunItemSpawnEvent event = new SlimefunItemSpawnEvent(player, loc, item, reason); Slimefun.instance().getServer().getPluginManager().callEvent(event); @@ -592,8 +550,7 @@ public static boolean canPlayerUseItem(Player p, @Nullable ItemStack item, boole * @return The dropped {@link Item} (or null if the {@link SlimefunItemSpawnEvent} was cancelled) */ @ParametersAreNonnullByDefault - public static @Nullable Item spawnItem( - Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) { + public static @Nullable Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset) { return spawnItem(loc, item, reason, addRandomOffset, null); } 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..5549fcab83 --- /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(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..5d00d00b1d --- /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(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..a9a6a20fe4 --- /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(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..0a8c2539c1 --- /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(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..5e5f7cf903 --- /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(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..10f76f6603 --- /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(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); }); } }