mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Allow books and signs to use SafeMiniMessage
This commit is contained in:
parent
45b338fd9b
commit
0e3eeaeac3
@ -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));
|
||||
}
|
||||
}
|
@ -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))));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user