Skip to content

Commit

Permalink
fixup biome condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Nov 25, 2024
1 parent cf67461 commit f2f468e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 70 deletions.
3 changes: 2 additions & 1 deletion src/main/java/xyz/oribuin/fishing/augment/Augment.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public Augment(String name, String description) {
this.enabled = true;
this.name = name;
this.description = description;
this.maxLevel = 1;
this.maxLevel = 5;
this.requiredLevel = 1;
this.displayItem = ItemConstruct.EMPTY;
this.displayLine = "&c" + StringUtils.capitalize(this.name.replace("_", " ")) + " %level_roman%";
this.permission = "fishing.augment." + name;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class AugmentBiomeDisrupt extends Augment {

public AugmentBiomeDisrupt() {
super("biome_disruption", "When a player catches a fish, there is a chance to ignore the biome restrictions.");

this.maxLevel = 3;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class AugmentCallOfTheSea extends Augment {

public AugmentCallOfTheSea() {
super("call_of_the_sea", "Increases the amount of fish caught when the weather is raining");

this.maxLevel = 15;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class AugmentHotspot extends Augment {

public AugmentHotspot() {
super("hotspot", "Increases the amount of fish caught when the weather is clear");

this.maxLevel = 15;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class AugmentIntellect extends Augment {
*/
public AugmentIntellect() {
super("intellect", "Increases the base minecraft xp earned from catching fish.");

this.maxLevel = 3;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class AugmentPerception extends Augment {
*/
public AugmentPerception() {
super("perception", "Increases the base entropy earned from catching fish.");

this.maxLevel = 5;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import xyz.oribuin.fishing.gui.StatsMenu;
import xyz.oribuin.fishing.manager.MenuManager;

// suppress experimental
public class MenuCommand extends BaseRoseCommand {

public MenuCommand(RosePlugin rosePlugin) {
Expand All @@ -24,6 +25,7 @@ public void execute(CommandContext context) {
if (menu == null) return;

menu.open(player);

}

@Override
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/xyz/oribuin/fishing/fish/Fish.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,22 @@ public Fish(@NotNull String name, @NotNull String tier) {
*/
@Override
public void loadSettings(@NotNull CommentedConfigurationSection config) {
Fish fish = new Fish(name, tier);

// Catch Conditions
this.displayName = config.getString("display-name", StringUtils.capitalize(this.name));
this.description = config.getStringList("description");
this.modelData = config.getInt("model-data", -1);

// Catch Conditions
Condition condition = new Condition();
condition.biomes(config.getStringList("biomes"));
condition.weather(FishUtils.getEnum(Weather.class, config.getString("weather")));
condition.time(FishUtils.getEnum(Time.class, config.getString("time")));
condition.worlds(config.getStringList("worlds"));
condition.environment(FishUtils.getEnum(World.Environment.class, config.getString("environment")));
condition.waterDepth((Integer) config.get("water-depth"));
condition.iceFishing(config.getBoolean("ice-fishing"));
condition.lightLevel((Integer) config.get("light-level"));
condition.height(FishUtils.getHeight(config.getString("height")));
condition.boatFishing(config.getBoolean("boat-fishing"));
fish.condition(condition);
this.condition.biomes(config.getStringList("biomes"));
this.condition.weather(FishUtils.getEnum(Weather.class, config.getString("weather")));
this.condition.time(FishUtils.getEnum(Time.class, config.getString("time")));
this.condition.worlds(config.getStringList("worlds"));
this.condition.environment(FishUtils.getEnum(World.Environment.class, config.getString("environment")));
this.condition.waterDepth((Integer) config.get("water-depth"));
this.condition.iceFishing(config.getBoolean("ice-fishing"));
this.condition.lightLevel((Integer) config.get("light-level"));
this.condition.height(FishUtils.getHeight(config.getString("height")));
this.condition.boatFishing(config.getBoolean("boat-fishing"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

import java.util.List;

@SuppressWarnings("deprecation")

@SuppressWarnings({ "deprecation", "removal" })
public class BiomeCondition implements CatchCondition {

/**
Expand Down Expand Up @@ -42,21 +43,31 @@ public boolean check(Fish fish, Player player, ItemStack rod, FishHook hook) {
Location loc = hook.getLocation();
List<String> biomes = fish.condition().biomes();

// Use the old method if the server is not running paper
if (!NMSUtil.isPaper()) {
return biomes.contains(loc.getBlock().getBiome().name());
// 1.21.3+ Biome Check
if (NMSUtil.getVersionNumber() > 21 && NMSUtil.getMinorVersionNumber() >= 3) {
String value = this.keyValue(loc.getBlock().getBiome().getKey());
return biomes.stream().anyMatch(value::equalsIgnoreCase);
}

// Server is running paper
List<NamespacedKey> biomeKeys = biomes.stream().map(NamespacedKey::fromString).toList();
// 1.21.2 and below Biome Check
NamespacedKey current = Bukkit.getUnsafe().getBiomeKey(
loc.getWorld(),
loc.getBlockX(),
loc.getBlockY(),
loc.getBlockZ()
);

return biomeKeys.contains(current);
return biomes.stream().anyMatch(x -> this.keyValue(current).equalsIgnoreCase(x));
}

/**
* Get the key value of the biome
*
* @param key The key to get the value of
*
* @return The value of the key
*/
private String keyValue(NamespacedKey key) {
return key.value();
}
}
5 changes: 2 additions & 3 deletions src/main/java/xyz/oribuin/fishing/listener/FishListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ public void onFish(PlayerFishEvent event) {
if (caught.isEmpty()) return;

// Add the fish into the player inventory
float baseExpGained = event.getExpToDrop();
double naturalExp = 0.0;
float naturalExp = event.getExpToDrop();
int newFishExp = 0;
int newEntropy = 0;

for (Fish fish : caught) {
if (fish == null) continue;

FishCatchEvent fishCatchEvent = new FishCatchEvent(event.getPlayer(), hand, event.getHook(), fish);
fishCatchEvent.setNaturalExp(baseExpGained); // Set the base experience gained
fishCatchEvent.setNaturalExp(naturalExp); // Set the base experience gained

fishCatchEvent.callEvent();
if (fishCatchEvent.isCancelled()) continue; // If the event is cancelled, do nothing
Expand Down
48 changes: 3 additions & 45 deletions src/main/java/xyz/oribuin/fishing/util/nms/SkullUtils.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package xyz.oribuin.fishing.util.nms;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import dev.rosewood.rosegarden.utils.NMSUtil;
import org.bukkit.Bukkit;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerProfile;
import org.bukkit.profile.PlayerTextures;

import java.lang.reflect.Method;
Expand All @@ -29,53 +25,15 @@ private SkullUtils() {
* @param skullMeta The ItemMeta for the Skull
* @param texture The texture to apply to the skull
*/
@SuppressWarnings("deprecation")
public static void setSkullTexture(SkullMeta skullMeta, String texture) {
if (texture == null || texture.isEmpty()) return;

// TODO: Add head database support
// if (texture != null && texture.startsWith("hdb:") && Bukkit.getPluginManager().isPluginEnabled("HeadDatabase")) {
// texture = new HeadDatabaseAPI().getBase64(texture.substring(4));
// }

if (texture == null || texture.isEmpty())
return;

if (NMSUtil.getVersionNumber() >= 18) { // No need to use NMS on 1.18.1+
if (NMSUtil.isPaper()) {
setTexturesPaper(skullMeta, texture);
return;
}

PlayerProfile profile = Bukkit.createPlayerProfile(UUID.nameUUIDFromBytes(texture.getBytes()), "");
PlayerTextures textures = profile.getTextures();

String decodedTextureJson = new String(Base64.getDecoder().decode(texture));
String decodedTextureUrl = decodedTextureJson.substring(28, decodedTextureJson.length() - 4);

try {
textures.setSkin(new URL(decodedTextureUrl));
} catch (MalformedURLException e) {
Bukkit.getLogger().severe("Failed to set skull texture: " + e.getMessage());
}

profile.setTextures(textures);
skullMeta.setOwnerProfile(profile);
return;
}

// 1.17 and below
GameProfile profile = new GameProfile(UUID.nameUUIDFromBytes(texture.getBytes()), "");
profile.getProperties().put("textures", new Property("textures", texture));

try {
if (method_SkullMeta_setProfile == null) {
method_SkullMeta_setProfile = skullMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
method_SkullMeta_setProfile.setAccessible(true);
}

method_SkullMeta_setProfile.invoke(skullMeta, profile);
} catch (ReflectiveOperationException e) {
Bukkit.getLogger().severe("Failed to set skull texture: " + e.getMessage());
}
setTexturesPaper(skullMeta, texture);
}

/**
Expand Down

0 comments on commit f2f468e

Please sign in to comment.