|
@@ -119,7 +119,7 @@ public class ScriptEvents implements BlockHarvest, Craft {
|
|
|
private void handleVar(Script sc, String event, String name, Consumer<Variable> c) {
|
|
|
try {
|
|
|
ifVarNotNull(sc, name, c);
|
|
|
- } catch (Exception ex) {
|
|
|
+ } catch(Exception ex) {
|
|
|
scripts.getLogger().print(String.format("invalid var in '%s' event", event), ex, null,
|
|
|
sc.getName(), sc, sc.getStackTrace());
|
|
|
}
|
|
@@ -135,7 +135,7 @@ public class ScriptEvents implements BlockHarvest, Craft {
|
|
|
private void simpleCancel(Script sc, Event e, String name) {
|
|
|
try {
|
|
|
ifVarNotNull(sc, "cancel", v -> e.setCanceled(v.getBoolean(sc)));
|
|
|
- } catch (Exception ex) {
|
|
|
+ } catch(Exception ex) {
|
|
|
scripts.getLogger().print(String.format("invalid var in '%s' event", name), ex, null,
|
|
|
sc.getName(), sc, sc.getStackTrace());
|
|
|
}
|
|
@@ -273,7 +273,7 @@ public class ScriptEvents implements BlockHarvest, Craft {
|
|
|
final Location loc;
|
|
|
|
|
|
RayTraceResult ray = e.getRayTraceResult();
|
|
|
- switch (ray.getType()) {
|
|
|
+ switch(ray.getType()) {
|
|
|
case ENTITY:
|
|
|
hitEntity = ((EntityRayTraceResult) e.getRayTraceResult()).getEntity();
|
|
|
loc = null;
|
|
@@ -327,7 +327,7 @@ public class ScriptEvents implements BlockHarvest, Craft {
|
|
|
setEntity(sc, ent);
|
|
|
setItem(sc, stack);
|
|
|
}, ScriptEvents::nothing);
|
|
|
- } catch (Exception ex) {
|
|
|
+ } catch(Exception ex) {
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
return list;
|
|
@@ -412,7 +412,14 @@ public class ScriptEvents implements BlockHarvest, Craft {
|
|
|
ScriptEvents.setBlock(sc, e.getWorld(), e.getPos());
|
|
|
sc.setVar("cancel", e.isCanceled());
|
|
|
}, (sc) -> {
|
|
|
- simpleCancel(sc, e, "block_click");
|
|
|
+ handleVar(sc, "block_click", "cancel", v -> {
|
|
|
+ boolean b = v.getBoolean(sc);
|
|
|
+ e.setCanceled(b);
|
|
|
+ if(!b) {
|
|
|
+ e.setUseBlock(Result.DEFAULT);
|
|
|
+ e.setUseItem(Result.DEFAULT);
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -425,7 +432,14 @@ public class ScriptEvents implements BlockHarvest, Craft {
|
|
|
ScriptEvents.setBlock(sc, e.getWorld(), e.getPos());
|
|
|
sc.setVar("cancel", e.isCanceled());
|
|
|
}, (sc) -> {
|
|
|
- simpleCancel(sc, e, "block_click");
|
|
|
+ handleVar(sc, "block_click", "cancel", v -> {
|
|
|
+ boolean b = v.getBoolean(sc);
|
|
|
+ e.setCanceled(b);
|
|
|
+ if(!b) {
|
|
|
+ e.setUseBlock(Result.DEFAULT);
|
|
|
+ e.setUseItem(Result.DEFAULT);
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|