Skip to content

Commit 355d28a

Browse files
committed
Update to 5.0.1
1 parent 886ba0a commit 355d28a

File tree

69 files changed

+3771
-1129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3771
-1129
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "com.moulberry.axiom"
11-
version = "4.0.5+1.20.4"
11+
version = "5.0.1+1.20.4"
1212
description = "Serverside component for Axiom on Paper"
1313

1414
java {
@@ -22,8 +22,8 @@ repositories {
2222
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
2323
maven("https://jitpack.io")
2424
maven("https://repo.papermc.io/repository/maven-public/")
25-
maven("https://maven.enginehub.org/repo/")
26-
maven("https://maven.playpro.com")
25+
maven("https://maven.enginehub.org/repo/") // WorldGuard
26+
maven("https://maven.playpro.com") // CoreProtect
2727
}
2828

2929
dependencies {

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[versions]
22
# Dependencies
33
bom-newest = "1.37"
4-
cloud-paper = "2.0.0-20240516.054251-69"
4+
cloud-paper = "2.0.0-beta.11"
55
coreprotect = "22.4"
66
paper = "1.20.4-R0.1-SNAPSHOT"
77
plotsquared = "7.3.8"
8-
reflection-remapper = "0.1.2-20240315.033304-2"
9-
viaversion-api = "5.0.1"
8+
reflection-remapper = "0.1.2"
9+
viaversion-api = "5.4.2-SNAPSHOT"
1010
worldguard-bukkit = "7.0.9-SNAPSHOT"
1111
zstd-jni = "1.5.5-4"
1212

src/main/java/com/moulberry/axiom/AxiomConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public class AxiomConstants {
1212
}
1313
}
1414

15-
public static final int API_VERSION = 8;
15+
public static final int API_VERSION = 9;
1616

1717
}

src/main/java/com/moulberry/axiom/AxiomPaper.java

Lines changed: 426 additions & 191 deletions
Large diffs are not rendered by default.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.moulberry.axiom;
2+
3+
import net.minecraft.world.level.block.entity.BlockEntity;
4+
import net.minecraft.world.level.chunk.LevelChunk;
5+
import xyz.jpenilla.reflectionremapper.ReflectionRemapper;
6+
7+
import java.lang.reflect.Method;
8+
9+
public class AxiomReflection {
10+
11+
private static Method updateBlockEntityTicker = null;
12+
13+
public static void init() {
14+
ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar();
15+
String methodName = reflectionRemapper.remapMethodName(LevelChunk.class, "updateBlockEntityTicker", BlockEntity.class);
16+
17+
try {
18+
updateBlockEntityTicker = LevelChunk.class.getDeclaredMethod(methodName, BlockEntity.class);
19+
updateBlockEntityTicker.setAccessible(true);
20+
} catch (Exception e) {
21+
e.printStackTrace();
22+
throw new RuntimeException(e);
23+
}
24+
}
25+
26+
public static void updateBlockEntityTicker(LevelChunk levelChunk, BlockEntity blockEntity) {
27+
try {
28+
updateBlockEntityTicker.invoke(levelChunk, blockEntity);
29+
} catch (Exception e) {
30+
throw new RuntimeException(e);
31+
}
32+
}
33+
34+
}

src/main/java/com/moulberry/axiom/Restrictions.java

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/main/java/com/moulberry/axiom/VersionHelper.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
1111
import org.bukkit.entity.Player;
1212

13+
import java.util.List;
14+
1315
public class VersionHelper {
1416

1517
public static void sendCustomPayload(Player player, String id, byte[] data) {
@@ -24,10 +26,20 @@ public static void sendCustomPayload(ServerPlayer serverPlayer, ResourceLocation
2426
serverPlayer.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(id, data)));
2527
}
2628

