From 8ecd670fb968b961677c529b03c8041122c96840 Mon Sep 17 00:00:00 2001 From: XiaoMoMi <972454774@qq.com> Date: Mon, 20 Nov 2023 16:19:31 +0800 Subject: [PATCH] fix bugs --- .../command/sub/DebugCommand.java | 21 ++++++++++++++++++- .../mechanic/competition/Competition.java | 3 +-- .../mechanic/item/ItemManagerImpl.java | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/net/momirealms/customfishing/command/sub/DebugCommand.java b/plugin/src/main/java/net/momirealms/customfishing/command/sub/DebugCommand.java index 80b21604..40080b61 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/command/sub/DebugCommand.java +++ b/plugin/src/main/java/net/momirealms/customfishing/command/sub/DebugCommand.java @@ -17,6 +17,7 @@ package net.momirealms.customfishing.command.sub; +import de.tr7zw.changeme.nbtapi.NBTItem; import dev.jorel.commandapi.CommandAPICommand; import dev.jorel.commandapi.IStringTooltip; import dev.jorel.commandapi.StringTooltip; @@ -32,7 +33,10 @@ import net.momirealms.customfishing.api.mechanic.condition.FishingPreparation; import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier; import net.momirealms.customfishing.api.mechanic.effect.EffectModifier; import net.momirealms.customfishing.api.mechanic.effect.FishingEffect; +import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.util.NBTUtils; import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; @@ -50,7 +54,8 @@ public class DebugCommand { getBiomeCommand(), getSeasonCommand(), getGroupCommand(), - getCategoryCommand() + getCategoryCommand(), + getNBTCommand() ); } @@ -61,6 +66,20 @@ public class DebugCommand { }); } + public CommandAPICommand getNBTCommand() { + return new CommandAPICommand("nbt") + .executesPlayer((player, arg) -> { + ItemStack item = player.getInventory().getItemInMainHand(); + if (item.getType() == Material.AIR) + return; + ArrayList list = new ArrayList<>(); + ConfigUtils.mapToReadableStringList(NBTUtils.compoundToMap(new NBTItem(item)), list, 0, false); + for (String line : list) { + AdventureManagerImpl.getInstance().sendMessage(player, line); + } + }); + } + public CommandAPICommand getSeasonCommand() { return new CommandAPICommand("season") .executesPlayer((player, arg) -> { diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java index 6a17e1a8..1da461b1 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/competition/Competition.java @@ -182,13 +182,11 @@ public class Competition implements FishingCompetition { Pair competitionPlayer = iterator.next(); this.publicPlaceholders.put("{" + i + "_player}", competitionPlayer.left()); this.publicPlaceholders.put("{" + i + "_score}", String.format("%.2f", competitionPlayer.right())); - i++; if (i < rewardsMap.size()) { Player player = Bukkit.getPlayer(competitionPlayer.left()); if (player != null) for (Action action : rewardsMap.get(String.valueOf(i))) action.trigger(new Condition(player)); - } else { Action[] actions = rewardsMap.get("participation"); if (actions != null) { @@ -199,6 +197,7 @@ public class Competition implements FishingCompetition { } } } + i++; } } diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java index c0636ac6..d96f8117 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java @@ -726,7 +726,7 @@ public class ItemManagerImpl implements ItemManager, Listener { if (size == null) return this; editors.put("size", (player, nbtItem, placeholders) -> { NBTCompound cfCompound = nbtItem.getOrCreateCompound("CustomFishing"); - float random = size.left() + ThreadLocalRandom.current().nextFloat(size.right() - size.left()); + float random = size.left() + size.left() <= size.right() ? 0 : ThreadLocalRandom.current().nextFloat(size.right() - size.left()); float bonus = Float.parseFloat(placeholders.getOrDefault("{size-multiplier}", "1.0")); double fixed = Double.parseDouble(placeholders.getOrDefault("{size-fixed}", "0.0")); random *= bonus;