Skip to content

Commit e1b4c95

Browse files
committed
fix anchor update npe and update mc version range
1 parent b65a07a commit e1b4c95

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

common/src/main/java/de/z0rdak/yawp/commands/RegionCommands.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import static de.z0rdak.yawp.constants.Constants.MAX_BUILD_LIMIT;
5959
import static de.z0rdak.yawp.constants.Constants.MIN_BUILD_LIMIT;
6060
import static de.z0rdak.yawp.util.ChatComponentBuilder.shortBlockPos;
61+
import static de.z0rdak.yawp.util.ChatComponentBuilder.shortBlockPosBracketed;
6162
import static de.z0rdak.yawp.util.ChatLinkBuilder.*;
6263

6364

@@ -649,10 +650,14 @@ private static int updateTeleportAnchor(CommandContext<CommandSourceStack> ctx,
649650
return -1;
650651
}
651652
if (!region.getArea().contains(pos)) {
652-
sendCmdFeedback(ctx.getSource(), Component.translatableWithFallback("cli.msg.info.region.tp-anchor.fail-msg.not-contained", "Teleport Anchor pos must be inside the region.", name, buildRegionInfoLink(region)));
653+
sendCmdFeedback(ctx.getSource(), Component.translatableWithFallback("cli.msg.info.region.tp-anchor.fail-msg.not-contained", "Region %s doesn't contain %s - invalid position for teleport anchor supplied.", buildRegionInfoLink(region), shortBlockPosBracketed(pos), name));
653654
return -1;
654655
}
655-
if (tpAnchors.getTpAnchor(name).getPos().equals(pos)) {
656+
if (tpAnchors.hasAnchorWithPos(pos)) {
657+
sendCmdFeedback(ctx.getSource(), Component.translatableWithFallback("cli.msg.info.region.tp-anchor.fail-msg.duplicate-pos", "Region %s already contains a Teleport Anchor with the same pos (%s).", buildRegionInfoLink(region), shortBlockPosBracketed(pos)));
658+
return -1;
659+
}
660+
if (tpAnchors.hasAnchor(name, pos)) {
656661
// they are the same
657662
return 0;
658663
}

common/src/main/java/de/z0rdak/yawp/core/area/RegionAnchors.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
package de.z0rdak.yawp.core.area;
22

3-
import com.mojang.serialization.Codec;
4-
import com.mojang.serialization.Lifecycle;
5-
import com.mojang.serialization.MapCodec;
6-
import com.mojang.serialization.codecs.RecordCodecBuilder;
7-
import de.z0rdak.yawp.core.group.PlayerContainer;
8-
import de.z0rdak.yawp.core.region.IMarkableRegion;
93
import net.minecraft.core.BlockPos;
10-
import net.minecraft.core.UUIDUtil;
11-
import net.minecraft.nbt.CompoundTag;
12-
import net.minecraft.resources.Identifier;
134

14-
import java.util.*;
5+
import java.util.ArrayList;
6+
import java.util.HashMap;
7+
import java.util.List;
8+
import java.util.Map;
159

1610
import static de.z0rdak.yawp.util.ChatComponentBuilder.tinyBlockPos;
1711

@@ -44,6 +38,15 @@ public boolean hasAnchor(String name) {
4438
return this.tpAnchors.containsKey(name);
4539
}
4640

41+
public boolean hasAnchor(String name, BlockPos pos) {
42+
return this.tpAnchors.containsKey(name)
43+
&& this.tpAnchors.get(name).getPos().equals(pos);
44+
}
45+
46+
public boolean hasAnchorWithPos(BlockPos pos) {
47+
return this.tpAnchors.values().stream()
48+
.anyMatch(tpAnchor -> tpAnchor.getPos().equals(pos));
49+
}
4750

4851
public TeleportAnchor addTpAnchor(BlockPos pos, String name) {
4952
var anchor = new TeleportAnchor(pos, name);

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ description=Yet Another World Protector (YAWP) is a server-side mod to protect y
1818
resource_pack_desc=Internationalisation keys for Yet Another World Protector
1919
credits=Thanks to all contributors (see CREDITS.txt)!
2020

21-
minecraft_version_range=1.21.10
21+
minecraft_version_range=1.21.11
2222
## This is the version of minecraft that the 'common' project uses, you can find a list of all versions here
2323
## https://projects.neoforged.net/neoforged/neoform
2424
neo_form_version=1.21.11-20251209.172050

0 commit comments

Comments
 (0)