From f67e30641d172fe2158e77e2b1dd2a4d9cab6ae4 Mon Sep 17 00:00:00 2001 From: Lego Date: Wed, 28 Aug 2024 13:13:19 -0400 Subject: [PATCH 1/3] Update locale_en_US.properties (#5066) Removed Water Lily from Vanilla Potions Changed Sulphur to Gunpowder Moved Rabbits Foot from Tier 3 to Vanilla Potions --- src/main/resources/locale/locale_en_US.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index bae179cd4..ff84615c2 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -957,8 +957,8 @@ Guides.Acrobatics.Section.2=&3How does Dodge work?\n&eDodge is a passive chance Guides.Alchemy.Section.0=[[DARK_AQUA]]About Alchemy:\n[[YELLOW]]Alchemy is about brewing potions.\n[[YELLOW]]It provides a speed increase in the potion brew time, as well\n[[YELLOW]]as the addition of new (previously) unobtainable potions.\n\n\n[[DARK_AQUA]]XP GAIN:\n[[YELLOW]]To gain XP in this skill you need to brew potions. Guides.Alchemy.Section.1=[[DARK_AQUA]]How does Catalysis work?\n[[YELLOW]]Catalysis speeds of the brewing process, with a\n[[YELLOW]]max speed of 4x at level 1000.\n[[YELLOW]]This ability is unlocked at level 100 by default. Guides.Alchemy.Section.2=[[DARK_AQUA]]How does Concoctions work?\n[[YELLOW]]Concoctions allows brewing of more potions with custom ingredients.\n[[YELLOW]]Which special ingredients are unlocked is determined\n[[YELLOW]]by your Rank. There are 8 ranks to unlock. -Guides.Alchemy.Section.3=[[DARK_AQUA]]Concoctions tier 1 ingredients:\n[[YELLOW]]Blaze Powder, Fermented Spider Eye, Ghast Tear, Redstone,\n[[YELLOW]]Glowstone Dust, Sugar, Glistering Melon, Golden Carrot,\n[[YELLOW]]Magma Cream, Nether Wart, Spider Eye, Suplhur, Water Lily,\n[[YELLOW]]Pufferfish\n[[YELLOW]](Vanilla Potions) -Guides.Alchemy.Section.4=[[DARK_AQUA]]Concoctions tier 2 ingredients:\n[[YELLOW]]Carrot (Potion of Haste)\n[[YELLOW]]Slimeball (Potion of Dullness)\n\n[[DARK_AQUA]]Concoctions tier 3 ingredients:\n[[YELLOW]]Quartz (Potion of Absorption)\n[[YELLOW]]Rabbit's Foot (Potion of Leaping) +Guides.Alchemy.Section.3=[[DARK_AQUA]]Concoctions tier 1 ingredients:\n[[YELLOW]]Blaze Powder, Fermented Spider Eye, Ghast Tear, Redstone,\n[[YELLOW]]Glowstone Dust, Sugar, Glistering Melon, Golden Carrot,\n[[YELLOW]]Magma Cream, Nether Wart, Spider Eye, Gunpowder, Rabbit's Foot,\n[[YELLOW]]Pufferfish\n[[YELLOW]](Vanilla Potions) +Guides.Alchemy.Section.4=[[DARK_AQUA]]Concoctions tier 2 ingredients:\n[[YELLOW]]Carrot (Potion of Haste)\n[[YELLOW]]Slimeball (Potion of Dullness)\n\n[[DARK_AQUA]]Concoctions tier 3 ingredients:\n[[YELLOW]]Quartz (Potion of Absorption)\n[[YELLOW]] Guides.Alchemy.Section.5=[[DARK_AQUA]]Concoctions tier 4 ingredients:\n[[YELLOW]]Apple (Potion of Health Boost)\n[[YELLOW]]Rotten Flesh (Potion of Hunger)\n\n[[DARK_AQUA]]Concoctions tier 5 ingredients:\n[[YELLOW]]Brown Mushroom (Potion of Nausea)\n[[YELLOW]]Ink Sack (Potion of Blindness) Guides.Alchemy.Section.6=[[DARK_AQUA]]Concoctions tier 6 ingredients:\n[[YELLOW]]Fern (Potion of Saturation)\n\n[[DARK_AQUA]]Concoctions tier 7 ingredients:\n[[YELLOW]]Poisonous Potato (Potion of Decay)\n\n[[DARK_AQUA]]Concoctions tier 8 ingredients:\n[[YELLOW]]Regular Golden Apple (Potion of Resistance) @@ -1227,4 +1227,4 @@ Broadcasts.LevelUpMilestone=&6(&amcMMO&6) {0}&7 has reached level &a{1}&7 in &3{ Broadcasts.PowerLevelUpMilestone=&6(&amcMMO&6) {0}&7 has reached a Power level of &a{1}&7! Scoreboard.Recovery=Attempting to recover mcMMO scoreboard... Scoreboard.Disabled=The mcMMO scoreboards for this server are disabled, this setting is found in mcMMO/config.yml -Scoreboard.NotSetupYet=Your mcMMO scoreboard has not been setup yet, try again later. \ No newline at end of file +Scoreboard.NotSetupYet=Your mcMMO scoreboard has not been setup yet, try again later. From 93bb1607421b61ee8f56b9fd62251a36ab878282 Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Sat, 31 Aug 2024 22:02:00 +0200 Subject: [PATCH 2/3] Fix exceptions when shooting entities through worlds on folia (#5024) --- .../com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java | 4 +++- .../java/com/gmail/nossr50/skills/taming/TamingManager.java | 3 +++ src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java index bd2e4ae1c..faf29a204 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AwardCombatXpTask.java @@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.CancellableRunnable; import org.bukkit.entity.LivingEntity; @@ -44,6 +45,7 @@ public class AwardCombatXpTask extends CancellableRunnable { damage = Math.min(damage, ExperienceConfig.getInstance().getCombatHPCeiling()); } - mcMMOPlayer.beginXpGain(primarySkillType, (int) (damage * baseXp), xpGainReason, XPGainSource.SELF); + final double finalDamage = damage; + mcMMO.p.getFoliaLib().getImpl().runAtEntity(mcMMOPlayer.getPlayer(), task -> mcMMOPlayer.beginXpGain(primarySkillType, (int) (finalDamage * baseXp), xpGainReason, XPGainSource.SELF)); } } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 42ed59a9e..16bab8a43 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -287,6 +287,9 @@ public class TamingManager extends SkillManager { double range = 5; Player player = getPlayer(); + if (!target.getWorld().equals(player.getWorld())) + return; + for (Entity entity : player.getNearbyEntities(range, range, range)) { if (entity.getType() != EntityType.WOLF) { continue; diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index adb98e06f..8916c2cbe 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -945,7 +945,7 @@ public final class CombatUtils { baseXP *= multiplier; if (baseXP > 0) { - mcMMO.p.getFoliaLib().getImpl().runAtEntity(mcMMOPlayer.getPlayer(), new AwardCombatXpTask(mcMMOPlayer, primarySkillType, baseXP, target, xpGainReason)); + mcMMO.p.getFoliaLib().getImpl().runAtEntity(target, new AwardCombatXpTask(mcMMOPlayer, primarySkillType, baseXP, target, xpGainReason)); } } From dcf83a8d20798d1a4c4f96b7b8bad4863d88eab9 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR <9496359+MrPowerGamerBR@users.noreply.github.com> Date: Sat, 31 Aug 2024 17:11:17 -0300 Subject: [PATCH 3/3] Cache ItemMeta instead of creating a new ItemMeta for each potion check (#5075) * Cache ItemMeta instead of creating a new ItemMeta for each potion check * Check if the item has item meta and, if it doesn't, bail out * Also cache the potion item meta too * Add requireNonNull to the potionItemMeta --- .../config/skills/alchemy/PotionConfig.java | 8 +++++++- .../datatypes/skills/alchemy/AlchemyPotion.java | 14 +++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java index d0cad88b5..7d1ff04e0 100644 --- a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java +++ b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java @@ -9,6 +9,7 @@ import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -334,9 +335,14 @@ public class PotionConfig extends LegacyConfigLoader { * @return AlchemyPotion that corresponds to the given ItemStack. */ public AlchemyPotion getPotion(ItemStack item) { + // Fast return if the item does not have any item meta to avoid initializing an unnecessary ItemMeta instance + if (!item.hasItemMeta()) + return null; + + ItemMeta itemMeta = item.getItemMeta(); final List potionList = alchemyPotions.values() .stream() - .filter(potion -> potion.isSimilarPotion(item)) + .filter(potion -> potion.isSimilarPotion(item, itemMeta)) .toList(); if(potionList.size() > 1) { mcMMO.p.getLogger().severe("Multiple potions defined in config have matched this potion, for mcMMO to behave" + diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/AlchemyPotion.java b/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/AlchemyPotion.java index 0b0654dda..214bd703b 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/AlchemyPotion.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/alchemy/AlchemyPotion.java @@ -4,6 +4,7 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.PotionUtil; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -18,6 +19,7 @@ import static java.util.Objects.requireNonNull; public class AlchemyPotion { private final @NotNull String potionConfigName; private final @NotNull ItemStack potionItemStack; + private final @NotNull ItemMeta potionItemMeta; private final @NotNull Map alchemyPotionChildren; public AlchemyPotion(@NotNull String potionConfigName, @NotNull ItemStack potionItemStack, @@ -25,6 +27,7 @@ public class AlchemyPotion { this.potionConfigName = requireNonNull(potionConfigName, "potionConfigName cannot be null"); this.potionItemStack = requireNonNull(potionItemStack, "potionItemStack cannot be null"); this.alchemyPotionChildren = requireNonNull(alchemyPotionChildren, "alchemyPotionChildren cannot be null"); + this.potionItemMeta = requireNonNull(potionItemStack.getItemMeta(), "potionItemMeta cannot be null"); // The potion item meta should never be null because it is a potion, but if it is null, then something went terribly wrong } public @NotNull ItemStack toItemStack(int amount) { @@ -49,13 +52,18 @@ public class AlchemyPotion { } public boolean isSimilarPotion(@NotNull ItemStack otherPotion) { + return isSimilarPotion(otherPotion, otherPotion.getItemMeta()); + } + + public boolean isSimilarPotion(@NotNull ItemStack otherPotion, @Nullable ItemMeta otherMeta) { requireNonNull(otherPotion, "otherPotion cannot be null"); + if (otherPotion.getType() != potionItemStack.getType()) { return false; } // no potion meta, no match - if (!otherPotion.hasItemMeta()) { + if (otherMeta == null) { return false; } @@ -63,7 +71,7 @@ public class AlchemyPotion { * Compare custom effects on both potions. */ - final PotionMeta otherPotionMeta = (PotionMeta) otherPotion.getItemMeta(); + final PotionMeta otherPotionMeta = (PotionMeta) otherMeta; // compare custom effects on both potions, this has to be done in two traversals // comparing thisPotionMeta -> otherPotionMeta and otherPotionMeta -> thisPotionMeta if (hasDifferingCustomEffects(getAlchemyPotionMeta(), otherPotionMeta) @@ -114,7 +122,7 @@ public class AlchemyPotion { } public PotionMeta getAlchemyPotionMeta() { - return (PotionMeta) potionItemStack.getItemMeta(); + return (PotionMeta) potionItemMeta; } public boolean isSplash() {