Skip to content

Commit

Permalink
Update to 1.20.2 and Axiom Protocol V7
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulberry committed Oct 10, 2023
1 parent e68cbdb commit 21ac713
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 155 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
plugins {
`java-library`
id("io.papermc.paperweight.userdev") version "1.5.5"
id("xyz.jpenilla.run-paper") version "2.1.0" // Adds runServer and runMojangMappedServer tasks for testing
id("io.papermc.paperweight.userdev") version "1.5.8"
id("xyz.jpenilla.run-paper") version "2.2.0" // Adds runServer and runMojangMappedServer tasks for testing

// Shades and relocates dependencies into our plugin jar. See https://imperceptiblethoughts.com/shadow/introduction/
id("com.github.johnrengelman.shadow") version "8.1.1"
}

group = "com.moulberry.axiom"
version = "1.4.0"
version = "1.4.1"
description = "Serverside component for Axiom on Paper"

java {
Expand All @@ -25,7 +25,7 @@ repositories {
}

dependencies {
paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT")
paperweight.paperDevBundle("1.20.2-R0.1-20231010.011415-29")
implementation("xyz.jpenilla:reflection-remapper:0.1.0-SNAPSHOT")

// Zstd Compression Library
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion src/main/java/com/moulberry/axiom/AxiomConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class AxiomConstants {
}
}

public static final int API_VERSION = 6;
public static final int API_VERSION = 7;
public static final NamespacedKey ACTIVE_HOTBAR_INDEX = new NamespacedKey("axiom", "active_hotbar_index");
public static final NamespacedKey HOTBAR_DATA = new NamespacedKey("axiom", "hotbar_data");

Expand Down
15 changes: 6 additions & 9 deletions src/main/java/com/moulberry/axiom/AxiomPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.moulberry.axiom.buffer.CompressedBlockEntity;
import com.moulberry.axiom.event.AxiomCreateWorldPropertiesEvent;
import com.moulberry.axiom.event.AxiomTimeChangeEvent;
import com.moulberry.axiom.packet.*;
import com.moulberry.axiom.world_properties.WorldPropertyCategory;
import com.moulberry.axiom.world_properties.WorldPropertyWidgetType;
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import com.moulberry.axiom.world_properties.server.ServerWorldProperty;
import io.netty.buffer.Unpooled;
Expand All @@ -20,15 +17,13 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.GameRules;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.Messenger;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand Down Expand Up @@ -56,7 +51,7 @@ public void onEnable() {
msg.registerOutgoingPluginChannel(this, "axiom:enable");
msg.registerOutgoingPluginChannel(this, "axiom:initialize_hotbars");
msg.registerOutgoingPluginChannel(this, "axiom:set_editor_views");
msg.registerOutgoingPluginChannel(this, "axiom:block_entities");
msg.registerOutgoingPluginChannel(this, "axiom:response_chunk_data");
msg.registerOutgoingPluginChannel(this, "axiom:register_world_properties");
msg.registerOutgoingPluginChannel(this, "axiom:set_world_property");
msg.registerOutgoingPluginChannel(this, "axiom:ack_world_properties");
Expand All @@ -71,7 +66,7 @@ public void onEnable() {
msg.registerIncomingPluginChannel(this, "axiom:switch_active_hotbar", new SwitchActiveHotbarPacketListener());
msg.registerIncomingPluginChannel(this, "axiom:teleport", new TeleportPacketListener());
msg.registerIncomingPluginChannel(this, "axiom:set_editor_views", new SetEditorViewsPacketListener());
msg.registerIncomingPluginChannel(this, "axiom:request_block_entity", new RequestBlockEntityPacketListener(this));
msg.registerIncomingPluginChannel(this, "axiom:request_chunk_data", new RequestChunkDataPacketListener(this));

SetBlockBufferPacketListener setBlockBufferPacketListener = new SetBlockBufferPacketListener(this);

Expand Down Expand Up @@ -104,7 +99,9 @@ public void afterInitChannel(@NonNull Channel channel) {
if (!player.hasPermission("axiom.*")) {
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
buf.writeBoolean(false);
player.sendPluginMessage(this, "axiom:enable", buf.accessByteBufWithCorrectSize());
byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes);
player.sendPluginMessage(this, "axiom:enable", bytes);
} else {
newActiveAxiomPlayers.add(player.getUniqueId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static RegionProtectionWorldGuard tryCreate(Player player, World world) {
// Don't do any protection if player has bypass
if (platform.getSessionManager().hasBypass(worldGuardPlayer, worldEditWorld)) {
// todo: enable bypass
// return null;
return null;
}

RegionManager regionManager = regionContainer.get(worldEditWorld);
Expand Down Expand Up @@ -108,7 +108,7 @@ public SectionProtection getSection(int cx, int cy, int cz) {
// }
}

System.out.println("returning default");
// System.out.println("returning default");
StateFlag.State fallback = Flags.BUILD.getDefault();
return fallback == StateFlag.State.DENY ? SectionProtection.DENY : SectionProtection.ALLOW;
}
Expand All @@ -117,7 +117,7 @@ public SectionProtection getSection(int cx, int cy, int cz) {
for (Map.Entry<ProtectedRegion, StateFlag.State> entry : consideredValues.entrySet()) {
ProtectedRegion region = entry.getKey();
if (entry.getValue() == StateFlag.State.DENY) {
System.out.println("found region with deny!");
// System.out.println("found region with deny!");
if (region instanceof GlobalProtectedRegion) {
return SectionProtection.DENY;
} else if (region instanceof ProtectedCuboidRegion && doesRegionCompletelyContainSection(region, cx, cy, cz)) {
Expand All @@ -128,7 +128,7 @@ public SectionProtection getSection(int cx, int cy, int cz) {
}

if (hasPartialDeny) {
System.out.println("returning check!");
// System.out.println("returning check!");
return new SectionProtection() {
@Override
public SectionState getSectionState() {
Expand All @@ -143,7 +143,7 @@ public boolean check(int wx, int wy, int wz) {
// return complex thing
}

System.out.println("returning allow!");
// System.out.println("returning allow!");
return SectionProtection.ALLOW;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.moulberry.axiom.packet;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;

public record CustomByteArrayPayload(ResourceLocation id, byte[] bytes) implements CustomPacketPayload {
@Override
public void write(FriendlyByteBuf buf) {
buf.writeBytes(bytes);
}
}
23 changes: 19 additions & 4 deletions src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry;
import io.netty.buffer.Unpooled;
import net.kyori.adventure.text.Component;
import net.minecraft.SharedConstants;
import net.minecraft.network.FriendlyByteBuf;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataContainer;
Expand Down Expand Up @@ -42,8 +43,14 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla

FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message));
int apiVersion = friendlyByteBuf.readVarInt();
int dataVersion = friendlyByteBuf.readVarInt();
friendlyByteBuf.readNbt(); // Discard

if (dataVersion != SharedConstants.getCurrentVersion().getDataVersion().getVersion()) {
player.kick(Component.text("Axiom: Incompatible data version detected, are you using ViaVersion?"));
return;
}

if (apiVersion != AxiomConstants.API_VERSION) {
player.kick(Component.text("Unsupported Axiom API Version. Server supports " + AxiomConstants.API_VERSION +
", while client is " + apiVersion));
Expand All @@ -68,7 +75,10 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla
buf.writeVarInt(5); // Maximum Reach
buf.writeVarInt(16); // Max editor views
buf.writeBoolean(true); // Editable Views
player.sendPluginMessage(this.plugin, "axiom:enable", buf.accessByteBufWithCorrectSize());

byte[] enableBytes = new byte[buf.writerIndex()];
buf.getBytes(0, enableBytes);
player.sendPluginMessage(this.plugin, "axiom:enable", enableBytes);

// Initialize Hotbars
PersistentDataContainer container = player.getPersistentDataContainer();
Expand All @@ -86,7 +96,10 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla
buf.writeItem(CraftItemStack.asNMSCopy(stack));
}
}
player.sendPluginMessage(this.plugin, "axiom:initialize_hotbars", buf.accessByteBufWithCorrectSize());

byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes);
player.sendPluginMessage(this.plugin, "axiom:initialize_hotbars", bytes);
}

// Initialize Views
Expand All @@ -101,7 +114,9 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player pla
View.load(view).write(buf);
}

player.sendPluginMessage(this.plugin, "axiom:set_editor_views", buf.accessByteBufWithCorrectSize());
byte[] bytes = new byte[buf.writerIndex()];
buf.getBytes(0, bytes);
player.sendPluginMessage(this.plugin, "axiom:set_editor_views", bytes);
}

// Register world properties
Expand Down

This file was deleted.

Loading

0 comments on commit 21ac713

Please sign in to comment.