Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.20.6 #39

Merged
merged 23 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17
java-version: 21
- uses: actions/setup-node@v3
with:
node-version: 16
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [17]
java: [21]
fail-fast: true
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17
java-version: 21
- uses: actions/setup-node@v3
with:
node-version: 16
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Maven
<dependency>
<groupId>maven.modrinth</groupId>
<artifactId>pl3xmap</artifactId>
<version>1.20.4-476</version>
<version>1.20.6-493</version>
<scope>provided</scope>
</dependency>
```
Expand All @@ -101,7 +101,7 @@ repositories {
}

dependencies {
compileOnly 'maven.modrinth:pl3xmap:1.20.4-476'
compileOnly 'maven.modrinth:pl3xmap:1.20.6-493'
}
```

Expand Down
36 changes: 27 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def combineJars = tasks.register('combineJars', Jar) {

def copyWebmap = tasks.register('copyWebmap', Copy) {
dependsOn ':webmap:buildWebmap'
duplicatesStrategy = DuplicatesStrategy.INHERIT
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from "$rootDir/webmap/public", "$rootDir/webmap/dist"
include '**/*'
exclude 'tiles*/'
Expand All @@ -70,21 +70,39 @@ allprojects {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
languageVersion = JavaLanguageVersion.of(21)
}
}

repositories {
mavenCentral()
mavenLocal()
maven { url = 'https://jitpack.io' }
maven {
url = 'https://repo.granny.dev/snapshots/'
}
maven {
name = 'sonatype-snapshots'
url = 'https://oss.sonatype.org/content/repositories/snapshots/'
mavenContent {
snapshotsOnly()
}
}
maven {
url = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
mavenContent {
snapshotsOnly()
}
}
maven {
url = 'https://jitpack.io'
}
}

dependencies {
implementation "cloud.commandframework:cloud-core:$cloudVersion"
implementation "cloud.commandframework:cloud-brigadier:$cloudVersion"
implementation "cloud.commandframework:cloud-paper:$cloudVersion"
implementation("cloud.commandframework:cloud-minecraft-extras:$cloudVersion") {
implementation "org.incendo:cloud-core:$cloudVersion"
implementation "org.incendo:cloud-brigadier:$cloudVersion"
implementation "org.incendo:cloud-paper:$cloudVersion"
implementation "org.incendo:cloud-processors-confirmation:1.0.0-SNAPSHOT"
implementation("org.incendo:cloud-minecraft-extras:$cloudVersion") {
exclude group: 'net.kyori', module: '*'
}

Expand Down Expand Up @@ -120,7 +138,7 @@ allprojects {

compileJava {
options.encoding = 'UTF-8'
options.release.set(17)
options.release.set(21)
}

processResources {
Expand Down
114 changes: 64 additions & 50 deletions bukkit/src/main/java/net/pl3x/map/bukkit/BukkitNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@
*/
package net.pl3x.map.bukkit;

import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.pl3x.map.bukkit.network.ClientboundMapPayload;
import net.pl3x.map.bukkit.network.ClientboundServerPayload;
import net.pl3x.map.bukkit.network.ServerboundMapPayload;
import net.pl3x.map.bukkit.network.ServerboundServerPayload;
import net.pl3x.map.core.configuration.Config;
import net.pl3x.map.core.network.Constants;
import net.pl3x.map.core.network.Network;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R3.map.CraftMapRenderer;
import org.bukkit.entity.Player;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import org.jetbrains.annotations.NotNull;

public class BukkitNetwork extends Network {
private final Pl3xMapBukkit plugin;
Expand All @@ -42,69 +48,77 @@ public BukkitNetwork(Pl3xMapBukkit plugin) {
}

public void register() {
Bukkit.getMessenger().registerOutgoingPluginChannel(this.plugin, Network.CHANNEL);
Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, Network.CHANNEL,
Bukkit.getMessenger().registerOutgoingPluginChannel(this.plugin, ClientboundServerPayload.TYPE.id().toString());
Bukkit.getMessenger().registerOutgoingPluginChannel(this.plugin, ClientboundMapPayload.TYPE.id().toString());
Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, ServerboundServerPayload.TYPE.id().toString(),
(channel, player, bytes) -> {
ByteArrayDataInput in = in(bytes);
int protocol = in.readInt();
if (protocol != Constants.PROTOCOL) {
ClientboundServerPayload payload = new ClientboundServerPayload(Constants.PROTOCOL, Constants.RESPONSE_SUCCESS, Config.WEB_ADDRESS);
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.buffer());
ClientboundServerPayload.STREAM_CODEC.encode(friendlyByteBuf, payload);
sendCustomPayloadPacket(player, payload, friendlyByteBuf);
}
);
Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, ServerboundMapPayload.TYPE.id().toString(),
(channel, player, bytes) -> {
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.copiedBuffer(bytes));
ServerboundMapPayload payload = ServerboundMapPayload.STREAM_CODEC.decode(byteBuf);

MapView map = Bukkit.getMap(payload.mapId());
if (map == null) {
ClientboundMapPayload customPacketPayload = new ClientboundMapPayload(Constants.PROTOCOL, Constants.ERROR_NO_SUCH_MAP, payload.mapId());
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.buffer(bytes.length));
ClientboundMapPayload.STREAM_CODEC.encode(friendlyByteBuf, customPacketPayload);
sendCustomPayloadPacket(player, customPacketPayload, friendlyByteBuf);
return;
}
int action = in.readInt();
switch (action) {
case Constants.SERVER_DATA -> sendServerData(player);
case Constants.MAP_DATA -> sendMapData(player, in.readInt());

World world = map.getWorld();
if (world == null) {
ClientboundMapPayload customPacketPayload = new ClientboundMapPayload(Constants.PROTOCOL, Constants.ERROR_NO_SUCH_WORLD, payload.mapId());
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.buffer());
ClientboundMapPayload.STREAM_CODEC.encode(friendlyByteBuf, customPacketPayload);
sendCustomPayloadPacket(player, customPacketPayload, friendlyByteBuf);
return;
}

ClientboundMapPayload customPacketPayload = new ClientboundMapPayload(
Constants.PROTOCOL, Constants.RESPONSE_SUCCESS, payload.mapId(),
getScale(map), map.getCenterX(), map.getCenterZ(), world.getName()
);
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.buffer());
ClientboundMapPayload.STREAM_CODEC.encode(friendlyByteBuf, customPacketPayload);
sendCustomPayloadPacket(player, customPacketPayload, friendlyByteBuf);
}
);
}

@NotNull
private void sendCustomPayloadPacket(Player player, CustomPacketPayload customPacketPayload, FriendlyByteBuf friendlyByteBuf) {
byte[] byteArray = new byte[friendlyByteBuf.readableBytes()];
friendlyByteBuf.readBytes(byteArray);
player.sendPluginMessage(this.plugin, customPacketPayload.type().id().toString(), byteArray);
}

public void unregister() {
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, Network.CHANNEL);
Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, Network.CHANNEL);
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, ClientboundServerPayload.TYPE.id().toString());
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, ClientboundMapPayload.TYPE.id().toString());
Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, ServerboundServerPayload.TYPE.id().toString());
Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, ServerboundMapPayload.TYPE.id().toString());
}

