Skip to content

Commit 80c7775

Browse files
committed
v9.1.0
1 parent d302fea commit 80c7775

File tree

8 files changed

+162
-154
lines changed

8 files changed

+162
-154
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ another class ([ParticleDisplay](src/main/java/com/cryptomorin/xseries/particles
4545
</dependency>
4646
```
4747

48+
Gradle
49+
```kotlin
50+
repositories {
51+
mavenCentral()
52+
}
53+
dependencies {
54+
implementation("com.github.cryptomorin:XSeries:version") { isTransitive = false }
55+
}
56+
```
57+
4858
You shouldn't worry if the reflection or other classes are going to use your memory with heavy useless static cache.
4959
As long as you don't use them anywhere in your code, they won't initialize.
5060
The memory usage of these utilities are extremely enhanced.
@@ -92,6 +102,20 @@ To shade the library, add the following under your maven plugins:
92102
</plugin>
93103
```
94104

105+
Gradle
106+
```kotlin
107+
plugins {
108+
java
109+
id("com.github.johnrengelman.shadow") version ("7.1.2")
110+
}
111+
112+
tasks {
113+
named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
114+
relocate("com.cryptomorin.xseries", "my.plugin.utils")
115+
}
116+
}
117+
```
118+
95119
### Contributing
96120

97121
There's always room for improvement. If you know better ways of doing things, I really appreciate it if you can share it with me,

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>9.0.0</version>
9+
<version>9.1.0</version>
1010

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ public Instruction(int restatement, int restatementFermata, int fermata) {
665665
public abstract void play(Player player, Supplier<Location> location);
666666

667667
public long getEstimatedLength() {
668-
return restatement * restatementFermata;
668+
return (long) restatement * restatementFermata;
669669
}
670670
}
671671

@@ -727,7 +727,7 @@ public void addInstruction(Instruction instruction) {
727727

728728
@Override
729729
public long getEstimatedLength() {
730-
long result = restatement * restatementFermata;
730+
long result = (long) restatement * restatementFermata;
731731
for (Instruction instruction : instructions) result += instruction.getEstimatedLength();
732732
return result;
733733
}

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
* ItemStack: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html
7474
*
7575
* @author Crypto Morin
76-
* @version 7.2.0.1
76+
* @version 7.3.0
7777
* @see XMaterial
7878
* @see XPotion
7979
* @see SkullUtils
@@ -83,6 +83,11 @@
8383
public final class XItemStack {
8484
public static final ItemFlag[] ITEM_FLAGS = ItemFlag.values();
8585

86+
/**
87+
* Because item metas cannot be applied to AIR apparently.
88+
*/
89+
private static final XMaterial DEFAULT_MATERIAL = XMaterial.NETHER_PORTAL;
90+
8691
private XItemStack() {}
8792

8893
/**
@@ -182,7 +187,8 @@ public static void serialize(@Nonnull ItemStack item, @Nonnull ConfigurationSect
182187
config.set(entry, enchant.getValue());
183188
}
184189
} else if (meta instanceof SkullMeta) {
185-
config.set("skull", SkullUtils.getSkinValue(meta));
190+
String skull = SkullUtils.getSkinValue(meta);
191+
if (skull != null) config.set("skull", skull);
186192
} else if (meta instanceof BannerMeta) {
187193
BannerMeta banner = (BannerMeta) meta;
188194
ConfigurationSection patterns = config.createSection("patterns");
@@ -341,6 +347,10 @@ public static void serialize(@Nonnull ItemStack item, @Nonnull ConfigurationSect
341347
}
342348
}
343349

350+
public static boolean isDefaultItem(ItemStack item) {
351+
return DEFAULT_MATERIAL.isSimilar(item);
352+
}
353+
344354
/**
345355
* Writes an ItemStack properties into a {@code Map}.
346356
*
@@ -365,7 +375,7 @@ public static Map<String, Object> serialize(@Nonnull ItemStack item) {
365375
*/
366376
@Nonnull
367377
public static ItemStack deserialize(@Nonnull ConfigurationSection config) {
368-
return edit(new ItemStack(Material.AIR), config, Function.identity(), null);
378+
return edit(new ItemStack(DEFAULT_MATERIAL.parseMaterial()), config, Function.identity(), null);
369379
}
370380

371381
private static List<String> splitNewLine(String str) {
@@ -414,7 +424,7 @@ public static ItemStack deserialize(@Nonnull ConfigurationSection config,
414424
public static ItemStack deserialize(@Nonnull ConfigurationSection config,
415425
@Nonnull Function<String, String> translator,
416426
@Nullable Consumer<Exception> restart) {
417-
return edit(new ItemStack(Material.AIR), config, translator, restart);
427+
return edit(new ItemStack(DEFAULT_MATERIAL.parseMaterial()), config, translator, restart);
418428
}
419429

420430

@@ -528,8 +538,18 @@ public static ItemStack edit(@Nonnull ItemStack item,
528538
int amount = config.getInt("amount");
529539
if (amount > 1) item.setAmount(amount);
530540

531-
ItemMeta meta = item.getItemMeta();
532-
if (meta == null) return item;
541+
ItemMeta meta;
542+
{ // For Java's stupid closure capture system.
543+
ItemMeta tempMeta = item.getItemMeta();
544+
if (tempMeta == null) {
545+
// When AIR is null. Useful for when you just want to use the meta to save data and
546+
// set the type later. A simple CraftMetaItem.
547+
meta = Bukkit.getItemFactory().getItemMeta(XMaterial.STONE.parseMaterial());
548+
} else {
549+
meta = tempMeta;
550+
}
551+
}
552+
533553

534554
// Durability - Damage
535555
if (supports(13)) {
@@ -881,6 +901,11 @@ public static ItemStack edit(@Nonnull ItemStack item,
881901
if (!flags.isEmpty()) {
882902
for (String flag : flags) {
883903
flag = flag.toUpperCase(Locale.ENGLISH);
904+
if (flag.equals("ALL")) {
905+
meta.addItemFlags(ITEM_FLAGS);
906+
break;
907+
}
908+
884909
ItemFlag itemFlag = Enums.getIfPresent(ItemFlag.class, flag).orNull();
885910
if (itemFlag != null) meta.addItemFlags(itemFlag);
886911
}
@@ -1104,7 +1129,7 @@ public static List<ItemStack> addItems(@Nonnull Inventory inventory, boolean spl
11041129
if (++lastEmpty == invSize) lastEmpty = -1;
11051130
} else {
11061131
ItemStack partialItem = inventory.getItem(firstPartial);
1107-
int maxAmount = partialItem.getMaxStackSize();
1132+
int maxAmount = split ? partialItem.getMaxStackSize() : inventory.getMaxStackSize();
11081133
int partialAmount = partialItem.getAmount();
11091134
int amount = item.getAmount();
11101135
int sum = amount + partialAmount;

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

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
* <b>/give @p minecraft:dirt 1 10</b> where 1 is the item amount, and 10 is the data value. The material {@link #DIRT} with a data value of {@code 10} doesn't exist.
6262
*
6363
* @author Crypto Morin
64-
* @version 11.0.0
64+
* @version 11.2.0
6565
* @see Material
6666
* @see ItemStack
6767
*/
@@ -1009,36 +1009,36 @@ public enum XMaterial {
10091009
POTATOES("POTATO"),
10101010
POTION,
10111011
POTTED_ACACIA_SAPLING(4, "FLOWER_POT"),
1012-
POTTED_ALLIUM(2, "RED_ROSE", "FLOWER_POT"),
1012+
POTTED_ALLIUM(2, "FLOWER_POT"),
10131013
POTTED_AZALEA_BUSH,
1014-
POTTED_AZURE_BLUET(3, "RED_ROSE", "FLOWER_POT"),
1014+
POTTED_AZURE_BLUET(3, "FLOWER_POT"),
10151015
POTTED_BAMBOO,
10161016
POTTED_BIRCH_SAPLING(2, "FLOWER_POT"),
1017-
POTTED_BLUE_ORCHID(1, "RED_ROSE", "FLOWER_POT"),
1017+
POTTED_BLUE_ORCHID(1, "FLOWER_POT"),
10181018
POTTED_BROWN_MUSHROOM("FLOWER_POT"),
10191019
POTTED_CACTUS("FLOWER_POT"),
10201020
POTTED_CORNFLOWER,
10211021
POTTED_CRIMSON_FUNGUS,
10221022
POTTED_CRIMSON_ROOTS,
1023-
POTTED_DANDELION("YELLOW_FLOWER", "FLOWER_POT"),
1023+
POTTED_DANDELION("FLOWER_POT"),
10241024
POTTED_DARK_OAK_SAPLING(5, "FLOWER_POT"),
10251025
POTTED_DEAD_BUSH("FLOWER_POT"),
1026-
POTTED_FERN(2, "LONG_GRASS", "FLOWER_POT"),
1026+
POTTED_FERN(2, "FLOWER_POT"),
10271027
POTTED_FLOWERING_AZALEA_BUSH,
10281028
POTTED_JUNGLE_SAPLING(3, "FLOWER_POT"),
10291029
POTTED_LILY_OF_THE_VALLEY,
10301030
POTTED_MANGROVE_PROPAGULE,
10311031
POTTED_OAK_SAPLING("FLOWER_POT"),
1032-
POTTED_ORANGE_TULIP(5, "RED_ROSE", "FLOWER_POT"),
1033-
POTTED_OXEYE_DAISY(8, "RED_ROSE", "FLOWER_POT"),
1034-
POTTED_PINK_TULIP(7, "RED_ROSE", "FLOWER_POT"),
1035-
POTTED_POPPY("RED_ROSE", "FLOWER_POT"),
1032+
POTTED_ORANGE_TULIP(5, "FLOWER_POT"),
1033+
POTTED_OXEYE_DAISY(8, "FLOWER_POT"),
1034+
POTTED_PINK_TULIP(7, "FLOWER_POT"),
1035+
POTTED_POPPY("FLOWER_POT"),
10361036
POTTED_RED_MUSHROOM("FLOWER_POT"),
1037-
POTTED_RED_TULIP(4, "RED_ROSE", "FLOWER_POT"),
1037+
POTTED_RED_TULIP(4, "FLOWER_POT"),
10381038
POTTED_SPRUCE_SAPLING(1, "FLOWER_POT"),
10391039
POTTED_WARPED_FUNGUS,
10401040
POTTED_WARPED_ROOTS,
1041-
POTTED_WHITE_TULIP(6, "RED_ROSE", "FLOWER_POT"),
1041+
POTTED_WHITE_TULIP(6, "FLOWER_POT"),
10421042
POTTED_WITHER_ROSE,
10431043
POWDER_SNOW,
10441044
POWDER_SNOW_BUCKET,
@@ -1127,6 +1127,10 @@ public enum XMaterial {
11271127
RED_CARPET(14, "CARPET"),
11281128
RED_CONCRETE(14, "CONCRETE"),
11291129
RED_CONCRETE_POWDER(14, "CONCRETE_POWDER"),
1130+
/**
1131+
* 1.13 renamed to ROSE_RED
1132+
* 1.14 renamed to RED_DYE
1133+
*/
11301134
RED_DYE(1, "INK_SACK", "ROSE_RED"),
11311135
RED_GLAZED_TERRACOTTA,
11321136
RED_MUSHROOM,
@@ -1429,6 +1433,10 @@ public enum XMaterial {
14291433
YELLOW_CARPET(4, "CARPET"),
14301434
YELLOW_CONCRETE(4, "CONCRETE"),
14311435
YELLOW_CONCRETE_POWDER(4, "CONCRETE_POWDER"),
1436+
/**
1437+
* 1.13 renamed to DANDELION_YELLOW
1438+
* 1.14 renamed to YELLOW_DYE
1439+
*/
14321440
YELLOW_DYE(11, "INK_SACK", "DANDELION_YELLOW"),
14331441
YELLOW_GLAZED_TERRACOTTA,
14341442
YELLOW_SHULKER_BOX,
@@ -1570,45 +1578,6 @@ public enum XMaterial {
15701578

15711579
XMaterial(String... legacy) {this(0, legacy);}
15721580

1573-
/**
1574-
* Checks if the version is 1.13 Aquatic Update or higher.
1575-
* An invocation of this method yields the cached result from the expression:
1576-
* <p>
1577-
* <blockquote>
1578-
* {@link #supports(int) 13}}
1579-
* </blockquote>
1580-
*
1581-
* @return true if 1.13 or higher.
1582-
* @see #getVersion()
1583-
* @see #supports(int)
1584-
* @since 1.0.0
1585-
* @deprecated Use {@code XMaterial.supports(13)} instead. This method name can be confusing.
1586-
*/
1587-
@Deprecated
1588-
public static boolean isNewVersion() {
1589-
return Data.ISFLAT;
1590-
}
1591-
1592-
/**
1593-
* This is just an extra method that can be used for many cases.
1594-
* It can be used in {@link org.bukkit.event.player.PlayerInteractEvent}
1595-
* or when accessing {@link org.bukkit.entity.Player#getMainHand()},
1596-
* or other compatibility related methods.
1597-
* <p>
1598-
* An invocation of this method yields exactly the same result as the expression:
1599-
* <p>
1600-
* <blockquote>
1601-
* !{@link #supports(int)} 9
1602-
* </blockquote>
1603-
*
1604-
* @since 2.0.0
1605-
* @deprecated Use {@code !XMaterial.supports(9)} instead.
1606-
*/
1607-
@Deprecated
1608-
public static boolean isOneEight() {
1609-
return !supports(9);
1610-
}
1611-
16121581
/**
16131582
* Gets the XMaterial with this name similar to {@link #valueOf(String)}
16141583
* without throwing an exception.
@@ -1757,11 +1726,15 @@ public static XMaterial matchXMaterial(@Nonnull ItemStack item) {
17571726
}
17581727

17591728
// Refer to the enum for info.
1760-
// Currently this is the only material with a non-zero data value
1729+
// Currently, these are the only materials with a non-zero data value
17611730
// that has been renamed after the flattening update.
1762-
// If this happens to more materials in the future,
1763-
// I might have to change then system.
1764-
if (Data.ISFLAT && !supports(14) && material.equals("CACTUS_GREEN")) return GREEN_DYE;
1731+
// If this happens to more materials in the future, I might have to change the system.
1732+
if (supports(13) && !supports(14)) {
1733+
// https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/diff/src/main/java/org/bukkit/Material.java?until=67d908a9830c71267ee740f5bddd728ce9c64cc7
1734+
if (material.equals("CACTUS_GREEN")) return GREEN_DYE;
1735+
if (material.equals("ROSE_RED")) return RED_DYE;
1736+
if (material.equals("DANDELION_YELLOW")) return YELLOW_DYE;
1737+
}
17651738

17661739
// Check FILLED_MAP enum for more info.
17671740
// if (!Data.ISFLAT && item.hasItemMeta() && item.getItemMeta() instanceof org.bukkit.inventory.meta.MapMeta) return FILLED_MAP;
@@ -2162,7 +2135,8 @@ public boolean isSupported() {
21622135
* @param alternateMaterial the material to get if this one is not supported.
21632136
* @return this material or the {@code alternateMaterial} if not supported.
21642137
*/
2165-
public XMaterial or(XMaterial alternateMaterial) {
2138+
@Nullable
2139+
public XMaterial or(@Nullable XMaterial alternateMaterial) {
21662140
return isSupported() ? this : alternateMaterial;
21672141
}
21682142

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.bukkit.Sound;
3030
import org.bukkit.entity.Entity;
3131
import org.bukkit.entity.Player;
32-
import org.bukkit.plugin.java.JavaPlugin;
32+
import org.bukkit.plugin.Plugin;
3333
import org.bukkit.scheduler.BukkitRunnable;
3434
import org.bukkit.scheduler.BukkitTask;
3535

@@ -55,7 +55,7 @@
5555
* play command: https://minecraft.gamepedia.com/Commands/play
5656
*
5757
* @author Crypto Morin
58-
* @version 8.0.0
58+
* @version 8.0.1
5959
* @see Sound
6060
*/
6161
public enum XSound {
@@ -1520,18 +1520,13 @@ public static CompletableFuture<Record> play(@Nonnull Player player, @Nullable S
15201520
* @see #play(Location, String)
15211521
* @since 3.0.0
15221522
*/
1523-
@Nonnull
1524-
public static CompletableFuture<Record> play(@Nonnull Location location, @Nullable String sound) {
1523+
@Nullable
1524+
public static Record play(@Nonnull Location location, @Nullable String sound) {
15251525
Objects.requireNonNull(location, "Cannot play sound to null location");
1526-
return CompletableFuture.supplyAsync(() -> {
1527-
Record record = parse(sound);
1528-
if (record == null) return null;
1529-
record.atLocation(location).play();
1530-
return record;
1531-
}).exceptionally(x -> {
1532-
x.printStackTrace();
1533-
return null;
1534-
});
1526+
Record record = parse(sound);
1527+
if (record == null) return null;
1528+
record.atLocation(location).play();
1529+
return record;
15351530
}
15361531

15371532
private static List<String> split(@Nonnull String str, @SuppressWarnings("SameParameterValue") char separatorChar) {
@@ -1680,7 +1675,7 @@ public static void stopMusic(@Nonnull Player player) {
16801675
* @since 2.0.0
16811676
*/
16821677
@Nonnull
1683-
public static BukkitTask playAscendingNote(@Nonnull JavaPlugin plugin, @Nonnull Player player, @Nonnull Entity playTo, @Nonnull Instrument instrument,
1678+
public static BukkitTask playAscendingNote(@Nonnull Plugin plugin, @Nonnull Player player, @Nonnull Entity playTo, @Nonnull Instrument instrument,
16841679
int ascendLevel, int delay) {
16851680
Objects.requireNonNull(player, "Cannot play note from null player");
16861681
Objects.requireNonNull(playTo, "Cannot play note to null entity");
@@ -1754,7 +1749,7 @@ public boolean isSupported() {
17541749
* @since 2.0.0
17551750
*/
17561751
@Nonnull
1757-
public BukkitTask playRepeatedly(@Nonnull JavaPlugin plugin, @Nonnull Entity entity, float volume, float pitch, int repeat, int delay) {
1752+
public BukkitTask playRepeatedly(@Nonnull Plugin plugin, @Nonnull Entity entity, float volume, float pitch, int repeat, int delay) {
17581753
Objects.requireNonNull(plugin, "Cannot play repeating sound from null plugin");
17591754
Objects.requireNonNull(entity, "Cannot play repeating sound at null location");
17601755

0 commit comments

Comments
 (0)