From 811434fb76112c2f30eabffbd0828bb3870ec53f Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Fri, 3 Jan 2025 00:43:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=AF=BC=E8=87=B4NPE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../atsuishio/superbwarfare/command/AmmoCommand.java | 11 ++++++----- .../superbwarfare/entity/ClaymoreEntity.java | 3 +-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/command/AmmoCommand.java b/src/main/java/com/atsuishio/superbwarfare/command/AmmoCommand.java index e20d5fa4e..2ffe11fdc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/command/AmmoCommand.java +++ b/src/main/java/com/atsuishio/superbwarfare/command/AmmoCommand.java @@ -2,27 +2,28 @@ package com.atsuishio.superbwarfare.command; import com.atsuishio.superbwarfare.network.ModVariables; +import com.atsuishio.superbwarfare.tools.GunInfo; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.atsuishio.superbwarfare.tools.GunInfo; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.network.chat.Component; import net.minecraftforge.server.command.EnumArgument; -import java.util.Objects; - public class AmmoCommand { + public static LiteralArgumentBuilder get() { // mojang你看看你写的是个牛魔Builder😅 return Commands.literal("ammo").requires(s -> s.hasPermission(0)) .then(Commands.literal("get").then(Commands.argument("player", EntityArgument.player()).then(Commands.argument("type", EnumArgument.enumArgument(GunInfo.Type.class)).executes(context -> { var player = EntityArgument.getPlayer(context, "player"); + var source = context.getSource(); + // 权限不足时,只允许玩家查询自己的弹药数量 - if (context.getSource().isPlayer() && !context.getSource().hasPermission(2)) { - if (!Objects.requireNonNull(context.getSource().getPlayer()).getUUID().equals(player.getUUID())) { + if (source.isPlayer() && !source.hasPermission(2)) { + if (source.getPlayer() != null && !source.getPlayer().getUUID().equals(player.getUUID())) { context.getSource().sendFailure(Component.translatable("commands.ammo.no_permission")); return 0; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java index dbbc5cc8f..ac559150b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java @@ -34,7 +34,6 @@ import software.bernie.geckolib.util.GeckoLibUtil; import javax.annotation.Nullable; import java.util.Comparator; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -184,7 +183,7 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, && target instanceof LivingEntity && !(target instanceof TargetEntity) && !(target instanceof Player player && (player.isCreative() || player.isSpectator())) - && (!Objects.requireNonNull(this.getOwner()).isAlliedTo(target) || target.getTeam() == null || target.getTeam().getName().equals("TDM")) + && (this.getOwner() != null && !this.getOwner().isAlliedTo(target) || target.getTeam() == null || target.getTeam().getName().equals("TDM")) && !target.isShiftKeyDown(); if (!condition) continue;