Fix PR 3 review findings [skip ci]

This commit is contained in:
SCOPEDD committed 2026-09-29 23:21:14 -04:00
1 parent 590178e41a
commit 454620f21e
21 files changed
+522 -160

No files matched your search

@@ -4,6 +4,7 @@ import net.scopenet.integration.*;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.chat.Component;
import net.minecraft.core.BlockPos;
import java.net.*;
import java.nio.file.Path;
import java.util.*;
@@ -72,6 +73,18 @@ public final class Bridge {
if (current != null) current.activity.action(player.getUUID(), player.getName().getString(), action, amount);
}
/** Fail closed while a claim lookup is pending or the panel is unavailable. */
public static boolean canModify(ServerPlayer player, BlockPos pos) {
Integration current = integration;
if (current == null) return false;
if (!current.settings().guildsEnabled() || !current.settings().landClaimingEnabled()) return true;
String dimension = player.serverLevel().dimension().location().toString();
ChunkCheckResult check = current.checkChunk(dimension, pos.getX() >> 4, pos.getZ() >> 4, player.getUUID());
if (check.allowed()) return true;
player.displayClientMessage(Component.literal("This chunk is protected by a guild or the claim check is unavailable."), true);
return false;
}
public static void command(ServerPlayer player, String command) {
String name = command.strip().split("\\s+", 2)[0];
Integration current = integration;
@@ -0,0 +1,20 @@
package net.scopenet.minecraft.mixin;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.scopenet.minecraft.Bridge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerPlayerGameMode.class)
public abstract class BlockBreakMixin {
@Shadow protected net.minecraft.server.level.ServerPlayer player;
@Inject(method = "destroyBlock", at = @At("HEAD"), cancellable = true)
private void scopenet$protectBreak(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if (!Bridge.canModify(player, pos)) cir.setReturnValue(false);
}
}
@@ -0,0 +1,26 @@
package net.scopenet.minecraft.mixin;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.scopenet.minecraft.Bridge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerPlayerGameMode.class)
public abstract class BlockInteractMixin {
@Inject(method = "useItemOn", at = @At("HEAD"), cancellable = true)
private void scopenet$protectInteraction(ServerPlayer player, Level level, ItemStack stack,
InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable<InteractionResult> cir) {
if (!Bridge.canModify(player, hit.getBlockPos())
|| !Bridge.canModify(player, hit.getBlockPos().relative(hit.getDirection()))) {
cir.setReturnValue(InteractionResult.FAIL);
}
}
}
@@ -4,6 +4,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.core.registries.BuiltInRegistries;
import net.scopenet.minecraft.Bridge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
@@ -11,11 +12,20 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BlockItem.class)
public abstract class BlockItemMixin {
@Inject(method = "place(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/InteractionResult;", at = @At("HEAD"), cancellable = true)
private void scopenet$protectPlace(BlockPlaceContext context, CallbackInfoReturnable<InteractionResult> cir) {
if (context.getPlayer() instanceof ServerPlayer player && !Bridge.canModify(player, context.getClickedPos())) {
cir.setReturnValue(InteractionResult.FAIL);
}
}
@Inject(method = "place(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/InteractionResult;", at = @At("RETURN"))
private void scopenet$placed(BlockPlaceContext context, CallbackInfoReturnable<InteractionResult> cir) {
if (cir.getReturnValue().consumesAction() && context.getPlayer() instanceof ServerPlayer player) {
Bridge.stat(player, "blocks_placed", 1);
Bridge.action(player, "block_placed:" + context.getClickedPos().toShortString(), 1);
String material = BuiltInRegistries.BLOCK.getKey(context.getLevel().getBlockState(context.getClickedPos()).getBlock())
.getPath().toUpperCase(java.util.Locale.ROOT);
Bridge.action(player, "block_placed:" + material + "@" + player.serverLevel().dimension().location(), 1);
}
}
}
@@ -2,6 +2,9 @@ package net.scopenet.minecraft.mixin;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.entity.EntityType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.scopenet.minecraft.Bridge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
@@ -13,8 +16,16 @@ public abstract class PlayerMixin {
private void scopenet$stat(Stat<?> stat, int amount, CallbackInfo ci) {
Bridge.action((ServerPlayer) (Object) this, stat.getName(), amount);
String key = null;
if (stat.getType() == Stats.BLOCK_MINED) key = "blocks_broken";
else if (stat.getType() == Stats.CUSTOM) {
if (stat.getType() == Stats.BLOCK_MINED) {
key = "blocks_broken";
String material = BuiltInRegistries.BLOCK.getKey((Block) stat.getValue()).getPath().toUpperCase(java.util.Locale.ROOT);
Bridge.action((ServerPlayer) (Object) this, "block_broken:" + material + "@"
+ ((ServerPlayer) (Object) this).serverLevel().dimension().location(), amount);
} else if (stat.getType() == Stats.ENTITY_KILLED) {
String entity = BuiltInRegistries.ENTITY_TYPE.getKey((EntityType<?>) stat.getValue()).getPath().toUpperCase(java.util.Locale.ROOT);
Bridge.action((ServerPlayer) (Object) this, "mob_kills:" + entity, amount);
}
if (stat.getType() == Stats.CUSTOM) {
key = switch (stat.getValue().toString()) {
case "minecraft:deaths" -> "deaths";
case "minecraft:player_kills" -> "player_kills";
@@ -4,6 +4,6 @@
"package": "net.scopenet.minecraft.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "scopenet.refmap.json",
"mixins": ["DedicatedMixin", "ServerMixin", "LoginMixin", "PlayerMixin", "BlockItemMixin", "ChatMixin", "CommandMixin", "AdvancementMixin"],
"mixins": ["DedicatedMixin", "ServerMixin", "LoginMixin", "PlayerMixin", "BlockItemMixin", "BlockBreakMixin", "BlockInteractMixin", "ChatMixin", "CommandMixin", "AdvancementMixin"],
"injectors": { "defaultRequire": 1 }
}