prevent dragon block interaction near no permission claims fix #218
This commit is contained in:
parent
3ab4e66f6a
commit
17ee9d2355
@ -233,6 +233,8 @@ public class ClaimStorage implements IPermissionStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canInteract(BlockPos pos, int radius, ServerPlayer player, ClaimPermission perm, boolean message) {
|
public boolean canInteract(BlockPos pos, int radius, ServerPlayer player, ClaimPermission perm, boolean message) {
|
||||||
|
boolean realPlayer = player != null && player.getClass().equals(ServerPlayer.class);
|
||||||
|
message = message && realPlayer;
|
||||||
ChunkPos c = new ChunkPos(new BlockPos(pos.getX() - radius, pos.getY(), pos.getZ() - radius));
|
ChunkPos c = new ChunkPos(new BlockPos(pos.getX() - radius, pos.getY(), pos.getZ() - radius));
|
||||||
List<Claim> affected = new ArrayList<>();
|
List<Claim> affected = new ArrayList<>();
|
||||||
for (int x = 0; SectionPos.sectionToBlockCoord(c.x + x) <= pos.getX() + radius; x++) {
|
for (int x = 0; SectionPos.sectionToBlockCoord(c.x + x) <= pos.getX() + radius; x++) {
|
||||||
@ -247,16 +249,22 @@ public class ClaimStorage implements IPermissionStorage {
|
|||||||
pos.getX() + radius, pos.getY(), pos.getZ() + radius)) {
|
pos.getX() + radius, pos.getY(), pos.getZ() + radius)) {
|
||||||
if (last != null) {
|
if (last != null) {
|
||||||
if (last.insideClaim(ipos)) {
|
if (last.insideClaim(ipos)) {
|
||||||
if (!last.canInteract(player, perm, ipos, message))
|
if (!last.canInteract(player, perm, ipos, false)) {
|
||||||
|
if (message)
|
||||||
|
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("noPermissionTooClose"), ChatFormatting.DARK_RED), true);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
} else last = null;
|
} else last = null;
|
||||||
}
|
}
|
||||||
for (Claim claim : affected) {
|
for (Claim claim : affected) {
|
||||||
if (claim.insideClaim(ipos)) {
|
if (claim.insideClaim(ipos)) {
|
||||||
last = claim;
|
last = claim;
|
||||||
if (!claim.canInteract(player, perm, ipos, message))
|
if (!claim.canInteract(player, perm, ipos, message)) {
|
||||||
|
if (message)
|
||||||
|
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("noPermissionTooClose"), ChatFormatting.DARK_RED), true);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ public class LangManager {
|
|||||||
|
|
||||||
this.defaultTranslation.put("noPermission", "You don't have the required permissions to do that here!");
|
this.defaultTranslation.put("noPermission", "You don't have the required permissions to do that here!");
|
||||||
this.defaultTranslation.put("noPermissionSimple", "Sorry you can't do that here!");
|
this.defaultTranslation.put("noPermissionSimple", "Sorry you can't do that here!");
|
||||||
|
this.defaultTranslation.put("noPermissionTooClose", "Sorry you are too close to a claim to do that here!");
|
||||||
this.defaultTranslation.put("tooCloseClaim", "You are too close to a protected area to do that!");
|
this.defaultTranslation.put("tooCloseClaim", "You are too close to a protected area to do that!");
|
||||||
|
|
||||||
this.defaultTranslation.put("configReload", "Configs reloaded");
|
this.defaultTranslation.put("configReload", "Configs reloaded");
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package io.github.flemmli97.flan.mixin;
|
||||||
|
|
||||||
|
import io.github.flemmli97.flan.api.permission.ClaimPermission;
|
||||||
|
import io.github.flemmli97.flan.api.permission.ObjectToPermissionMap;
|
||||||
|
import io.github.flemmli97.flan.api.permission.PermissionRegistry;
|
||||||
|
import io.github.flemmli97.flan.claim.ClaimStorage;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.DragonEggBlock;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(DragonEggBlock.class)
|
||||||
|
public class DragonEggBlockMixin {
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private Player flanTempPlayer;
|
||||||
|
|
||||||
|
@Inject(method = "use", at = @At("HEAD"))
|
||||||
|
private void onUse(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable<InteractionResult> info) {
|
||||||
|
this.flanTempPlayer = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "use", at = @At("RETURN"))
|
||||||
|
private void onUseReturn(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable<InteractionResult> info) {
|
||||||
|
this.flanTempPlayer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "attack", at = @At("HEAD"))
|
||||||
|
private void onAttack(BlockState state, Level level, BlockPos pos, Player player, CallbackInfo info) {
|
||||||
|
this.flanTempPlayer = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "attack", at = @At("RETURN"))
|
||||||
|
private void onAttackReturn(BlockState state, Level level, BlockPos pos, Player player, CallbackInfo info) {
|
||||||
|
this.flanTempPlayer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "teleport", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void onTeleport(BlockState state, Level level, BlockPos pos, CallbackInfo info) {
|
||||||
|
if (this.flanTempPlayer instanceof ServerPlayer player) {
|
||||||
|
ClaimPermission perm = ObjectToPermissionMap.getFromBlock((DragonEggBlock) (Object) this);
|
||||||
|
if (perm == null)
|
||||||
|
perm = PermissionRegistry.INTERACTBLOCK;
|
||||||
|
if (!ClaimStorage.get(player.getLevel()).canInteract(pos, 16, player, perm, true))
|
||||||
|
info.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,8 @@
|
|||||||
"MossBlockCheckMixin",
|
"MossBlockCheckMixin",
|
||||||
"EnderMitePearlCheck",
|
"EnderMitePearlCheck",
|
||||||
"SculkSensorMixin",
|
"SculkSensorMixin",
|
||||||
"SculkShriekerMixin"
|
"SculkShriekerMixin",
|
||||||
|
"DragonEggBlockMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user