Skip to content

Commit 4e730e5

Browse files
committed
v8.6.0
Unit tests are now much more complete. XTag A class similar to Spigots XTag, but with more features and directly works with XSeries. Note that this is a huge class. It's recommended that you exclude this from your project if you don't want to use it. MaterialUtils Removed in favor of XTag. ReflectionUtils Fixed an issue with 1.17 Attempted to fix a few issues with Bukkit-Forge servers. XMaterial Fixed an issue with Regex cache. XSound Added a method to stop a particular sound from XSound.Record NMSExtras Added support for 1.18 and fixed a small issue for 1.17 XPotion If you're using this utility, you should consider recoding all those parts. Most methods are renamed to a shorter and concise version. Added a wrapper for PotionEffect for chances. matchXPotion(PotionEffectType) is now extremely more efficient.
1 parent f445518 commit 4e730e5

25 files changed

+857
-805
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2021 Crypto Morin
3+
Copyright (c) 2022 Crypto Morin
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ To shade the library, add the following under your maven plugins:
7676
<exclude>com/cryptomorin/xseries/XBiome*</exclude>
7777
<exclude>com/cryptomorin/xseries/NMSExtras*</exclude>
7878
<exclude>com/cryptomorin/xseries/NoteBlockMusic*</exclude>
79+
<exclude>com/cryptomorin/xseries/SkullCacheListener*</exclude>
7980
</excludes>
8081
</filter>
8182
</filters>

pom.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.cryptomorin</groupId>
88
<artifactId>XSeries</artifactId>
9-
<version>8.5.0.1</version>
9+
<version>8.6.0</version>
1010

1111
<name>XSeries</name>
1212
<description>A set of utilities for Minecraft plugins</description>
@@ -62,14 +62,14 @@
6262
</repositories>
6363

6464
<properties>
65-
<spigotVersion>1.18-rc3-R0.1-SNAPSHOT</spigotVersion>
65+
<spigotVersion>1.18.1-R0.1-SNAPSHOT</spigotVersion>
6666
</properties>
6767

6868
<dependencies>
6969
<dependency>
7070
<groupId>org.spigotmc</groupId>
7171
<artifactId>spigot</artifactId>
72-
<version>1.18-rc3-R0.1-SNAPSHOT</version>
72+
<version>${spigotVersion}</version>
7373
<scope>provided</scope>
7474
</dependency>
7575
<dependency>
@@ -156,7 +156,6 @@
156156
</compilerArgs>
157157
<excludes>
158158
<exclude>com/cryptomorin/xseries/unused/</exclude>
159-
<exclude>com/cryptomorin/xseries/XMaterialUtil.java</exclude>
160159
<exclude>com/cryptomorin/xseries/SkullCacheListener.java</exclude>
161160
</excludes>
162161
</configuration>
@@ -244,7 +243,7 @@
244243
<id>18</id>
245244
<properties>
246245
<nms>18_R1</nms>
247-
<spigotVersion>1.18-rc3-R0.1-SNAPSHOT</spigotVersion>
246+
<spigotVersion>1.18.1-R0.1-SNAPSHOT</spigotVersion>
248247
</properties>
249248
</profile>
250249
<profile>

src/main/java/com/cryptomorin/xseries/NMSExtras.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2021 Crypto Morin
4+
* Copyright (c) 2022 Crypto Morin
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -241,7 +241,7 @@ public final class NMSExtras {
241241
SET_BLOCK_DATA = setBlockData;
242242
}
243243

244-
private NMSExtras() { }
244+
private NMSExtras() {}
245245

