Skip to content

Commit bc3a2d9

Browse files
committed
Add itemsadder emoji support
1 parent 9532ebb commit bc3a2d9

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'com.maximde'
8-
version = '1.5.2'
8+
version = '1.5.3'
99

1010
tasks.withType(JavaCompile).configureEach {
1111
options.release = 17
@@ -28,6 +28,7 @@ dependencies {
2828
compileOnly ("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT")
2929
compileOnly 'com.github.retrooper.packetevents:api:2.2.1'
3030
implementation "net.kyori:adventure-text-minimessage:4.17.0"
31+
compileOnly 'com.github.LoneDev6:API-ItemsAdder:3.6.1'
3132
}
3233

3334
publishing {

src/main/java/com/maximde/betterchatbubbles/api/BubbleAPI.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.maximde.betterchatbubbles.api;
22

3+
import com.maximde.betterchatbubbles.api.utils.ItemsAdderHolder;
4+
import com.maximde.betterchatbubbles.api.utils.ReplaceText;
5+
import lombok.Getter;
36
import org.bukkit.Bukkit;
47

58
import java.util.Optional;
@@ -9,8 +12,20 @@ public record BubbleAPI(BubbleGenerator bubbleGenerator) {
912

1013
private static BubbleAPI bubbleAPI;
1114

15+
private static ReplaceText replaceText;
16+
1217
public static void setAPI(BubbleAPI bubbleAPI) {
1318
BubbleAPI.bubbleAPI = bubbleAPI;
19+
try {
20+
replaceText = new ItemsAdderHolder();
21+
} catch (ClassNotFoundException exception) {
22+
replaceText = new ReplaceText() {
23+
@Override
24+
public String replace(String s) {
25+
return s;
26+
}
27+
};
28+
}
1429
}
1530

1631
public static Optional<BubbleAPI> getBubbleAPI() {
@@ -21,4 +36,8 @@ public static Optional<BubbleAPI> getBubbleAPI() {
2136

2237
return Optional.of(bubbleAPI);
2338
}
39+
40+
public ReplaceText getReplaceText() {
41+
return replaceText;
42+
}
2443
}

src/main/java/com/maximde/betterchatbubbles/api/ChatBubble.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.lang.reflect.Field;
2020
import java.util.ArrayList;
2121
import java.util.List;
22+
import java.util.Optional;
23+
import java.util.concurrent.atomic.AtomicReference;
2224
import java.util.logging.Level;
2325

2426
public class ChatBubble {
@@ -223,7 +225,7 @@ public String getTextWithoutColor() {
223225
}
224226

225227
public ChatBubble setText(String text) {
226-
this.text = Component.text(text);
228+
this.text = Component.text(replaceFontImages(text));
227229
return this;
228230
}
229231

@@ -233,10 +235,17 @@ public ChatBubble setText(Component component) {
233235
}
234236

235237
public ChatBubble setMiniMessageText(String text) {
236-
this.text = Mini.message(text);
238+
this.text = Mini.message(replaceFontImages(text));
237239
return this;
238240
}
239241

242+
private String replaceFontImages(String s) {
243+
AtomicReference<String> news = new AtomicReference<>(s);
244+
Optional<BubbleAPI> bubble = BubbleAPI.getBubbleAPI();
245+
bubble.ifPresent(bubbleAPI -> news.set(bubbleAPI.getReplaceText().replace(news.get())));
246+
return news.get();
247+
}
248+
240249
/**
241250
* This is the correct way to get the location without any possible errors!
242251
*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.maximde.betterchatbubbles.api.utils;
2+
3+
import dev.lone.itemsadder.api.FontImages.FontImageWrapper;
4+
import org.bukkit.Bukkit;
5+
6+
import java.util.logging.Level;
7+
8+
public class ItemsAdderHolder implements ReplaceText {
9+
10+
public ItemsAdderHolder() throws ClassNotFoundException {
11+
if (Bukkit.getPluginManager().getPlugin("ItemsAdder") == null) {
12+
Bukkit.getLogger().log(Level.WARNING, "[BetterChatBubbles] ItemsAdder plugin not found! No custom emojis support.");
13+
throw new ClassNotFoundException();
14+
}
15+
}
16+
17+
@Override
18+
public String replace(String s) {
19+
return FontImageWrapper.replaceFontImages(s);
20+
}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.maximde.betterchatbubbles.api.utils;
2+
3+
public interface ReplaceText {
4+
String replace(String s);
5+
}

0 commit comments

Comments
 (0)