-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTradeCraftRepairShop.java
More file actions
54 lines (40 loc) · 1.53 KB
/
TradeCraftRepairShop.java
File metadata and controls
54 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.List;
public class TradeCraftRepairShop extends TradeCraftShop {
public TradeCraftRepairShop(TradeCraft plugin, Sign sign, Chest chest) {
super(plugin, sign, chest);
}
public void handleRightClick(Player player) {
int gold = chest.getAmountOfCurrencyInChest();
List<Item> items = chest.getNonCurrencyItems();
int repairCost = plugin.properties.getRepairCost();
if (gold == 0 && items.size() == 0) {
plugin.sendMessage(player, "It costs %d gold to repair an item.", repairCost);
return;
}
int actualCost = items.size() * repairCost;
if (items.size() == 0) {
plugin.sendMessage(player, "With this much gold, you can repair %d items.", gold / repairCost);
return;
}
if (gold < actualCost) {
if (gold > 0) {
plugin.sendMessage(player, "That's not enough gold.");
}
plugin.sendMessage(player, "You need %d gold to repair all this.", actualCost);
return;
}
chest.clear();
for (Item item : items) {
chest.add(item.getType().getId(), 1);
}
chest.add(Item.Type.GoldIngot.getId(), (gold - actualCost));
chest.update();
plugin.sendMessage(player, "You repaired %d items for %d gold.", items.size(), actualCost);
}
public boolean playerCanDestroy(Player player) {
return true;
}
public boolean shopCanBeWithdrawnFrom() {
return false;
}
}