Skip to content

Commit

Permalink
Merge pull request #140 from josemmo/develop
Browse files Browse the repository at this point in the history
v1.3.2
  • Loading branch information
josemmo authored Oct 13, 2024
2 parents a51c777 + a9ff08f commit 655cf82
Show file tree
Hide file tree
Showing 16 changed files with 710 additions and 1,192 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'

# Build plugin
- name: Build with Maven
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 8
continue-on-error: ${{ matrix.version == '1.20.4' }}
continue-on-error: ${{ matrix.version == '1.21.1' }}
strategy:
fail-fast: false
matrix:
flavor: ['bukkit', 'spigot', 'paper', 'purpur']
version: ['1.20.4', '1.19.4', '1.18.2', '1.17.1', '1.16.5']
version: ['1.21.1', '1.20.6', '1.19.4', '1.18.2', '1.17.1', '1.16.5']
steps:
# Download code from repository
- name: Checkout code
Expand All @@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'

# Build plugin
- name: Build with Maven
Expand All @@ -33,7 +33,14 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ startsWith(matrix.version, '1.16') && '11' || (startsWith(matrix.version, '1.17') && '16' || '17') }}
java-version: |
${{
startsWith(matrix.version, '1.16') && '11' ||
startsWith(matrix.version, '1.17') && '16' ||
startsWith(matrix.version, '1.18') && '17' ||
startsWith(matrix.version, '1.19') && '17' ||
'21'
}}
# Setup Node.js
- name: Setup Node.js
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Download the JAR file for the [latest release](https://github.com/josemmo/yamipa
Before installing Yamipa make sure you meet the following requirements:

- CraftBukkit, Spigot or PaperMC 1.16 or higher
- [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) v5.0.0 or higher
- [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) v5.3.0 or higher

Here are the Minecraft distributions where Yamipa should be able to run:
| Minecraft version | CraftBukkit | Spigot | PaperMC |
Expand All @@ -35,6 +35,7 @@ Here are the Minecraft distributions where Yamipa should be able to run:
| 1.18 & 1.18.x ||||
| 1.19 & 1.19.x ||||
| 1.20 & 1.20.x ||||
| 1.21 & 1.21.x ||||

## Configuration
Yamipa is ready-to-go right out of the box. By default, it creates the following files and directories under the
Expand Down
1,179 changes: 237 additions & 942 deletions automata/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions automata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "node index.js"
},
"dependencies": {
"mineflayer": "^4.14.0",
"rcon-client": "^4.2.3"
"mineflayer": "^4.21.0",
"rcon-client": "^4.2.5"
}
}
4 changes: 2 additions & 2 deletions automata/src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function startBot() {
return new Promise(resolve => {
const bot = mineflayer.createBot({
host: '127.0.0.1',
username: 'test'
username: 'test',
})
bot.once('spawn', () => resolve(bot))
})
Expand All @@ -23,6 +23,6 @@ export function placeBlockOnTheFloor(bot) {
hand: 0,
cursorX: 0,
cursorY: 0,
cursorZ: 0
cursorZ: 0,
})
}
2 changes: 1 addition & 1 deletion automata/src/rcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const CONNECTION = {
host: '127.0.0.1',
port: 25575,
password: 'rcon',
timeout: 1000*20
timeout: 1000*20,
}

