Skip to content

Commit

Permalink
Add support for 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cerus committed Mar 2, 2022
1 parent 2f0d38e commit 8b0a195
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 14 deletions.
6 changes: 3 additions & 3 deletions bukkit-17_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>maps</artifactId>
<groupId>dev.cerus</groupId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>dev.cerus.maps</groupId>
<artifactId>bukkit-17_R1</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>

<properties>
<maven.compiler.target>16</maven.compiler.target>
Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>dev.cerus.maps</groupId>
<artifactId>common</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions bukkit-18_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>maps</artifactId>
<groupId>dev.cerus</groupId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>dev.cerus.maps</groupId>
<artifactId>bukkit-18_R1</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>dev.cerus.maps</groupId>
<artifactId>common</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
36 changes: 36 additions & 0 deletions bukkit-18_R2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maps</artifactId>
<groupId>dev.cerus</groupId>
<version>1.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>dev.cerus.maps</groupId>
<artifactId>bukkit-18_R2</artifactId>
<version>1.0.6</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>dev.cerus.maps</groupId>
<artifactId>common</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dev.cerus.maps.version;

import dev.cerus.maps.api.ClientsideMap;
import dev.cerus.maps.api.version.VersionAdapter;
import dev.cerus.maps.util.ReflectionUtil;
import java.util.Collections;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
import net.minecraft.network.protocol.game.PacketPlayOutMap;
import net.minecraft.network.syncher.DataWatcher;
import net.minecraft.network.syncher.DataWatcherObject;
import net.minecraft.network.syncher.DataWatcherRegistry;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.saveddata.maps.WorldMap;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.MapMeta;

public class VersionAdapter18R2 implements VersionAdapter {

@Override
public Object makeMapPacket(final ClientsideMap map) {
return new PacketPlayOutMap(map.getId(),
(byte) 0,
true,
Collections.emptyList(),
new WorldMap.b(0,
0,
128,
128,
map.getGraphics().getData()));
}

@Override
public Object makeFramePacket(final int frameId, final ClientsideMap map) {
final PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(frameId, new DataWatcher(null), false);

final org.bukkit.inventory.ItemStack mapItem = new org.bukkit.inventory.ItemStack(Material.FILLED_MAP, 1);
final MapMeta mapMeta = (MapMeta) mapItem.getItemMeta();
mapMeta.setMapId(map.getId());
mapItem.setItemMeta(mapMeta);

try {
final DataWatcherObject<ItemStack> itemObj = DataWatcherRegistry.g.a((byte) 8);
final DataWatcher.Item<ItemStack> itemItem = new DataWatcher.Item<>(itemObj, CraftItemStack.asNMSCopy(mapItem));
ReflectionUtil.set("b", packet.getClass(), packet, Collections.singletonList(itemItem));
} catch (final NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
return packet;
}

@Override
public void sendPacket(final Player player, final Object packet) {
((CraftPlayer) player).getHandle().b.a((Packet<?>) packet);
}

}
4 changes: 2 additions & 2 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>maps</artifactId>
<groupId>dev.cerus</groupId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>dev.cerus.maps</groupId>
<artifactId>common</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>

<properties>
<maven.compiler.target>16</maven.compiler.target>
Expand Down
16 changes: 11 additions & 5 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<artifactId>maps</artifactId>
<groupId>dev.cerus</groupId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>dev.cerus.maps</groupId>
<artifactId>plugin</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>

<properties>
<maven.compiler.target>16</maven.compiler.target>
Expand Down Expand Up @@ -54,19 +54,25 @@
<dependency>
<groupId>dev.cerus.maps</groupId>
<artifactId>common</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>dev.cerus.maps</groupId>
<artifactId>bukkit-17_R1</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>dev.cerus.maps</groupId>
<artifactId>bukkit-18_R1</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>dev.cerus.maps</groupId>
<artifactId>bukkit-18_R2</artifactId>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public VersionAdapter makeAdapter() {
return switch (version) {
case "1.17", "1.17.0", "1.17.1" -> new VersionAdapter17R1();
case "1.18", "1.18.1" -> new VersionAdapter18R1();
case "1.18.2" -> new VersionAdapter18R2();
default -> null;
};
}
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
<groupId>dev.cerus</groupId>
<artifactId>maps</artifactId>
<packaging>pom</packaging>
<version>1.0.5</version>
<version>1.0.6</version>
<modules>
<module>common</module>
<module>bukkit-17_R1</module>
<module>bukkit-18_R1</module>
<module>plugin</module>
<module>bukkit-18_R2</module>
</modules>

<name>${artifactId}</name>
Expand Down

0 comments on commit 8b0a195

Please sign in to comment.