From 8acba5649d04893008e22731d5ff5ed02148bd65 Mon Sep 17 00:00:00 2001 From: samo_lego <34912839+samolego@users.noreply.github.com> Date: Sun, 27 Sep 2020 11:15:50 +0200 Subject: [PATCH] New fapi block break event --- .../java/org/samo_lego/simpleauth/SimpleAuth.java | 14 ++++++++------ .../simpleauth/event/AuthEventHandler.java | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index 76b0876..b0bb451 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -39,6 +39,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import static org.iq80.leveldb.impl.Iq80DBFactory.bytes; +import static org.samo_lego.simpleauth.commands.AuthCommand.reloadConfig; +import static org.samo_lego.simpleauth.event.AuthEventHandler.*; import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake; import static org.samo_lego.simpleauth.utils.SimpleLogger.logError; import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo; @@ -122,12 +124,12 @@ public class SimpleAuth implements DedicatedServerModInitializer { PlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove); // From Fabric API - AttackBlockCallback.EVENT.register((playerEntity, world, hand, blockPos, direction) -> AuthEventHandler.onAttackBlock(playerEntity)); - UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> AuthEventHandler.onUseBlock(player)); - UseItemCallback.EVENT.register((player, world, hand) -> AuthEventHandler.onUseItem(player)); - AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onAttackEntity(player)); - UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> AuthEventHandler.onUseEntity(player)); - ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> AuthCommand.reloadConfig(null)); + PlayerBlockBreakEvents.BEFORE.register((world, playerEntity, blockPos, blockState, blockEntity) -> onBreakBlock(playerEntity)); + UseBlockCallback.EVENT.register((player, world, hand, blockHitResult) -> onUseBlock(player)); + UseItemCallback.EVENT.register((player, world, hand) -> onUseItem(player)); + AttackEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onAttackEntity(player)); + UseEntityCallback.EVENT.register((player, world, hand, entity, entityHitResult) -> onUseEntity(player)); + ServerLifecycleEvents.START_DATA_PACK_RELOAD.register((server, serverResourceManager) -> reloadConfig(null)); ServerLifecycleEvents.SERVER_STOPPED.register(this::onStopServer); } diff --git a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java index 8c01114..4040a4d 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -174,13 +174,13 @@ public class AuthEventHandler { return ActionResult.PASS; } - // Punching a block - public static ActionResult onAttackBlock(PlayerEntity player) { + // Breaking a block + public static boolean onBreakBlock(PlayerEntity player) { if(!isAuthenticated((ServerPlayerEntity) player) && !config.experimental.allowBlockPunch) { player.sendMessage(notAuthenticated(player), false); - return ActionResult.FAIL; + return false; } - return ActionResult.PASS; + return true; } // Using an item