mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-09 16:47:36 +01:00
Update the container on item transfers (Fixes #217)
This was removed when the item transfer code changed which stopped comparators from working. This shouldn't be a true block update that observers can detect but only a notification for surrounding blocks that the content might have changed.
This commit is contained in:
parent
eb7abda01f
commit
6e78fea880
@ -3,10 +3,13 @@ package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
|||||||
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
||||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||||
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY;
|
||||||
@ -23,8 +26,6 @@ public class ItemManager implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transferItems(event.getOwnerInventory(), event.getClientInventory(), event.getStock());
|
transferItems(event.getOwnerInventory(), event.getClientInventory(), event.getStock());
|
||||||
|
|
||||||
event.getClient().updateInventory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
@ -34,8 +35,6 @@ public class ItemManager implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transferItems(event.getClientInventory(), event.getOwnerInventory(), event.getStock());
|
transferItems(event.getClientInventory(), event.getOwnerInventory(), event.getStock());
|
||||||
|
|
||||||
event.getClient().updateInventory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void transferItems(Inventory sourceInventory, Inventory targetInventory, ItemStack[] items) {
|
private static void transferItems(Inventory sourceInventory, Inventory targetInventory, ItemStack[] items) {
|
||||||
@ -48,5 +47,16 @@ public class ItemManager implements Listener {
|
|||||||
InventoryUtil.transfer(item, sourceInventory, targetInventory);
|
InventoryUtil.transfer(item, sourceInventory, targetInventory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
update(sourceInventory.getHolder());
|
||||||
|
update(targetInventory.getHolder());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void update(InventoryHolder holder) {
|
||||||
|
if (holder instanceof Player) {
|
||||||
|
((Player) holder).updateInventory();
|
||||||
|
}
|
||||||
|
if (holder instanceof BlockState) {
|
||||||
|
((BlockState) holder).update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user