Ajouts/suppression de librairies (sources) + Ajout support basique 1.10
- Transfert de la librairie com.luckycatlabs.sunrisesunset vers un autre module Pandacube. - Ajout de l'utilitaire OfflineUUID développé précédemment hors projet. - Ajout de Minecraft 1.10 dans l'enum des versions de Minecraft - Ajout d'une libraire d'accès aux anciens pseudos des joueurs - L'historique de login enregistre des informations supplémentaires (pseudo actuel, version de MC) - ORM : retrait des SuppressWarnings("rawtypes") et ajout des <?> pour retirer proprement ces warnings
This commit is contained in:
@@ -7,7 +7,8 @@ public enum MinecraftVersion {
|
||||
v1_9(107, "1.9"),
|
||||
v1_9_1(108, "1.9.1"),
|
||||
v1_9_2(109, "1.9.2"),
|
||||
v1_9_3_to_1_9_4(110, "1.9.3-1.9.4");
|
||||
v1_9_3_to_1_9_4(110, "1.9.3-1.9.4"),
|
||||
v1_10(210, "1.10");
|
||||
|
||||
public final int versionNumber;
|
||||
public final String versionDisplay;
|
||||
|
121
src/fr/pandacube/java/util/PlayerNameHistoryLookup.java
Normal file
121
src/fr/pandacube/java/util/PlayerNameHistoryLookup.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package fr.pandacube.java.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* This class performs a name lookup for a player and gets back all the name changes of the player (if any).
|
||||
* <br/><a href="https://bukkit.org/threads/player-name-history-lookup.412679/">https://bukkit.org/threads/player-name-history-lookup.412679/</a>
|
||||
* @since 25-3-2016
|
||||
* @author mine-care (AKA fillpant)
|
||||
*
|
||||
*/
|
||||
public class PlayerNameHistoryLookup {
|
||||
|
||||
/**
|
||||
* The URL from Mojang API that provides the JSON String in response.
|
||||
*/
|
||||
private static final String LOOKUP_URL = "https://api.mojang.com/user/profiles/%s/names";
|
||||
|
||||
private static final Gson JSON_PARSER = new Gson();
|
||||
|
||||
/**
|
||||
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread!It blocks while attempting to get a response from Mojang servers!</h1>
|
||||
* @param player The UUID of the player to be looked up.
|
||||
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||
* @throws IOException {@link #getPlayerPreviousNames(String)}
|
||||
*/
|
||||
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(UUID player) throws IOException {
|
||||
return getPlayerPreviousNames(player.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread! It blocks while attempting to get a response from Mojang servers!</h1>
|
||||
* Alternative method accepting an {@link OfflinePlayer} (and therefore {@link Player}) objects as parameter.
|
||||
* @param uuid The UUID String to lookup
|
||||
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||
* @throws IOException {@link #getRawJsonResponse(String)}
|
||||
*/
|
||||
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(String uuid) throws IOException {
|
||||
if (uuid == null || uuid.isEmpty())
|
||||
return null;
|
||||
uuid = uuid.replace("-", "");
|
||||
String response = getRawJsonResponse(new URL(String.format(LOOKUP_URL, uuid)));
|
||||
PreviousPlayerNameEntry[] names = JSON_PARSER.fromJson(response, PreviousPlayerNameEntry[].class);
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a helper method used to read the response of Mojang's API webservers.
|
||||
* @param u the URL to connect to
|
||||
* @return a String with the data read.
|
||||
* @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
|
||||
*/
|
||||
private static String getRawJsonResponse(URL u) throws IOException {
|
||||
HttpURLConnection con = (HttpURLConnection) u.openConnection();
|
||||
con.setDoInput(true);
|
||||
con.setConnectTimeout(2000);
|
||||
con.setReadTimeout(2000);
|
||||
con.connect();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
String response = in.readLine();
|
||||
in.close();
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class represents the typical response expected by Mojang servers when requesting the name history of a player.
|
||||
*/
|
||||
public class PreviousPlayerNameEntry {
|
||||
private String name;
|
||||
@SerializedName("changedToAt")
|
||||
private long changeTime;
|
||||
|
||||
/**
|
||||
* Gets the player name of this entry.
|
||||
* @return The name of the player.
|
||||
*/
|
||||
public String getPlayerName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time of change of the name.
|
||||
* <br><b>Note: This will return 0 if the name is the original (initial) name of the player! Make sure you check if it is 0 before handling!
|
||||
* <br>Parsing 0 to a Date will result in the date "01/01/1970".</b>
|
||||
* @return a timestamp in miliseconds that you can turn into a date or handle however you want :)
|
||||
*/
|
||||
public long getChangeTime() {
|
||||
return changeTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this name is the name used to register the account (the initial/original name)
|
||||
* @return a boolean, true if it is the the very first name of the player, otherwise false.
|
||||
*/
|
||||
public boolean isPlayersInitialName() {
|
||||
return getChangeTime() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Name: " + name + " Date of change: " + new Date(changeTime).toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println(Arrays.toString(getPlayerPreviousNames("a18d9b2c-e18f-4933-9e15-36452bc36857")));
|
||||
}
|
||||
|
||||
}
|
@@ -8,27 +8,28 @@ public class LoginHistoryElement extends SQLElement {
|
||||
|
||||
private long time;
|
||||
private String playerId;
|
||||
private String ip;
|
||||
private String ip = null;
|
||||
private ActionType actionType;
|
||||
private int nbOnline;
|
||||
private String playerName;
|
||||
private int minecraftVersion = 0;
|
||||
|
||||
|
||||
public LoginHistoryElement(long t, UUID pId, InetAddress IP, ActionType action, int nbO) {
|
||||
public LoginHistoryElement(long t, UUID pId, ActionType action, int nbO) {
|
||||
super("pandacube_login_history");
|
||||
setTime(t);
|
||||
setPlayerId(pId);
|
||||
setIp(IP);
|
||||
setActionType(action);
|
||||
setNbOnline(nbO);
|
||||
}
|
||||
|
||||
LoginHistoryElement(int id, long t, String pId, String IP, ActionType action, int nbO) {
|
||||
LoginHistoryElement(int id, long t, String pId, String ip, ActionType action, int nbO) {
|
||||
super("pandacube_login_history", id);
|
||||
if (IP == null || pId == null)
|
||||
throw new IllegalArgumentException("pId et IP ne peuvent être null");
|
||||
if (pId == null)
|
||||
throw new IllegalArgumentException("pId ne peuvent être null");
|
||||
setTime(t);
|
||||
playerId = pId;
|
||||
ip = IP;
|
||||
this.ip = ip;
|
||||
setActionType(action);
|
||||
setNbOnline(nbO);
|
||||
}
|
||||
@@ -40,7 +41,9 @@ public class LoginHistoryElement extends SQLElement {
|
||||
playerId,
|
||||
ip,
|
||||
actionType.toString(),
|
||||
Integer.toString(nbOnline)
|
||||
Integer.toString(nbOnline),
|
||||
playerName,
|
||||
Integer.toString(minecraftVersion)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -51,7 +54,9 @@ public class LoginHistoryElement extends SQLElement {
|
||||
"playerId",
|
||||
"ip",
|
||||
"actionType",
|
||||
"nbOnline"
|
||||
"nbOnline",
|
||||
"playerName",
|
||||
"minecraftVersion"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -82,8 +87,9 @@ public class LoginHistoryElement extends SQLElement {
|
||||
|
||||
public void setIp(InetAddress addr) {
|
||||
if (addr == null)
|
||||
throw new IllegalArgumentException("addr ne peut être null");
|
||||
ip = addr.getHostAddress();
|
||||
ip = null;
|
||||
else
|
||||
ip = addr.getHostAddress();
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +111,31 @@ public class LoginHistoryElement extends SQLElement {
|
||||
public void setNbOnline(int nbOnline) {
|
||||
this.nbOnline = nbOnline;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String pn) {
|
||||
playerName = pn;
|
||||
}
|
||||
|
||||
public int getMinecraftVersion() {
|
||||
return minecraftVersion;
|
||||
}
|
||||
|
||||
public void setMinecraftVersion(int m) {
|
||||
minecraftVersion = m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public enum ActionType {
|
||||
|
@@ -16,9 +16,11 @@ public class LoginHistoryTable extends SQLTable<LoginHistoryElement> {
|
||||
return "id INT AUTO_INCREMENT PRIMARY KEY,"
|
||||
+ "time BIGINT NOT NULL,"
|
||||
+ "playerId CHAR(36) NOT NULL,"
|
||||
+ "ip VARCHAR(128) NOT NULL,"
|
||||
+ "ip VARCHAR(128) NULL,"
|
||||
+ "actionType ENUM('LOGIN', 'LOGOUT') NOT NULL,"
|
||||
+ "nbOnline INT NOT NULL";
|
||||
+ "nbOnline INT NOT NULL,"
|
||||
+ "playerName VARCHAR(16) NULL,"
|
||||
+ "minecraftVersion INT NOT NULL DEFAULT 0";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,6 +32,8 @@ public class LoginHistoryTable extends SQLTable<LoginHistoryElement> {
|
||||
sqlResult.getString("ip"),
|
||||
ActionType.valueOf(sqlResult.getString("actionType")),
|
||||
sqlResult.getInt("nbOnline"));
|
||||
el.setPlayerName(sqlResult.getString("playerName"));
|
||||
el.setMinecraftVersion(sqlResult.getInt("minecraftVersion"));
|
||||
return el;
|
||||
}
|
||||
|
||||
|
@@ -22,8 +22,7 @@ import java.util.List;
|
||||
*/
|
||||
public final class ORM {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static List<SQLTable> tables = new ArrayList<SQLTable>();
|
||||
private static List<SQLTable<?>> tables = new ArrayList<SQLTable<?>>();
|
||||
|
||||
/* package */ static DBConnection connection;
|
||||
|
||||
@@ -39,18 +38,21 @@ public final class ORM {
|
||||
tables.add(new LoginHistoryTable());
|
||||
|
||||
tables.add(new ModoHistoryTable());
|
||||
|
||||
tables.add(new StaffTicketTable());
|
||||
|
||||
tables.add(new MPMessageTable());
|
||||
tables.add(new MPGroupTable());
|
||||
tables.add(new MPGroupUserTable());
|
||||
tables.add(new MPMessageTable());
|
||||
|
||||
tables.add(new OnlineShopHistoryTable());
|
||||
|
||||
tables.add(new PlayerTable());
|
||||
|
||||
tables.add(new PlayerIgnoreTable());
|
||||
|
||||
tables.add(new ShopStockTable());
|
||||
|
||||
tables.add(new StaffTicketTable());
|
||||
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -61,10 +63,9 @@ public final class ORM {
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public synchronized static <T extends SQLTable> T getTable(Class<T> c) {
|
||||
public synchronized static <T extends SQLTable<?>> T getTable(Class<T> c) {
|
||||
if (c == null) return null;
|
||||
for (SQLTable table : tables) {
|
||||
for (SQLTable<?> table : tables) {
|
||||
|
||||
if (c.isAssignableFrom(table.getClass())) {
|
||||
return c.cast(table);
|
||||
@@ -83,4 +84,12 @@ public final class ORM {
|
||||
private ORM() { } // rend la classe non instanciable
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user