@Override
protected <T> void sendServerData(T player) {

}

@Override
protected <T> void sendMapData(T player, int id) {
ByteArrayDataOutput out = out();

out.writeInt(Constants.PROTOCOL);
out.writeInt(Constants.MAP_DATA);
out.writeInt(Constants.RESPONSE_SUCCESS);

MapView map = Bukkit.getMap(id);
if (map == null) {
out.writeInt(Constants.ERROR_NO_SUCH_MAP);
out.writeInt(id);
return;
}

World world = map.getWorld();
if (world == null) {
out.writeInt(Constants.ERROR_NO_SUCH_WORLD);
out.writeInt(id);
return;
}

for (MapRenderer renderer : map.getRenderers()) {
if (!renderer.getClass().getName().equals(CraftMapRenderer.class.getName())) {
out.writeInt(Constants.ERROR_NOT_VANILLA_MAP);
out.writeInt(id);
return;
}
}

out.writeInt(id);
out.writeByte(getScale(map));
out.writeInt(map.getCenterX());
out.writeInt(map.getCenterZ());
out.writeUTF(world.getName());

send(player, out);

}

@Override
protected <T> void send(T player, ByteArrayDataOutput out) {
((Player) player).sendPluginMessage(this.plugin, Network.CHANNEL, out.toByteArray());

}

