第99批续2:三处交互补耐久 + 连锁采集按方块数消耗耐久
Auto Release / build (push) Successful in 2m32s

① 耕地(锄)/去皮(斧)分支补 1 点耐久,与压地(铲)同构对齐原版;
   三处均走 PlayerItemDamageEvent 让其它插件耐久保护/豁免照常介入,
   超最大耐久按原版行为工具损坏消失(数量-1)。
② 连锁采集:按住Shift+镐/斧范围采集后,按破坏方块数(broken)消耗
   主手工具耐久(每方块1点),在延迟任务 broken>0 时应用;
   超耐久同样数量-1 并提示「工具耐久耗尽,已损坏」。
This commit is contained in:
youpaishidifu
2026-11-09 11:49:40 +08:00
parent 89abac4feb
commit 13305a29cc
+53
View File
@@ -4034,6 +4034,21 @@ public class Main extends JavaPlugin
e.setCancelled(true);
clicked.setType(Material.FARMLAND);
clicked.getWorld().playSound(clicked.getLocation(), Sound.BLOCK_GRASS_HIT, 1, 1);
// ★ 第99批续:耕地消耗锄头 1 点耐久(对齐原版锄地行为,同压地分支)
org.bukkit.event.player.PlayerItemDamageEvent die =
new org.bukkit.event.player.PlayerItemDamageEvent(p, hand, 1);
getServer().getPluginManager().callEvent(die);
if (!die.isCancelled() && die.getDamage() > 0
&& hand.getItemMeta() instanceof org.bukkit.inventory.meta.Damageable dm) {
int max = hand.getType().getMaxDurability();
int newDamage = dm.getDamage() + die.getDamage();
if (max > 0 && newDamage > max) {
hand.setAmount(hand.getAmount() - 1);
} else {
dm.setDamage(newDamage);
hand.setItemMeta(dm);
}
}
return;
}
}
@@ -4082,6 +4097,21 @@ public class Main extends JavaPlugin
if (strippedMat != null) {
clicked.setType(strippedMat);
clicked.getWorld().playSound(clicked.getLocation(), Sound.BLOCK_WOOD_HIT, 1, 1);
// ★ 第99批续:去皮消耗斧头 1 点耐久(对齐原版去皮行为,同压地分支)
org.bukkit.event.player.PlayerItemDamageEvent die =
new org.bukkit.event.player.PlayerItemDamageEvent(p, hand, 1);
getServer().getPluginManager().callEvent(die);
if (!die.isCancelled() && die.getDamage() > 0
&& hand.getItemMeta() instanceof org.bukkit.inventory.meta.Damageable dm) {
int max = hand.getType().getMaxDurability();
int newDamage = dm.getDamage() + die.getDamage();
if (max > 0 && newDamage > max) {
hand.setAmount(hand.getAmount() - 1);
} else {
dm.setDamage(newDamage);
hand.setItemMeta(dm);
}
}
return;
}
}
@@ -4236,6 +4266,29 @@ public class Main extends JavaPlugin
if (broken > 0) {
p.sendMessage("§a§l[连锁采集] §f采集了 §e" + broken + " §f个" + (isLog ? "方块" : "矿物"));
// ★ 第99批续:连锁采集按破坏方块数消耗主手工具耐久(连锁多少块扣多少点)。
// 与单块交互耐久同语义:走 PlayerItemDamageEvent 让其它插件(耐久保护/豁免)照常介入;
// 超最大耐久按原版行为工具损坏消失(数量-1)。
if (hand != null && hand.getType() != org.bukkit.Material.AIR
&& hand.getItemMeta() instanceof org.bukkit.inventory.meta.Damageable dm) {
int each = 1; // 每方块消耗 1 点耐久
int total = each * broken;
org.bukkit.event.player.PlayerItemDamageEvent die =
new org.bukkit.event.player.PlayerItemDamageEvent(p, hand, total);
org.bukkit.Bukkit.getPluginManager().callEvent(die);
if (!die.isCancelled() && die.getDamage() > 0) {
int dmg = die.getDamage();
int max = hand.getType().getMaxDurability();
int newDamage = dm.getDamage() + dmg;
if (max > 0 && newDamage > max) {
hand.setAmount(hand.getAmount() - 1);
p.sendMessage("§c§l[连锁采集] §f工具耐久耗尽,已损坏");
} else {
dm.setDamage(newDamage);
hand.setItemMeta(dm);
}
}
}
}
}, 1L);
}