Skip to content

Commit edf04a0

Browse files
committed
add emotes asynchronously
1 parent dfb063a commit edf04a0

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/main/kotlin/me/apyr/chatemotes/commands/AddCommand.kt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import net.md_5.bungee.api.ChatColor
1010
import net.md_5.bungee.api.chat.ClickEvent
1111
import net.md_5.bungee.api.chat.ComponentBuilder
1212
import net.md_5.bungee.api.chat.TextComponent
13+
import org.bukkit.Bukkit
1314
import org.bukkit.command.CommandSender
1415

1516
class AddCommand : ChatEmotesCommand {
@@ -25,20 +26,25 @@ class AddCommand : ChatEmotesCommand {
2526
throw InvalidEmoteNameException()
2627
}
2728

28-
ChatEmotes.getInstance().getEmoteProvider().addEmote(name, url)
29-
sender.spigot().sendMessage(
30-
*ComponentBuilder("Emote successfully added. ")
31-
.color(ChatColor.GREEN)
32-
.append(
33-
TextComponent("Click here").apply {
34-
isUnderlined = true
35-
clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/emote refresh")
36-
}
29+
Bukkit.getScheduler().runTaskAsynchronously(ChatEmotes.getInstance(), Runnable {
30+
ChatEmotes.getInstance().getEmoteProvider().addEmote(name, url)
31+
32+
Bukkit.getScheduler().runTask(ChatEmotes.getInstance(), Runnable {
33+
sender.spigot().sendMessage(
34+
*ComponentBuilder("Emote successfully added. ")
35+
.color(ChatColor.GREEN)
36+
.append(
37+
TextComponent("Click here").apply {
38+
isUnderlined = true
39+
clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/emote refresh")
40+
}
41+
)
42+
.append(" to announce the resource pack", ComponentBuilder.FormatRetention.NONE)
43+
.color(ChatColor.GREEN)
44+
.create()
3745
)
38-
.append(" to announce the resource pack", ComponentBuilder.FormatRetention.NONE)
39-
.color(ChatColor.GREEN)
40-
.create()
41-
)
46+
})
47+
})
4248
}
4349

4450
override fun onTabComplete(sender: CommandSender, args: List<String>): List<String> {

src/main/kotlin/me/apyr/chatemotes/emote/local/LocalEmoteProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class LocalEmoteProvider : EmoteProvider {
115115
PlayerLoginEvent.getHandlerList().unregister(loginListener)
116116
}
117117

118-
private fun saveToFile(emotes: Collection<LocalEmote>) {
118+
private fun saveToFile(emotes: Collection<LocalEmote>): Unit = synchronized(this) {
119119
val map: List<Map<String, String>> = emotes.map { emote ->
120120
mapOf(
121121
"name" to emote.name,

0 commit comments

Comments
 (0)