Skip to content

Commit

Permalink
fix issues with Alchemy and older MC versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed May 3, 2024
1 parent 5b822bc commit 7556135
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 125 deletions.
4 changes: 2 additions & 2 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Version 2.2.007
Compatibility with the 1.20.5 / 1.20.6 MC Update
Added armadillo to combat experience in experience.yml
Fixed bug where Alchemy was not brewing certain potions (haste, etc)
Alchemy now has more warning/errors that will print out to help debug
Fixed bug where the probability of success of Graceful Roll was not being calculated correctly
Added armadillo to combat experience in experience.yml
Fixed bug where Green Thumb did not replant if seed was in the off hand

NOTES:
Expand Down
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
</pluginRepositories>

<repositories>
<!-- Protocol Lib Repository -->
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
Expand Down Expand Up @@ -268,6 +273,12 @@
<version>3.25.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down Expand Up @@ -364,7 +375,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.5-R0.1-SNAPSHOT</version>
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.codehaus.plexus.util.StringUtils;
import org.jetbrains.annotations.VisibleForTesting;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static com.gmail.nossr50.util.PotionUtil.*;
import static com.gmail.nossr50.util.text.StringUtils.convertKeyToName;

public class PotionConfig extends LegacyConfigLoader {

Expand Down Expand Up @@ -130,7 +129,7 @@ private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
final String key = potion_section.getName();
final String displayName = potion_section.getString("Name") != null
? LocaleLoader.addColors(potion_section.getString("Name"))
: null;
: convertKeyToName(key);

final ConfigurationSection potionData = potion_section.getConfigurationSection("PotionData");
boolean extended = false;
Expand Down Expand Up @@ -165,12 +164,16 @@ private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
return null;
}

// Set the name of the potion
potionMeta.setDisplayName(displayName);

// extended and upgraded seem to be mutually exclusive
if (extended && upgraded) {
mcMMO.p.getLogger().warning("Potion " + key + " has both Extended and Upgraded set to true," +
" defaulting to Extended.");
upgraded = false;
}

