mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-26 10:29:16 +00:00
durability changes
This commit is contained in:
@@ -101,7 +101,7 @@ public class IntegrationManagerImpl implements IntegrationManager {
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("Jobs")) {
|
||||
registerLevelPlugin("JobsReborn", new JobsRebornImpl());
|
||||
hookMessage("Jobs");
|
||||
hookMessage("JobsReborn");
|
||||
}
|
||||
if (plugin.isHookedPluginEnabled("MMOCore")) {
|
||||
registerLevelPlugin("MMOCore", new MMOCoreImpl());
|
||||
|
||||
@@ -609,7 +609,7 @@ public class ActionManagerImpl implements ActionManager {
|
||||
if (amount > 0) {
|
||||
ItemUtils.increaseDurability(itemStack, amount, true);
|
||||
} else {
|
||||
ItemUtils.decreaseDurability(itemStack, -amount, true);
|
||||
ItemUtils.decreaseDurability(condition.getPlayer(), itemStack, -amount, true);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
|
||||
@@ -256,7 +256,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
if (compound != null && compound.hasTag("max_dur")) {
|
||||
event.setCancelled(true);
|
||||
hook.remove();
|
||||
ItemUtils.decreaseDurability(itemStack, 2, true);
|
||||
ItemUtils.decreaseDurability(player, itemStack, 2, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -367,7 +367,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
if (nbtCompound != null && nbtCompound.hasTag("max_dur")) {
|
||||
event.getHook().remove();
|
||||
event.setCancelled(true);
|
||||
ItemUtils.decreaseDurability(itemStack, 5, true);
|
||||
ItemUtils.decreaseDurability(player, itemStack, 5, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -537,7 +537,7 @@ public class FishingManagerImpl implements Listener, FishingManager {
|
||||
break outer;
|
||||
}
|
||||
ItemUtils.decreaseHookDurability(rod, 1, false);
|
||||
ItemUtils.decreaseDurability(rod, 1, true);
|
||||
ItemUtils.decreaseDurability(player, rod, 1, true);
|
||||
}
|
||||
|
||||
if (gamingPlayer.isSuccessful())
|
||||
|
||||
@@ -26,6 +26,7 @@ import net.momirealms.customfishing.api.mechanic.condition.Condition;
|
||||
import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier;
|
||||
import net.momirealms.customfishing.api.mechanic.hook.HookSetting;
|
||||
import net.momirealms.customfishing.api.util.LogUtils;
|
||||
import net.momirealms.customfishing.mechanic.item.ItemManagerImpl;
|
||||
import net.momirealms.customfishing.util.ItemUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -185,12 +186,16 @@ public class HookManagerImpl implements Listener, HookManager {
|
||||
if (setting == null)
|
||||
return false;
|
||||
|
||||
var curDurability = ItemUtils.getCustomDurability(hook);
|
||||
if (curDurability.left() == 0)
|
||||
return false;
|
||||
|
||||
NBTItem rodNBTItem = new NBTItem(rod);
|
||||
NBTCompound cfCompound = rodNBTItem.getOrCreateCompound("CustomFishing");
|
||||
|
||||
cfCompound.setString("hook_id", hookID);
|
||||
cfCompound.setItemStack("hook_item", hook);
|
||||
cfCompound.setInteger("hook_dur", ItemUtils.getDurability(hook));
|
||||
cfCompound.setInteger("hook_dur", curDurability.right());
|
||||
|
||||
ItemUtils.updateNBTItemLore(rodNBTItem);
|
||||
rod.setItemMeta(rodNBTItem.getItem().getItemMeta());
|
||||
@@ -273,6 +278,24 @@ public class HookManagerImpl implements Listener, HookManager {
|
||||
if (setting == null)
|
||||
return;
|
||||
|
||||
var cursorDurability = ItemUtils.getCustomDurability(cursor);
|
||||
if (cursorDurability.left() == 0) {
|
||||
if (plugin.getItemManager().getBuildableItem("hook", hookID) instanceof ItemManagerImpl.CFBuilder cfBuilder) {
|
||||
ItemStack itemStack = cfBuilder.build(player, new HashMap<>());
|
||||
var pair = ItemUtils.getCustomDurability(itemStack);
|
||||
cursorDurability = pair;
|
||||
NBTItem nbtItem = new NBTItem(cursor);
|
||||
NBTCompound compound = nbtItem.getOrCreateCompound("CustomFishing");
|
||||
compound.setInteger("max_dur", pair.left());
|
||||
compound.setInteger("cur_dur", pair.right());
|
||||
compound.setString("type", "hook");
|
||||
compound.setString("id", hookID);
|
||||
cursor.setItemMeta(nbtItem.getItem().getItemMeta());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Condition condition = new Condition(player, new HashMap<>());
|
||||
condition.insertArg("{rod}", plugin.getItemManager().getAnyPluginItemID(clicked));
|
||||
EffectCarrier effectCarrier = plugin.getEffectManager().getEffectCarrier("hook", hookID);
|
||||
@@ -305,7 +328,7 @@ public class HookManagerImpl implements Listener, HookManager {
|
||||
|
||||
cfCompound.setString("hook_id", hookID);
|
||||
cfCompound.setItemStack("hook_item", clonedHook);
|
||||
cfCompound.setInteger("hook_dur", ItemUtils.getDurability(clonedHook));
|
||||
cfCompound.setInteger("hook_dur", cursorDurability.right());
|
||||
|
||||
ItemUtils.updateNBTItemLore(rodNBTItem);
|
||||
clicked.setItemMeta(rodNBTItem.getItem().getItemMeta());
|
||||
|
||||
@@ -446,13 +446,14 @@ public class ItemManagerImpl implements ItemManager, Listener {
|
||||
/**
|
||||
* Decreases the durability of an ItemStack by a specified amount and optionally updates its lore.
|
||||
*
|
||||
* @param player Player
|
||||
* @param itemStack The ItemStack to modify.
|
||||
* @param amount The amount by which to decrease the durability.
|
||||
* @param updateLore Whether to update the lore of the ItemStack.
|
||||
*/
|
||||
@Override
|
||||
public void decreaseDurability(ItemStack itemStack, int amount, boolean updateLore) {
|
||||
ItemUtils.decreaseDurability(itemStack, amount, updateLore);
|
||||
public void decreaseDurability(Player player, ItemStack itemStack, int amount, boolean updateLore) {
|
||||
ItemUtils.decreaseDurability(player, itemStack, amount, updateLore);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,12 +25,15 @@ import net.kyori.adventure.text.ScoreComponent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.momirealms.customfishing.adventure.AdventureManagerImpl;
|
||||
import net.momirealms.customfishing.api.CustomFishingPlugin;
|
||||
import net.momirealms.customfishing.api.common.Pair;
|
||||
import net.momirealms.customfishing.api.mechanic.hook.HookSetting;
|
||||
import net.momirealms.customfishing.api.util.LogUtils;
|
||||
import net.momirealms.customfishing.setting.CFConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
@@ -52,9 +55,6 @@ public class ItemUtils {
|
||||
if (cfCompound == null)
|
||||
return nbtItem;
|
||||
|
||||
boolean hasLoreUpdate = cfCompound.hasTag("hook_id") || cfCompound.hasTag("max_dur");
|
||||
if (!hasLoreUpdate) return nbtItem;
|
||||
|
||||
NBTCompound displayCompound = nbtItem.getOrCreateCompound("display");
|
||||
NBTList<String> lore = displayCompound.getStringList("Lore");
|
||||
lore.removeIf(it -> GsonComponentSerializer.gson().deserialize(it) instanceof ScoreComponent scoreComponent && scoreComponent.name().equals("cf"));
|
||||
@@ -202,7 +202,7 @@ public class ItemUtils {
|
||||
* @param amount The amount by which to reduce durability
|
||||
* @param updateLore Whether to update the lore after reducing durability
|
||||
*/
|
||||
public static void decreaseDurability(ItemStack itemStack, int amount, boolean updateLore) {
|
||||
public static void decreaseDurability(Player player, ItemStack itemStack, int amount, boolean updateLore) {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR)
|
||||
return;
|
||||
int unBreakingLevel = itemStack.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
@@ -227,6 +227,12 @@ public class ItemUtils {
|
||||
itemStack.setAmount(0);
|
||||
}
|
||||
} else {
|
||||
ItemMeta previousMeta = itemStack.getItemMeta().clone();
|
||||
PlayerItemDamageEvent itemDamageEvent = new PlayerItemDamageEvent(player, itemStack, amount);
|
||||
Bukkit.getPluginManager().callEvent(itemDamageEvent);
|
||||
if (!itemStack.getItemMeta().equals(previousMeta)) {
|
||||
return;
|
||||
}
|
||||
int damage = nbtItem.getInteger("Damage") + amount;
|
||||
if (damage > itemStack.getType().getMaxDurability()) {
|
||||
itemStack.setAmount(0);
|
||||
@@ -304,17 +310,17 @@ public class ItemUtils {
|
||||
* @param itemStack The ItemStack to get durability from
|
||||
* @return The current durability value
|
||||
*/
|
||||
public static int getDurability(ItemStack itemStack) {
|
||||
if (!(itemStack.getItemMeta() instanceof Damageable damageable))
|
||||
return -1;
|
||||
if (damageable.isUnbreakable())
|
||||
return -1;
|
||||
public static Pair<Integer, Integer> getCustomDurability(ItemStack itemStack) {
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR)
|
||||
return Pair.of(0, 0);
|
||||
if (itemStack.getItemMeta() instanceof Damageable damageable && damageable.isUnbreakable())
|
||||
return Pair.of(-1, -1);
|
||||
NBTItem nbtItem = new NBTItem(itemStack);
|
||||
NBTCompound cfCompound = nbtItem.getCompound("CustomFishing");
|
||||
if (cfCompound != null && cfCompound.hasTag("max_dur")) {
|
||||
return cfCompound.getInteger("cur_dur");
|
||||
return Pair.of(cfCompound.getInteger("max_dur"), cfCompound.getInteger("cur_dur"));
|
||||
} else {
|
||||
return itemStack.getType().getMaxDurability() - damageable.getDamage();
|
||||
return Pair.of(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
# Note: These are the default configurations of the plugin
|
||||
# and do not necessarily mean that players can have a good
|
||||
# gaming experience. We hope that you will create
|
||||
# customized configurations based on your own ideas,
|
||||
# allowing players to experience the uniqueness of your server.
|
||||
|
||||
delicate_hook:
|
||||
material: SHEARS
|
||||
display:
|
||||
@@ -13,6 +19,8 @@ delicate_hook:
|
||||
- '<#FFD700>Effects:'
|
||||
- '<gray> - Increase the chance of getting high quality fish'
|
||||
max-durability: 16
|
||||
custom-model-data: 50000
|
||||
# {dur} / {max}
|
||||
lore-on-rod:
|
||||
- ''
|
||||
- '<#7FFFAA>Equipped hook:'
|
||||
|
||||
Reference in New Issue
Block a user