Skip to content

Commit ee8f5f9

Browse files
committed
v13.0.0
* Added XProxifier for XReflection IV * **[XReflection]** Using the suffix support for JetBrains `@Language` annotation, we no longer need to add semicolons or `{}` at the end of string APIs. Other than the readability improvement, this results in a slight performance improvement as well, since fewer characters are needed for parsing. * Improved Unit Tests. * Added `@Contract` annotations to most APIs. * **[XTag]** Fixed `INVENTORY_NOT_DISPLAYABLE` for wheat.
1 parent 79dc6f9 commit ee8f5f9

36 files changed

+1122
-123
lines changed

TODO.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ This file simply highlighs things that need to be done in future releases or oth
22
solution is yet to be found. It's also a simple list of planned decisions for the future of the project that other
33
developers can see and perhaps give suggestions about. Anyone is welcome to complete any of the listed issues.
44

5+
* **[XMaterial]** We have to convert this into a XModule/XRegistry class soon. Wait and see what Spigot/Pape does first.
6+
57
* **[Unit Tests]** Improve Maven's unit testing (Read #149 issue for more info.)
68

79
* **[XReflectASM/ReflectiveProxy]** Add more benchmarking for XReflection Stage III & IV with different method
@@ -22,6 +24,39 @@ developers can see and perhaps give suggestions about. Anyone is welcome to comp
2224
of using the annotations. This is useful for situations where annotations will seem bulky or the data is more complex
2325
and must be calculated during runtime.
2426

27+
* **[ReflectiveProxyObject]** Add a way to ignore certain methods if they're not supported in a specific
28+
version instead of throwing an error (related to the issue below)
29+
30+
* **[ReflectiveProxyObject]** Add some sort of `boolean isSupported(String method, MethodType type)` to
31+
**ReflectiveProxyObject**. So we can test whether a method is supported in the current version or not.
32+
If we could make the method signature more simple, that'd be nice as well. For example, we could take the
33+
string approach and do `boolean isSupported(String signature)` to be used
34+
like `isSupported("private method(int a, String b, ...)")` that could work. A more strict approach using the
35+
already existing interface would've been nicer. For example, in JavaScript we could reference the method
36+
itself and add properties to it. I guess an ideal approach would be how you link methods in javadocs.
37+
38+
* **[ReflectiveProxyObject]** Add a simple enum class scanner that uses `@Proxify` and `@ReflectName` annotations to
39+
parse an enum class and map the correct values to field. How this value gets saved should be handled by
40+
an interface class like `interface A { void mapValue(Object) }` which our enum implements. Then we could
41+
also add a parent interface for **ReflectiveProxyObject** that enums also share, allowing us to use its
42+
`instance()` method. Which also means that we can use our enum class in other proxy methods.
43+
44+
* **[ReflectiveProxyObject]** Add interface inheritance support. (This might already be a thing, we just need to test)
45+
46+
* **[ReflectiveProxyObject]** Add support for inner classes.
47+
48+
* **[ReflectiveProxyObject]** Create a Maven and Gradle plugin for real class support that remaps fields, constructors
49+
and static member accesses to proxy access.
50+
51+
* **[XProxifier]** Implement configurable settings. (Read the TODO list inside that class for more info.)
52+
53+
* **[XProxifier]** Turn this into an IntelliJ plugin that allows proxifying any compiled file. Will probably
54+
need ASM to read the class file due to class loader issues? Not sure, needs to be tested.
55+
56+
* **[XProxifier]** Add a way to automatically generate mappings for different versions of a proxified class.
57+
We might define download links to mapping files, download the needed mapping, parse it and generate a class
58+
container for it?
59+
2560
* **[XTag]** Inline all fields. Using a `static {}` block is unnecessary and makes things really hard to track.
2661
Currently, this is not possible using IntelliJ's `Refactor -> Inline Field` feature, because you'll get a
2762
`No initializer present for the field` error. Not sure if this is a bug or some sort of tricky feature.
@@ -33,6 +68,7 @@ developers can see and perhaps give suggestions about. Anyone is welcome to comp
3368
including the current version and methods to enable/disable certain features that are currently handled by system
3469
properties? One thing we could do is to add an option to enable debug mode, certain exceptions that are normally
3570
suppressed are printed.
71+
3672
* **[General]** Don't forget to remove pre-12.0.0 deprecated codes in MC v1.22
3773