String potionTypeStr = potionData.getString("PotionType", null);
if (potionTypeStr == null) {
mcMMO.p.getLogger().severe("PotionConfig: Missing PotionType for " + displayName + ", from configuration section:" +
Expand All @@ -186,7 +189,9 @@ private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
}

if (potionType == null) {
mcMMO.p.getLogger().severe("PotionConfig: Failed to parse potion type for: " + potionTypeStr);
mcMMO.p.getLogger().severe("PotionConfig: Failed to parse potion type for: " + potionTypeStr
+ ", upgraded: " + upgraded + ", extended: " + extended + " for potion " + displayName
+ ", from configuration section: " + potion_section);
return null;
}

Expand Down Expand Up @@ -357,5 +362,4 @@ public Color calculateAverageColor(List<Color> colors) {
}
return Color.fromRGB(red / colors.size(), green / colors.size(), blue / colors.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand All @@ -16,18 +15,18 @@
import static java.util.Objects.requireNonNull;

public class AlchemyPotion {
private final ItemStack potion;
private final Map<ItemStack, String> alchemyPotionChildren;
private final @NotNull ItemStack potionItemstack;
private final @NotNull Map<ItemStack, String> alchemyPotionChildren;

public AlchemyPotion(ItemStack potion, Map<ItemStack, String> alchemyPotionChildren) {
this.potion = requireNonNull(potion, "potion cannot be null");
public AlchemyPotion(@NotNull ItemStack potionItemStack, @NotNull Map<ItemStack, String> alchemyPotionChildren) {
this.potionItemstack = requireNonNull(potionItemStack, "potionItemStack cannot be null");
this.alchemyPotionChildren = requireNonNull(alchemyPotionChildren, "alchemyPotionChildren cannot be null");
}

public @NotNull ItemStack toItemStack(int amount) {
final ItemStack potion = new ItemStack(this.potion);
potion.setAmount(Math.max(1, amount));
return potion;
final ItemStack clone = potionItemstack.clone();
clone.setAmount(Math.max(1, amount));
return clone;
}

public Map<ItemStack, String> getAlchemyPotionChildren() {
Expand All @@ -49,7 +48,7 @@ public boolean isSimilarPotion(@NotNull ItemStack otherPotion) {
requireNonNull(otherPotion, "otherPotion cannot be null");
// TODO: Investigate?
// We currently don't compare base potion effects, likely because they are derived from the potion type
if (otherPotion.getType() != potion.getType() || !otherPotion.hasItemMeta()) {
if (otherPotion.getType() != potionItemstack.getType() || !otherPotion.hasItemMeta()) {
return false;
}

Expand All @@ -76,44 +75,38 @@ public boolean isSimilarPotion(@NotNull ItemStack otherPotion) {
return false;
}

if (!otherPotionMeta.hasDisplayName() && getAlchemyPotionMeta().hasDisplayName()) {
return false;
}

var alchemyPotionName = getAlchemyPotionMeta().hasDisplayName() ? getAlchemyPotionMeta().getDisplayName() : null;

return (alchemyPotionName == null && !otherPotionMeta.hasDisplayName()) || otherPotionMeta.getDisplayName().equals(alchemyPotionName);
return true;
}

public PotionMeta getAlchemyPotionMeta() {
return (PotionMeta) potion.getItemMeta();
return (PotionMeta) potionItemstack.getItemMeta();
}

public boolean isSplash() {
return potion.getType() == Material.SPLASH_POTION;
return potionItemstack.getType() == Material.SPLASH_POTION;
}

public boolean isLingering() {
return potion.getType() == Material.LINGERING_POTION;
return potionItemstack.getType() == Material.LINGERING_POTION;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AlchemyPotion that = (AlchemyPotion) o;
return Objects.equals(potion, that.potion) && Objects.equals(alchemyPotionChildren, that.alchemyPotionChildren);
return Objects.equals(potionItemstack, that.potionItemstack) && Objects.equals(alchemyPotionChildren, that.alchemyPotionChildren);
}

@Override
public int hashCode() {
return Objects.hash(potion, alchemyPotionChildren);
return Objects.hash(potionItemstack, alchemyPotionChildren);
}

@Override
public String toString() {
return "AlchemyPotion{" +
"potion=" + potion +
"potion=" + potionItemstack +
", alchemyPotionChildren=" + alchemyPotionChildren +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void addStats(TextComponent.Builder componentBuilder, Player player) {
* Graceful is double the odds of a normal roll
*/
Probability probability = getRollProbability(player);
Probability gracefulProbability = Probability.ofPercent(probability.getValue() * 2);
Probability gracefulProbability = Probability.ofValue(probability.getValue() * 2);
String[] gracefulRollStrings = ProbabilityUtil.getRNGDisplayValues(gracefulProbability);
gracefulRollChance = gracefulRollStrings[0];
gracefulRollChanceLucky = gracefulRollStrings[1];
Expand Down Expand Up @@ -274,7 +274,7 @@ else if (!isFatal(player, damage)) {
@NotNull
public static Probability getGracefulProbability(Player player) {
double gracefulOdds = ProbabilityUtil.getSubSkillProbability(SubSkillType.ACROBATICS_ROLL, player).getValue() * 2;
return Probability.ofPercent(gracefulOdds);
return Probability.ofValue(gracefulOdds);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gmail.nossr50.protocollib;

import com.gmail.nossr50.mcMMO;
import org.bukkit.plugin.Plugin;

// TODO: Finish this class
public class ProtocolLibManager {
Plugin protocolLibPluginRef;
mcMMO pluginRef;
public ProtocolLibManager(mcMMO pluginRef) {
this.pluginRef = pluginRef;
}

public boolean isProtocolLibPresent() {
protocolLibPluginRef = pluginRef.getServer().getPluginManager().getPlugin("ProtocolLib");
return protocolLibPluginRef != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gmail.nossr50.skills.alchemy.Alchemy;
import com.gmail.nossr50.skills.alchemy.AlchemyPotionBrewer;
import com.gmail.nossr50.util.CancellableRunnable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.BrewingStand;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -31,8 +32,7 @@ public void run() {
if (oldInventory[Alchemy.INGREDIENT_SLOT] == null || newInventory[Alchemy.INGREDIENT_SLOT] == null || !oldInventory[Alchemy.INGREDIENT_SLOT].isSimilar(newInventory[Alchemy.INGREDIENT_SLOT]) || !validBrew) {
Alchemy.brewingStandMap.get(location).cancelBrew();
}
}
else if (validBrew) {
} else if (validBrew) {
Alchemy.brewingStandMap.put(location, new AlchemyBrewTask(brewingStand, player));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
Expand Down Expand Up @@ -67,33 +68,65 @@ public AlchemyBrewTask(BlockState brewingStand, Player player) {

@Override
public void run() {
if (player == null || !player.isValid() || brewingStand == null || brewingStand.getType() != Material.BREWING_STAND || !AlchemyPotionBrewer.isValidIngredient(player, ((BrewingStand) brewingStand).getInventory().getContents()[Alchemy.INGREDIENT_SLOT])) {
// Check if preconditions for brewing are not met
if (shouldCancelBrewing()) {
if (Alchemy.brewingStandMap.containsKey(location)) {
Alchemy.brewingStandMap.remove(location);
}

this.cancel();

return;
}

if (firstRun) {
firstRun = false;
((BrewingStand) brewingStand).setFuelLevel(fuel);
}
// Initialize the brewing stand on the first run
initializeBrewing();

// Update the brewing process timer
brewTimer -= brewSpeed;

// Vanilla potion brewing completes when BrewingTime == 1
if (brewTimer < Math.max(brewSpeed, 2)) {
// Check if the brewing process should finish
if (isBrewingComplete()) {
this.cancel();
finish();
} else {
updateBrewingTime();
}
}

private boolean shouldCancelBrewing() {
if (player == null) {
return true;
}
if (!player.isValid()) {
return true;
}
if (brewingStand == null) {
return true;
}
if (brewingStand.getType() != Material.BREWING_STAND) {
return true;
}
else {
((BrewingStand) brewingStand).setBrewingTime((int) brewTimer);
if (!AlchemyPotionBrewer.isValidIngredient(player, ((BrewingStand) brewingStand).getInventory().getContents()[Alchemy.INGREDIENT_SLOT])) {
return true;
}
return false;
}

private void initializeBrewing() {
if (firstRun) {
firstRun = false;
((BrewingStand) brewingStand).setFuelLevel(fuel);
}
}

private boolean isBrewingComplete() {
return brewTimer < Math.max(brewSpeed, 2);
}

private void updateBrewingTime() {
((BrewingStand) brewingStand).setBrewingTime((int) brewTimer);
}


private void finish() {
McMMOPlayerBrewEvent event = new McMMOPlayerBrewEvent(player, brewingStand);
mcMMO.p.getServer().getPluginManager().callEvent(event);
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/com/gmail/nossr50/skills/alchemy/Alchemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,6 @@
import java.util.Map;

public final class Alchemy {
/*public enum Tier {
EIGHT(8),
SEVEN(7),
SIX(6),
FIVE(5),
FOUR(4),
THREE(3),
TWO(2),
ONE(1);
int numerical;
private Tier(int numerical) {
this.numerical = numerical;
}
public int toNumerical() {
return numerical;
}
public static Tier fromNumerical(int numerical) {
for (Tier tier : Tier.values()) {
if (tier.toNumerical() == numerical) {
return tier;
}
}
return null;
}
protected int getLevel() {
return mcMMO.p.getAdvancedConfig().getConcoctionsTierLevel(this);
}
}*/

public static final int INGREDIENT_SLOT = 3;

public static int catalysisMaxBonusLevel = mcMMO.p.getAdvancedConfig().getCatalysisMaxBonusLevel();
Expand Down

0 comments on commit 7556135

Please sign in to comment.