修复了可能导致NPE的问题

This commit is contained in:
17146 2025-01-03 00:43:17 +08:00
parent 6dc14b53a5
commit 811434fb76
2 changed files with 7 additions and 7 deletions

View file

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

View file

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