mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
add /csay
make /say and /csay not parse minimessage messages add a strip color function to strip a message of minimessage strings
This commit is contained in:
parent
b449d732b0
commit
dc65187381
31
src/main/java/dev/plex/command/impl/ConsoleSayCommand.java
Normal file
31
src/main/java/dev/plex/command/impl/ConsoleSayCommand.java
Normal file
@ -0,0 +1,31 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
|
||||
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
||||
public class ConsoleSayCommand extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayCommand", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -173,8 +173,8 @@ public class NotesCMD extends PlexCommand
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
||||
for (Note note : notes)
|
||||
{
|
||||
Component noteLine = Component.text(note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + DATE_FORMAT.format(note.getTimestamp())).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false);
|
||||
noteLine = noteLine.append(Component.space()).append(Component.text(note.getNote())).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, true);
|
||||
Component noteLine = mmString("<gold><!italic>" + note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + DATE_FORMAT.format(note.getTimestamp()));
|
||||
noteLine = noteLine.append(mmString("<newline><yellow># " + note.getNote()));
|
||||
noteList.set(noteList.get().append(Component.newline()));
|
||||
noteList.set(noteList.get().append(noteLine));
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -25,7 +26,7 @@ public class SayCMD extends PlexCommand
|
||||
return usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("sayCommand", sender.getName(), StringUtils.join(args, " ")));
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("sayCommand", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||
return null;
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.player.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -34,7 +35,7 @@ public class PunishedPlayerMenu extends AbstractMenu
|
||||
this.punishedPlayer = player;
|
||||
for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++)
|
||||
{
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, "Punishments Page " + (i + 1));
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Punishments Page " + (i + 1)));
|
||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE));
|
||||
|
@ -3,6 +3,7 @@ package dev.plex.menu;
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -27,15 +28,15 @@ public class PunishmentMenu extends AbstractMenu
|
||||
super("§c§lPunishments");
|
||||
for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++)
|
||||
{
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, "Punishments Page " + (i + 1));
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Punishments Page " + (i + 1)));
|
||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page");
|
||||
meta.displayName(PlexUtils.mmDeserialize("<light_purple>Next Page"));
|
||||
nextPage.setItemMeta(meta);
|
||||
|
||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta2 = previousPage.getItemMeta();
|
||||
meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page");
|
||||
meta2.displayName(PlexUtils.mmDeserialize("<light_purple>Previous Page"));
|
||||
previousPage.setItemMeta(meta2);
|
||||
|
||||
inventory.setItem(50, nextPage);
|
||||
@ -72,7 +73,7 @@ public class PunishmentMenu extends AbstractMenu
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
meta.setOwningPlayer(players);
|
||||
meta.setDisplayName(ChatColor.YELLOW + players.getName());
|
||||
meta.displayName(PlexUtils.mmDeserialize("<!italic><yellow>" + players.getName()));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inv.setItem(currentItemIndex, item);
|
||||
@ -98,11 +99,19 @@ public class PunishmentMenu extends AbstractMenu
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getCurrentItem().hasItemMeta())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!event.getCurrentItem().getItemMeta().hasDisplayName())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getCurrentItem();
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
||||
if (item.getItemMeta().displayName().equals(PlexUtils.mmDeserialize("<light_purple>Next Page")))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
||||
{
|
||||
@ -114,7 +123,7 @@ public class PunishmentMenu extends AbstractMenu
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
}
|
||||
else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page"))
|
||||
else if (item.getItemMeta().displayName().equals(PlexUtils.mmDeserialize("<light_purple>Previous Page")))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0)
|
||||
{
|
||||
|
@ -157,6 +157,11 @@ public class PlexUtils extends PlexBase
|
||||
StandardTags.reset()
|
||||
).build()).build();
|
||||
|
||||
public static String mmStripColor(String input)
|
||||
{
|
||||
return PlainTextComponentSerializer.plainText().serialize(mmDeserialize(input));
|
||||
}
|
||||
|
||||
public static Component mmDeserialize(String input)
|
||||
{
|
||||
boolean aprilFools = true; // true by default
|
||||
@ -336,7 +341,7 @@ public class PlexUtils extends PlexBase
|
||||
|
||||
public static void broadcast(String s)
|
||||
{
|
||||
Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(s));
|
||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(s));
|
||||
}
|
||||
|
||||
public static void broadcast(Component component)
|
||||
|
@ -170,4 +170,7 @@ allowDropsEnabled: "<gray>Now allowing drops from players."
|
||||
commandBlocked: "<gray>That command is blocked."
|
||||
# 0 - The command sender
|
||||
# 1 - The message being said
|
||||
sayCommand: "[Server: {0}] {1}"
|
||||
sayCommand: "<blue>[Server: {0}] {1}"
|
||||
# 0 - The command sender
|
||||
# 1 - The message being said
|
||||
consoleSayCommand: "<gray>[Console: {0}] <white>{1}"
|
Loading…
Reference in New Issue
Block a user