Permalink
Browse files

Better handle air in player_interact

  • Loading branch information...
PseudoKnight committed Aug 8, 2018
1 parent 7488722 commit 6944aba6017e1a7d15454da0b64e3fb3508e1aeb
Showing with 15 additions and 13 deletions.
  1. +15 −13 src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java
@@ -861,9 +861,9 @@ public String getName() {
@Override
public String docs() {
return "{block: <string match> The block type the player interacts with is this"
return "{block: <string match> The block type the player interacts with, or null if nothing"
+ " | button: <string match> left or right. If they left or right clicked |"
+ " itemname: <string match> The item type they are holding when they interacted |"
+ " itemname: <string match> The item type they are holding when they interacted, or null |"
+ " hand: <string match> The hand the player clicked with |"
+ " player: <macro> The player that triggered the event} "
+ "Fires when a player left or right clicks a block or the air"
@@ -940,23 +940,25 @@ public boolean matches(Map<String, Construct> prefilter, BindableEvent e) throws
}
if(prefilter.containsKey("itemname")) {
String value = prefilter.get("itemname").val();
Construct item = prefilter.get("itemname");
MCMaterial mat = pie.getItem().getType();
if(mat != null && !mat.getName().equals(value) || mat == null && !value.equals("AIR")) {
if(mat == null) {
if(!(item instanceof CNull)) {
return false;
}
} else if(!mat.getName().equals(item.val())) {
return false;
}
}
if(prefilter.containsKey("block")) {
Construct value = prefilter.get("block");
Construct block = prefilter.get("block");
MCBlock b = pie.getClickedBlock();
if(value instanceof CNull) {
if(!b.isEmpty()) {
return false;
}
} else {
if(!b.getType().getName().equals(value.val())) {
if(b.isEmpty()) {
if(!(block instanceof CNull)) {
return false;
}
} else if(!b.getType().getName().equals(block.val())) {
return false;
}
}
Prefilters.match(prefilter, "player", pie.getPlayer().getName(), PrefilterType.MACRO);
@@ -979,8 +981,8 @@ public boolean matches(Map<String, Construct> prefilter, BindableEvent e) throws
Map<String, Construct> map = evaluate_helper(e);
MCAction a = pie.getAction();
map.put("action", new CString(a.name().toLowerCase(), Target.UNKNOWN));
MCMaterial block = pie.getClickedBlock().getType();
map.put("block", block == null ? CNull.NULL : new CString(block.getName(), Target.UNKNOWN));
MCBlock block = pie.getClickedBlock();
map.put("block", block.isEmpty() ? CNull.NULL : new CString(block.getType().getName(), Target.UNKNOWN));
if(a == MCAction.LEFT_CLICK_AIR || a == MCAction.LEFT_CLICK_BLOCK) {
map.put("button", new CString("left", Target.UNKNOWN));
} else {

0 comments on commit 6944aba

Please sign in to comment.