More PlayerEvent fixes.

This commit is contained in:
MattBDev 2019-12-15 12:53:16 -05:00
parent ed8fa0a2a5
commit 478c761750

View File

@ -1924,23 +1924,15 @@ import java.util.regex.Pattern;
//todo rearrange the right click code. it is all over the place. //todo rearrange the right click code. it is all over the place.
case RIGHT_CLICK_BLOCK: { case RIGHT_CLICK_BLOCK: {
Material blockType = block.getType(); Material blockType = block.getType();
eventType = PlayerBlockEventType.INTERACT_BLOCK;
if (blockType.isInteractable() && player.isSneaking()) { if (blockType.isInteractable() && player.isSneaking()) {
return; //this returns so the block place event is called return; //this returns so the block place event is called
} }
if (blockType.isInteractable()) {
eventType = PlayerBlockEventType.INTERACT_BLOCK;
}
blocktype1 = BukkitAdapter.asBlockType(block.getType()); blocktype1 = BukkitAdapter.asBlockType(block.getType());
if (eventType != null && !player.isSneaking()) { if (!player.isSneaking()) {
break; break;
} }
Material type = event.getMaterial(); Material type = event.getMaterial();
if (type == Material.AIR) {
if (!player.isSneaking() && blockType.isInteractable()) {
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break outer;
}
}
// in the following, lb needs to have the material of the item in hand i.e. type // in the following, lb needs to have the material of the item in hand i.e. type
if (type == Material.REDSTONE || type == Material.STRING if (type == Material.REDSTONE || type == Material.STRING
@ -2001,7 +1993,7 @@ import java.util.regex.Pattern;
} }
case LEFT_CLICK_BLOCK: { case LEFT_CLICK_BLOCK: {
location = BukkitUtil.getLocation(block.getLocation()); location = BukkitUtil.getLocation(block.getLocation());
// eventType = PlayerBlockEventType.BREAK_BLOCK; //eventType = PlayerBlockEventType.BREAK_BLOCK;
blocktype1 = BukkitAdapter.asBlockType(block.getType()); blocktype1 = BukkitAdapter.asBlockType(block.getType());
if (block.getType() == Material.DRAGON_EGG) { if (block.getType() == Material.DRAGON_EGG) {
eventType = PlayerBlockEventType.TELEPORT_OBJECT; eventType = PlayerBlockEventType.TELEPORT_OBJECT;
@ -2018,18 +2010,6 @@ import java.util.regex.Pattern;
return; return;
} }
} }
if (eventType == null) {
PlotSquared.log("Please report this to PlotSquared Developers: ");
PlotSquared.log("Action: " + event.getAction().toString());
PlotSquared.log("HasItem: " + event.hasItem());
PlotSquared.log("HasBlock: " + event.hasBlock());
PlotSquared.log("getItem: " + (event.hasItem() ? Objects.requireNonNull(event.getItem())
.toString() : "null"));
PlotSquared.log("getBlockFace: " + (event.getBlockFace() != null ? event.getBlockFace().toString() : "null"));
PlotSquared.log("isBlockInHand: " + (event.isBlockInHand()));
PlotSquared.log("getClickedBlock: " + (event.getClickedBlock() != null ? event.getClickedBlock().toString() : "null"));
return;
}
if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) { if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) {
event.setCancelled(true); event.setCancelled(true);
event.setUseInteractedBlock(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY);