mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-24 00:51:41 +01:00
Fix /npc text remove clickable not working, make /npc shop item action work on material alone for now
This commit is contained in:
parent
ebe1d27986
commit
a91f0cd2ee
@ -296,13 +296,13 @@ public class ShopTrait extends Trait {
|
||||
}
|
||||
|
||||
public void onClick(NPCShop shop, CitizensInventoryClickEvent event) {
|
||||
if (shop.type != ShopType.COMMAND) {
|
||||
List<Transaction> take = execute(cost, action -> action.take(event.getWhoClicked()));
|
||||
if (take == null)
|
||||
return;
|
||||
if (execute(result, action -> action.grant(event.getWhoClicked())) == null) {
|
||||
take.forEach(a -> a.rollback());
|
||||
}
|
||||
if (shop.type == ShopType.COMMAND)
|
||||
return;
|
||||
List<Transaction> take = execute(cost, action -> action.take(event.getWhoClicked()));
|
||||
if (take == null)
|
||||
return;
|
||||
if (execute(result, action -> action.grant(event.getWhoClicked())) == null) {
|
||||
take.forEach(a -> a.rollback());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,9 +68,7 @@ public class ItemAction extends NPCShopAction {
|
||||
.collect(Collectors.toMap(k -> k.getType(), v -> v.getAmount()));
|
||||
boolean contains = true;
|
||||
for (Map.Entry<Material, Integer> entry : required.entrySet()) {
|
||||
if (!source.contains(entry.getKey(), entry.getValue())) {
|
||||
contains = false;
|
||||
}
|
||||
contains &= source.contains(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (ItemStack item : items) {
|
||||
if (item.hasItemMeta() && !source.contains(item)) {
|
||||
@ -79,7 +77,26 @@ public class ItemAction extends NPCShopAction {
|
||||
}
|
||||
return contains;
|
||||
}, () -> {
|
||||
source.removeItem(items.toArray(new ItemStack[items.size()]));
|
||||
Map<Material, Integer> required = items.stream()
|
||||
.collect(Collectors.toMap(k -> k.getType(), v -> v.getAmount()));
|
||||
ItemStack[] contents = source.getContents();
|
||||
for (int i = 0; i < contents.length; i++) {
|
||||
ItemStack stack = contents[i];
|
||||
if (stack == null || stack.getType() == Material.AIR || !required.containsKey(stack.getType()))
|
||||
continue;
|
||||
Material type = stack.getType();
|
||||
int remaining = required.remove(type);
|
||||
int taken = stack.getAmount() > remaining ? remaining : stack.getAmount();
|
||||
if (stack.getAmount() == taken) {
|
||||
source.clear(i);
|
||||
} else {
|
||||
stack.setAmount(stack.getAmount() - taken);
|
||||
source.setItem(i, stack);
|
||||
}
|
||||
if (remaining - taken > 0) {
|
||||
required.put(type, remaining - taken);
|
||||
}
|
||||
}
|
||||
}, () -> {
|
||||
source.addItem(items.toArray(new ItemStack[items.size()]));
|
||||
});
|
||||
@ -105,7 +122,7 @@ public class ItemAction extends NPCShopAction {
|
||||
for (int i = 0; i < 3 * 9; i++) {
|
||||
InventoryMenuSlot slot = ctx.getSlot(i);
|
||||
slot.clear();
|
||||
if (i < base.items.size()) {
|
||||
if (base != null && i < base.items.size()) {
|
||||
slot.setItemStack(base.items.get(i).clone());
|
||||
}
|
||||
slot.setClickHandler(event -> {
|
||||
|
@ -234,8 +234,8 @@ public class Text extends Trait implements Runnable, Listener, ConversationAband
|
||||
Paginator paginator = new Paginator().header("Current Texts").enablePageSwitcher();
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
paginator.addLine(text.get(i) + " <green>(<click:suggest_command:edit " + i
|
||||
+ " ><yellow>edit</click>) (<click:run_command:remove " + i
|
||||
+ "><hover:show_text:Remove this text><red>-</hover></click>)");
|
||||
+ " ><yellow>edit</click>) (<hover:show_text:Remove this text><click:run_command:/npc text remove "
|
||||
+ i + "><red>-</click></hover>)");
|
||||
}
|
||||
return paginator.sendPage(player, page);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user