This commit is contained in:
nossr50 2024-08-31 13:26:16 -07:00
commit b87efb3f76
6 changed files with 28 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@ -334,9 +335,14 @@ public class PotionConfig extends LegacyConfigLoader {
* @return AlchemyPotion that corresponds to the given ItemStack. * @return AlchemyPotion that corresponds to the given ItemStack.
*/ */
public AlchemyPotion getPotion(ItemStack item) { 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<AlchemyPotion> potionList = alchemyPotions.values() final List<AlchemyPotion> potionList = alchemyPotions.values()
.stream() .stream()
.filter(potion -> potion.isSimilarPotion(item)) .filter(potion -> potion.isSimilarPotion(item, itemMeta))
.toList(); .toList();
if(potionList.size() > 1) { if(potionList.size() > 1) {
mcMMO.p.getLogger().severe("Multiple potions defined in config have matched this potion, for mcMMO to behave" + mcMMO.p.getLogger().severe("Multiple potions defined in config have matched this potion, for mcMMO to behave" +

View File

@ -4,6 +4,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.PotionUtil; import com.gmail.nossr50.util.PotionUtil;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -18,6 +19,7 @@ import static java.util.Objects.requireNonNull;
public class AlchemyPotion { public class AlchemyPotion {
private final @NotNull String potionConfigName; private final @NotNull String potionConfigName;
private final @NotNull ItemStack potionItemStack; private final @NotNull ItemStack potionItemStack;
private final @NotNull ItemMeta potionItemMeta;
private final @NotNull Map<ItemStack, String> alchemyPotionChildren; private final @NotNull Map<ItemStack, String> alchemyPotionChildren;
public AlchemyPotion(@NotNull String potionConfigName, @NotNull ItemStack potionItemStack, public AlchemyPotion(@NotNull String potionConfigName, @NotNull ItemStack potionItemStack,
@ -25,6 +27,7 @@ public class AlchemyPotion {
this.potionConfigName = requireNonNull(potionConfigName, "potionConfigName cannot be null"); this.potionConfigName = requireNonNull(potionConfigName, "potionConfigName cannot be null");
this.potionItemStack = requireNonNull(potionItemStack, "potionItemStack cannot be null"); this.potionItemStack = requireNonNull(potionItemStack, "potionItemStack cannot be null");
this.alchemyPotionChildren = requireNonNull(alchemyPotionChildren, "alchemyPotionChildren 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) { public @NotNull ItemStack toItemStack(int amount) {
@ -49,13 +52,18 @@ public class AlchemyPotion {
} }
public boolean isSimilarPotion(@NotNull ItemStack otherPotion) { 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"); requireNonNull(otherPotion, "otherPotion cannot be null");
if (otherPotion.getType() != potionItemStack.getType()) { if (otherPotion.getType() != potionItemStack.getType()) {
return false; return false;
} }
// no potion meta, no match // no potion meta, no match
if (!otherPotion.hasItemMeta()) { if (otherMeta == null) {
return false; return false;
} }
@ -63,7 +71,7 @@ public class AlchemyPotion {
* Compare custom effects on both potions. * 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 // compare custom effects on both potions, this has to be done in two traversals
// comparing thisPotionMeta -> otherPotionMeta and otherPotionMeta -> thisPotionMeta // comparing thisPotionMeta -> otherPotionMeta and otherPotionMeta -> thisPotionMeta
if (hasDifferingCustomEffects(getAlchemyPotionMeta(), otherPotionMeta) if (hasDifferingCustomEffects(getAlchemyPotionMeta(), otherPotionMeta)
@ -114,7 +122,7 @@ public class AlchemyPotion {
} }
public PotionMeta getAlchemyPotionMeta() { public PotionMeta getAlchemyPotionMeta() {
return (PotionMeta) potionItemStack.getItemMeta(); return (PotionMeta) potionItemMeta;
} }
public boolean isSplash() { public boolean isSplash() {

View File

@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.CancellableRunnable; import com.gmail.nossr50.util.CancellableRunnable;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -44,6 +45,7 @@ public class AwardCombatXpTask extends CancellableRunnable {
damage = Math.min(damage, ExperienceConfig.getInstance().getCombatHPCeiling()); 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));
} }
} }

View File

@ -287,6 +287,9 @@ public class TamingManager extends SkillManager {
double range = 5; double range = 5;
Player player = getPlayer(); Player player = getPlayer();
if (!target.getWorld().equals(player.getWorld()))
return;
for (Entity entity : player.getNearbyEntities(range, range, range)) { for (Entity entity : player.getNearbyEntities(range, range, range)) {
if (entity.getType() != EntityType.WOLF) { if (entity.getType() != EntityType.WOLF) {
continue; continue;

View File

@ -945,7 +945,7 @@ public final class CombatUtils {
baseXP *= multiplier; baseXP *= multiplier;
if (baseXP > 0) { 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));
} }
} }

View File

@ -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.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.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.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.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]]Rabbit's Foot (Potion of Leaping) 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.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) 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)