Skip to content

Commit bb3bc16

Browse files
committed
1.12.2
1 parent 2dc13bd commit bb3bc16

9 files changed

Lines changed: 66 additions & 23 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'dev.pixelstudios'
9-
version = '1.12.1'
9+
version = '1.12.2'
1010

1111
repositories {
1212
mavenCentral()
@@ -22,7 +22,7 @@ repositories {
2222
maven { url 'https://repo.auxilor.io/repository/maven-public/' }
2323
maven { url 'https://nexus.phoenixdevt.fr/repository/maven-public/' }
2424
maven { url 'https://repo.momirealms.net/releases/' }
25-
maven { url 'https://repo.nexomc.com/releases'}
25+
maven { url 'https://repo.nexomc.com/releases' }
2626
}
2727

2828
dependencies {

src/main/java/dev/pixelstudios/xutils/config/Configuration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import dev.pixelstudios.xutils.FileUtil;
44
import dev.pixelstudios.xutils.config.serializer.ConfigSerializer;
55
import dev.pixelstudios.xutils.XUtils;
6+
import org.bukkit.configuration.ConfigurationSection;
67
import org.bukkit.configuration.InvalidConfigurationException;
78
import org.bukkit.configuration.file.YamlConfiguration;
89

910
import java.io.File;
1011
import java.io.IOException;
1112
import java.io.InputStreamReader;
1213
import java.util.Collections;
14+
import java.util.List;
1315
import java.util.Set;
1416

1517
public class Configuration extends YamlConfiguration {
@@ -92,4 +94,8 @@ public <T> T deserialize(String path, Class<T> objectClass) {
9294
return ConfigSerializer.deserialize(objectClass, this, path);
9395
}
9496

97+
public List<ConfigurationSection> getSubSections(String path) {
98+
return ConfigUtil.getSubSections(getConfigurationSection(path));
99+
}
100+
95101
}

src/main/java/dev/pixelstudios/xutils/config/serializer/ColorSerializer.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,29 @@ public class ColorSerializer implements Serializer<Color> {
77

88
@Override
99
public Color deserialize(String serialized) {
10-
String[] split = serialized.split(":");
10+
serialized = serialized.trim();
1111

12-
Color color;
12+
// Hex format
13+
if (serialized.startsWith("#") && serialized.length() == 7) {
14+
return Color.fromRGB(Integer.parseInt(serialized.substring(1), 16));
15+
}
1316

14-
if (split.length != 3) {
15-
color = DyeColor.valueOf(serialized).getColor();
16-
} else {
17-
color = Color.fromRGB(
17+
// RGB format
18+
String[] split = serialized.split(":");
19+
if (split.length == 3) {
20+
return Color.fromRGB(
1821
Integer.parseInt(split[0]),
1922
Integer.parseInt(split[1]),
2023
Integer.parseInt(split[2])
2124
);
2225
}
2326

24-
return color;
27+
// Bukkit DyeColor
28+
try {
29+
return DyeColor.valueOf(serialized.toUpperCase()).getColor();
30+
} catch (IllegalArgumentException e) {
31+
throw new IllegalArgumentException("Invalid color: " + serialized);
32+
}
2533
}
2634

2735
}

src/main/java/dev/pixelstudios/xutils/config/serializer/LocationSerializer.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
import org.bukkit.Bukkit;
44
import org.bukkit.Location;
55

6+
import java.text.DecimalFormat;
7+
68
public class LocationSerializer implements Serializer<Location> {
79

10+
private final DecimalFormat formatter = new DecimalFormat("#.##");
11+
812
@Override
913
public String serialize(Location location) {
1014
StringBuilder builder = new StringBuilder();
1115

1216
builder.append(location.getWorld().getName())
13-
.append(":").append(location.getX())
14-
.append(":").append(location.getY())
15-
.append(":").append(location.getZ());
17+
.append(":").append(formatter.format(location.getX()))
18+
.append(":").append(formatter.format(location.getY()))
19+
.append(":").append(formatter.format(location.getZ()));
1620

1721
if (location.getYaw() != 0 && location.getPitch() != 0) {
18-
builder.append(":").append(location.getYaw())
19-
.append(":").append(location.getPitch());
22+
builder.append(":").append(formatter.format(location.getYaw()))
23+
.append(":").append(formatter.format(location.getPitch()));
2024
}
2125

2226
return builder.toString();

src/main/java/dev/pixelstudios/xutils/item/ItemUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public static ItemStack parsePlaceholders(ItemStack item, OfflinePlayer player)
4949
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
5050
return setNameAndLore(
5151
item,
52-
text -> PlaceholderAPI.setPlaceholders(player, text),
53-
lines -> PlaceholderAPI.setPlaceholders(player, lines)
52+
text -> TextUtil.color(PlaceholderAPI.setPlaceholders(player, text)),
53+
lines -> TextUtil.color(PlaceholderAPI.setPlaceholders(player, lines))
5454
);
5555
}
5656
return item;

src/main/java/dev/pixelstudios/xutils/menu/Menu.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,13 @@ private ItemStack processItem(MenuItem item) {
244244
}
245245

246246
private String processText(String text) {
247+
text = placeholders.parse(text);
248+
247249
if (parsePlaceholders) {
248250
text = TextUtil.parsePlaceholders(player, text);
249251
}
250252

251-
return placeholders.parse(text);
253+
return TextUtil.color(text);
252254
}
253255

254256
}

src/main/java/dev/pixelstudios/xutils/text/placeholder/PlaceholderMap.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,24 @@ public PlaceholderMap add(String key, Supplier<String> value) {
2222
return this;
2323
}
2424

25+
public PlaceholderMap add(String key, Supplier<String> value, String defaultValue) {
26+
placeholders.put(key, () -> {
27+
String val = value.get();
28+
return val != null ? val : defaultValue;
29+
});
30+
return this;
31+
}
32+
2533
public PlaceholderMap add(String key, String value) {
2634
placeholders.put(key, () -> value);
2735
return this;
2836
}
2937

38+
public PlaceholderMap add(String key, String value, String defaultValue) {
39+
placeholders.put(key, () -> value != null ? value : defaultValue);
40+
return this;
41+
}
42+
3043
public PlaceholderMap addNumber(String key, Supplier<Number> value) {
3144
placeholders.put(key, () -> String.valueOf(value.get()));
3245
return this;

src/main/java/dev/pixelstudios/xutils/text/placeholder/papi/Argument.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,30 @@ public class Argument {
1212
private final String id;
1313
private final Function<String, Object> function;
1414
private final boolean required;
15+
private final Object defaultValue;
1516

1617
public static Argument required(String id) {
17-
return new Argument(id, string -> string, true);
18+
return new Argument(id, string -> string, true, null);
1819
}
1920

2021
public static Argument required(String id, Function<String, Object> function) {
21-
return new Argument(id, function, true);
22+
return new Argument(id, function, true, null);
2223
}
2324

2425
public static Argument optional(String id) {
25-
return new Argument(id, string -> string, false);
26+
return new Argument(id, string -> string, false, null);
2627
}
2728

2829
public static Argument optional(String id, Function<String, Object> function) {
29-
return new Argument(id, function, false);
30+
return new Argument(id, function, false, null);
31+
}
32+
33+
public static Argument optional(String id, Object defaultValue) {
34+
return new Argument(id, string -> string, false, defaultValue);
35+
}
36+
37+
public static Argument optional(String id, Function<String, Object> function, Object defaultValue) {
38+
return new Argument(id, function, false, defaultValue);
3039
}
3140

3241
}

src/main/java/dev/pixelstudios/xutils/text/placeholder/papi/PAPIPlaceholder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ private Map<String, Object> parseArguments(String input) {
6969
arguments.put(argument.getId(), value);
7070
} else {
7171
if (split.length <= i) {
72-
break;
72+
arguments.put(argument.getId(), argument.getDefaultValue());
73+
} else {
74+
arguments.put(argument.getId(), argument.getFunction().apply(split[i]));
7375
}
74-
arguments.put(argument.getId(), argument.getFunction().apply(split[i]));
7576
}
7677
}
7778

0 commit comments

Comments
 (0)