Skip to content

Commit fecc0fc

Browse files
committed
update plugin
1 parent 851ca3c commit fecc0fc

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<parent>
88
<groupId>me.hsgamer.bettergui</groupId>
99
<artifactId>addon-parent</artifactId>
10-
<version>3.0</version>
10+
<version>4.0</version>
1111
</parent>
1212

1313
<artifactId>PaperSpec</artifactId>
14-
<version>3.0</version>
14+
<version>4.0</version>
1515
<packaging>jar</packaging>
1616

1717
<name>PaperSpec</name>

src/main/java/me/hsgamer/bettergui/paperspec/action/ComponentAction.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package me.hsgamer.bettergui.paperspec.action;
22

3-
import me.hsgamer.bettergui.api.action.BaseAction;
43
import me.hsgamer.bettergui.builder.ActionBuilder;
54
import me.hsgamer.bettergui.paperspec.util.AdventureUtils;
6-
import me.hsgamer.hscore.bukkit.scheduler.Scheduler;
5+
import me.hsgamer.bettergui.util.SchedulerUtil;
6+
import me.hsgamer.hscore.action.common.Action;
7+
import me.hsgamer.hscore.common.StringReplacer;
78
import me.hsgamer.hscore.task.element.TaskProcess;
89
import net.kyori.adventure.text.Component;
910
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
@@ -16,13 +17,14 @@
1617
import java.util.UUID;
1718
import java.util.function.BiFunction;
1819

19-
public abstract class ComponentAction extends BaseAction {
20+
public abstract class ComponentAction implements Action {
21+
protected final String value;
2022
protected final List<String> options;
2123
private final BiFunction<UUID, String, Component> serializer;
2224
private final boolean trimColor;
2325

2426
protected ComponentAction(ActionBuilder.Input input) {
25-
super(input);
27+
this.value = input.getValue();
2628
options = input.getOptionAsList();
2729
String type = options.isEmpty() ? "legacy" : options.get(0).toLowerCase();
2830
if (type.contains("mini")) {
@@ -40,20 +42,20 @@ protected ComponentAction(ActionBuilder.Input input) {
4042
protected abstract void accept(Player player, Component component);
4143

4244
@Override
43-
public void accept(UUID uuid, TaskProcess process) {
45+
public void apply(UUID uuid, TaskProcess process, StringReplacer stringReplacer) {
4446
Player player = Bukkit.getPlayer(uuid);
4547
if (player == null) {
4648
process.next();
4749
return;
4850
}
4951

50-
String replaced = getReplacedString(uuid);
52+
String replaced = stringReplacer.replaceOrOriginal(value, uuid);
5153
if (trimColor) {
5254
replaced = ChatColor.stripColor(replaced);
5355
}
5456
Component component = serializer.apply(uuid, replaced);
5557

56-
Scheduler.current().sync().runTask(() -> {
58+
SchedulerUtil.global().run(() -> {
5759
accept(player, component);
5860
process.next();
5961
});

src/main/java/me/hsgamer/bettergui/paperspec/modifier/AdventureLoreModifier.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@
1010
import org.jetbrains.annotations.NotNull;
1111

1212
import java.util.ArrayList;
13-
import java.util.Collection;
1413
import java.util.List;
1514
import java.util.UUID;
1615

1716
public class AdventureLoreModifier implements ItemMetaModifier, ItemMetaComparator {
1817
private final List<String> lore = new ArrayList<>(); // Stored as MiniMessage representation
1918

20-
private List<String> getReplacedLore(UUID uuid, Collection<StringReplacer> stringReplacers) {
19+
private List<String> getReplacedLore(UUID uuid, StringReplacer stringReplacer) {
2120
List<String> replacedLore = new ArrayList<>(lore);
22-
replacedLore.replaceAll(s -> StringReplacer.replace(s, uuid, stringReplacers));
21+
replacedLore.replaceAll(s -> stringReplacer.replaceOrOriginal(s, uuid));
2322
return replacedLore;
2423
}
2524

2625
@Override
27-
public @NotNull ItemMeta modifyMeta(ItemMeta meta, UUID uuid, @NotNull Collection<StringReplacer> stringReplacers) {
28-
List<Component> lore = AdventureUtils.toComponent(uuid, getReplacedLore(uuid, stringReplacers));
26+
public @NotNull ItemMeta modifyMeta(ItemMeta meta, UUID uuid, @NotNull StringReplacer stringReplacer) {
27+
List<Component> lore = AdventureUtils.toComponent(uuid, getReplacedLore(uuid, stringReplacer));
2928
List<Component> noItalic = AdventureUtils.disableItalic(lore);
3029
meta.lore(noItalic);
3130
return meta;
@@ -44,14 +43,14 @@ public boolean loadFromItemMeta(ItemMeta meta) {
4443

4544
@SuppressWarnings("DataFlowIssue")
4645
@Override
47-
public boolean compare(ItemMeta meta, UUID uuid, @NotNull Collection<StringReplacer> stringReplacers) {
46+
public boolean compare(ItemMeta meta, UUID uuid, @NotNull StringReplacer stringReplacer) {
4847
if (!meta.hasLore() && this.lore.isEmpty()) {
4948
return true;
5049
}
5150

5251
// Since text components are complex, we compare the plain text representation for equality
5352
List<Component> itemLore = meta.lore();
54-
List<Component> compareLore = AdventureUtils.toComponent(uuid, getReplacedLore(uuid, stringReplacers));
53+
List<Component> compareLore = AdventureUtils.toComponent(uuid, getReplacedLore(uuid, stringReplacer));
5554
if (itemLore.size() != compareLore.size()) {
5655
return false;
5756
}

src/main/java/me/hsgamer/bettergui/paperspec/modifier/AdventureNameModifier.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
import org.bukkit.inventory.meta.ItemMeta;
99
import org.jetbrains.annotations.NotNull;
1010

11-
import java.util.Collection;
1211
import java.util.Objects;
1312
import java.util.UUID;
1413

1514
public class AdventureNameModifier implements ItemMetaModifier, ItemMetaComparator {
1615
private String name; // Stored as MiniMessage representation
1716

1817
@Override
19-
public @NotNull ItemMeta modifyMeta(ItemMeta meta, UUID uuid, @NotNull Collection<StringReplacer> stringReplacers) {
20-
Component displayName = AdventureUtils.toComponent(uuid, StringReplacer.replace(name, uuid, stringReplacers));
18+
public @NotNull ItemMeta modifyMeta(ItemMeta meta, UUID uuid, @NotNull StringReplacer stringReplacer) {
19+
Component displayName = AdventureUtils.toComponent(uuid, stringReplacer.replaceOrOriginal(name, uuid));
2120
Component noItalic = AdventureUtils.disableItalic(displayName);
2221
meta.displayName(noItalic);
2322
return meta;
@@ -34,8 +33,8 @@ public boolean loadFromItemMeta(ItemMeta meta) {
3433
}
3534

3635
@Override
37-
public boolean compare(ItemMeta meta, UUID uuid, @NotNull Collection<StringReplacer> stringReplacers) {
38-
String replaced = StringReplacer.replace(this.name, uuid, stringReplacers);
36+
public boolean compare(ItemMeta meta, UUID uuid, @NotNull StringReplacer stringReplacer) {
37+
String replaced = stringReplacer.replaceOrOriginal(name, uuid);
3938
// Since text components are complex, we compare the plain text representation for equality
4039
Component displayName = meta.displayName();
4140
Component compareName = AdventureUtils.toComponent(uuid, replaced);

src/main/java/me/hsgamer/bettergui/paperspec/modifier/PaperSkullModifier.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.bukkit.inventory.meta.SkullMeta;
1515
import org.jetbrains.annotations.NotNull;
1616

17-
import java.util.Collection;
17+
import java.util.Optional;
1818
import java.util.UUID;
1919

2020
import static java.util.concurrent.TimeUnit.MINUTES;
@@ -27,8 +27,9 @@ public class PaperSkullModifier implements ItemMetaModifier, ItemMetaComparator
2727
@Override
2828
public @NotNull PlayerProfile load(@NotNull String key) {
2929
PlayerProfile playerProfile;
30-
if (Validate.isValidUUID(key)) {
31-
UUID uuid = UUID.fromString(key);
30+
Optional<UUID> optionalUUID = Validate.getUUID(key);
31+
if (optionalUUID.isPresent()) {
32+
UUID uuid = optionalUUID.get();
3233
Player player = Bukkit.getPlayer(uuid);
3334
if (player != null) {
3435
playerProfile = player.getPlayerProfile();
@@ -49,11 +50,11 @@ public class PaperSkullModifier implements ItemMetaModifier, ItemMetaComparator
4950
private String headValue = "Steve";
5051

5152
@Override
52-
public @NotNull ItemMeta modifyMeta(@NotNull ItemMeta itemMeta, UUID uuid, @NotNull Collection<StringReplacer> stringReplacers) {
53+
public @NotNull ItemMeta modifyMeta(@NotNull ItemMeta itemMeta, UUID uuid, @NotNull StringReplacer stringReplacer) {
5354
if (!(itemMeta instanceof SkullMeta skullMeta)) {
5455
return itemMeta;
5556
}
56-
String value = StringReplacer.replace(headValue, uuid, stringReplacers);
57+
String value = stringReplacer.replaceOrOriginal(headValue, uuid);
5758
try {
5859
PlayerProfile playerProfile = CACHE.get(value);
5960
skullMeta.setPlayerProfile(playerProfile);
@@ -80,11 +81,11 @@ public boolean loadFromItemMeta(ItemMeta itemMeta) {
8081
}
8182

8283
@Override
83-
public boolean compare(@NotNull ItemMeta itemMeta, UUID uuid, @NotNull Collection<StringReplacer> stringReplacers) {
84+
public boolean compare(@NotNull ItemMeta itemMeta, UUID uuid, @NotNull StringReplacer stringReplacer) {
8485
if (!(itemMeta instanceof SkullMeta skullMeta)) {
8586
return false;
8687
}
87-
String value = StringReplacer.replace(headValue, uuid, stringReplacers);
88+
String value = stringReplacer.replaceOrOriginal(headValue, uuid);
8889
PlayerProfile playerProfile = skullMeta.getPlayerProfile();
8990
if (playerProfile == null) {
9091
return false;

0 commit comments

Comments
 (0)