Skip to content

Commit

Permalink
v11.3.0
Browse files Browse the repository at this point in the history
* Replaced all JavaX annotations with JetBrains annotations.
* Added more annotations to XSkull APIs.
* Fixed some errors with XSkull API (specially when used for XItemStack) (Fixes #300)
* Added AggregateReflectiveSupplier
* Added more tests.
* XSkull will now try to create less verbose profile values which can be used for XItemStack but requires extra settings.
  • Loading branch information
CryptoMorin committed Sep 27, 2024
1 parent 95b0796 commit 8053b32
Show file tree
Hide file tree
Showing 40 changed files with 1,035 additions and 606 deletions.
2 changes: 1 addition & 1 deletion 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>11.2.2</version>
<version>11.3.0</version>

<name>XSeries</name>
<description>A set of utilities for Minecraft plugins</description>
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/cryptomorin/xseries/NoteBlockMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -118,8 +118,8 @@ public final class NoteBlockMusic {
private NoteBlockMusic() {
}

@Nonnull
public static XSound getSoundFromInstrument(@Nonnull Instrument instrument) {
@NotNull
public static XSound getSoundFromInstrument(@NotNull Instrument instrument) {
return INSTRUMENT_TO_SOUND.get(instrument);
}

Expand Down Expand Up @@ -167,7 +167,7 @@ public static Note.Tone getNoteTone(char ch) {
* @return the async task handling the notes.
* @since 1.0.0
*/
public static CompletableFuture<Void> testMusic(@Nonnull Player player) {
public static CompletableFuture<Void> testMusic(@NotNull Player player) {
return playMusic(player, player::getLocation, // Starting piece of Megalovania (not perfectly toned, it's screwed up)
"PIANO,D,2,100 PIANO,B#1 200 PIANO,F 250 PIANO,E 250 PIANO,B 200 PIANO,A 100 PIANO,B 100 PIANO,E");
}
Expand All @@ -183,7 +183,7 @@ public static CompletableFuture<Void> testMusic(@Nonnull Player player) {
* @see #playMusic(Player, Supplier, String)
* @since 1.0.0
*/
public static CompletableFuture<Void> fromFile(@Nonnull Player player, @Nonnull Supplier<Location> location, @Nonnull Path path) {
public static CompletableFuture<Void> fromFile(@NotNull Player player, @NotNull Supplier<Location> location, @NotNull Path path) {
return CompletableFuture.runAsync(() -> {
try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
String line;
Expand Down Expand Up @@ -244,7 +244,7 @@ public static CompletableFuture<Void> fromFile(@Nonnull Player player, @Nonnull
* @see #fromFile(Player, Supplier, Path)
* @since 1.0.0
*/
public static CompletableFuture<Void> playMusic(@Nonnull Player player, @Nonnull Supplier<Location> location, @Nullable String script) {
public static CompletableFuture<Void> playMusic(@NotNull Player player, @NotNull Supplier<Location> location, @Nullable String script) {
// We don't want to mess around in the main thread.
// Sounds are thread-safe.
return CompletableFuture.runAsync(() -> {
Expand All @@ -257,7 +257,7 @@ public static CompletableFuture<Void> playMusic(@Nonnull Player player, @Nonnull
});
}

public static Sequence parseInstructions(@Nonnull CharSequence script) {
public static Sequence parseInstructions(@NotNull CharSequence script) {
return new InstructionBuilder(script).sequence;
}

Expand Down Expand Up @@ -299,7 +299,7 @@ private static void sleep(long fermata) {
* @since 3.0.0
*/
@Nullable
public static Note parseNote(@Nonnull String note) {
public static Note parseNote(@NotNull String note) {
Note.Tone tone = getNoteTone((char) (note.charAt(0) & 0x5f)); // Doesn't matter if it's already uppercase.
if (tone == null) return null;

Expand Down Expand Up @@ -336,7 +336,7 @@ private static boolean isDigit(char ch) {
}

@SuppressWarnings("deprecation")
public static float noteToPitch(@Nonnull Note note) {
public static float noteToPitch(@NotNull Note note) {
return (float) Math.pow(2.0D, ((double) note.getId() - 12.0D) / 12.0D);
}

Expand Down Expand Up @@ -422,7 +422,7 @@ protected char checkup(char ch) {

@SuppressWarnings("StringBufferField")
private static final class InstructionBuilder {
@Nonnull final CharSequence script;
@NotNull final CharSequence script;
final int len;
final StringBuilder
instrumentBuilder = new StringBuilder(10),
Expand All @@ -436,7 +436,7 @@ private static final class InstructionBuilder {
StringBuilder currentBuilder;


public InstructionBuilder(@Nonnull CharSequence script) {
public InstructionBuilder(@NotNull CharSequence script) {
this.script = script;
len = script.length();

Expand Down Expand Up @@ -665,8 +665,8 @@ public String toString() {
* @return the async task handling the operation.
* @since 2.0.0
*/
@Nonnull
public static BukkitTask playAscendingNote(@Nonnull Plugin plugin, @Nonnull Player player, @Nonnull Entity playTo, @Nonnull Instrument instrument,
@NotNull
public static BukkitTask playAscendingNote(@NotNull Plugin plugin, @NotNull Player player, @NotNull Entity playTo, @NotNull Instrument instrument,
int ascendLevel, int delay) {
Objects.requireNonNull(player, "Cannot play note from null player");
Objects.requireNonNull(playTo, "Cannot play note to null entity");
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/com/cryptomorin/xseries/XBiome.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -161,22 +161,22 @@ public enum XBiome {
private static final boolean HORIZONTAL_SUPPORT = XMaterial.supports(16), EXTENDED_MINIMUM = XMaterial.supports(17);
@Nullable
private final Biome biome;
@Nonnull
@NotNull
private final World.Environment environment;

XBiome(@Nonnull World.Environment environment, @Nonnull String... legacies) {
XBiome(@NotNull World.Environment environment, @NotNull String... legacies) {
this(environment, null, legacies);
}

XBiome(@Nonnull String... legacies) {
XBiome(@NotNull String... legacies) {
this(World.Environment.NORMAL, legacies);
}

XBiome(@Nullable XBiome newVersion, @Nonnull String... legacies) {
XBiome(@Nullable XBiome newVersion, @NotNull String... legacies) {
this(World.Environment.NORMAL, newVersion, legacies);
}

XBiome(@Nonnull World.Environment environment, @Nullable XBiome newVersion, @Nonnull String... legacies) {
XBiome(@NotNull World.Environment environment, @Nullable XBiome newVersion, @NotNull String... legacies) {
this.environment = environment;
Data.NAMES.put(this.name(), this);
for (String legacy : legacies) Data.NAMES.put(legacy, this);
Expand Down Expand Up @@ -204,8 +204,8 @@ public enum XBiome {
* @return an enum name.
* @since 1.0.0
*/
@Nonnull
private static String format(@Nonnull String name) {
@NotNull
private static String format(@NotNull String name) {
int len = name.length();
char[] chs = new char[len];
int count = 0;
Expand Down Expand Up @@ -236,8 +236,8 @@ private static String format(@Nonnull String name) {
* @return a matched XBiome.
* @since 1.0.0
*/
@Nonnull
public static Optional<XBiome> matchXBiome(@Nonnull String biome) {
@NotNull
public static Optional<XBiome> matchXBiome(@NotNull String biome) {
if (biome == null || biome.isEmpty())
throw new IllegalArgumentException("Cannot match XBiome of a null or empty biome name");
return Optional.ofNullable(Data.NAMES.get(format(biome)));
Expand All @@ -251,8 +251,8 @@ public static Optional<XBiome> matchXBiome(@Nonnull String biome) {
* @throws IllegalArgumentException may be thrown as an unexpected exception.
* @since 1.0.0
*/
@Nonnull
public static XBiome matchXBiome(@Nonnull Biome biome) {
@NotNull
public static XBiome matchXBiome(@NotNull Biome biome) {
Objects.requireNonNull(biome, "Cannot match XBiome of a null biome");
return Objects.requireNonNull(Data.NAMES.get(biome.name()), () -> "Unsupported biome: " + biome.name());
}
Expand Down Expand Up @@ -293,7 +293,7 @@ public XBiome or(@Nullable XBiome alternateBiome) {
* @return the environment that this biome belongs to.
* @since 4.0.0
*/
@Nonnull
@NotNull
public World.Environment getEnvironment() {
return environment;
}
Expand All @@ -318,8 +318,8 @@ public Biome getBiome() {
* @return the async task handling this operation.
* @since 1.0.0
*/
@Nonnull
public CompletableFuture<Void> setBiome(@Nonnull Chunk chunk) {
@NotNull
public CompletableFuture<Void> setBiome(@NotNull Chunk chunk) {
Objects.requireNonNull(biome, () -> "Unsupported biome: " + this.name());
Objects.requireNonNull(chunk, "Cannot set biome of null chunk");
if (!chunk.isLoaded()) {
Expand Down Expand Up @@ -357,8 +357,8 @@ public CompletableFuture<Void> setBiome(@Nonnull Chunk chunk) {
* @param end the end position.
* @since 1.0.0
*/
@Nonnull
public CompletableFuture<Void> setBiome(@Nonnull Location start, @Nonnull Location end) {
@NotNull
public CompletableFuture<Void> setBiome(@NotNull Location start, @NotNull Location end) {
Objects.requireNonNull(start, "Start location cannot be null");
Objects.requireNonNull(end, "End location cannot be null");
Objects.requireNonNull(biome, () -> "Unsupported biome: " + this.name());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/cryptomorin/xseries/XBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import org.bukkit.block.data.BlockData;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.material.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;

/**
Expand Down Expand Up @@ -242,7 +242,7 @@ public static boolean setDirection(Block block, BlockFace facing) {
return false;
}

public static boolean setType(@Nonnull Block block, @Nullable XMaterial material, boolean applyPhysics) {
public static boolean setType(@NotNull Block block, @Nullable XMaterial material, boolean applyPhysics) {
Objects.requireNonNull(block, "Cannot set type of null block");
if (material == null) material = XMaterial.AIR;
XMaterial smartConversion = ITEM_TO_BLOCK.get(material);
Expand Down Expand Up @@ -406,7 +406,7 @@ public static SkullType getSkullType(XMaterial material) {
}
}

public static boolean setType(@Nonnull Block block, @Nullable XMaterial material) {
public static boolean setType(@NotNull Block block, @Nullable XMaterial material) {
return setType(block, material, true);
}

Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/cryptomorin/xseries/XEnchantment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -146,7 +146,7 @@ public enum XEnchantment {
*
* @see NamespacedKey#getKey()
*/
XEnchantment(@Nonnull String... aliases) {
XEnchantment(@NotNull String... aliases) {
Enchantment enchantment = getBukkitEnchant(this.name());

Data.NAMES.put(this.name(), this);
Expand Down Expand Up @@ -205,8 +205,8 @@ public static boolean isArthropodsEffectiveAgainst(@Nullable EntityType type) {
* @return an enum name.
* @since 1.0.0
*/
@Nonnull
private static String format(@Nonnull String name) {
@NotNull
private static String format(@NotNull String name) {
int len = name.length();
char[] chs = new char[len];
int count = 0;
Expand Down Expand Up @@ -239,8 +239,8 @@ private static String format(@Nonnull String name) {
* @return an enchantment.
* @since 1.0.0
*/
@Nonnull
public static Optional<XEnchantment> matchXEnchantment(@Nonnull String enchantment) {
@NotNull
public static Optional<XEnchantment> matchXEnchantment(@NotNull String enchantment) {
if (enchantment == null || enchantment.isEmpty())
throw new IllegalArgumentException("Enchantment name cannot be null or empty");
return Optional.ofNullable(Data.NAMES.get(format(enchantment)));
Expand All @@ -255,9 +255,9 @@ public static Optional<XEnchantment> matchXEnchantment(@Nonnull String enchantme
* @throws IllegalArgumentException may be thrown as an unexpected exception.
* @since 1.0.0
*/
@Nonnull
@NotNull
@SuppressWarnings("deprecation")
public static XEnchantment matchXEnchantment(@Nonnull Enchantment enchantment) {
public static XEnchantment matchXEnchantment(@NotNull Enchantment enchantment) {
Objects.requireNonNull(enchantment, "Cannot parse XEnchantment of a null enchantment");
return Objects.requireNonNull(Data.NAMES.get(enchantment.getName()), () -> "Unsupported enchantment: " + enchantment.getName());
}
Expand All @@ -269,7 +269,7 @@ public static XEnchantment matchXEnchantment(@Nonnull Enchantment enchantment) {
* @return an enchanted book.
* @since 1.0.0
*/
@Nonnull
@NotNull
public ItemStack getBook(int level) {
ItemStack book = new ItemStack(Material.ENCHANTED_BOOK);
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta();
Expand Down Expand Up @@ -327,7 +327,7 @@ public XEnchantment or(@Nullable XEnchantment alternateEnchantment) {
* @return a friendly readable string name.
*/
@Override
@Nonnull
@NotNull
public String toString() {
return Arrays.stream(name().split("_"))
.map(t -> t.charAt(0) + t.substring(1).toLowerCase())
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/cryptomorin/xseries/XEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.loot.Lootable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -244,7 +243,7 @@ public static boolean isUndead(@Nullable EntityType type) {
}

@Nullable
public static Entity spawn(@Nonnull Location location, @Nonnull ConfigurationSection config) {
public static Entity spawn(@NotNull Location location, @NotNull ConfigurationSection config) {
Objects.requireNonNull(location, "Cannot spawn entity at a null location.");
Objects.requireNonNull(config, "Cannot spawn entity from a null configuration section");

Expand All @@ -270,8 +269,8 @@ private static void map(Class<?> target, Entity entity, ConfigurationSection con
}

@SuppressWarnings({"deprecation", "Guava"})
@Nonnull
public static Entity edit(@Nonnull Entity entity, @Nonnull ConfigurationSection config) {
@NotNull
public static Entity edit(@NotNull Entity entity, @NotNull ConfigurationSection config) {
Objects.requireNonNull(entity, "Cannot edit properties of a null entity");
Objects.requireNonNull(config, "Cannot edit an entity from a null configuration section");

Expand Down
Loading

0 comments on commit 8053b32

Please sign in to comment.