3874
* **[General]** Add a guide for Maven and Gradle users on how to properly exclude XSeries XReflection's III and IV proxy
@@ -44,7 +80,5 @@ developers can see and perhaps give suggestions about. Anyone is welcome to comp
4480
have to spend a lot of time to design one.
4581

4682
* **[Documentation]** While the javadocs are pretty comprehensive for most classes, they're mostly flooded with small
47-
and
48-
technical details that most developers don't have to be concerned about. We should make a guide on the wiki with
49-
screenshots
50-
and a general overview of all the features which makes it much easier for developers to get started.
83+
and technical details that most developers don't have to be concerned about. We should make a guide on the wiki with
84+
screenshots and a general overview of all the features which makes it much easier for developers to get started.

pom.xml

Lines changed: 1 addition & 1 deletion
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>12.1.0</version>
9+
<version>13.0.0</version>
1010

1111
<name>XSeries</name>
1212
<description>A set of utilities for Minecraft plugins</description>

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

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@
4242
import org.bukkit.entity.EntityType;
4343
import org.bukkit.entity.Player;
4444
import org.bukkit.entity.TropicalFish;
45-
import org.bukkit.inventory.EquipmentSlot;
46-
import org.bukkit.inventory.Inventory;
47-
import org.bukkit.inventory.ItemFlag;
48-
import org.bukkit.inventory.ItemStack;
45+
import org.bukkit.inventory.*;
4946
import org.bukkit.inventory.meta.*;
5047
import org.bukkit.inventory.meta.trim.ArmorTrim;
5148
import org.bukkit.inventory.meta.trim.TrimMaterial;
@@ -55,8 +52,10 @@
5552
import org.bukkit.material.SpawnEgg;
5653
import org.bukkit.potion.PotionEffect;
5754
import org.bukkit.potion.PotionType;
55+
import org.jetbrains.annotations.Contract;
5856
import org.jetbrains.annotations.NotNull;
5957
import org.jetbrains.annotations.Nullable;
58+
import org.jetbrains.annotations.Range;
6059

