fixed fishing errors Fixes #5108

This commit is contained in:
nossr50 2024-11-04 18:56:38 -08:00
parent 6ed4ad76cd
commit 04007f6dbc
4 changed files with 35 additions and 39 deletions

View File

@ -13,6 +13,7 @@
</scm>
<properties>
<!-- <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>-->
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
<adventure.version>4.3.5-SNAPSHOT</adventure.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -3,23 +3,17 @@ package com.gmail.nossr50.skills.fishing;
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.adapter.BiomeAdapter;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
public final class Fishing {
protected static final HashMap<Material, List<Enchantment>> ENCHANTABLE_CACHE = new HashMap<>();
public static Set<Biome> masterAnglerBiomes = BiomeAdapter.WATER_BIOMES;
public static Set<Biome> iceFishingBiomes = BiomeAdapter.ICE_BIOMES;
static final HashMap<Material, List<Enchantment>> ENCHANTABLE_CACHE = new HashMap<>();
private Fishing() {}
@ -30,7 +24,7 @@ public final class Fishing {
* Targeted entity
* @return possibleDrops List of ItemStack that can be dropped
*/
protected static List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
static List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
if (FishingTreasureConfig.getInstance().shakeMap.containsKey(target.getType()))
return FishingTreasureConfig.getInstance().shakeMap.get(target.getType());
@ -44,7 +38,7 @@ public final class Fishing {
* List of ItemStack that can be dropped
* @return Chosen ItemStack
*/
protected static ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
static ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
int dropProbability = Misc.getRandom().nextInt(100);
double cumulatedProbability = 0;

View File

@ -16,6 +16,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.MasterAnglerTask;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.*;
import com.gmail.nossr50.util.adapter.BiomeAdapter;
import com.gmail.nossr50.util.compat.layers.skills.MasterAnglerCompatibilityLayer;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.random.ProbabilityUtil;
@ -173,7 +174,8 @@ public class FishingManager extends SkillManager {
}
// Make sure this is a body of water, not just a block of ice.
if (!Fishing.iceFishingBiomes.contains(block.getBiome()) && (block.getRelative(BlockFace.DOWN, 3).getType() != Material.WATER)) {
if (!BiomeAdapter.ICE_BIOMES.contains(block.getBiome())
&& (block.getRelative(BlockFace.DOWN, 3).getType() != Material.WATER)) {
return false;
}

View File

@ -1,45 +1,44 @@
package com.gmail.nossr50.util.adapter;
import org.bukkit.block.Biome;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.function.Function;
public class BiomeAdapter {
public static final Set<Biome> WATER_BIOMES;
public static final Set<Biome> ICE_BIOMES;
static final List<String> knownColdBiomes = Arrays.asList("COLD_OCEAN", "DEEP_COLD_OCEAN", "ICE_SPIKES",
"FROZEN_PEAKS", "FROZEN_OCEAN", "FROZEN_RIVER", "DEEP_FROZEN_OCEAN", "SNOWY_TAIGA",
"OLD_GROWTH_PINE_TAIGA", "OLD_GROWTH_SPRUCE_TAIGA", "TAIGA", "SNOWY_SLOPES", "SNOWY_BEACH");
static {
final List<Biome> allBiomes = getAllBiomes();
final Set<Biome> waterBiomes = new HashSet<>();
final Set<Biome> iceBiomes = new HashSet<>();
for (Biome biome : allBiomes) {
String biomeName = getBiomeName(biome);
if (isWater(biomeName) && !isCold(biomeName)) {
waterBiomes.add(biome);
} else if (isCold(biomeName)) {
iceBiomes.add(biome);
}
}
WATER_BIOMES = Collections.unmodifiableSet(waterBiomes);
knownColdBiomes.stream()
.map(biomeFromString())
.filter(Objects::nonNull)
.forEach(iceBiomes::add);
ICE_BIOMES = Collections.unmodifiableSet(iceBiomes);
}
@SuppressWarnings("deprecation")
private static List<Biome> getAllBiomes() {
return Arrays.asList(Biome.values());
}
@SuppressWarnings("deprecation")
private static String getBiomeName(Biome biome) {
return biome.name();
}
private static boolean isWater(String name) {
return name.contains("RIVER") || name.contains("OCEAN");
}
private static boolean isCold(String name) {
return (name.contains("COLD") || name.contains("ICE")
|| name.contains("FROZEN") || name.contains("TAIGA")) && !name.contains("WARM");
private static @NotNull Function<String, Biome> biomeFromString() {
return potentialBiome -> {
try {
Class<?> biomeClass = Class.forName("org.bukkit.block.Biome");
Method methodValueOf = biomeClass.getMethod("valueOf", String.class);
return methodValueOf.invoke(null, potentialBiome) == null
? null
: (Biome) methodValueOf.invoke(null, potentialBiome);
} catch (IllegalArgumentException | NullPointerException e) {
return null;
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException
| IllegalAccessException e) {
// Thrown when the method is not found or the class is not found
throw new RuntimeException(e);
}
};
}
}