Quellcode durchsuchen

stupid bugfix because Forge does not really uncancel blick clicks

Kajetan Johannes Hammerle vor 4 Jahren
Ursprung
Commit
6b41b7b2e5

+ 1 - 5
src/main/java/me/km/plots/ProtectionEvents.java

@@ -140,11 +140,7 @@ public class ProtectionEvents {
     @SubscribeEvent(priority = EventPriority.HIGHEST)
     public void onPlayerInteract(PlayerInteractEvent.LeftClickBlock e) {
         PlayerEntity p = e.getPlayer();
-        if(canBypass(p)) {
-            return;
-        }
-        Block b = e.getWorld().getBlockState(e.getPos()).getBlock();
-        if(b == Blocks.FIRE && !plots.canBreakBlock(e.getWorld(), e.getPos(), p)) {
+        if(!canBypass(p) && !plots.canInteractWithBlock(e.getWorld(), e.getPos(), p)) {
             e.setCanceled(true);
         }
     }

+ 20 - 6
src/main/java/me/km/snuviscript/ScriptEvents.java

@@ -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);
+                }
+            });
         });
     }