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:
@@ -6,7 +6,7 @@ public class BungeeMain extends Plugin {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
PandacubeUtil.setServerLogger(getProxy().getLogger());
|
||||
PandacubeUtil.setMasterLogger(getProxy().getLogger());
|
||||
PandacubeUtil.setPluginLogger(getLogger());
|
||||
}
|
||||
|
||||
|
@@ -1,25 +1,37 @@
|
||||
package fr.pandacube.java;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class PandacubeUtil {
|
||||
|
||||
|
||||
|
||||
public static final Charset NETWORK_CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
public static final int NETWORK_TCP_BUFFER_SIZE = 1024*1024;
|
||||
|
||||
public static final int NETWORK_TIMEOUT = 30*1000; // 30 secondes
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Représente le logger du serveur Spigot ou de Bungee,selon l'environnement
|
||||
*/
|
||||
private static Logger serverLogger;
|
||||
private static Logger masterLogger;
|
||||
|
||||
/**
|
||||
* Représente le logger de PandacubeUtil, mais défini selon l'environnement Spigot ou Bungee.
|
||||
*/
|
||||
private static Logger pluginLogger;
|
||||
|
||||
public static Logger getServerLogger() {
|
||||
return serverLogger;
|
||||
public static Logger getMasterLogger() {
|
||||
return masterLogger;
|
||||
}
|
||||
|
||||
public static void setServerLogger(Logger serverLogger) {
|
||||
PandacubeUtil.serverLogger = serverLogger;
|
||||
public static void setMasterLogger(Logger masterLogger) {
|
||||
PandacubeUtil.masterLogger = masterLogger;
|
||||
}
|
||||
|
||||
public static Logger getPluginLogger() {
|
||||
|
@@ -6,7 +6,7 @@ public class SpigotMain extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
PandacubeUtil.setServerLogger(getServer().getLogger());
|
||||
PandacubeUtil.setMasterLogger(getServer().getLogger());
|
||||
PandacubeUtil.setPluginLogger(getLogger());
|
||||
}
|
||||
|
||||
|
@@ -1,84 +0,0 @@
|
||||
package fr.pandacube.java.external_tools;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConvertToSQLBungeePerms {
|
||||
public static void main(String[] ç) throws Exception {
|
||||
|
||||
List<String> content = getFileLines(true, false, true, new File("convertToBungeePerms.txt"));
|
||||
FileOutputStream output = new FileOutputStream(new File("output.sql"));
|
||||
|
||||
|
||||
String currentSQLFormat = null;
|
||||
|
||||
|
||||
for (String line : content) {
|
||||
|
||||
if (line.startsWith("#sql:"))
|
||||
currentSQLFormat = line.substring("#sql:".length());
|
||||
else
|
||||
output.write(currentSQLFormat.replace("%%%perm%%%", line).concat("\n").getBytes());
|
||||
}
|
||||
|
||||
output.flush();
|
||||
output.close();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retourne toutes les lignes d'un fichier donné
|
||||
* @param ignoreEmpty <code>true</code> si on doit ignorer les lignes vides
|
||||
* @param ignoreHashtagComment <code>true</code> si on doit ignorer les lignes commentés (commençant par un #)
|
||||
* @param trimOutput <code>true</code> si on doit appeller la méthode String.trim() sur chaque ligne retournée
|
||||
* @param f le fichier à lire
|
||||
* @return la liste des lignes utiles
|
||||
* @throws IOException
|
||||
*/
|
||||
protected static List<String> getFileLines(boolean ignoreEmpty, boolean ignoreHashtagComment, boolean trimOutput, File f) throws IOException {
|
||||
if (!f.isFile())
|
||||
return null;
|
||||
|
||||
BufferedReader reader = new BufferedReader(new FileReader(f));
|
||||
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String trimmedLine = line.trim();
|
||||
|
||||
if (ignoreEmpty && trimmedLine.equals(""))
|
||||
continue;
|
||||
|
||||
if (ignoreHashtagComment && trimmedLine.startsWith("#"))
|
||||
continue;
|
||||
|
||||
if (trimOutput)
|
||||
lines.add(trimmedLine);
|
||||
else
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
|
||||
reader.close();
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
}
|
35
src/fr/pandacube/java/external_tools/OfflineUUID.java
Normal file
35
src/fr/pandacube/java/external_tools/OfflineUUID.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package fr.pandacube.java.external_tools;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
|
||||
public class OfflineUUID {
|
||||
public static void main(String[] args) {
|
||||
for (String arg : args)
|
||||
{
|
||||
System.out.println(""+arg+":"+getFromNickName(arg));
|
||||
}
|
||||
if (args.length == 0)
|
||||
throw new IllegalArgumentException("no argument given. Please give at least one argument.");
|
||||
}
|
||||
|
||||
public static UUID getFromNickName(String nickname)
|
||||
{
|
||||
String str = "OfflinePlayer:"+nickname;
|
||||
byte[] from_str = str.getBytes(Charset.forName("UTF-8"));
|
||||
return UUID.nameUUIDFromBytes(from_str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static UUID[] getFromNickName(String[] nicknames)
|
||||
{
|
||||
if (nicknames == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
UUID[] uuids = new UUID[nicknames.length];
|
||||
for (int i=0; i<nicknames.length; i++)
|
||||
uuids[i] = getFromNickName(nicknames[i]);
|
||||
return uuids;
|
||||
}
|
||||
}
|
@@ -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