Fix many bugs

This commit is contained in:
Telesphoreo 2022-03-18 20:12:05 -05:00
parent d8c6c3b4a8
commit 6a569bb638
8 changed files with 52 additions and 43 deletions

View File

@ -10,8 +10,6 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
/** /**
* SQL fetching utilities for players * SQL fetching utilities for players
@ -68,7 +66,7 @@ public class SQLPlayerData
{ {
String name = set.getString("name"); String name = set.getString("name");
String loginMSG = set.getString("login_msg"); String loginMSG = set.getString("login_msg");
Component prefix = Component.text(set.getString("prefix")); String prefix = set.getString("prefix");
String rankName = set.getString("rank").toUpperCase(); String rankName = set.getString("rank").toUpperCase();
long coins = set.getLong("coins"); long coins = set.getLong("coins");
boolean vanished = set.getBoolean("vanished"); boolean vanished = set.getBoolean("vanished");
@ -107,7 +105,7 @@ public class SQLPlayerData
PreparedStatement statement = con.prepareStatement(UPDATE); PreparedStatement statement = con.prepareStatement(UPDATE);
statement.setString(1, player.getName()); statement.setString(1, player.getName());
statement.setString(2, player.getLoginMessage()); statement.setString(2, player.getLoginMessage());
statement.setString(3, LegacyComponentSerializer.legacySection().serialize(player.getPrefix())); statement.setString(3, player.getPrefix());
statement.setString(4, player.getRank().toLowerCase()); statement.setString(4, player.getRank().toLowerCase());
statement.setString(5, new Gson().toJson(player.getIps())); statement.setString(5, new Gson().toJson(player.getIps()));
statement.setLong(6, player.getCoins()); statement.setLong(6, player.getCoins());
@ -136,7 +134,7 @@ public class SQLPlayerData
statement.setString(1, player.getUuid()); statement.setString(1, player.getUuid());
statement.setString(2, player.getName()); statement.setString(2, player.getName());
statement.setString(3, player.getLoginMessage()); statement.setString(3, player.getLoginMessage());
statement.setString(4, LegacyComponentSerializer.legacySection().serialize(player.getPrefix())); statement.setString(4, player.getPrefix());
statement.setString(5, player.getRank().toLowerCase()); statement.setString(5, player.getRank().toLowerCase());
statement.setString(6, new Gson().toJson(player.getIps())); statement.setString(6, new Gson().toJson(player.getIps()));
statement.setLong(7, player.getCoins()); statement.setLong(7, player.getCoins());

View File

@ -1,13 +1,16 @@
package dev.plex.command.impl; package dev.plex.command.impl;
import dev.plex.cache.PlayerCache;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.listener.impl.ChatListener; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -25,7 +28,30 @@ public class AdminChatCMD extends PlexCommand
return usage(); return usage();
} }
ChatListener.adminChat(sender, StringUtils.join(args, " ")); adminChat(sender, StringUtils.join(args, " "));
return null; return null;
} }
private void adminChat(CommandSender sender, String message)
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (player.hasPermission("plex.adminchat"))
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
}
}
plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
} }

View File

@ -55,7 +55,7 @@ public class TagCMD extends PlexCommand
return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16)); return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
} }
player.setPrefix(Component.text(MiniMessage.miniMessage().serialize(convertedComponent))); player.setPrefix(MiniMessage.miniMessage().serialize(convertedComponent));
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent)); return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
} }
@ -69,14 +69,14 @@ public class TagCMD extends PlexCommand
} }
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId()); PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
player.setPrefix(null); player.setPrefix("");
return messageComponent("prefixCleared"); return messageComponent("prefixCleared");
} }
checkRank(sender, Rank.ADMIN, "plex.tag.clear.others"); checkRank(sender, Rank.ADMIN, "plex.tag.clear.others");
Player target = getNonNullPlayer(args[1]); Player target = getNonNullPlayer(args[1]);
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId()); PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
plexTarget.setPrefix(null); plexTarget.setPrefix("");
messageComponent("otherPrefixCleared"); messageComponent("otherPrefixCleared");
} }
return usage(); return usage();

View File

@ -1,6 +1,7 @@
package dev.plex.handlers; package dev.plex.handlers;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.listener.impl.AdminListener; import dev.plex.listener.impl.AdminListener;
import dev.plex.listener.impl.BanListener; import dev.plex.listener.impl.BanListener;
@ -23,7 +24,10 @@ public class ListenerHandler
List<PlexListener> listeners = Lists.newArrayList(); List<PlexListener> listeners = Lists.newArrayList();
listeners.add(new AdminListener()); listeners.add(new AdminListener());
listeners.add(new BanListener()); listeners.add(new BanListener());
if (Plex.get().config.getBoolean("chat.enabled"))
{
listeners.add(new ChatListener()); listeners.add(new ChatListener());
}
listeners.add(new CommandListener()); listeners.add(new CommandListener());
listeners.add(new FreezeListener()); listeners.add(new FreezeListener());
listeners.add(new GameModeListener()); listeners.add(new GameModeListener());

View File

@ -3,7 +3,6 @@ package dev.plex.listener.impl;
import dev.plex.cache.PlayerCache; import dev.plex.cache.PlayerCache;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexLog; import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import io.papermc.paper.chat.ChatRenderer; import io.papermc.paper.chat.ChatRenderer;
@ -12,8 +11,6 @@ import net.kyori.adventure.audience.Audience;
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.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -22,29 +19,6 @@ public class ChatListener extends PlexListener
{ {
private final PlexChatRenderer renderer = new PlexChatRenderer(); private final PlexChatRenderer renderer = new PlexChatRenderer();
public static void adminChat(CommandSender sender, String message)
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (player.hasPermission("plex.adminchat"))
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
}
}
plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
@EventHandler @EventHandler
public void onChat(AsyncChatEvent event) public void onChat(AsyncChatEvent event)
{ {
@ -80,7 +54,8 @@ public class ChatListener extends PlexListener
{ {
if (hasPrefix) if (hasPrefix)
{ {
return Component.empty().append(prefix) return Component.empty()
.append(prefix)
.append(Component.space()) .append(Component.space())
.append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName))) .append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName)))
.append(Component.space()) .append(Component.space())
@ -89,7 +64,7 @@ public class ChatListener extends PlexListener
.append(message); .append(message);
} }
return Component.empty() return Component.empty()
.append(sourceDisplayName) .append(LegacyComponentSerializer.legacyAmpersand().deserialize("&" + plugin.config.getString("chat.name-color") + LegacyComponentSerializer.legacyAmpersand().serialize(sourceDisplayName)))
.append(Component.space()) .append(Component.space())
.append(Component.text("»").color(NamedTextColor.GRAY)) .append(Component.text("»").color(NamedTextColor.GRAY))
.append(Component.space()) .append(Component.space())

View File

@ -35,7 +35,7 @@ public class PlexPlayer
private Player player; private Player player;
private String loginMessage; private String loginMessage;
private Component prefix; private String prefix;
private boolean vanished; private boolean vanished;
private boolean commandSpy; private boolean commandSpy;
@ -60,7 +60,7 @@ public class PlexPlayer
this.player = Bukkit.getPlayer(name); this.player = Bukkit.getPlayer(name);
this.loginMessage = ""; this.loginMessage = "";
this.prefix = null; this.prefix = "";
this.vanished = false; this.vanished = false;
this.commandSpy = false; this.commandSpy = false;

View File

@ -4,6 +4,7 @@ import dev.plex.Plex;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.rank.enums.Title; import dev.plex.rank.enums.Title;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils; import dev.plex.util.PlexUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -14,6 +15,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 org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener; import org.json.JSONTokener;
@ -92,9 +94,9 @@ public class RankManager
public Component getPrefix(PlexPlayer player) public Component getPrefix(PlexPlayer player)
{ {
if (Component.IS_NOT_EMPTY.test(player.getPrefix())) if (!player.getPrefix().equals(""))
{ {
return player.getPrefix(); return MiniMessage.miniMessage().deserialize(player.getPrefix());
} }
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()))
{ {

View File

@ -18,6 +18,10 @@ banning:
ban_url: "https://forum.plex.us.org" ban_url: "https://forum.plex.us.org"
chat: chat:
# Should the server use Plex's chat system? It is recommended to keep this on if you are using ranks.
# If you are using permissions, you should turn this off and use Vault to handle prefixes with a different chat plugin
enabled: true
# The maximum amount of characters a player can have for their tag
max-tag-length: 16 max-tag-length: 16
# Color code for name color # Color code for name color
name-color: 'f' name-color: 'f'