mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
add warning for querying plex players by ip when using sqlite
This commit is contained in:
parent
ee18ae324d
commit
9600f2d5d9
@ -16,6 +16,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -5,6 +5,9 @@ import com.google.gson.Gson;
|
|||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.PlayerCache;
|
import dev.plex.cache.PlayerCache;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.storage.StorageType;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -35,8 +38,7 @@ public class SQLPlayerData
|
|||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
return set.next();
|
return set.next();
|
||||||
}
|
} catch (SQLException throwables)
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -51,8 +53,7 @@ public class SQLPlayerData
|
|||||||
statement.setString(1, username);
|
statement.setString(1, username);
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
return set.next();
|
return set.next();
|
||||||
}
|
} catch (SQLException throwables)
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -103,8 +104,7 @@ public class SQLPlayerData
|
|||||||
plexPlayer.setCommandSpy(commandspy);
|
plexPlayer.setCommandSpy(commandspy);
|
||||||
}
|
}
|
||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
}
|
} catch (SQLException throwables)
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -148,8 +148,7 @@ public class SQLPlayerData
|
|||||||
return plexPlayer;
|
return plexPlayer;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
} catch (SQLException throwables)
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -171,44 +170,90 @@ public class SQLPlayerData
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
if (Plex.get().getStorageType() == StorageType.MARIADB)
|
||||||
{
|
{
|
||||||
PreparedStatement statement = con.prepareStatement("select * from `players` where json_search(ips, ?, ?) IS NOT NULL LIMIT 1");
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
statement.setString(1, "one");
|
|
||||||
statement.setString(2, ip);
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
|
|
||||||
PlexPlayer plexPlayer = null;
|
|
||||||
while (set.next())
|
|
||||||
{
|
{
|
||||||
String uuid = set.getString("uuid");
|
PreparedStatement statement = con.prepareStatement("select * from `players` where json_search(ips, ?, ?) IS NOT NULL LIMIT 1");
|
||||||
String name = set.getString("name");
|
statement.setString(1, "one");
|
||||||
String loginMSG = set.getString("login_msg");
|
statement.setString(2, ip);
|
||||||
String prefix = set.getString("prefix");
|
ResultSet set = statement.executeQuery();
|
||||||
String rankName = set.getString("rank").toUpperCase();
|
|
||||||
boolean adminActive = set.getBoolean("adminActive");
|
PlexPlayer plexPlayer = null;
|
||||||
long coins = set.getLong("coins");
|
while (set.next())
|
||||||
boolean vanished = set.getBoolean("vanished");
|
|
||||||
boolean commandspy = set.getBoolean("commandspy");
|
|
||||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
|
||||||
{
|
{
|
||||||
}.getType());
|
String uuid = set.getString("uuid");
|
||||||
plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
String name = set.getString("name");
|
||||||
plexPlayer.setName(name);
|
String loginMSG = set.getString("login_msg");
|
||||||
plexPlayer.setLoginMessage(loginMSG);
|
String prefix = set.getString("prefix");
|
||||||
plexPlayer.setPrefix(prefix);
|
String rankName = set.getString("rank").toUpperCase();
|
||||||
plexPlayer.setRank(rankName);
|
boolean adminActive = set.getBoolean("adminActive");
|
||||||
plexPlayer.setAdminActive(adminActive);
|
long coins = set.getLong("coins");
|
||||||
plexPlayer.setIps(ips);
|
boolean vanished = set.getBoolean("vanished");
|
||||||
plexPlayer.setCoins(coins);
|
boolean commandspy = set.getBoolean("commandspy");
|
||||||
plexPlayer.setVanished(vanished);
|
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||||
plexPlayer.setCommandSpy(commandspy);
|
{
|
||||||
|
}.getType());
|
||||||
|
plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
||||||
|
plexPlayer.setName(name);
|
||||||
|
plexPlayer.setLoginMessage(loginMSG);
|
||||||
|
plexPlayer.setPrefix(prefix);
|
||||||
|
plexPlayer.setRank(rankName);
|
||||||
|
plexPlayer.setAdminActive(adminActive);
|
||||||
|
plexPlayer.setIps(ips);
|
||||||
|
plexPlayer.setCoins(coins);
|
||||||
|
plexPlayer.setVanished(vanished);
|
||||||
|
plexPlayer.setCommandSpy(commandspy);
|
||||||
|
}
|
||||||
|
return plexPlayer;
|
||||||
|
} catch (SQLException throwables)
|
||||||
|
{
|
||||||
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
return plexPlayer;
|
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
||||||
}
|
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
PlexLog.warn("Querying a user by IP running SQLite can cause performance issues! Please try to switch to a remote DB ASAP!");
|
||||||
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
|
{
|
||||||
|
PreparedStatement statement = con.prepareStatement("select * from `players`");
|
||||||
|
ResultSet set = statement.executeQuery();
|
||||||
|
|
||||||
|
PlexPlayer plexPlayer = null;
|
||||||
|
while (set.next())
|
||||||
|
{
|
||||||
|
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||||
|
{
|
||||||
|
}.getType());
|
||||||
|
if (!ips.contains(ip))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String uuid = set.getString("uuid");
|
||||||
|
String name = set.getString("name");
|
||||||
|
String loginMSG = set.getString("login_msg");
|
||||||
|
String prefix = set.getString("prefix");
|
||||||
|
String rankName = set.getString("rank").toUpperCase();
|
||||||
|
boolean adminActive = set.getBoolean("adminActive");
|
||||||
|
long coins = set.getLong("coins");
|
||||||
|
boolean vanished = set.getBoolean("vanished");
|
||||||
|
boolean commandspy = set.getBoolean("commandspy");
|
||||||
|
|
||||||
|
plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
||||||
|
plexPlayer.setName(name);
|
||||||
|
plexPlayer.setLoginMessage(loginMSG);
|
||||||
|
plexPlayer.setPrefix(prefix);
|
||||||
|
plexPlayer.setRank(rankName);
|
||||||
|
plexPlayer.setAdminActive(adminActive);
|
||||||
|
plexPlayer.setIps(ips);
|
||||||
|
plexPlayer.setCoins(coins);
|
||||||
|
plexPlayer.setVanished(vanished);
|
||||||
|
plexPlayer.setCommandSpy(commandspy);
|
||||||
|
}
|
||||||
|
return plexPlayer;
|
||||||
|
} catch (SQLException throwables)
|
||||||
|
{
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -235,8 +280,7 @@ public class SQLPlayerData
|
|||||||
statement.setBoolean(9, player.isCommandSpy());
|
statement.setBoolean(9, player.isCommandSpy());
|
||||||
statement.setString(10, player.getUuid().toString());
|
statement.setString(10, player.getUuid().toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
} catch (SQLException throwables)
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -264,8 +308,7 @@ public class SQLPlayerData
|
|||||||
statement.setBoolean(9, player.isVanished());
|
statement.setBoolean(9, player.isVanished());
|
||||||
statement.setBoolean(10, player.isCommandSpy());
|
statement.setBoolean(10, player.isCommandSpy());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
}
|
} catch (SQLException throwables)
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
{
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,21 @@ public class PlexLog
|
|||||||
message = message.replace("{" + i + "}", strings[i].toString());
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.RED + "[Plex Error] " + ChatColor.GOLD + "%s", message));
|
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<red>[Plex Error] <gold>" + message));
|
||||||
|
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.RED + "[Plex Error] " + ChatColor.GOLD + "%s", message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warn(String message, Object... strings)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < strings.length; i++)
|
||||||
|
{
|
||||||
|
if (message.contains("{" + i + "}"))
|
||||||
|
{
|
||||||
|
message = message.replace("{" + i + "}", strings[i].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.YELLOW + "[Plex Warning] " + ChatColor.GOLD + "%s", message));
|
||||||
|
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<#eb7c0e>[Plex Warning] <gold>" + message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(String message, Object... strings)
|
public static void debug(String message, Object... strings)
|
||||||
@ -48,7 +62,8 @@ public class PlexLog
|
|||||||
}
|
}
|
||||||
if (Plex.get().config.getBoolean("debug"))
|
if (Plex.get().config.getBoolean("debug"))
|
||||||
{
|
{
|
||||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.DARK_PURPLE + "[Plex Debug] " + ChatColor.GOLD + "%s", message));
|
Bukkit.getConsoleSender().sendMessage(PlexUtils.mmDeserialize("<dark_purple>[Plex Debug] <gold>" + message));
|
||||||
|
// Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.DARK_PURPLE + "[Plex Debug] " + ChatColor.GOLD + "%s", message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user