@SuppressWarnings("deprecation")
Expand Down
4 changes: 2 additions & 2 deletions bukkit/src/main/java/net/pl3x/map/bukkit/BukkitPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
2 changes: 1 addition & 1 deletion bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public BukkitWorld(@NotNull ServerLevel level, @NotNull String name) {
super(
name,
level.getSeed(),
Point.of(level.getLevelData().getXSpawn(), level.getLevelData().getZSpawn()),
Point.of(level.getLevelData().getSpawnPos().getX(), level.getLevelData().getSpawnPos().getZ()),
Type.get(level.dimension().location().toString()),
level.convertable.getDimensionPath(level.dimension()).resolve("region")
);
Expand Down
4 changes: 2 additions & 2 deletions bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapBukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import net.pl3x.map.core.player.PlayerListener;
import net.pl3x.map.core.player.PlayerRegistry;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void onEnable() {
}

getServer().getScheduler().runTaskTimer(this, () ->
this.pl3xmap.getScheduler().tick(), 20, 20);
this.pl3xmap.getScheduler().tick(), 20, 1);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import net.pl3x.map.core.registry.BlockRegistry;
import net.pl3x.map.core.world.World;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@
*/
package net.pl3x.map.bukkit.command;

import cloud.commandframework.Command;
import cloud.commandframework.brigadier.CloudBrigadierManager;
import cloud.commandframework.bukkit.CloudBukkitCapabilities;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.paper.PaperCommandManager;
import net.pl3x.map.core.command.CommandHandler;
import net.pl3x.map.core.command.Sender;
import net.pl3x.map.core.command.parser.PlatformParsers;
import org.bukkit.plugin.Plugin;
import org.incendo.cloud.Command;
import org.incendo.cloud.SenderMapper;
import org.incendo.cloud.brigadier.CloudBrigadierManager;
import org.incendo.cloud.bukkit.CloudBukkitCapabilities;
import org.incendo.cloud.execution.ExecutionCoordinator;
import org.incendo.cloud.paper.PaperCommandManager;
import org.jetbrains.annotations.NotNull;

public class BukkitCommandManager implements CommandHandler {
private final PaperCommandManager<@NotNull Sender> manager;
private final Command.Builder<@NotNull Sender> root;

public BukkitCommandManager(@NotNull Plugin plugin) throws Exception {
this.manager = new PaperCommandManager<>(plugin, CommandExecutionCoordinator.simpleCoordinator(), BukkitSender::create, Sender::getSender);
this.manager = new PaperCommandManager<Sender>(plugin,
ExecutionCoordinator.simpleCoordinator(),
SenderMapper.create(BukkitSender::create, Sender::getSender));

if (getManager().hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
getManager().registerBrigadier();
Expand All @@ -64,6 +68,11 @@ public BukkitCommandManager(@NotNull Plugin plugin) throws Exception {
return this.manager;
}

@Override
public @NotNull PlatformParsers getPlatformParsers() {
return new BukkitParsers();
}

@Override
public Command.@NotNull Builder<@NotNull Sender> getRoot() {
return this.root;
Expand Down
Loading
Loading