- Fix login messages to match with titles

This commit is contained in:
Taah 2022-02-21 23:17:00 -08:00
parent 137bc44212
commit a2aea5bf1c
5 changed files with 56 additions and 46 deletions

View File

@ -73,7 +73,7 @@ public class MongoPlayerData
Update<PlexPlayer> updateOps = filter
.update(
UpdateOperators.set("name", player.getName()),
UpdateOperators.set("loginMSG", player.getLoginMSG()),
UpdateOperators.set("loginMSG", player.getLoginMessage()),
UpdateOperators.set("prefix", player.getPrefix()),
UpdateOperators.set("rank", player.getRank().toLowerCase()),
UpdateOperators.set("ips", player.getIps()),

View File

@ -75,7 +75,7 @@ public class SQLPlayerData
{
}.getType());
plexPlayer.setName(name);
plexPlayer.setLoginMSG(loginMSG);
plexPlayer.setLoginMessage(loginMSG);
plexPlayer.setPrefix(prefix);
plexPlayer.setRank(rankName);
plexPlayer.setIps(ips);
@ -104,7 +104,7 @@ public class SQLPlayerData
{
PreparedStatement statement = con.prepareStatement(UPDATE);
statement.setString(1, player.getName());
statement.setString(2, player.getLoginMSG());
statement.setString(2, player.getLoginMessage());
statement.setString(3, player.getPrefix());
statement.setString(4, player.getRank().toLowerCase());
statement.setString(5, new Gson().toJson(player.getIps()));
@ -133,7 +133,7 @@ public class SQLPlayerData
PreparedStatement statement = con.prepareStatement(INSERT);
statement.setString(1, player.getUuid());
statement.setString(2, player.getName());
statement.setString(3, player.getLoginMSG());
statement.setString(3, player.getLoginMessage());
statement.setString(4, player.getPrefix());
statement.setString(5, player.getRank().toLowerCase());
statement.setString(6, new Gson().toJson(player.getIps()));

View File

@ -1,6 +1,5 @@
package dev.plex.listener.impl;
import dev.plex.admin.Admin;
import dev.plex.cache.DataUtils;
import dev.plex.cache.MongoPlayerData;
import dev.plex.cache.PlayerCache;
@ -8,11 +7,9 @@ import dev.plex.cache.SQLPlayerData;
import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer;
import dev.plex.player.PunishedPlayer;
import dev.plex.rank.enums.Title;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import java.util.Collections;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -21,6 +18,9 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Collections;
import java.util.UUID;
public class PlayerListener extends PlexListener
{
private final MongoPlayerData mongoPlayerData = plugin.getMongoPlayerData() != null ? plugin.getMongoPlayerData() : null;
@ -38,8 +38,7 @@ public class PlayerListener extends PlexListener
{
player.setOp(true);
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
player.setOp(false);
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
@ -52,8 +51,7 @@ public class PlayerListener extends PlexListener
plexPlayer.setName(player.getName()); //set the name of the player
plexPlayer.setIps(Collections.singletonList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
DataUtils.insert(plexPlayer); // insert data in some wack db
}
else
} else
{
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
}
@ -64,8 +62,7 @@ public class PlayerListener extends PlexListener
{
punishedPlayer = new PunishedPlayer(player.getUniqueId());
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), punishedPlayer);
}
else
} else
{
punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
}
@ -73,29 +70,15 @@ public class PlayerListener extends PlexListener
assert plexPlayer != null;
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid())) // don't remove or we will front door ur mother
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
if (!loginMessage.isEmpty())
{
PlexUtils.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + Title.DEV.getLoginMessage()));
}
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
if (plugin.getRankManager().isAdmin(plexPlayer))
{
Admin admin = new Admin(UUID.fromString(plexPlayer.getUuid()));
admin.setRank(plexPlayer.getRankFromString());
plugin.getAdminList().addToCache(admin);
if (!plexPlayer.getLoginMSG().isEmpty())
{
event.joinMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getLoginMSG()));
}
else
{
event.joinMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMessage()));
}
}
event.joinMessage(
Component.text(ChatColor.AQUA + player.getName() + " is ").color(NamedTextColor.AQUA).append(LegacyComponentSerializer.legacyAmpersand().deserialize(loginMessage))
.append(Component.newline())
.append(Component.text(player.getName() + " joined the game").color(NamedTextColor.YELLOW))
);
}
}
@ -113,8 +96,7 @@ public class PlayerListener extends PlexListener
if (mongoPlayerData != null) //back to mongo checking
{
mongoPlayerData.update(plexPlayer); //update the player's document
}
else if (sqlPlayerData != null) //sql checking
} else if (sqlPlayerData != null) //sql checking
{
sqlPlayerData.update(plexPlayer);
}

View File

@ -33,7 +33,7 @@ public class PlexPlayer
private String name;
private Player player;
private String loginMSG;
private String loginMessage;
private String prefix;
private boolean vanished;
@ -58,7 +58,7 @@ public class PlexPlayer
this.name = "";
this.player = Bukkit.getPlayer(name);
this.loginMSG = "";
this.loginMessage = "";
this.prefix = "";
this.vanished = false;

View File

@ -1,6 +1,5 @@
package dev.plex.rank;
import com.google.gson.Gson;
import dev.plex.Plex;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
@ -11,9 +10,11 @@ import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class RankManager
@ -65,7 +66,8 @@ public class RankManager
JSONObject object = new JSONObject(tokener);
JSONArray ranks = object.getJSONArray("ranks");
ranks.forEach(r -> {
ranks.forEach(r ->
{
JSONObject rank = new JSONObject(r.toString());
String key = rank.keys().next();
Rank.valueOf(key).setLoginMessage(rank.getJSONObject(key).getString("loginMessage"));
@ -73,7 +75,8 @@ public class RankManager
});
JSONArray titles = object.getJSONArray("titles");
titles.forEach(t -> {
titles.forEach(t ->
{
JSONObject title = new JSONObject(t.toString());
String key = title.keys().next();
Title.valueOf(key).setLoginMessage(title.getJSONObject(key).getString("loginMessage"));
@ -110,6 +113,31 @@ public class RankManager
return "";
}
public String getLoginMessage(PlexPlayer player)
{
if (!player.getLoginMessage().isEmpty())
{
return player.getLoginMessage();
}
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
{
return Title.OWNER.getLoginMessage();
}
if (PlexUtils.DEVELOPERS.contains(player.getUuid())) // don't remove or we will front door ur mother
{
return Title.DEV.getLoginMessage();
}
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName()))
{
return Title.MASTER_BUILDER.getLoginMessage();
}
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
{
return player.getRankFromString().getLoginMessage();
}
return "";
}
public boolean isAdmin(PlexPlayer plexPlayer)
{
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN);