Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.

Commit 9837135

Browse files
committed
repair now increase limit count
1 parent f0bfe55 commit 9837135

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/cat/nyaa/nyaautils/repair/RepairCommands.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.bukkit.command.CommandSender;
1010
import org.bukkit.entity.Player;
1111
import org.bukkit.inventory.ItemStack;
12+
import org.bukkit.inventory.meta.ItemMeta;
1213
import org.bukkit.inventory.meta.Repairable;
1314

1415
import static cat.nyaa.nyaautils.repair.RepairInstance.RepairStat.REPAIRABLE;
@@ -72,6 +73,18 @@ public void repairInfo(CommandSender sender, Arguments args) {
7273
}
7374
}
7475

76+
private void increaseReapirCount(ItemStack item, int x) {
77+
if (x == 0) return;
78+
ItemMeta meta = item.getItemMeta();
79+
if (meta instanceof Repairable) {
80+
Repairable r = (Repairable) meta;
81+
int count = r.getRepairCost() + x;
82+
if (count < 0) count = 0;
83+
r.setRepairCost(count);
84+
item.setItemMeta(meta);
85+
}
86+
}
87+
7588
@SubCommand(value = "hand", permission = "nu.repair")
7689
public void repairHand(CommandSender sender, Arguments args) {
7790
ItemStack item = getItemInHand(sender);
@@ -97,6 +110,7 @@ public void repairHand(CommandSender sender, Arguments args) {
97110
dur -= info.durRecovered;
98111
if (dur < 0) dur = 0;
99112
item.setDurability((short) dur);
113+
increaseReapirCount(item, 1);
100114
p.getInventory().setItemInMainHand(item);
101115
int count = material.getAmount();
102116
if (count <= 1) {
@@ -137,6 +151,7 @@ public void repairFull(CommandSender sender, Arguments args) {
137151
dur -= info.durRecovered*repairAmount;
138152
if (dur < 0) dur = 0;
139153
item.setDurability((short) dur);
154+
increaseReapirCount(item, 1);
140155
p.getInventory().setItemInMainHand(item);
141156
int count = material.getAmount() - repairAmount;
142157
if (count <= 0) {

0 commit comments

Comments
 (0)