Update double chests too after transactions (Fixes #412)
This commit is contained in:
parent
7b2fe6c1f3
commit
227e3e77f0
|
@ -2,6 +2,7 @@ package com.Acrobot.Breeze.Utils;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.DoubleChest;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
|
@ -10,6 +11,8 @@ import java.util.function.BiFunction;
|
||||||
public class ImplementationAdapter {
|
public class ImplementationAdapter {
|
||||||
|
|
||||||
private static BiFunction<Inventory, Boolean, InventoryHolder> HOLDER_PROVIDER;
|
private static BiFunction<Inventory, Boolean, InventoryHolder> HOLDER_PROVIDER;
|
||||||
|
private static BiFunction<DoubleChest, Boolean, InventoryHolder> LEFT_HOLDER_PROVIDER;
|
||||||
|
private static BiFunction<DoubleChest, Boolean, InventoryHolder> RIGHT_HOLDER_PROVIDER;
|
||||||
private static BiFunction<Block, Boolean, BlockState> STATE_PROVIDER;
|
private static BiFunction<Block, Boolean, BlockState> STATE_PROVIDER;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -17,8 +20,12 @@ public class ImplementationAdapter {
|
||||||
Inventory.class.getMethod("getHolder", boolean.class);
|
Inventory.class.getMethod("getHolder", boolean.class);
|
||||||
Class c = Class.forName("com.Acrobot.Breeze.Utils.ImplementationFeatures.PaperLatestHolder");
|
Class c = Class.forName("com.Acrobot.Breeze.Utils.ImplementationFeatures.PaperLatestHolder");
|
||||||
HOLDER_PROVIDER = (BiFunction<Inventory, Boolean, InventoryHolder>) c.getDeclaredField("PROVIDER").get(null);
|
HOLDER_PROVIDER = (BiFunction<Inventory, Boolean, InventoryHolder>) c.getDeclaredField("PROVIDER").get(null);
|
||||||
|
LEFT_HOLDER_PROVIDER = (BiFunction<DoubleChest, Boolean, InventoryHolder>) c.getDeclaredField("LEFT_PROVIDER").get(null);
|
||||||
|
RIGHT_HOLDER_PROVIDER = (BiFunction<DoubleChest, Boolean, InventoryHolder>) c.getDeclaredField("RIGHT_PROVIDER").get(null);
|
||||||
} catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
|
} catch (NoSuchMethodException | ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
|
||||||
HOLDER_PROVIDER = (inventory, useSnapshot) -> inventory.getHolder();
|
HOLDER_PROVIDER = (inventory, useSnapshot) -> inventory.getHolder();
|
||||||
|
LEFT_HOLDER_PROVIDER = (doubleChest, useSnapshot) -> doubleChest.getLeftSide();
|
||||||
|
RIGHT_HOLDER_PROVIDER = (doubleChest, useSnapshot) -> doubleChest.getRightSide();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Block.class.getMethod("getState", boolean.class);
|
Block.class.getMethod("getState", boolean.class);
|
||||||
|
@ -39,6 +46,26 @@ public class ImplementationAdapter {
|
||||||
return HOLDER_PROVIDER.apply(inventory, useSnapshot);
|
return HOLDER_PROVIDER.apply(inventory, useSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the a DoubleChest's left side
|
||||||
|
* @param doubleChest The DoubleChest
|
||||||
|
* @param useSnapshot Whether or not the holder should be a snapshot (if possible)
|
||||||
|
* @return The left side's holder
|
||||||
|
*/
|
||||||
|
public static InventoryHolder getLeftSide(DoubleChest doubleChest, boolean useSnapshot) {
|
||||||
|
return LEFT_HOLDER_PROVIDER.apply(doubleChest, useSnapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the a DoubleChest's right side
|
||||||
|
* @param doubleChest The DoubleChest
|
||||||
|
* @param useSnapshot Whether or not the holder should be a snapshot (if possible)
|
||||||
|
* @return The left right's holder
|
||||||
|
*/
|
||||||
|
public static InventoryHolder getRightSide(DoubleChest doubleChest, boolean useSnapshot) {
|
||||||
|
return RIGHT_HOLDER_PROVIDER.apply(doubleChest, useSnapshot);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a block state
|
* Get a block state
|
||||||
* @param block The block to get the state from
|
* @param block The block to get the state from
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.Acrobot.Breeze.Utils.ImplementationFeatures;
|
package com.Acrobot.Breeze.Utils.ImplementationFeatures;
|
||||||
|
|
||||||
|
import org.bukkit.block.DoubleChest;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
|
||||||
|
@ -9,4 +10,8 @@ public class PaperLatestHolder {
|
||||||
|
|
||||||
public static final BiFunction<Inventory, Boolean, InventoryHolder> PROVIDER = Inventory::getHolder;
|
public static final BiFunction<Inventory, Boolean, InventoryHolder> PROVIDER = Inventory::getHolder;
|
||||||
|
|
||||||
|
public static final BiFunction<DoubleChest, Boolean, InventoryHolder> LEFT_PROVIDER = DoubleChest::getLeftSide;
|
||||||
|
|
||||||
|
public static final BiFunction<DoubleChest, Boolean, InventoryHolder> RIGHT_PROVIDER = DoubleChest::getRightSide;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
package com.Acrobot.ChestShop.Listeners.PostTransaction;
|
||||||
|
|
||||||
|
import com.Acrobot.Breeze.Utils.ImplementationAdapter;
|
||||||
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
||||||
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
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.block.BlockState;
|
||||||
|
import org.bukkit.block.DoubleChest;
|
||||||
import org.bukkit.entity.Player;
|
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;
|
||||||
|
@ -54,9 +57,11 @@ public class ItemManager implements Listener {
|
||||||
private static void update(InventoryHolder holder) {
|
private static void update(InventoryHolder holder) {
|
||||||
if (holder instanceof Player) {
|
if (holder instanceof Player) {
|
||||||
((Player) holder).updateInventory();
|
((Player) holder).updateInventory();
|
||||||
}
|
} else if (holder instanceof BlockState) {
|
||||||
if (holder instanceof BlockState) {
|
|
||||||
((BlockState) holder).update();
|
((BlockState) holder).update();
|
||||||
|
} else if (holder instanceof DoubleChest) {
|
||||||
|
update(ImplementationAdapter.getLeftSide((DoubleChest) holder, false));
|
||||||
|
update(ImplementationAdapter.getRightSide((DoubleChest) holder, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue