mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 06:06:45 +01:00
fixed fishing errors Fixes #5108
This commit is contained in:
parent
6ed4ad76cd
commit
04007f6dbc
1
pom.xml
1
pom.xml
@ -13,6 +13,7 @@
|
|||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<!-- <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>-->
|
||||||
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
|
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
|
||||||
<adventure.version>4.3.5-SNAPSHOT</adventure.version>
|
<adventure.version>4.3.5-SNAPSHOT</adventure.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -3,23 +3,17 @@ package com.gmail.nossr50.skills.fishing;
|
|||||||
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
|
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
|
||||||
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
|
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.adapter.BiomeAdapter;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public final class Fishing {
|
public final class Fishing {
|
||||||
|
|
||||||
protected static final HashMap<Material, List<Enchantment>> ENCHANTABLE_CACHE = new HashMap<>();
|
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;
|
|
||||||
|
|
||||||
private Fishing() {}
|
private Fishing() {}
|
||||||
|
|
||||||
@ -30,7 +24,7 @@ public final class Fishing {
|
|||||||
* Targeted entity
|
* Targeted entity
|
||||||
* @return possibleDrops List of ItemStack that can be dropped
|
* @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()))
|
if (FishingTreasureConfig.getInstance().shakeMap.containsKey(target.getType()))
|
||||||
return FishingTreasureConfig.getInstance().shakeMap.get(target.getType());
|
return FishingTreasureConfig.getInstance().shakeMap.get(target.getType());
|
||||||
|
|
||||||
@ -44,7 +38,7 @@ public final class Fishing {
|
|||||||
* List of ItemStack that can be dropped
|
* List of ItemStack that can be dropped
|
||||||
* @return Chosen ItemStack
|
* @return Chosen ItemStack
|
||||||
*/
|
*/
|
||||||
protected static ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
|
static ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
|
||||||
int dropProbability = Misc.getRandom().nextInt(100);
|
int dropProbability = Misc.getRandom().nextInt(100);
|
||||||
double cumulatedProbability = 0;
|
double cumulatedProbability = 0;
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import com.gmail.nossr50.mcMMO;
|
|||||||
import com.gmail.nossr50.runnables.skills.MasterAnglerTask;
|
import com.gmail.nossr50.runnables.skills.MasterAnglerTask;
|
||||||
import com.gmail.nossr50.skills.SkillManager;
|
import com.gmail.nossr50.skills.SkillManager;
|
||||||
import com.gmail.nossr50.util.*;
|
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.compat.layers.skills.MasterAnglerCompatibilityLayer;
|
||||||
import com.gmail.nossr50.util.player.NotificationManager;
|
import com.gmail.nossr50.util.player.NotificationManager;
|
||||||
import com.gmail.nossr50.util.random.ProbabilityUtil;
|
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.
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,45 +1,44 @@
|
|||||||
package com.gmail.nossr50.util.adapter;
|
package com.gmail.nossr50.util.adapter;
|
||||||
|
|
||||||
import org.bukkit.block.Biome;
|
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.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class BiomeAdapter {
|
public class BiomeAdapter {
|
||||||
public static final Set<Biome> WATER_BIOMES;
|
|
||||||
public static final Set<Biome> ICE_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 {
|
static {
|
||||||
final List<Biome> allBiomes = getAllBiomes();
|
|
||||||
final Set<Biome> waterBiomes = new HashSet<>();
|
|
||||||
final Set<Biome> iceBiomes = new HashSet<>();
|
final Set<Biome> iceBiomes = new HashSet<>();
|
||||||
for (Biome biome : allBiomes) {
|
knownColdBiomes.stream()
|
||||||
String biomeName = getBiomeName(biome);
|
.map(biomeFromString())
|
||||||
if (isWater(biomeName) && !isCold(biomeName)) {
|
.filter(Objects::nonNull)
|
||||||
waterBiomes.add(biome);
|
.forEach(iceBiomes::add);
|
||||||
} else if (isCold(biomeName)) {
|
|
||||||
iceBiomes.add(biome);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WATER_BIOMES = Collections.unmodifiableSet(waterBiomes);
|
|
||||||
ICE_BIOMES = Collections.unmodifiableSet(iceBiomes);
|
ICE_BIOMES = Collections.unmodifiableSet(iceBiomes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
private static @NotNull Function<String, Biome> biomeFromString() {
|
||||||
private static List<Biome> getAllBiomes() {
|
return potentialBiome -> {
|
||||||
return Arrays.asList(Biome.values());
|
try {
|
||||||
}
|
Class<?> biomeClass = Class.forName("org.bukkit.block.Biome");
|
||||||
|
Method methodValueOf = biomeClass.getMethod("valueOf", String.class);
|
||||||
@SuppressWarnings("deprecation")
|
return methodValueOf.invoke(null, potentialBiome) == null
|
||||||
private static String getBiomeName(Biome biome) {
|
? null
|
||||||
return biome.name();
|
: (Biome) methodValueOf.invoke(null, potentialBiome);
|
||||||
}
|
} catch (IllegalArgumentException | NullPointerException e) {
|
||||||
|
return null;
|
||||||
private static boolean isWater(String name) {
|
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException
|
||||||
return name.contains("RIVER") || name.contains("OCEAN");
|
| IllegalAccessException e) {
|
||||||
}
|
// Thrown when the method is not found or the class is not found
|
||||||
|
throw new RuntimeException(e);
|
||||||
private static boolean isCold(String name) {
|
}
|
||||||
return (name.contains("COLD") || name.contains("ICE")
|
};
|
||||||
|| name.contains("FROZEN") || name.contains("TAIGA")) && !name.contains("WARM");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user