mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-23 01:27:37 +00:00
find player by ip + reload system on /plex reload
This commit is contained in:
parent
d350ff4542
commit
6e768c0e0f
25
src/main/java/dev/plex/cache/DataUtils.java
vendored
25
src/main/java/dev/plex/cache/DataUtils.java
vendored
@ -53,6 +53,31 @@ public class DataUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a player from cache or from the database
|
||||||
|
*
|
||||||
|
* @param ip The IP address of the player.
|
||||||
|
* @return a PlexPlayer object
|
||||||
|
* @see PlexPlayer
|
||||||
|
*/
|
||||||
|
public static PlexPlayer getPlayerByIP(String ip)
|
||||||
|
{
|
||||||
|
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getIps().contains(ip)).findFirst().orElse(null);
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||||
|
{
|
||||||
|
return Plex.get().getMongoPlayerData().getByIP(ip);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Plex.get().getSqlPlayerData().getByIP(ip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a player from cache or from the database
|
* Gets a player from cache or from the database
|
||||||
*
|
*
|
||||||
|
@ -7,6 +7,8 @@ import dev.morphia.query.experimental.filters.Filters;
|
|||||||
import dev.morphia.query.experimental.updates.UpdateOperators;
|
import dev.morphia.query.experimental.updates.UpdateOperators;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +61,25 @@ public class MongoPlayerData
|
|||||||
return query2.first();
|
return query2.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player from cache or from mongo's database
|
||||||
|
*
|
||||||
|
* @param ip The IP address of the player.
|
||||||
|
* @return a PlexPlayer object
|
||||||
|
* @see PlexPlayer
|
||||||
|
*/
|
||||||
|
public PlexPlayer getByIP(String ip)
|
||||||
|
{
|
||||||
|
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getIps().contains(ip)).findFirst().orElse(null);
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
Query<PlexPlayer> query2 = datastore.find(PlexPlayer.class).filter(Filters.in("ips", Collections.singleton(ip)));
|
||||||
|
return query2.first();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a player's information in the mongo database
|
* Updates a player's information in the mongo database
|
||||||
*
|
*
|
||||||
|
56
src/main/java/dev/plex/cache/SQLPlayerData.java
vendored
56
src/main/java/dev/plex/cache/SQLPlayerData.java
vendored
@ -10,6 +10,7 @@ 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 java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL fetching utilities for players
|
* SQL fetching utilities for players
|
||||||
@ -92,6 +93,61 @@ public class SQLPlayerData
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player from cache or from the SQL database
|
||||||
|
*
|
||||||
|
* @param ip The IP address of the player.
|
||||||
|
* @return a PlexPlayer object
|
||||||
|
* @see PlexPlayer
|
||||||
|
*/
|
||||||
|
public PlexPlayer getByIP(String ip)
|
||||||
|
{
|
||||||
|
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getIps().contains(ip)).findFirst().orElse(null);
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||||
|
{
|
||||||
|
PreparedStatement statement = con.prepareStatement("select * from `players` where json_search(ips, ?, ?) IS NOT NULL LIMIT 1");
|
||||||
|
statement.setString(1, "one");
|
||||||
|
statement.setString(2, ip);
|
||||||
|
ResultSet set = statement.executeQuery();
|
||||||
|
|
||||||
|
PlexPlayer plexPlayer = null;
|
||||||
|
while (set.next())
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
long coins = set.getLong("coins");
|
||||||
|
boolean vanished = set.getBoolean("vanished");
|
||||||
|
boolean commandspy = set.getBoolean("commandspy");
|
||||||
|
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||||
|
{
|
||||||
|
}.getType());
|
||||||
|
plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
||||||
|
plexPlayer.setName(name);
|
||||||
|
plexPlayer.setLoginMessage(loginMSG);
|
||||||
|
plexPlayer.setPrefix(prefix);
|
||||||
|
plexPlayer.setRank(rankName);
|
||||||
|
plexPlayer.setIps(ips);
|
||||||
|
plexPlayer.setCoins(coins);
|
||||||
|
plexPlayer.setVanished(vanished);
|
||||||
|
plexPlayer.setCommandSpy(commandspy);
|
||||||
|
}
|
||||||
|
return plexPlayer;
|
||||||
|
}
|
||||||
|
catch (SQLException throwables)
|
||||||
|
{
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a player's information in the SQL database
|
* Updates a player's information in the SQL database
|
||||||
*
|
*
|
||||||
|
@ -50,6 +50,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
plugin.getRankManager().importDefaultRanks();
|
plugin.getRankManager().importDefaultRanks();
|
||||||
send(sender, "Imported ranks");
|
send(sender, "Imported ranks");
|
||||||
send(sender, "Plex successfully reloaded.");
|
send(sender, "Plex successfully reloaded.");
|
||||||
|
plugin.setSystem(plugin.config.getString("commands.permissions"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("redis"))
|
else if (args[0].equalsIgnoreCase("redis"))
|
||||||
|
Loading…
Reference in New Issue
Block a user