27-
public static void sendCustomPayload(ServerPlayer serverPlayer, ResourceLocation id, FriendlyByteBuf friendlyByteBuf) {
28-
byte[] data = new byte[friendlyByteBuf.writerIndex()];
29-
friendlyByteBuf.getBytes(friendlyByteBuf.readerIndex(), data);
30-
sendCustomPayload(serverPlayer, id, data);
29+
public static void sendCustomPayloadToAll(List<ServerPlayer> players, String id, byte[] data) {
30+
sendCustomPayloadToAll(players, createResourceLocation(id), data);
31+
}
32+
33+
public static void sendCustomPayloadToAll(List<ServerPlayer> players, ResourceLocation id, byte[] data) {
34+
if (players.isEmpty()) {
35+
return;
36+
}
37+
38+
var payload = new CustomByteArrayPayload(id, data);
39+
var packet = new ClientboundCustomPayloadPacket(payload);
40+
for (ServerPlayer player : players) {
41+
player.connection.send(packet);
42+
}
3143
}
3244

3345
public static ResourceLocation createResourceLocation(String composed) {

src/main/java/com/moulberry/axiom/WorldExtension.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import com.moulberry.axiom.annotations.ServerAnnotations;
44
import com.moulberry.axiom.marker.MarkerData;
5+
import com.moulberry.axiom.paperapi.entity.ImplAxiomHiddenEntities;
56
import io.netty.buffer.ByteBufUtil;
67
import io.netty.buffer.Unpooled;
78
import it.unimi.dsi.fastutil.longs.*;
9+
import net.kyori.adventure.text.Component;
10+
import net.kyori.adventure.text.format.NamedTextColor;
811
import net.minecraft.network.FriendlyByteBuf;
912
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
1013
import net.minecraft.resources.ResourceKey;
@@ -38,7 +41,7 @@ public static void onPlayerJoin(World world, Player player) {
3841
ServerLevel level = ((CraftWorld)world).getHandle();
3942
get(level).onPlayerJoin(player);
4043

41-
if (AxiomPaper.PLUGIN.canUseAxiom(player, "axiom.annotations.view")) {
44+
if (AxiomPaper.PLUGIN.canUseAxiom(player)) {
4245
ServerAnnotations.sendAll(world, ((CraftPlayer)player).getHandle());
4346
}
4447
}
@@ -76,6 +79,14 @@ public void onPlayerJoin(Player player) {
7679
byte[] bytes = ByteBufUtil.getBytes(buf);
7780
VersionHelper.sendCustomPayload(player, "axiom:marker_data", bytes);
7881
}
82+
83+
try {
84+
ServerPlayer serverPlayer = ((CraftPlayer)player).getHandle();
85+
if (this.level.chunkPacketBlockController.shouldModify(serverPlayer, this.level.getChunkIfLoaded(serverPlayer.blockPosition()))) {
86+
Component text = Component.text("Axiom: Warning, anti-xray is enabled. This will cause issues when copying blocks. Please turn anti-xray off");
87+
player.sendMessage(text.color(NamedTextColor.RED));
88+
}
89+
} catch (Throwable ignored) {}
7990
}
8091

8192
public void tick(boolean sendMarkers, int maxChunkRelightsPerTick, int maxChunkSendsPerTick) {
@@ -92,6 +103,10 @@ private void tickMarkers() {
92103

93104
for (Entity entity : this.level.getEntities().getAll()) {
94105
if (entity instanceof Marker marker) {
106+
if (ImplAxiomHiddenEntities.isMarkerHidden((org.bukkit.entity.Marker) marker.getBukkitEntity())) {
107+
continue;
108+
}
109+
95110
MarkerData currentData = MarkerData.createFrom(marker);
96111

97112
MarkerData previousData = this.previousMarkerData.get(marker.getUUID());
@@ -104,21 +119,25 @@ private void tickMarkers() {
104119
}
105120
}
106121

107-
Set<UUID> oldUuids = new HashSet<>(this.previousMarkerData.keySet());
108-
oldUuids.removeAll(allMarkers);
109-
this.previousMarkerData.keySet().removeAll(oldUuids);
122+
Set<UUID> missingUuids = new HashSet<>(this.previousMarkerData.keySet());
123+
missingUuids.removeAll(allMarkers);
124+
this.previousMarkerData.keySet().removeAll(missingUuids);
110125

111-
if (!changedData.isEmpty() || !oldUuids.isEmpty()) {
126+
if (!changedData.isEmpty() || !missingUuids.isEmpty()) {
112127
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
113128
buf.writeCollection(changedData, MarkerData::write);
114-
buf.writeCollection(oldUuids, (buffer, uuid) -> buffer.writeUUID(uuid));
129+
buf.writeCollection(missingUuids, (buffer, uuid) -> buffer.writeUUID(uuid));
115130
byte[] bytes = ByteBufUtil.getBytes(buf);
116131

132+
List<ServerPlayer> players = new ArrayList<>();
133+
117134
for (ServerPlayer player : this.level.players()) {
118-
if (AxiomPaper.PLUGIN.activeAxiomPlayers.contains(player.getUUID())) {
119-
VersionHelper.sendCustomPayload(player, "axiom:marker_data", bytes);
135+
if (AxiomPaper.PLUGIN.canUseAxiom(player.getBukkitEntity())) {
136+
players.add(player);
120137
}
121138
}
139+
140+
VersionHelper.sendCustomPayloadToAll(players, "axiom:marker_data", bytes);
122141
}
123142
}
124143

@@ -131,10 +150,17 @@ private void tickChunkRelight(int maxChunkRelightsPerTick, int maxChunkSendsPerT
131150
LongIterator longIterator = this.pendingChunksToSend.longIterator();
132151
while (longIterator.hasNext()) {
133152
ChunkPos chunkPos = new ChunkPos(longIterator.nextLong());
153+
154+
LevelChunk chunk = this.level.getChunkIfLoaded(chunkPos.x, chunkPos.z);
155+
if (chunk == null) {
156+
continue;
157+
}
158+
134159
List<ServerPlayer> players = chunkMap.getPlayers(chunkPos, false);
135-
if (players.isEmpty()) continue;
160+
if (players.isEmpty()) {
161+
continue;
162+
}
136163

137-
LevelChunk chunk = this.level.getChunk(chunkPos.x, chunkPos.z);
138164
var packet = new ClientboundLevelChunkWithLightPacket(chunk, this.level.getLightEngine(), null, null, false);
139165
for (ServerPlayer player : players) {
140166
player.connection.send(packet);

src/main/java/com/moulberry/axiom/annotations/ServerAnnotations.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.moulberry.axiom.AxiomPaper;
44
import com.moulberry.axiom.VersionHelper;
55
import com.moulberry.axiom.annotations.data.AnnotationData;
6+
import com.moulberry.axiom.restrictions.AxiomPermission;
67
import io.netty.buffer.ByteBufUtil;
78
import io.netty.buffer.Unpooled;
89
import net.minecraft.nbt.CompoundTag;
@@ -123,7 +124,7 @@ public static void handleUpdates(World world, List<AnnotationUpdateAction> actio
123124
List<ServerPlayer> playersWithAxiom = new ArrayList<>();
124125

125126
for (ServerPlayer player : ((CraftWorld)world).getHandle().players()) {
126-
if (AxiomPaper.PLUGIN.canUseAxiom(player.getBukkitEntity(), "axiom.annotations.view")) {
127+
if (AxiomPaper.PLUGIN.canUseAxiom(player.getBukkitEntity())) {
127128
playersWithAxiom.add(player);
128129
}
129130
}

src/main/java/com/moulberry/axiom/blueprint/BlueprintHeader.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,26 @@
55
import net.minecraft.nbt.StringTag;
66
import net.minecraft.nbt.Tag;
77
import net.minecraft.network.FriendlyByteBuf;
8+
import net.minecraft.world.level.block.Blocks;
9+
import net.minecraft.world.level.block.state.BlockState;
810

911
import java.util.ArrayList;
1012
import java.util.List;
1113

12-
public record BlueprintHeader(String name, String author, List<String> tags, float thumbnailYaw, float thumbnailPitch, boolean lockedThumbnail, int blockCount, boolean containsAir) {
14+
public record BlueprintHeader(int version, String name, String author, List<String> tags, float thumbnailYaw, float thumbnailPitch, boolean lockedThumbnail, int blockCount, boolean containsAir) {
1315

14-
private static final int CURRENT_VERSION = 1;
16+
public static final int CURRENT_VERSION = 2;
17+
18+
public BlockState emptyBlockState() {
19+
if (this.version <= 1) {
20+
return Blocks.STRUCTURE_VOID.defaultBlockState();
21+
} else {
22+
return Blocks.VOID_AIR.defaultBlockState();
23+
}
24+
}
1525

1626
public void write(FriendlyByteBuf friendlyByteBuf) {
27+
friendlyByteBuf.writeVarInt(CURRENT_VERSION);
1728
friendlyByteBuf.writeUtf(this.name);
1829
friendlyByteBuf.writeUtf(this.author);
1930
friendlyByteBuf.writeCollection(this.tags, FriendlyByteBuf::writeUtf);
@@ -22,16 +33,17 @@ public void write(FriendlyByteBuf friendlyByteBuf) {
2233
}
2334

2435
public static BlueprintHeader read(FriendlyByteBuf friendlyByteBuf) {
36+
int version = friendlyByteBuf.readVarInt();
2537
String name = friendlyByteBuf.readUtf();
2638
String author = friendlyByteBuf.readUtf();
2739
List<String> tags = friendlyByteBuf.readList(FriendlyByteBuf::readUtf);
2840
int blockCount = friendlyByteBuf.readInt();
2941
boolean containsAir = friendlyByteBuf.readBoolean();
30-
return new BlueprintHeader(name, author, tags, 0, 0, true, blockCount, containsAir);
42+
return new BlueprintHeader(version, name, author, tags, 0, 0, true, blockCount, containsAir);
3143
}
3244

3345
public static BlueprintHeader load(CompoundTag tag) {
34-
long version = tag.getLong("Version");
46+
int version = tag.getInt("Version");
3547
String name = tag.getString("Name");
3648
String author = tag.getString("Author");
3749
float thumbnailYaw = tag.contains("ThumbnailYaw", Tag.TAG_FLOAT) ? tag.getFloat("ThumbnailYaw") : 135;
@@ -45,7 +57,7 @@ public static BlueprintHeader load(CompoundTag tag) {
4557
tags.add(string.getAsString());
4658
}
4759

48-
return new BlueprintHeader(name, author, tags, thumbnailYaw, thumbnailPitch, lockedThumbnail, blockCount, containsAir);
60+
return new BlueprintHeader(version, name, author, tags, thumbnailYaw, thumbnailPitch, lockedThumbnail, blockCount, containsAir);
4961
}
5062

5163
public CompoundTag save(CompoundTag tag) {
@@ -54,7 +66,7 @@ public CompoundTag save(CompoundTag tag) {
5466
listTag.add(StringTag.valueOf(string));
5567
}
5668

57-
tag.putLong("Version", CURRENT_VERSION);
69+
tag.putInt("Version", CURRENT_VERSION);
5870
tag.putString("Name", this.name);
5971
tag.putString("Author", this.author);
6072
tag.put("Tags", listTag);

0 commit comments

Comments
 (0)