Skip to content

Commit

Permalink
8.5.0.1
Browse files Browse the repository at this point in the history
Unit tests are now much more complete.

ReflectionUtils
Fixed an issue with 1.17

NMSExtras
Added support for 1.18 and fixed a small issue for 1.17
  • Loading branch information
CryptoMorin committed Dec 6, 2021
1 parent 949beeb commit 7477ef5
Show file tree
Hide file tree
Showing 16 changed files with 399 additions and 309 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $RECYCLE.BIN/
ChangeLog.txt
*.iml
.idea/
.gradle/
target/
repo/
out/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# XSeries
[![Bukkit Version](https://img.shields.io/badge/bukkit-1.16-dark_green.svg)](https://shields.io/)
[![Bukkit Version](https://img.shields.io/badge/bukkit-1.18-dark_green.svg)](https://shields.io/)
[![Java](https://img.shields.io/badge/java-8-dark_green.svg)](https://shields.io/)
[![Build Status](https://travis-ci.com/CryptoMorin/XSeries.svg?branch=master)](https://travis-ci.com/CryptoMorin/XSeries)
![maven-central](https://img.shields.io/maven-central/v/com.github.cryptomorin/XSeries)
Expand Down
101 changes: 44 additions & 57 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>8.5.0</version>
<version>8.5.0.1</version>

<name>XSeries</name>
<description>A set of utilities for Minecraft plugins</description>
Expand Down Expand Up @@ -61,11 +61,15 @@
</repository>
</repositories>

<properties>
<spigotVersion>1.18-rc3-R0.1-SNAPSHOT</spigotVersion>
</properties>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<version>1.18-rc3-R0.1-SNAPSHOT</version>

This comment has been minimized.

Copy link
@portlek

portlek Dec 6, 2021

Contributor

I guess you should use 1.18-R0.1-SNAPSHOT version which is the newest for 1.18, here;
image

This comment has been minimized.

Copy link
@CryptoMorin

CryptoMorin Dec 7, 2021

Author Owner

Problem is that for some reasons 1.18-R0.1-SNAPSHOT doesn't include Mojang library.

<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -98,7 +102,7 @@
<configuration>
<!--all,-missing-->
<doclint>none</doclint>
<source>8</source>
<release>8</release>
<excludePackageNames>com.cryptomorin.xseries.unused:com.cryptomorin.xseries.particles</excludePackageNames>
<!-- Apparently this is needed because it's a bug with maven JavaDoc plugin not being able to find the exe by itself. -->
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
Expand Down Expand Up @@ -174,15 +178,15 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!--<failIfNoTests>true</failIfNoTests>-->
<trimStackTrace>false</trimStackTrace>
<workingDirectory>${basedir}/target/tests</workingDirectory>
<!-- <dependenciesToScan>-->
<!-- <dependency>*:spigot:*:*:1.16.5-R0.1-SNAPSHOT</dependency>-->
<!-- </dependenciesToScan>-->
<includes>
<include>**/Spigot*.java</include>
<include>**/DummySpigot.java</include>
</includes>
<excludes>
<exclude>com/cryptomorin/xseries/unused/</exclude>
<exclude>com/cryptomorin/xseries/XMaterialUtil.java</exclude>
<exclude>com/cryptomorin/xseries/SkullCacheListener.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
Expand All @@ -191,62 +195,31 @@
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>

<profiles>
<profile>
<id>1_18</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<skip>false</skip>
<!-- <testExcludes>-->
<!-- <exclude>**/**1_18.java</exclude>-->
<!-- </testExcludes>-->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<id>tester</id>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<!-- For some reasons codemc's 1.18 doesn't include NMS -->
<version>1.17.1-R0.1-SNAPSHOT</version>
<scope>compile</scope>
<version>${spigotVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>1_16R2</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>17</source>
<target>17</target>
</configuration>
<executions>
<execution>
Expand All @@ -257,23 +230,37 @@
</goals>
<configuration>
<skip>false</skip>
<testExcludes>
<exclude>**/**1_16R3.java</exclude>
</testExcludes>
<testIncludes>
<include>*/**DummySpigot.java</include>
</testIncludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>18</id>
<properties>
<nms>18_R1</nms>
<spigotVersion>1.18-rc3-R0.1-SNAPSHOT</spigotVersion>
</properties>
</profile>
<profile>
<id>17</id>
<properties>
<nms>17_R1</nms>
<spigotVersion>1.17.1-R0.1-SNAPSHOT</spigotVersion>
</properties>
</profile>
<profile>
<!-- Doens't seem to work. I can't find a way to compile with one dependency and test with another -->
<id>16</id>
<properties>
<nms>16_R3</nms>
<spigotVersion>1.16.5-R0.1-SNAPSHOT</spigotVersion>
</properties>
</profile>
</profiles>
</project>
11 changes: 6 additions & 5 deletions src/main/java/com/cryptomorin/xseries/NMSExtras.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,19 @@ public final class NMSExtras {
Class<?> blockPos = getNMSClass("core", "BlockPosition");
Class<?> block = getNMSClass("world.level.block", "Block");
blockPosition = lookup.findConstructor(blockPos, MethodType.methodType(void.class, double.class, double.class, double.class));
getBlockType = lookup.findVirtual(world, "getType", MethodType.methodType(BLOCK_DATA, blockPos));
getBlock = lookup.findVirtual(BLOCK_DATA, "getBlock", MethodType.methodType(block));
playBlockAction = lookup.findVirtual(world, "playBlockAction", MethodType.methodType(void.class, blockPos, block, int.class, int.class));
getBlockType = lookup.findVirtual(world, v(18, "a_").orElse("getType"), MethodType.methodType(BLOCK_DATA, blockPos));
getBlock = lookup.findVirtual(BLOCK_DATA, v(18, "b").orElse("getBlock"), MethodType.methodType(block));
playBlockAction = lookup.findVirtual(world, v(18, "a").orElse("playBlockAction"), MethodType.methodType(void.class, blockPos, block, int.class, int.class));

signEditorPacket = lookup.findConstructor(signOpenPacket, MethodType.methodType(void.class, blockPos));
if (supports(17)) {
packetPlayOutBlockChange = lookup.findConstructor(packetPlayOutBlockChangeClass, MethodType.methodType(void.class, blockPos, BLOCK_DATA));
getIBlockData = lookup.findStatic(CraftMagicNumbers, "getBlock", MethodType.methodType(BLOCK_DATA, Material.class, byte.class));
sanitizeLines = lookup.findStatic(CraftSign, "SANITIZE_LINES", MethodType.methodType(toArrayClass(IChatBaseComponent), String[].class));
sanitizeLines = lookup.findStatic(CraftSign, v(17, "sanitizeLines").orElse("SANITIZE_LINES"),
MethodType.methodType(toArrayClass(IChatBaseComponent), String[].class));

tileEntitySign = lookup.findConstructor(TileEntitySign, MethodType.methodType(void.class, blockPos, BLOCK_DATA));
tileEntitySign_getUpdatePacket = lookup.findVirtual(TileEntitySign, "getUpdatePacket", MethodType.methodType(PacketPlayOutTileEntityData));
tileEntitySign_getUpdatePacket = lookup.findVirtual(TileEntitySign, v(18, "c").orElse("getUpdatePacket"), MethodType.methodType(PacketPlayOutTileEntityData));
tileEntitySign_setLine = lookup.findVirtual(TileEntitySign, "a", MethodType.methodType(void.class, int.class, IChatBaseComponent, IChatBaseComponent));
}
} catch (NoSuchMethodException | IllegalAccessException | NoSuchFieldException ex) {
Expand Down
38 changes: 32 additions & 6 deletions src/main/java/com/cryptomorin/xseries/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
package com.cryptomorin.xseries;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import javax.annotation.Nonnull;
Expand All @@ -47,7 +46,7 @@
* A useful resource used to compare mappings is <a href="https://minidigger.github.io/MiniMappingViewer/#/spigot">Mini's Mapping Viewer</a>
*
* @author Crypto Morin
* @version 5.0.0
* @version 6.0.0
*/
public final class ReflectionUtils {
/**
Expand All @@ -60,8 +59,8 @@ public final class ReflectionUtils {
* <p>
* Performance is not a concern for these specific statically initialized values.
*/
public static final String
VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
public static final String VERSION = parseVersion();

/**
* The raw minor version number.
* E.g. {@code v1_17_R1} to {@code 17}
Expand Down Expand Up @@ -105,8 +104,7 @@ public final class ReflectionUtils {
MethodHandle connection = null;
try {
connection = lookup.findGetter(entityPlayer,
v(18, "b").orElse("playerConnection"),
playerConnection);
v(17, "b").orElse("playerConnection"), playerConnection);
getHandle = lookup.findVirtual(craftPlayer, "getHandle", MethodType.methodType(entityPlayer));
sendPacket = lookup.findVirtual(playerConnection,
v(18, "a").orElse("sendPacket"),
Expand All @@ -122,6 +120,34 @@ public final class ReflectionUtils {

private ReflectionUtils() {}

/**
* Gets the package version used for NMS. This method is preferred over
* <code>
* Bukkit.getServer().getClass().getPackage()
* Bukkit.getVersion()
* </code>
* because the first solution doesn't work with unit tests and the second version
* doesn't have the exact package version.
* <p>
* Performance doesn't matter here as the method is only called once.
*
* @return the exact package version.
* @see #VERSION
* @since 6.0.0
*/
private static String parseVersion() {
String found = null;
for (Package pack : Package.getPackages()) {
if (pack.getName().startsWith("org.bukkit.craftbukkit.v")) { // .v because there are other packages.
found = pack.getName().split("\\.")[3];
break;
}
}

if (found == null) throw new IllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
return found;
}

/**
* This method is purely for readability.
* No performance is gained.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/cryptomorin/xseries/XMaterialUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class XMaterialUtil {
* @return true if this material is an item.
* @since 1.13
*/
public boolean isItem(XMaterial material) {
public static boolean isItem(XMaterial material) {
if (XMaterial.supports(13)) return material.parseMaterial().isItem();
switch (material) { // All the materials that are NOT an item (only 1.12 materials)
case ATTACHED_MELON_STEM:
Expand Down Expand Up @@ -117,7 +117,7 @@ public boolean isItem(XMaterial material) {
* @return true if this material can be interacted with.
* @since 1.13
*/
public boolean isInteractable(XMaterial material) {
public static boolean isInteractable(XMaterial material) {
if (XMaterial.supports(13)) return material.parseMaterial().isInteractable();
switch (material) { // 1.12 materials only
case ACACIA_BUTTON:
Expand Down Expand Up @@ -281,7 +281,7 @@ public boolean isInteractable(XMaterial material) {
* @return True if this material is an air block.
* @since 1.14.4
*/
public boolean isAir(XMaterial material) {
public static boolean isAir(XMaterial material) {
switch (material) {
case AIR:
case CAVE_AIR:
Expand Down
Loading

0 comments on commit 7477ef5

Please sign in to comment.