6160
import java.util.*;
6261
import java.util.function.BiPredicate;
@@ -77,7 +76,7 @@
7776
* <a href="https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html">ItemStack</a>
7877
*
7978
* @author Crypto Morin
80-
* @version 7.5.1
79+
* @version 7.5.2
8180
* @see XMaterial
8281
* @see XPotion
8382
* @see XSkull
@@ -1236,6 +1235,7 @@ public static Color parseColor(@Nullable String str) {
12361235
* @since 2.0.1
12371236
*/
12381237
@NotNull
1238+
@Contract(mutates = "param1")
12391239
public static List<ItemStack> giveOrDrop(@NotNull Player player, @Nullable ItemStack... items) {
12401240
return giveOrDrop(player, false, items);
12411241
}
@@ -1250,6 +1250,7 @@ public static List<ItemStack> giveOrDrop(@NotNull Player player, @Nullable ItemS
12501250
* @since 2.0.1
12511251
*/
12521252
@NotNull
1253+
@Contract(mutates = "param1")
12531254
public static List<ItemStack> giveOrDrop(@NotNull Player player, boolean split, @Nullable ItemStack... items) {
12541255
if (items == null || items.length == 0) return new ArrayList<>();
12551256
List<ItemStack> leftOvers = addItems(player.getInventory(), split, items);
@@ -1260,6 +1261,7 @@ public static List<ItemStack> giveOrDrop(@NotNull Player player, boolean split,
12601261
return leftOvers;
12611262
}
12621263

1264+
@Contract(mutates = "param1")
12631265
public static List<ItemStack> addItems(@NotNull Inventory inventory, boolean split, @NotNull ItemStack... items) {
12641266
return addItems(inventory, split, null, items);
12651267
}
@@ -1277,7 +1279,9 @@ public static List<ItemStack> addItems(@NotNull Inventory inventory, boolean spl
12771279
* @return items that didn't fit in the inventory.
12781280
* @since 4.0.0
12791281
*/
1282+
12801283
@NotNull
1284+
@Contract(mutates = "param1")
12811285
public static List<ItemStack> addItems(@NotNull Inventory inventory, boolean split,
12821286
@Nullable Predicate<Integer> modifiableSlots, @NotNull ItemStack... items) {
12831287
Objects.requireNonNull(inventory, "Cannot add items to null inventory");
@@ -1344,6 +1348,9 @@ public static List<ItemStack> addItems(@NotNull Inventory inventory, boolean spl
13441348
return leftOvers;
13451349
}
13461350

1351+
@NotNull
1352+
@Contract(pure = true)
1353+
@Range(from = -1, to = Integer.MAX_VALUE)
13471354
public static int firstPartial(@NotNull Inventory inventory, @Nullable ItemStack item, int beginIndex) {
13481355
return firstPartial(inventory, item, beginIndex, null);
13491356
}
@@ -1361,6 +1368,9 @@ public static int firstPartial(@NotNull Inventory inventory, @Nullable ItemStack
13611368
* @throws IndexOutOfBoundsException if the beginning index is less than 0 or greater than the inventory storage size.
13621369
* @since 4.0.0
13631370
*/
1371+
@NotNull
1372+
@Contract(pure = true)
1373+
@Range(from = -1, to = Integer.MAX_VALUE)
13641374
public static int firstPartial(@NotNull Inventory inventory, @Nullable ItemStack item, int beginIndex, @Nullable Predicate<Integer> modifiableSlots) {
13651375
if (item != null) {
13661376
ItemStack[] items = getStorageContents(inventory);
@@ -1378,6 +1388,8 @@ public static int firstPartial(@NotNull Inventory inventory, @Nullable ItemStack
13781388
return -1;
13791389
}
13801390

1391+
@NotNull
1392+
@Contract(pure = true)
13811393
public static List<ItemStack> stack(@NotNull Collection<ItemStack> items) {
13821394
return stack(items, ItemStack::isSimilar);
13831395
}
@@ -1396,6 +1408,7 @@ public static List<ItemStack> stack(@NotNull Collection<ItemStack> items) {
13961408
* @since 4.0.0
13971409
*/
13981410
@NotNull
1411+
@Contract(pure = true)
13991412
public static List<ItemStack> stack(@NotNull Collection<ItemStack> items, @NotNull BiPredicate<ItemStack, ItemStack> similarity) {
14001413
Objects.requireNonNull(items, "Cannot stack null items");
14011414
Objects.requireNonNull(similarity, "Similarity check cannot be null");
@@ -1418,6 +1431,8 @@ public static List<ItemStack> stack(@NotNull Collection<ItemStack> items, @NotNu
14181431
return stacked;
14191432
}
14201433

1434+
@Contract(pure = true)
1435+
@Range(from = -1, to = Integer.MAX_VALUE)
14211436
public static int firstEmpty(@NotNull Inventory inventory, int beginIndex) {
14221437
return firstEmpty(inventory, beginIndex, null);
14231438
}
@@ -1434,6 +1449,8 @@ public static int firstEmpty(@NotNull Inventory inventory, int beginIndex) {
14341449
* @throws IndexOutOfBoundsException if the beginning index is less than 0 or greater than the inventory storage size.
14351450
* @since 4.0.0
14361451
*/
1452+
@Contract(pure = true)
1453+
@Range(from = -1, to = Integer.MAX_VALUE)
14371454
public static int firstEmpty(@NotNull Inventory inventory, int beginIndex, @Nullable Predicate<Integer> modifiableSlots) {
14381455
ItemStack[] items = getStorageContents(inventory);
14391456
int invSize = items.length;
@@ -1458,6 +1475,8 @@ public static int firstEmpty(@NotNull Inventory inventory, int beginIndex, @Null
14581475
* @see #firstPartial(Inventory, ItemStack, int)
14591476
* @since 4.2.0
14601477
*/
1478+
@Contract(pure = true)
1479+
@Range(from = -1, to = Integer.MAX_VALUE)
14611480
public static int firstPartialOrEmpty(@NotNull Inventory inventory, @Nullable ItemStack item, int beginIndex) {
14621481
if (item != null) {
14631482
ItemStack[] items = getStorageContents(inventory);
@@ -1474,6 +1493,10 @@ public static int firstPartialOrEmpty(@NotNull Inventory inventory, @Nullable It
14741493
return -1;
14751494
}
14761495

1496+
/**
1497+
* Cross-version compatible version of {@link Inventory#getStorageContents()}.
1498+
*/
1499+
@Contract(pure = true)
14771500
public static ItemStack[] getStorageContents(Inventory inventory) {
14781501
// Mojang divides player inventory like this:
14791502
// public final ItemStack[] items = new ItemStack[36];
@@ -1489,6 +1512,31 @@ public static ItemStack[] getStorageContents(Inventory inventory) {
14891512
}
14901513
}
14911514

1515+
/**
1516+
* @see #isEmpty(ItemStack)
1517+
* @since 7.5.2
1518+
*/
1519+
@Contract(pure = true)
1520+
public static boolean notEmpty(@Nullable ItemStack item) {
1521+
return !isEmpty(item);
1522+
}
1523+
1524+
/**
1525+
* Checks if this item is {@code null} or {@link Material#AIR}.
1526+
* The latter can only happen in the following situations:
1527+
* <ul>
1528+
* <li>{@link PlayerInventory#getItemInMainHand()}</li>
1529+
* <li>{@link PlayerInventory#getItemInOffHand()}</li>
1530+
* </ul>
1531+
*
1532+
* @see #notEmpty(ItemStack)
1533+
* @since 7.5.2
1534+
*/
1535+
@Contract(pure = true)
1536+
public static boolean isEmpty(@Nullable ItemStack item) {
1537+
return item == null || item.getType() == Material.AIR;
1538+
}
1539+
14921540
public static class MaterialCondition extends RuntimeException {
14931541
protected XMaterial solution;
14941542

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ private static List<String> split(@NotNull String str, @SuppressWarnings("SamePa
333333
* Format: <b>Potion, Duration (in seconds), Amplifier (level) [%chance]</b>
334334
* <pre>
335335
* WEAKNESS, 30, 1
336-
* SLOWNESS 200 10
337-
* 1, 10000, 100 %50
336+
* SLOWNESS, 200, 10
337+
* 1, 10000, 100, %50
338338
* </pre>
339339
* The last argument can also include a chance (written in percent) which if not met, returns null.
340340
*

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,8 +2436,10 @@ public final class XTag<T extends XBase<?, ?>> {
24362436
)
24372437
.inheritFrom(
24382438
AIR, CAVE_VINES, FILLED_CAULDRONS, FIRE, FLUID, PORTALS,
2439-
WALL_SIGNS, WALL_HANGING_SIGNS, WALL_TORCHES, ALIVE_CORAL_WALL_FANS, DEAD_CORAL_WALL_FANS, WALL_HEADS,
2440-
CANDLE_CAKES, WALL_BANNERS, FLOWER_POTS.without(XMaterial.FLOWER_POT), CROPS.without(XMaterial.WHEAT)
2439+
WALL_SIGNS, WALL_HANGING_SIGNS, WALL_TORCHES, ALIVE_CORAL_WALL_FANS,
2440+
DEAD_CORAL_WALL_FANS, WALL_HEADS, CANDLE_CAKES, WALL_BANNERS,
2441+
FLOWER_POTS.without(XMaterial.FLOWER_POT),
2442+
CROPS.without(XMaterial.WHEAT_SEEDS, XMaterial.WHEAT)
24412443
).build();
24422444
}
24432445

src/main/java/com/cryptomorin/xseries/profiles/builder/XSkull.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public final class XSkull {
8585
* @return A {@link ProfileInstruction} that sets the profile for the generated {@link ItemStack}.
8686
*/
8787
@NotNull
88-
@Contract(pure = true)
88+
@Contract(value = "-> new", pure = true)
8989
public static ProfileInstruction<ItemStack> createItem() {
9090
return of(XMaterial.PLAYER_HEAD.parseItem());
9191
}
@@ -97,7 +97,7 @@ public static ProfileInstruction<ItemStack> createItem() {
9797
* @return A {@link ProfileInstruction} that sets the profile for the given {@link ItemStack}.
9898
*/
9999
@NotNull
100-
@Contract(pure = true)
100+
@Contract(value = "_ -> new", pure = true)
101101
public static ProfileInstruction<ItemStack> of(@NotNull ItemStack stack) {
102102
return new ProfileInstruction<>(new ProfileContainer.ItemStackProfileContainer(stack));
103103
}
@@ -109,7 +109,7 @@ public static ProfileInstruction<ItemStack> of(@NotNull ItemStack stack) {
109109
* @return An {@link ProfileInstruction} that sets the profile for the given {@link ItemMeta}.
110110
*/
111111
@NotNull
112-
@Contract(pure = true)
112+
@Contract(value = "_ -> new", pure = true)
113113
public static ProfileInstruction<ItemMeta> of(@NotNull ItemMeta meta) {
114114
return new ProfileInstruction<>(new ProfileContainer.ItemMetaProfileContainer((SkullMeta) meta));
115115
}
@@ -121,7 +121,7 @@ public static ProfileInstruction<ItemMeta> of(@NotNull ItemMeta meta) {
121121
* @return An {@link ProfileInstruction} that sets the profile for the given {@link Block}.
122122
*/
123123
@NotNull
124-
@Contract(pure = true)
124+
@Contract(value = "_ -> new", pure = true)
125125
public static ProfileInstruction<Block> of(@NotNull Block block) {
126126
return new ProfileInstruction<>(new ProfileContainer.BlockProfileContainer(block));
127127
}
@@ -133,7 +133,7 @@ public static ProfileInstruction<Block> of(@NotNull Block block) {
133133
* @return An {@link ProfileInstruction} that sets the profile for the given {@link BlockState}.
134134
*/
135135
@NotNull
136-
@Contract(pure = true)
136+
@Contract(value = "_ -> new", pure = true)
137137
public static ProfileInstruction<Skull> of(@NotNull BlockState state) {
138138
return new ProfileInstruction<>(new ProfileContainer.BlockStateProfileContainer((Skull) state));
139139
}
@@ -156,7 +156,7 @@ public static ProfileInstruction<Skull> of(@NotNull BlockState state) {
156156
* @return A clone of the default {@link GameProfile}.
157157
*/
158158
@NotNull
159-
@Contract(pure = true)
159+
@Contract(value = "-> new", pure = true)
160160
protected static Profileable getDefaultProfile() {
161161
// We copy this just in case something changes the GameProfile properties.
162162
GameProfile clone = PlayerProfiles.createGameProfile(DEFAULT_PROFILE.getId(), DEFAULT_PROFILE.getName());

0 commit comments

Comments
 (0)