New fapi block break event

This commit is contained in:
samo_lego 2020-09-27 11:15:50 +02:00
parent 7def6aea23
commit 8acba5649d
2 changed files with 12 additions and 10 deletions

View File

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

View File

@ -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