export async function waitForServer() {
Expand Down
28 changes: 14 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.josemmo.bukkit.plugin</groupId>
<artifactId>YamipaPlugin</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down Expand Up @@ -42,15 +42,15 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- https://repo.dmulloy2.net/service/rest/repository/browse/public/com/comphenix/protocol/ProtocolLib/ -->
<!-- https://jitpack.io/com/github/dmulloy2/ProtocolLib/ -->
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>com.github.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.2.0-SNAPSHOT</version>
<version>1e3fa2d36e</version>
<scope>provided</scope>
</dependency>

Expand All @@ -66,7 +66,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<version>3.1.0</version>
</dependency>

<!-- https://central.sonatype.com/artifact/net.luckperms/api -->
Expand All @@ -93,35 +93,35 @@
<scope>provided</scope>
</dependency>

<!-- https://jitpack.io/com/github/TechFortress/GriefPrevention/ -->
<!-- https://jitpack.io/com/github/GriefPrevention/GriefPrevention/ -->
<dependency>
<groupId>com.github.TechFortress</groupId>
<groupId>com.github.GriefPrevention</groupId>
<artifactId>GriefPrevention</artifactId>
<version>16.18.2</version>
<version>16.18.4</version>
<scope>provided</scope>
</dependency>

<!-- https://jitpack.io/com/github/TownyAdvanced/towny/ -->
<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<groupId>com.github.TownyAdvanced.Towny</groupId>
<artifactId>towny</artifactId>
<version>0.100.1.17</version>
<version>0.100.4.4</version>
<scope>provided</scope>
</dependency>

<!-- https://jitpack.io/com/github/Angeschossen/LandsAPI/ -->
<dependency>
<groupId>com.github.angeschossen</groupId>
<groupId>com.github.Angeschossen</groupId>
<artifactId>LandsAPI</artifactId>
<version>6.44.10</version>
<version>7.9.17</version>
<scope>provided</scope>
</dependency>

<!-- https://central.sonatype.com/artifact/org.jetbrains/annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
<version>26.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class EntityMetadataPacket extends PacketContainer {
private final List<WrappedDataValue> values = new ArrayList<>(); // For >= 1.19.3

static {
USE_DATA_WATCHER = (Internals.MINECRAFT_VERSION < 19.3f);
USE_DATA_WATCHER = (Internals.MINECRAFT_VERSION < 19.3);
ITEM_INDEX = (Internals.MINECRAFT_VERSION < 17) ? 7 : 8;
ROTATION_INDEX = ITEM_INDEX + 1;
}
Expand Down
39 changes: 34 additions & 5 deletions src/main/java/io/josemmo/bukkit/plugin/packets/MapDataPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,65 @@

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.injector.StructureCache;
import com.comphenix.protocol.reflect.ExactReflection;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection;
import io.josemmo.bukkit.plugin.utils.Internals;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.ParameterizedType;
import java.util.Optional;

public class MapDataPacket extends PacketContainer {
private static final int LOCKED_INDEX;
private static final @Nullable Constructor<?> MAP_ID_CONSTRUCTOR;
private @Nullable StructureModifier<?> mapDataModifier;

static {
LOCKED_INDEX = (Internals.MINECRAFT_VERSION < 17) ? 1 : 0;
if (Internals.MINECRAFT_VERSION < 20.5) {
MAP_ID_CONSTRUCTOR = null;
} else {
Class<?> mapIdClass = MinecraftReflection.getNullableNMS("world.level.saveddata.maps.MapId");
MAP_ID_CONSTRUCTOR = ExactReflection.fromClass(mapIdClass, true).findConstructor(int.class);
}
}

public MapDataPacket() {
super(PacketType.Play.Server.MAP);
getModifier().writeDefaults();

if (Internals.MINECRAFT_VERSION < 17) {
// Disable tracking position
getBooleans().write(0, false);
} else {
// Create modifier for map data instance
getBooleans().write(0, false); // Disable tracking position
} else if (Internals.MINECRAFT_VERSION < 20.5) {
Class<?> mapDataType = getModifier().getField(4).getType();
Object mapDataInstance = getModifier().read(4);
mapDataModifier = new StructureModifier<>(mapDataType).withTarget(mapDataInstance);
} else {
ParameterizedType genericType = (ParameterizedType) getModifier().getField(4).getGenericType();
Class<?> mapDataType = (Class<?>) genericType.getActualTypeArguments()[0];
Object mapDataInstance = StructureCache.newInstance(mapDataType);
getModifier().write(3, Optional.empty());
getModifier().write(4, Optional.of(mapDataInstance));
mapDataModifier = new StructureModifier<>(mapDataType).withTarget(mapDataInstance);
}
}

@SuppressWarnings({"unchecked", "rawtypes"})
public @NotNull MapDataPacket setId(int id) {
getIntegers().write(0, id);
if (MAP_ID_CONSTRUCTOR == null) {
getIntegers().write(0, id);
} else {
try {
Class<?> mapIdClass = MAP_ID_CONSTRUCTOR.getDeclaringClass();
Object mapIdInstance = MAP_ID_CONSTRUCTOR.newInstance(id);
((StructureModifier) getSpecificModifier(mapIdClass)).write(0, mapIdInstance);
} catch (Exception e) {
throw new RuntimeException("Failed to instantiate MapId for map #" + id);
}
}
return this;
}

Expand Down
22 changes: 13 additions & 9 deletions src/main/java/io/josemmo/bukkit/plugin/renderer/FakeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.injector.player.PlayerInjectionHandler;
import com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import io.josemmo.bukkit.plugin.YamipaPlugin;
import io.josemmo.bukkit.plugin.utils.Internals;
Expand All @@ -17,23 +17,23 @@
public abstract class FakeEntity {
private static final Logger LOGGER = Logger.getLogger("FakeEntity");
private static final ProtocolManager CONNECTION = ProtocolLibrary.getProtocolManager();
private static @Nullable PlayerInjectionHandler PLAYER_INJECTION_HANDLER;
private static @Nullable NetworkManagerInjector NETWORK_MANAGER_INJECTOR;
private static boolean READY = false;

static {
try {
for (Field field : CONNECTION.getClass().getDeclaredFields()) {
if (field.getType().equals(PlayerInjectionHandler.class)) {
if (field.getType().equals(NetworkManagerInjector.class)) {
field.setAccessible(true);
PLAYER_INJECTION_HANDLER = (PlayerInjectionHandler) field.get(CONNECTION);
NETWORK_MANAGER_INJECTOR = (NetworkManagerInjector) field.get(CONNECTION);
break;
}
}
if (PLAYER_INJECTION_HANDLER == null) {
if (NETWORK_MANAGER_INJECTOR == null) {
throw new RuntimeException("No valid candidate field found in ProtocolManager");
}
} catch (Exception e) {
LOGGER.severe("Failed to get PlayerInjectionHandler from ProtocolLib", e);
LOGGER.severe("Failed to get NetworkManagerInjector from ProtocolLib", e);
}
}

Expand Down Expand Up @@ -85,10 +85,14 @@ protected static void tryToSleep(long ms) {
*/
protected static void tryToSendPacket(@NotNull Player player, @NotNull PacketContainer packet) {
try {
if (PLAYER_INJECTION_HANDLER == null) { // Use single-threaded packet sending if reflection failed
if (NETWORK_MANAGER_INJECTOR == null) { // Use single-threaded packet sending if reflection failed
CONNECTION.sendServerPacket(player, packet);
} else { // Use non-blocking packet sending if available (faster, the expected case)
PLAYER_INJECTION_HANDLER.sendServerPacket(player, packet, null, false);
NETWORK_MANAGER_INJECTOR.getInjector(player).sendClientboundPacket(
packet.getHandle(),
null,
false
);
}
} catch (IllegalStateException e) {
// Server is shutting down and cannot send the packet, ignore
Expand All @@ -103,7 +107,7 @@ protected static void tryToSendPacket(@NotNull Player player, @NotNull PacketCon
* @param packets Packets to send
*/
protected static void tryToSendPackets(@NotNull Player player, @NotNull Iterable<PacketContainer> packets) {
if (Internals.MINECRAFT_VERSION < 19.4f) {
if (Internals.MINECRAFT_VERSION < 19.4) {
for (PacketContainer packet : packets) {
tryToSendPacket(player, packet);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.josemmo.bukkit.plugin.renderer;

import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import io.josemmo.bukkit.plugin.packets.DestroyEntityPacket;
import io.josemmo.bukkit.plugin.packets.EntityMetadataPacket;
import io.josemmo.bukkit.plugin.packets.SpawnEntityPacket;
Expand All @@ -16,9 +13,11 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

public class FakeItemFrame extends FakeEntity {
Expand Down Expand Up @@ -137,6 +136,7 @@ public int getId() {
* @param player Player who is expected to receive packets (for caching reasons)
* @param step Map step
*/
@SuppressWarnings("deprecation")
public @NotNull List<PacketContainer> getRenderPackets(@NotNull Player player, int step) {
List<PacketContainer> packets = new ArrayList<>(2);

Expand All @@ -147,10 +147,10 @@ public int getId() {
}

// Create and attach filled map
ItemStack itemStack = MinecraftReflection.getBukkitItemStack(new ItemStack(Material.FILLED_MAP));
NbtCompound itemStackNbt = NbtFactory.ofCompound("tag");
itemStackNbt.put("map", maps[step].getId());
NbtFactory.setItemTag(itemStack, itemStackNbt);
ItemStack itemStack = new ItemStack(Material.FILLED_MAP);
MapMeta itemStackMeta = Objects.requireNonNull((MapMeta) itemStack.getItemMeta());
itemStackMeta.setMapId(maps[step].getId());
itemStack.setItemMeta(itemStackMeta);

// Build entity metadata packet
EntityMetadataPacket metadataPacket = new EntityMetadataPacket();
Expand Down
Loading

0 comments on commit 655cf82

Please sign in to comment.