Skip to content

Commit f112225

Browse files
committed
v8.6.2
Titles You can now construct an object with this class that holds all title related information. Added a transformer function parameter to parseTitle for placeholder and other purposes. XMaterial Fixed Terracotta/clay/stained_clay/Hardened_clay related issues. Fixed an issue with pork/cooked XItemStack Added "glow" option which adds a random enchantment to the item for GUI aesthetics. "flag" option now only accepts "ALL" option as a string, not in the list.
1 parent b0664a1 commit f112225

File tree

6 files changed

+97
-33
lines changed

6 files changed

+97
-33
lines changed

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>8.6.1</version>
9+
<version>8.6.2</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: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ public static ItemStack deserialize(@Nonnull ConfigurationSection config) {
718718
Optional<XEnchantment> enchant = XEnchantment.matchXEnchantment(ench);
719719
enchant.ifPresent(xEnchantment -> meta.addEnchant(xEnchantment.getEnchant(), enchants.getInt(ench), true));
720720
}
721+
} else {
722+
if (config.getBoolean("glow")) meta.addEnchant(XEnchantment.DURABILITY.getEnchant(), 1, false);
721723
}
722724

723725
// Enchanted Books
@@ -732,15 +734,16 @@ public static ItemStack deserialize(@Nonnull ConfigurationSection config) {
732734

733735
// Flags
734736
List<String> flags = config.getStringList("flags");
735-
for (String flag : flags) {
736-
flag = flag.toUpperCase(Locale.ENGLISH);
737-
if (flag.equals("ALL")) {
738-
meta.addItemFlags(ItemFlag.values());
739-
break;
737+
if (!flags.isEmpty()) {
738+
for (String flag : flags) {
739+
flag = flag.toUpperCase(Locale.ENGLISH);
740+
ItemFlag itemFlag = Enums.getIfPresent(ItemFlag.class, flag).orNull();
741+
if (itemFlag != null) meta.addItemFlags(itemFlag);
740742
}
741-
742-
ItemFlag itemFlag = Enums.getIfPresent(ItemFlag.class, flag).orNull();
743-
if (itemFlag != null) meta.addItemFlags(itemFlag);
743+
} else {
744+
String allFlags = config.getString("flags");
745+
if (!Strings.isNullOrEmpty(allFlags) && allFlags.equalsIgnoreCase("ALL"))
746+
meta.addItemFlags(ItemFlag.values());
744747
}
745748

746749
// Atrributes - https://minecraft.gamepedia.com/Attribute

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public enum XMaterial {
281281
CHORUS_FLOWER,
282282
CHORUS_FRUIT,
283283
CHORUS_PLANT,
284-
CLAY("HARD_CLAY"),
284+
CLAY,
285285
CLAY_BALL,
286286
CLOCK("WATCH"),
287287
COAL,
@@ -319,7 +319,7 @@ public enum XMaterial {
319319
COOKED_CHICKEN,
320320
COOKED_COD("COOKED_FISH"),
321321
COOKED_MUTTON,
322-
COOKED_PORKCHOP("PORK", "GRILLED_PORK"),
322+
COOKED_PORKCHOP("GRILLED_PORK"),
323323
COOKED_RABBIT,
324324
COOKED_SALMON(1, "COOKED_FISH"),
325325
COOKIE,
@@ -729,7 +729,7 @@ public enum XMaterial {
729729
* Renamed to SILVER_GLAZED_TERRACOTTA in 1.12
730730
* Renamed to LIGHT_GRAY_GLAZED_TERRACOTTA in 1.14
731731
*/
732-
LIGHT_GRAY_GLAZED_TERRACOTTA("STAINED_CLAY", "LIGHT_GRAY_TERRACOTTA", "SILVER_GLAZED_TERRACOTTA"),
732+
LIGHT_GRAY_GLAZED_TERRACOTTA(8, "STAINED_CLAY", "SILVER_GLAZED_TERRACOTTA"),
733733
LIGHT_GRAY_SHULKER_BOX("SILVER_SHULKER_BOX"),
734734
LIGHT_GRAY_STAINED_GLASS(8, "STAINED_GLASS"),
735735
LIGHT_GRAY_STAINED_GLASS_PANE(8, "THIN_GLASS", "STAINED_GLASS_PANE"),
@@ -1245,7 +1245,7 @@ public enum XMaterial {
12451245
TALL_GRASS(2, "DOUBLE_PLANT"),
12461246
TALL_SEAGRASS,
12471247
TARGET,
1248-
TERRACOTTA("STAINED_CLAY"),
1248+
TERRACOTTA("HARD_CLAY"),
12491249
TINTED_GLASS,
12501250
TIPPED_ARROW,
12511251
TNT,
@@ -1349,7 +1349,7 @@ public enum XMaterial {
13491349
WHITE_SHULKER_BOX,
13501350
WHITE_STAINED_GLASS("STAINED_GLASS"),
13511351
WHITE_STAINED_GLASS_PANE("THIN_GLASS", "STAINED_GLASS_PANE"),
1352-
WHITE_TERRACOTTA("STAINED_CLAY", "TERRACOTTA"),
1352+
WHITE_TERRACOTTA("STAINED_CLAY"),
13531353
WHITE_TULIP(6, "RED_ROSE"),
13541354
WHITE_WALL_BANNER(15, "WALL_BANNER"),
13551355
WHITE_WOOL("WOOL"),

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
@SuppressWarnings("NotNullFieldNotInitialized")
3131
public final class XTag<@NonNull T extends Enum<T>> {
3232

33+
public static final @NonNull XTag<XMaterial> AIR;
34+
35+
public static final @NonNull XTag<XMaterial> INVENTORY_NOT_DISPLAYABLE;
36+
3337
/**
3438
* Tag representing all acacia log and bark variants
3539
*/
@@ -879,7 +883,10 @@ public final class XTag<@NonNull T extends Enum<T>> {
879883
}
880884

881885
static {
886+
AIR = new XTag<>(XMaterial.AIR, XMaterial.CAVE_AIR, XMaterial.VOID_AIR);
882887
PORTALS = new XTag<>(XMaterial.END_GATEWAY, XMaterial.END_PORTAL, XMaterial.NETHER_PORTAL);
888+
INVENTORY_NOT_DISPLAYABLE = new XTag<>(XMaterial.class, AIR, PORTALS);
889+
883890
WALLS = new XTag<>(XMaterial.POLISHED_DEEPSLATE_WALL,
884891
XMaterial.NETHER_BRICK_WALL,
885892
XMaterial.POLISHED_BLACKSTONE_WALL,
@@ -2270,21 +2277,23 @@ public static boolean isInteractable(XMaterial material) {
22702277
}
22712278

22722279
public boolean isTagged(@Nullable T value) {
2273-
// Just encase some plugins pass thru a null value.
2274-
if (value == null) {
2275-
return false;
2276-
}
2277-
return this.values.contains(value);
2280+
return value != null && this.values.contains(value);
22782281
}
22792282

22802283
@SafeVarargs
2281-
private final void inheritFrom(@NonNull XTag<@NonNull T>... values) {
2284+
private final XTag<T> inheritFrom(@NonNull XTag<@NonNull T>... values) {
2285+
// Copied because of Collections.unmodifiableSet.
2286+
// Better than wrapping it during getValues() every single time.
2287+
22822288
Set<@NonNull T> newValues;
22832289
if (this.values.isEmpty()) newValues = EnumSet.copyOf((EnumSet<T>) this.values);
22842290
else newValues = EnumSet.copyOf(this.values);
2291+
22852292
for (XTag<T> value : values) {
22862293
newValues.addAll(value.values);
22872294
}
2295+
22882296
this.values = Collections.unmodifiableSet(newValues);
2297+
return this;
22892298
}
22902299
}

src/main/java/com/cryptomorin/xseries/messages/Titles.java

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.lang.reflect.Field;
3434
import java.lang.reflect.Method;
3535
import java.util.Objects;
36+
import java.util.function.Function;
3637

3738
/**
3839
* A reflection API for titles in Minecraft.
@@ -45,7 +46,7 @@
4546
* PacketPlayOutTitle: https://wiki.vg/Protocol#Title
4647
*
4748
* @author Crypto Morin
48-
* @version 2.1.0
49+
* @version 3.0.0
4950
* @see ReflectionUtils
5051
*/
5152
public final class Titles {
@@ -61,6 +62,9 @@ public final class Titles {
6162
*/
6263
private static final MethodHandle CHAT_COMPONENT_TEXT;
6364

65+
private String title, subtitle;
66+
private final int fadeIn, stay, fadeOut;
67+
6468
static {
6569
MethodHandle packetCtor = null;
6670
MethodHandle chatComp = null;
@@ -112,7 +116,17 @@ public final class Titles {
112116
CHAT_COMPONENT_TEXT = chatComp;
113117
}
114118

115-
private Titles() {}
119+
public Titles(String title, String subtitle, int fadeIn, int stay, int fadeOut) {
120+
this.title = title;
121+
this.subtitle = subtitle;
122+
this.fadeIn = fadeIn;
123+
this.stay = stay;
124+
this.fadeOut = fadeOut;
125+
}
126+
127+
public void send(Player player) {
128+
sendTitle(player, fadeIn, stay, fadeOut, title, subtitle);
129+
}
116130

117131
/**
118132
* Sends a title message with title and subtitle to a player.
@@ -169,8 +183,12 @@ public static void sendTitle(@Nonnull Player player, @Nonnull String title, @Non
169183
sendTitle(player, 10, 20, 10, title, subtitle);
170184
}
171185

186+
public static Titles parseTitle(@Nonnull ConfigurationSection config) {
187+
return parseTitle(config, null);
188+
}
189+
172190
/**
173-
* Parses and sends a title from the config.
191+
* Parses a title from config.
174192
* The configuration section must at least
175193
* contain {@code title} or {@code subtitle}
176194
*
@@ -181,15 +199,19 @@ public static void sendTitle(@Nonnull Player player, @Nonnull String title, @Non
181199
* Titles.sendTitle(player, titleSection);
182200
* </pre></blockquote>
183201
*
184-
* @param player the player to send the title to.
185202
* @param config the configuration section to parse the title properties from.
186203
*
187-
* @since 1.0.0
204+
* @since 3.0.0
188205
*/
189-
public static void sendTitle(@Nonnull Player player, @Nonnull ConfigurationSection config) {
206+
public static Titles parseTitle(@Nonnull ConfigurationSection config, @Nullable Function<String, String> transformers) {
190207
String title = config.getString("title");
191208
String subtitle = config.getString("subtitle");
192209

210+
if (transformers != null) {
211+
title = transformers.apply(title);
212+
subtitle = transformers.apply(subtitle);
213+
}
214+
193215
int fadeIn = config.getInt("fade-in");
194216
int stay = config.getInt("stay");
195217
int fadeOut = config.getInt("fade-out");
@@ -198,7 +220,37 @@ public static void sendTitle(@Nonnull Player player, @Nonnull ConfigurationSecti
198220
if (stay < 1) stay = 20;
199221
if (fadeOut < 1) fadeOut = 10;
200222

201-
sendTitle(player, fadeIn, stay, fadeOut, title, subtitle);
223+
return new Titles(title, subtitle, fadeIn, stay, fadeOut);
224+
}
225+
226+
public String getTitle() {
227+
return title;
228+
}
229+
230+
public String getSubtitle() {
231+
return subtitle;
232+
}
233+
234+
public void setTitle(String title) {
235+
this.title = title;
236+
}
237+
238+
public void setSubtitle(String subtitle) {
239+
this.subtitle = subtitle;
240+
}
241+
242+
/**
243+
* Parses and sends a title from the config.
244+
*
245+
* @param player the player to send the title to.
246+
* @param config the configuration section to parse the title properties from.
247+
*
248+
* @since 1.0.0
249+
*/
250+
public static Titles sendTitle(@Nonnull Player player, @Nonnull ConfigurationSection config) {
251+
Titles titles = parseTitle(config, null);
252+
titles.send(player);
253+
return titles;
202254
}
203255

204256
/**

src/main/java/com/cryptomorin/xseries/particles/ParticleDisplay.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class ParticleDisplay implements Cloneable {
7878
*
7979
* @since 8.6.0.0.1
8080
*/
81-
private static final boolean ISFLAT2 = XParticle.getParticle("DUST_COLOR_TRANSITION") != null;
81+
private static final boolean SUPPORTS_DUST_TRANSITION = XParticle.getParticle("DUST_COLOR_TRANSITION") != null;
8282
private static final Axis[] DEFAULT_ROTATION_ORDER = {Axis.X, Axis.Y, Axis.Z};
8383
private static final Particle DEFAULT_PARTICLE = Particle.CLOUD;
8484

@@ -573,7 +573,7 @@ public ParticleDisplay withColor(@Nonnull Color color, float size) {
573573
* to get custom colors.
574574
*
575575
* @param color1 the RGB color of the particle on spawn.
576-
* @param size the size of the particle.
576+
* @param size the size of the particle.
577577
* @param color2 the RGB color of the particle at the end.
578578
*
579579
* @return the same particle display, but modified.
@@ -1010,15 +1010,15 @@ public Location spawn(Location loc, @Nullable Player... players) {
10101010
.fromRGB((int) datas[0], (int) datas[1], (int) datas[2]), datas[3]);
10111011
if (players == null) world.spawnParticle(particle, loc, count, offsetx, offsety, offsetz, extra, dust, force);
10121012
else for (Player player : players) player.spawnParticle(particle, loc, count, offsetx, offsety, offsetz, extra, dust);
1013-
1014-
} else if (ISFLAT2 && particle.getDataType() == Particle.DustTransition.class) {
1015-
Particle.DustOptions dust = new Particle.DustTransition(
1013+
} else if (SUPPORTS_DUST_TRANSITION && particle.getDataType() == Particle.DustTransition.class) {
1014+
// Having the variable type as Particle.DustOptions causes NoClassDefFoundError for DustOptions
1015+
// because of some weird upcasting stuff.
1016+
Particle.DustTransition dust = new Particle.DustTransition(
10161017
org.bukkit.Color.fromRGB((int) datas[0], (int) datas[1], (int) datas[2]),
10171018
org.bukkit.Color.fromRGB((int) datas[4], (int) datas[5], (int) datas[6]),
10181019
datas[3]);
10191020
if (players == null) world.spawnParticle(particle, loc, count, offsetx, offsety, offsetz, extra, dust, force);
10201021
else for (Player player : players) player.spawnParticle(particle, loc, count, offsetx, offsety, offsetz, extra, dust);
1021-
10221022
} else if (isDirectional()) {
10231023
// With count=0, color on offset e.g. for MOB_SPELL or 1.12 REDSTONE
10241024
float[] rgb = {datas[0] / 255f, datas[1] / 255f, datas[2] / 255f};

0 commit comments

Comments
 (0)