修复了可能导致NPE的问题
This commit is contained in:
parent
6dc14b53a5
commit
811434fb76
2 changed files with 7 additions and 7 deletions
|
@ -2,27 +2,28 @@
|
||||||
package com.atsuishio.superbwarfare.command;
|
package com.atsuishio.superbwarfare.command;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
import com.atsuishio.superbwarfare.network.ModVariables;
|
||||||
|
import com.atsuishio.superbwarfare.tools.GunInfo;
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.atsuishio.superbwarfare.tools.GunInfo;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
import net.minecraft.commands.arguments.EntityArgument;
|
import net.minecraft.commands.arguments.EntityArgument;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraftforge.server.command.EnumArgument;
|
import net.minecraftforge.server.command.EnumArgument;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class AmmoCommand {
|
public class AmmoCommand {
|
||||||
|
|
||||||
public static LiteralArgumentBuilder<CommandSourceStack> get() {
|
public static LiteralArgumentBuilder<CommandSourceStack> get() {
|
||||||
// mojang你看看你写的是个牛魔Builder😅
|
// mojang你看看你写的是个牛魔Builder😅
|
||||||
return Commands.literal("ammo").requires(s -> s.hasPermission(0))
|
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 -> {
|
.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 player = EntityArgument.getPlayer(context, "player");
|
||||||
|
|
||||||
|
var source = context.getSource();
|
||||||
|
|
||||||
// 权限不足时,只允许玩家查询自己的弹药数量
|
// 权限不足时,只允许玩家查询自己的弹药数量
|
||||||
if (context.getSource().isPlayer() && !context.getSource().hasPermission(2)) {
|
if (source.isPlayer() && !source.hasPermission(2)) {
|
||||||
if (!Objects.requireNonNull(context.getSource().getPlayer()).getUUID().equals(player.getUUID())) {
|
if (source.getPlayer() != null && !source.getPlayer().getUUID().equals(player.getUUID())) {
|
||||||
context.getSource().sendFailure(Component.translatable("commands.ammo.no_permission"));
|
context.getSource().sendFailure(Component.translatable("commands.ammo.no_permission"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -184,7 +183,7 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity,
|
||||||
&& target instanceof LivingEntity
|
&& target instanceof LivingEntity
|
||||||
&& !(target instanceof TargetEntity)
|
&& !(target instanceof TargetEntity)
|
||||||
&& !(target instanceof Player player && (player.isCreative() || player.isSpectator()))
|
&& !(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();
|
&& !target.isShiftKeyDown();
|
||||||
if (!condition) continue;
|
if (!condition) continue;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue