Skip to content

Commit 2be614a

Browse files
committed
v1.0.1 - Legacy Support Tag
Added %sp_prefix_legacy% for legacy chat formatting support. Fixed default Absorption tag cause I forgot to add </yellow>. Updated version to v1.0.1
1 parent d2ae879 commit 2be614a

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ A plugin aiming to allow for simple player-selected prefixes that can be used in
3232

3333
`%sp_prefix%`
3434
> Placeholder for the prefix. Use this in your chat plugin.
35-
>
35+
>
36+
> Example Usage: `%sp_prefix% %player_displayname% » {message}`
37+
38+
`%sp_prefix_legacy%`
39+
> Placeholder for the prefix. Necessary when you need the legacy (`&a` / `§a` instead of `<green>`) way to handle stuff.
40+
>
3641
> Example Usage: `%sp_prefix% %player_displayname% » {message}`
3742
3843
`/sp gui`

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ADHDMC</groupId>
88
<artifactId>SimplePrefixes</artifactId>
9-
<version>v1.0.0</version>
9+
<version>v1.0.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimplePrefixes</name>

src/main/java/adhdmc/simpleprefixes/SimplePrefixes.java

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import adhdmc.simpleprefixes.util.Prefix;
1111
import adhdmc.simpleprefixes.util.PrefixUtil;
1212
import net.kyori.adventure.text.minimessage.MiniMessage;
13+
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
14+
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
1315
import org.bukkit.Bukkit;
1416
import org.bukkit.plugin.Plugin;
1517
import org.bukkit.plugin.java.JavaPlugin;
@@ -20,12 +22,18 @@ public final class SimplePrefixes extends JavaPlugin {
2022

2123
private static Plugin plugin;
2224
private static MiniMessage miniMessage;
25+
private static MiniMessage miniMessageStripper;
2326
private static Logger logger;
2427

2528
@Override
2629
public void onEnable() {
2730
plugin = this;
2831
miniMessage = MiniMessage.miniMessage();
32+
miniMessageStripper = MiniMessage.builder().tags(
33+
TagResolver.builder()
34+
.resolver(StandardTags.clickEvent())
35+
.resolver(StandardTags.hoverEvent())
36+
.build()).build();
2937
logger = getPlugin().getLogger();
3038
configSetup();
3139
new PAPIExpansion(this).register();
@@ -40,6 +48,7 @@ public void onDisable() {
4048

4149
public static Plugin getPlugin() { return plugin; }
4250
public static MiniMessage getMiniMessage() { return miniMessage; }
51+
public static MiniMessage getStripper() { return miniMessageStripper; }
4352
public static Logger getPrefixLogger() { return logger; }
4453

4554

src/main/java/adhdmc/simpleprefixes/dependency/PAPIExpansion.java

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import adhdmc.simpleprefixes.util.PrefixUtil;
55
import me.clip.placeholderapi.PlaceholderAPI;
66
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
7+
import net.kyori.adventure.text.minimessage.MiniMessage;
8+
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
9+
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
10+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
711
import org.bukkit.OfflinePlayer;
812
import org.jetbrains.annotations.NotNull;
913

@@ -39,6 +43,12 @@ public String onRequest(OfflinePlayer player, @NotNull String params) {
3943
String prefix = PrefixUtil.getInstance().getPlayerPrefix(player);
4044
return PlaceholderAPI.setPlaceholders(player, prefix);
4145
}
46+
if (params.equalsIgnoreCase("prefix_legacy")) {
47+
String prefix = PrefixUtil.getInstance().getPlayerPrefix(player);
48+
String papiParsed = PlaceholderAPI.setPlaceholders(player, prefix);
49+
String stripped = SimplePrefixes.getStripper().stripTags(papiParsed);
50+
return LegacyComponentSerializer.legacySection().serialize(SimplePrefixes.getMiniMessage().deserialize(stripped));
51+
}
4252

4353
return null;
4454
}

src/main/resources/prefixes.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ absorption:
99
- "<yellow><bold>FUN FACT:"
1010
- "<white> This was a prefix I used during testing!"
1111
- "<white> This also supports PlaceholderAPI!"
12-
prefix: "<white>[<yellow>Absorption: %player_absorption%]</white>"
12+
prefix: "<white>[<yellow>Absorption: %player_absorption%</yellow>]</white>"
1313
verify-always: true
1414
requirements:
1515
- "compare_int %player_absorption% > 0"

0 commit comments

Comments
 (0)