mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Add customizable login messages
This commit is contained in:
parent
dbbaf4ab70
commit
f3f7daaafb
@ -0,0 +1,53 @@
|
|||||||
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
|
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.player.PlexPlayer;
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
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.removeloginmessage", source = RequiredCommandSource.ANY)
|
||||||
|
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
|
||||||
|
public class RemoveLoginMessageCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0 && !isConsole(sender))
|
||||||
|
{
|
||||||
|
if (playerSender != null)
|
||||||
|
{
|
||||||
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||||
|
plexPlayer.setLoginMessage("");
|
||||||
|
return messageComponent("removedOwnLoginMessage");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (args[0].equalsIgnoreCase("-o"))
|
||||||
|
{
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
|
return messageComponent("specifyPlayer");
|
||||||
|
}
|
||||||
|
|
||||||
|
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||||
|
if (plexPlayer == null)
|
||||||
|
{
|
||||||
|
return messageComponent("playerNotFound");
|
||||||
|
}
|
||||||
|
plexPlayer.setLoginMessage("");
|
||||||
|
return messageComponent("removedOtherLoginMessage", plexPlayer.getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return messageComponent("noPermissionConsole");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
|
import dev.plex.command.PlexCommand;
|
||||||
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
|
import dev.plex.command.exception.CommandFailException;
|
||||||
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.rank.enums.Rank;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.apache.commons.lang3.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.setloginmessage", source = RequiredCommandSource.ANY)
|
||||||
|
@CommandParameters(name = "setloginmessage", usage = "/<command> [-o <player>] <message>", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg")
|
||||||
|
public class SetLoginMessageCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
private final boolean nameRequired = plugin.getConfig().getBoolean("loginmessages.name");
|
||||||
|
private final boolean rankRequired = plugin.getConfig().getBoolean("loginmessages.rank");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
if (playerSender != null)
|
||||||
|
{
|
||||||
|
if (args[0].equals("-o"))
|
||||||
|
{
|
||||||
|
if (args.length < 2)
|
||||||
|
{
|
||||||
|
return messageComponent("specifyPlayer");
|
||||||
|
}
|
||||||
|
if (args.length < 3)
|
||||||
|
{
|
||||||
|
return messageComponent("specifyLoginMessage");
|
||||||
|
}
|
||||||
|
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
||||||
|
if (plexPlayer == null)
|
||||||
|
{
|
||||||
|
return messageComponent("playerNotFound");
|
||||||
|
}
|
||||||
|
String message = StringUtils.join(args, " ", 2, args.length);
|
||||||
|
message = message.replace(plexPlayer.getName(), "%player%");
|
||||||
|
validateMessage(message);
|
||||||
|
plexPlayer.setLoginMessage(message);
|
||||||
|
return messageComponent("setOtherPlayersLoginMessage", plexPlayer.getName(),
|
||||||
|
message.replace("%player%", plexPlayer.getName())
|
||||||
|
.replace("%rank%", plexPlayer.getRank()));
|
||||||
|
}
|
||||||
|
if (isConsole(sender))
|
||||||
|
{
|
||||||
|
return messageComponent("noPermissionConsole");
|
||||||
|
}
|
||||||
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||||
|
String message = StringUtils.join(args, " ", 0, args.length);
|
||||||
|
message = message.replace(plexPlayer.getName(), "%player%");
|
||||||
|
validateMessage(message);
|
||||||
|
plexPlayer.setLoginMessage(message);
|
||||||
|
return messageComponent("setOwnLoginMessage",
|
||||||
|
message.replace("%player%", plexPlayer.getName())
|
||||||
|
.replace("%rank%", plexPlayer.getRank()));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateMessage(String message)
|
||||||
|
{
|
||||||
|
if (nameRequired && !message.contains("%player%"))
|
||||||
|
{
|
||||||
|
PlexLog.debug("Validating login message has a valid name in it");
|
||||||
|
throw new CommandFailException(messageString("nameRequired"));
|
||||||
|
}
|
||||||
|
if (plugin.getSystem().equalsIgnoreCase("ranks") && rankRequired && !message.contains("%rank%"))
|
||||||
|
{
|
||||||
|
PlexLog.debug("Validating login message has a valid rank in it");
|
||||||
|
throw new CommandFailException(messageString("rankRequired"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -77,7 +77,7 @@ public class PlayerListener<T> extends PlexListener
|
|||||||
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
|
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
|
||||||
if (!loginMessage.isEmpty())
|
if (!loginMessage.isEmpty())
|
||||||
{
|
{
|
||||||
PlexUtils.broadcast(PlexUtils.mmDeserialize("<aqua>" + player.getName() + " is " + loginMessage));
|
PlexUtils.broadcast(loginMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
PermissionsUtil.setupPermissions(player);
|
PermissionsUtil.setupPermissions(player);
|
||||||
|
@ -16,6 +16,7 @@ import java.util.stream.Collectors;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -133,25 +134,33 @@ public class RankManager
|
|||||||
|
|
||||||
public String getLoginMessage(PlexPlayer player)
|
public String getLoginMessage(PlexPlayer player)
|
||||||
{
|
{
|
||||||
|
String prepend;
|
||||||
|
// We don't want to prepend the "<player> is" if the login message is custom
|
||||||
if (!player.getLoginMessage().isEmpty())
|
if (!player.getLoginMessage().isEmpty())
|
||||||
{
|
{
|
||||||
return player.getLoginMessage();
|
return player.getLoginMessage()
|
||||||
|
.replace("%player%", player.getName())
|
||||||
|
.replace("%rank%", player.getRank());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prepend = MiniMessage.miniMessage().serialize(Component.text(player.getName() + " is ").color(NamedTextColor.AQUA));
|
||||||
}
|
}
|
||||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||||
{
|
{
|
||||||
return Title.OWNER.getLoginMessage();
|
return prepend + Title.OWNER.getLoginMessage();
|
||||||
}
|
}
|
||||||
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
|
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
|
||||||
{
|
{
|
||||||
return Title.DEV.getLoginMessage();
|
return prepend + Title.DEV.getLoginMessage();
|
||||||
}
|
}
|
||||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName()))
|
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName()))
|
||||||
{
|
{
|
||||||
return Title.MASTER_BUILDER.getLoginMessage();
|
return prepend + Title.MASTER_BUILDER.getLoginMessage();
|
||||||
}
|
}
|
||||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
||||||
{
|
{
|
||||||
return player.getRankFromString().getLoginMessage();
|
return prepend + player.getRankFromString().getLoginMessage();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ public class PlexUtils implements PlexBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return ((TextComponent) component).content();
|
return ((TextComponent)component).content();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,13 @@ chat:
|
|||||||
# NOTE: If you are using a proxy such as BungeeCord or Velocity, it is highly recommended to use permissions
|
# NOTE: If you are using a proxy such as BungeeCord or Velocity, it is highly recommended to use permissions
|
||||||
system: ranks
|
system: ranks
|
||||||
|
|
||||||
|
# Login Messages
|
||||||
|
loginmessages:
|
||||||
|
# Should the player be required to put their name in the login message?
|
||||||
|
name: true
|
||||||
|
# If ranks are enabled, should the player be required to put their rank in the login message?
|
||||||
|
rank: true
|
||||||
|
|
||||||
data:
|
data:
|
||||||
central:
|
central:
|
||||||
storage: sqlite # Use mariadb, mongodb, or sqlite here
|
storage: sqlite # Use mariadb, mongodb, or sqlite here
|
||||||
|
@ -18,6 +18,7 @@ banMessage: "<red>You have been banned! You may appeal at <gold>{0}.\n<red>Reaso
|
|||||||
# 1 - Appeal URL
|
# 1 - Appeal URL
|
||||||
indefBanMessage: "<red>Your {0} is indefinitely banned! You may appeal at <gold>{1}."
|
indefBanMessage: "<red>Your {0} is indefinitely banned! You may appeal at <gold>{1}."
|
||||||
playerNotFound: "<red>Player not found!"
|
playerNotFound: "<red>Player not found!"
|
||||||
|
specifyPlayer: "<red>You must specify a player!"
|
||||||
worldNotFound: "<red>World not found!"
|
worldNotFound: "<red>World not found!"
|
||||||
# 0 - The world you have been teleported to
|
# 0 - The world you have been teleported to
|
||||||
playerWorldTeleport: "<aqua>You have been teleported to {0}."
|
playerWorldTeleport: "<aqua>You have been teleported to {0}."
|
||||||
@ -183,4 +184,15 @@ noteNotFound: "<red>A note with this ID could not be found."
|
|||||||
removedNote: "<green>Removed note with ID: {0}"
|
removedNote: "<green>Removed note with ID: {0}"
|
||||||
# 0 - The number of notes cleared
|
# 0 - The number of notes cleared
|
||||||
clearedNotes: "<green>Cleared {0} notes."
|
clearedNotes: "<green>Cleared {0} notes."
|
||||||
invalidToggle: "<red>That is not a valid toggle."
|
invalidToggle: "<red>That is not a valid toggle."
|
||||||
|
specifyLoginMessage: "<red>Please specify a login message."
|
||||||
|
# 0 - The login message
|
||||||
|
setOwnLoginMessage: "<gray>Your login message is now:<newline><gray>> <reset>{0}"
|
||||||
|
# 0 - The player
|
||||||
|
# 1 - The login message
|
||||||
|
setOtherPlayersLoginMessage: "<gray>{0}'s login message is now:<newline><gray>> <reset>{1}"
|
||||||
|
removedOwnLoginMessage: "<gray>Your login message has been removed."
|
||||||
|
# 0 - The player
|
||||||
|
removedOtherLoginMessage: "<gray>You removed {0}'s login message."
|
||||||
|
nameRequired: "<red>Policy requires that you must state your player name in your login message. You can either do this by inserting your name or %player%."
|
||||||
|
rankRequired: "<red>Policy requires that you must state your rank in your login message. You can do this by using %rank% in your login message."
|
||||||
|
Loading…
Reference in New Issue
Block a user