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

v1.3.2 #140

Merged
merged 26 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f0cb770
Added support for BentoBox
josemmo Mar 24, 2024
16a1c28
Fixed file changes detection without inotify
josemmo Mar 28, 2024
713957c
v1.3.2-SNAPSHOT
josemmo Mar 28, 2024
a4a0b07
Added compatibility with PhantomWorlds
josemmo Apr 17, 2024
adc4245
v1.3.2-SNAPSHOT-b2
josemmo Apr 17, 2024
39fb971
Upgraded dependencies
josemmo May 26, 2024
806e023
Upgraded automata
josemmo May 26, 2024
a90aad5
Upgraded Java version in workflows
josemmo May 26, 2024
7726b9a
Fixed command dispatcher in MC 1.20.6
josemmo May 26, 2024
549a4ad
Upgraded Java version in workflows (II)
josemmo May 26, 2024
424aa67
Upgraded Java version in workflows (III)
josemmo May 26, 2024
a7770d9
Minor version fix in command dispatcher
josemmo Sep 28, 2024
c156508
Minor lint change
josemmo Sep 28, 2024
3f5c990
Fixed GriefPrevention dependency
josemmo Oct 5, 2024
ab16089
Upgraded ProtocolLib dependency
josemmo Oct 5, 2024
25ef6fa
Migrated to network injection handler
josemmo Oct 5, 2024
0e678dd
Switched filled map item stack instantiation method
josemmo Oct 5, 2024
ffb7d97
feat: add support for 1.21
Ingrim4 Oct 6, 2024
f322213
fix: add support for vanilla class mappings
Ingrim4 Oct 6, 2024
25d5a33
Simplified MapDataPacket
josemmo Oct 13, 2024
c6ff5bb
Minor code style changes
josemmo Oct 13, 2024
955c7c2
Upgraded dependencies
josemmo Oct 13, 2024
055eced
Merge pull request #137 from Ingrim4/feat/support-1.21
josemmo Oct 13, 2024
4ed37c6
Upgraded automata
josemmo Oct 13, 2024
9933b43
Added 1.21.x to tests
josemmo Oct 13, 2024
a9ff08f
v1.3.2
josemmo Oct 13, 2024
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 @@ -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
Loading