Skip to content

Commit

Permalink
Quick fix attempt for placed material issues with off-hand.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Jul 20, 2016
1 parent 2077944 commit 7243ab7
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -103,7 +103,7 @@ public static int getBlockPlaceHash(final Block block, final Material mat) {
private final int idEnderPearl = counters.registerKey("throwenderpearl");

private final Class<?> blockMultiPlaceEvent = ReflectionUtil.getClass("org.bukkit.event.block.BlockMultiPlaceEvent");
private final boolean hasReplacedState = ReflectionUtil.getMethodNoArgs(BlockPlaceEvent.class, "getReplacedState", BlockState.class) != null;
private final boolean hasGetReplacedState = ReflectionUtil.getMethodNoArgs(BlockPlaceEvent.class, "getReplacedState", BlockState.class) != null;

public BlockPlaceListener() {
super(CheckType.BLOCKPLACE);
Expand All @@ -130,7 +130,17 @@ public void onBlockPlace(final BlockPlaceEvent event) {
// TODO: Revise material use (not block.get... ?)
//final Material mat = block.getType();
final Player player = event.getPlayer();
final Material placedMat = hasReplacedState ? event.getBlockPlaced().getType() : Bridge1_9.getItemInMainHand(player).getType(); // Safety first.
final Material placedMat;
if (hasGetReplacedState) {
placedMat = event.getBlockPlaced().getType();
}
else if (Bridge1_9.hasGetItemInOffHand()) {
final ItemStack stack = event.getItemInHand();
placedMat = BlockProperties.isAir(stack) ? Material.AIR : stack.getType();
}
else {
placedMat = Bridge1_9.getItemInMainHand(player).getType(); // Safety first.
}
boolean cancelled = false;

final BlockPlaceData data = BlockPlaceData.getData(player);
Expand Down

0 comments on commit 7243ab7

Please sign in to comment.