246246
public static void setExp(Player player, float bar, int lvl, int exp) {
247247
try {

src/main/java/com/cryptomorin/xseries/NoteBlockMusic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2021 Crypto Morin
4+
* Copyright (c) 2022 Crypto Morin
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/com/cryptomorin/xseries/ReflectionUtils.java

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2021 Crypto Morin
4+
* Copyright (c) 2022 Crypto Morin
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -46,7 +46,7 @@
4646
* A useful resource used to compare mappings is <a href="https://minidigger.github.io/MiniMappingViewer/#/spigot">Mini's Mapping Viewer</a>
4747
*
4848
* @author Crypto Morin
49-
* @version 6.0.0
49+
* @version 6.0.1
5050
*/
5151
public final class ReflectionUtils {
5252
/**
@@ -59,7 +59,34 @@ public final class ReflectionUtils {
5959
* <p>
6060
* Performance is not a concern for these specific statically initialized values.
6161
*/
62-
public static final String VERSION = parseVersion();
62+
public static final String VERSION;
63+
64+
static {
65+
// This package loop is used to avoid implementation-dependant strings like Bukkit.getVersion() or Bukkit.getBukkitVersion()
66+
// which allows easier testing as well.
67+
String found = null;
68+
for (Package pack : Package.getPackages()) {
69+
String name = pack.getName();
70+
if (name.startsWith("org.bukkit.craftbukkit.v") // .v because there are other packages.
71+
// As a protection for forge+bukkit implementation that tend to mix versions.
72+
// The real CraftPlayer should exist in the package.
73+
// Note: Doesn't seem to function properly. Will need to separate the version
74+
// handler for NMS and CraftBukkit for softwares like catmc.
75+
&& name.endsWith("entity")) {
76+
found = pack.getName().split("\\.")[3];
77+
78+
// Just a final guard to make sure it finds this important class.
79+
try {
80+
Class.forName("org.bukkit.craftbukkit." + found + ".entity.CraftPlayer");
81+
break;
82+
} catch (ClassNotFoundException e) {
83+
found = null;
84+
}
85+
}
86+
}
87+
if (found == null) throw new IllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
88+
VERSION = found;
89+
}
6390

6491
/**
6592
* The raw minor version number.
@@ -99,9 +126,8 @@ public final class ReflectionUtils {
99126
Class<?> playerConnection = getNMSClass("server.network", "PlayerConnection");
100127

101128
MethodHandles.Lookup lookup = MethodHandles.lookup();
102-
MethodHandle sendPacket = null;
103-
MethodHandle getHandle = null;
104-
MethodHandle connection = null;
129+
MethodHandle sendPacket = null, getHandle = null, connection = null;
130+
105131
try {
106132
connection = lookup.findGetter(entityPlayer,
107133
v(17, "b").orElse("playerConnection"), playerConnection);
@@ -120,34 +146,6 @@ public final class ReflectionUtils {
120146

121147
private ReflectionUtils() {}
122148

123-
/**
124-
* Gets the package version used for NMS. This method is preferred over
125-
* <code>
126-
* Bukkit.getServer().getClass().getPackage()
127-
* Bukkit.getVersion()
128-
* </code>
129-
* because the first solution doesn't work with unit tests and the second version
130-
* doesn't have the exact package version.
131-
* <p>
132-
* Performance doesn't matter here as the method is only called once.
133-
*
134-
* @return the exact package version.
135-
* @see #VERSION
136-
* @since 6.0.0
137-
*/
138-
private static String parseVersion() {
139-
String found = null;
140-
for (Package pack : Package.getPackages()) {
141-
if (pack.getName().startsWith("org.bukkit.craftbukkit.v")) { // .v because there are other packages.
142-
found = pack.getName().split("\\.")[3];
143-
break;
144-
}
145-
}
146-
147-
if (found == null) throw new IllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
148-
return found;
149-
}
150-
151149
/**
152150
* This method is purely for readability.
153151
* No performance is gained.
@@ -170,7 +168,7 @@ public static <T> CallableVersionHandler<T> v(int version, Callable<T> handle) {
170168
* @return true if the version is equal or newer, otherwise false.
171169
* @since 4.0.0
172170
*/
173-
public static boolean supports(int version) { return VER >= version; }
171+
public static boolean supports(int version) {return VER >= version;}
174172

175173
/**
176174
* Get a NMS (net.minecraft.server) class which accepts a package for 1.17 compatibility.

src/main/java/com/cryptomorin/xseries/SkullCacheListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2021 Crypto Morin
4+
* Copyright (c) 2022 Crypto Morin
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/com/cryptomorin/xseries/SkullUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2021 Crypto Morin
4+
* Copyright (c) 2022 Crypto Morin
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/com/cryptomorin/xseries/XBiome.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2021 Crypto Morin
4+
* Copyright (c) 2022 Crypto Morin
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

src/main/java/com/cryptomorin/xseries/XBlock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2021 Crypto Morin
4+
* Copyright (c) 2022 Crypto Morin
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -82,7 +82,7 @@ public final class XBlock {
8282
ITEM_TO_BLOCK.put(XMaterial.PUMPKIN_PIE, XMaterial.PUMPKIN);
8383
}
8484

85-
private XBlock() { }
85+
private XBlock() {}
8686

8787
public static boolean isLit(Block block) {
8888
if (ISFLAT) {

0 commit comments

Comments
 (0)