Allow books and signs to use SafeMiniMessage

This commit is contained in:
Business Goose 2022-05-04 17:40:58 +01:00
parent 45b338fd9b
commit 0e3eeaeac3
No known key found for this signature in database
GPG Key ID: 77DCA801362E9645
2 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,30 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.inventory.Book;
import net.kyori.adventure.text.Component;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.inventory.meta.BookMeta;
public class BookListener extends PlexListener
{
@EventHandler(priority = EventPriority.HIGHEST)
public void onBookEdit(PlayerEditBookEvent event)
{
List<Component> pages = new ArrayList<>();
for (Component page : event.getNewBookMeta().pages())
{
pages.add(SafeMiniMessage.mmDeserialize(PlexUtils.getTextFromComponent(page)));
}
event.setNewBookMeta((BookMeta)event.getNewBookMeta().pages(pages));
}
}

View File

@ -0,0 +1,20 @@
package dev.plex.listener.impl;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.SignChangeEvent;
public class SignListener extends PlexListener
{
@EventHandler(priority = EventPriority.HIGHEST)
public void onSignEdit(SignChangeEvent event)
{
for (int i = 0; i < event.lines().size(); i++)
{
event.line(i, SafeMiniMessage.mmDeserialize(PlexUtils.getTextFromComponent(event.line(i))));
}
}
}