From de056a35a5f9a328d61f1cb860003c729a0331f9 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 28 Dec 2016 00:54:06 +0100 Subject: [PATCH] =?UTF-8?q?Suppression=20de=20l'imprementation=20de=20l'OR?= =?UTF-8?q?M=20pour=20la=20basede=20donn=C3=A9es=20Pandacube.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les classes sont transféré dans un module privé. --- pom.xml | 7 - .../pandacube/java/util}/DateUtil.java | 47 +--- .../fr/pandacube/java/util/PlayerFinder.java | 208 ------------------ .../fr/pandacube/java/util/db/SQLContact.java | 43 ---- .../java/util/db/SQLForumCategorie.java | 25 --- .../pandacube/java/util/db/SQLForumForum.java | 36 --- .../pandacube/java/util/db/SQLForumPost.java | 41 ---- .../java/util/db/SQLForumThread.java | 45 ---- .../java/util/db/SQLLoginHistory.java | 48 ---- .../java/util/db/SQLLoginKickHistory.java | 42 ---- .../fr/pandacube/java/util/db/SQLMPGroup.java | 41 ---- .../java/util/db/SQLMPGroupUser.java | 63 ------ .../pandacube/java/util/db/SQLMPMessage.java | 137 ------------ .../java/util/db/SQLModoHistory.java | 57 ----- .../java/util/db/SQLOnlineshopHistory.java | 65 ------ .../java/util/db/SQLPingHistory.java | 30 --- .../fr/pandacube/java/util/db/SQLPlayer.java | 119 ---------- .../java/util/db/SQLPlayerIgnore.java | 91 -------- .../java/util/db/SQLPlayerTexture.java | 29 --- .../pandacube/java/util/db/SQLShopStock.java | 27 --- .../java/util/db/SQLStaffTicket.java | 50 ----- .../java/util/db/SQLStaticPages.java | 28 --- .../pandacube/java/util/db/SQLUUIDPlayer.java | 38 ---- .../pandacube/java/util/db/sql_tools/ORM.java | 53 +---- 24 files changed, 7 insertions(+), 1363 deletions(-) rename src/main/java/{com/earth2me/essentials/utils => fr/pandacube/java/util}/DateUtil.java (61%) delete mode 100644 src/main/java/fr/pandacube/java/util/PlayerFinder.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLContact.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLForumCategorie.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLForumForum.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLForumPost.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLForumThread.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLLoginHistory.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLLoginKickHistory.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLMPGroup.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLMPGroupUser.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLMPMessage.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLModoHistory.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLOnlineshopHistory.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLPingHistory.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLPlayer.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLPlayerIgnore.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLPlayerTexture.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLShopStock.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLStaffTicket.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLStaticPages.java delete mode 100644 src/main/java/fr/pandacube/java/util/db/SQLUUIDPlayer.java diff --git a/pom.xml b/pom.xml index 6cc291c..2793291 100644 --- a/pom.xml +++ b/pom.xml @@ -27,13 +27,6 @@ 1.11-SNAPSHOT compile - - fr.pandacube.local_dependencies - bungeeperms - 3.0-alpha1-modif - system - ${project.basedir}/../libs/BungeePerms-3.0-alpha1-modif.jar - org.javatuples javatuples diff --git a/src/main/java/com/earth2me/essentials/utils/DateUtil.java b/src/main/java/fr/pandacube/java/util/DateUtil.java similarity index 61% rename from src/main/java/com/earth2me/essentials/utils/DateUtil.java rename to src/main/java/fr/pandacube/java/util/DateUtil.java index c1d8feb..b5d5af2 100644 --- a/src/main/java/com/earth2me/essentials/utils/DateUtil.java +++ b/src/main/java/fr/pandacube/java/util/DateUtil.java @@ -1,4 +1,4 @@ -package com.earth2me.essentials.utils; +package fr.pandacube.java.util; import java.util.Calendar; import java.util.GregorianCalendar; @@ -6,6 +6,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class DateUtil { + + /** + * @see {@link com.earth2me.essentials.utils.DateUtil#parseDateDiff(String, boolean)} + */ public static long parseDateDiff(String time, boolean future) throws Exception { Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" @@ -53,45 +57,4 @@ public class DateUtil { return c.getTimeInMillis(); } - static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future) { - int diff = 0; - long savedDate = fromDate.getTimeInMillis(); - while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate))) { - savedDate = fromDate.getTimeInMillis(); - fromDate.add(type, future ? 1 : -1); - diff++; - } - diff--; - fromDate.setTimeInMillis(savedDate); - return diff; - } - - public static String formatDateDiff(long date) { - Calendar c = new GregorianCalendar(); - c.setTimeInMillis(date); - Calendar now = new GregorianCalendar(); - return DateUtil.formatDateDiff(now, c); - } - - public static String formatDateDiff(Calendar fromDate, Calendar toDate) { - boolean future = false; - if (toDate.equals(fromDate)) return "now"; - if (toDate.after(fromDate)) future = true; - StringBuilder sb = new StringBuilder(); - int[] types = new int[] { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, - Calendar.MINUTE, Calendar.SECOND }; - String[] names = new String[] { "year", "years", "month", "months", "day", "days", "hour", "hours", "minute", - "minutes", "second", "seconds" }; - int accuracy = 0; - for (int i = 0; i < types.length; i++) { - if (accuracy > 2) break; - int diff = dateDiff(types[i], fromDate, toDate, future); - if (diff > 0) { - accuracy++; - sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]); - } - } - if (sb.length() == 0) return "now"; - return sb.toString().trim(); - } } diff --git a/src/main/java/fr/pandacube/java/util/PlayerFinder.java b/src/main/java/fr/pandacube/java/util/PlayerFinder.java deleted file mode 100644 index f5d2853..0000000 --- a/src/main/java/fr/pandacube/java/util/PlayerFinder.java +++ /dev/null @@ -1,208 +0,0 @@ -package fr.pandacube.java.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import fr.pandacube.java.util.db.SQLLoginHistory; -import fr.pandacube.java.util.db.SQLPlayer; -import fr.pandacube.java.util.db.SQLUUIDPlayer; -import fr.pandacube.java.util.db.sql_tools.ORM; -import fr.pandacube.java.util.db.sql_tools.SQLOrderBy; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereLike; -import fr.pandacube.java.util.db.sql_tools.SQLOrderBy.Direction; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; -import net.alpenblock.bungeeperms.BungeePerms; - -/* - * Etape de recherche de joueur : - * Passer par bungeeperms (si accessible) - * utiliser directement la table pseudo <-> uuid - * chercher dans l'historique de login - */ -public class PlayerFinder { - - private static BungeePerms getPermPlugin() { - try { - return BungeePerms.getInstance(); - } catch (NoClassDefFoundError | Exception e) { - return null; - } - - } - - public static String getLastKnownName(UUID id) { - if (id == null) return null; - - // on passe par le plugin de permission (mise en cache ? ) - BungeePerms pl = getPermPlugin(); - if (pl != null) return pl.getPermissionsManager().getUUIDPlayerDB().getPlayerName(id); - - // on tente en accédant directement à la table des identifiants - try { - SQLUUIDPlayer el = ORM.getFirst(SQLUUIDPlayer.class, - new SQLWhereComp(SQLUUIDPlayer.uuid, SQLComparator.EQ, id.toString()), null); - if (el != null) return el.get(SQLUUIDPlayer.player); - } catch (Exception e) { - Log.severe("Can't search for player name from uuid in database", e); - } - - // le pseudo est introuvable - return null; - } - - public static List getLocalNameHistory(UUID id) { - List ret = new ArrayList<>(); - - if (id == null) return ret; - - String last = getLastKnownName(id); - if (last != null) ret.add(last); - - try { - List els = ORM.getAll(SQLLoginHistory.class, - new SQLWhereComp(SQLLoginHistory.playerId, SQLComparator.EQ, id.toString()), - new SQLOrderBy().addField(SQLLoginHistory.time, Direction.DESC), null, null); - - for (SQLLoginHistory el : els) { - String name = el.get(SQLLoginHistory.playerName); - if (ret.contains(name)) continue; - ret.add(name); - } - - } catch (Exception e) { - Log.severe("Can't search for olds players names from uuid in database", e); - } - - return ret; - - } - - /** - * Cherche un identifiant de compte en se basant sur le pseudo passé en - * paramètre. La méthode - * cherchera d'abord dans les derniers pseudos connus. Puis, cherchera la - * dernière personne à - * s'être connecté avec ce pseudo sur le serveur. - * - * @param exactName le pseudo complet, insensible à la casse, et dans un - * format de pseudo valide - * @param old si on doit chercher dans les anciens pseudos de joueurs - * @return l'UUID du joueur si trouvé, null sinon - */ - public static UUID getPlayerId(String exactName, boolean old) { - if (!isValidPlayerName(exactName)) return null; // évite une recherche - // inutile dans la base - // de donnée - - // on tente d'abord via le plugin de permission - BungeePerms pl = getPermPlugin(); - if (pl != null) return pl.getPermissionsManager().getUUIDPlayerDB().getUUID(exactName); - - // on tente en accédant directement à la table des identifiants - try { - SQLUUIDPlayer el = ORM.getFirst(SQLUUIDPlayer.class, - new SQLWhereLike(SQLUUIDPlayer.player, exactName.replace("_", "\\_")), null); - if (el != null) return el.getUUID(); - } catch (Exception e) { - Log.severe("Can't search for uuid from player name in database", e); - } - - if (!old) return null; - - // on recherche dans les anciens pseudos - try { - SQLLoginHistory el = ORM.getFirst(SQLLoginHistory.class, - new SQLWhereLike(SQLLoginHistory.playerName, exactName.replace("_", "\\_")), - new SQLOrderBy().addField(SQLLoginHistory.time, Direction.DESC)); - if (el != null) return el.getPlayerId(); - } catch (Exception e) { - Log.severe("Can't search for uuid from old player name in database", e); - } - - // on a pas trouvé - return null; - - } - - /** - * - * @param query le pseudo, partiel ou complet, insensible à la casse, qu'on - * recherche - * @param old si on cherche aussi dans les anciens pseudos - * @return - */ - public static List searchForPlayers(String query, boolean old) { - List res = new ArrayList<>(); - - if (!isValidPlayerName(query)) return res; - - // rechercher parmis les derniers pseudos connus de chaque joueurs - try { - List els = ORM.getAll(SQLUUIDPlayer.class, - new SQLWhereLike(SQLUUIDPlayer.player, "%" + query.replace("_", "\\_") + "%"), null, null, null); - - for (SQLUUIDPlayer el : els) - res.add(new PlayerSearchResult(el.getUUID(), el.get(SQLUUIDPlayer.player), null)); - - } catch (Exception e) { - Log.severe("Can't search for players names in database", e); - } - - if (!old) return res; - - // rechercher parmi les anciens pseudos de joueurs - try { - List els = ORM.getAll(SQLLoginHistory.class, - new SQLWhereLike(SQLLoginHistory.playerName, "%" + query.replace("_", "\\_") + "%"), - new SQLOrderBy().addField(SQLLoginHistory.time, Direction.DESC), null, null); - - for (SQLLoginHistory el : els) { - if (res.contains(new PlayerSearchResult(el.getPlayerId(), null, null))) continue; - res.add(new PlayerSearchResult(el.getPlayerId(), getLastKnownName(el.getPlayerId()), - el.get(SQLLoginHistory.playerName))); - } - - } catch (Exception e) { - Log.severe("Can't search for uuid from player name in database", e); - } - - return res; - } - - public static class PlayerSearchResult { - public final UUID uuid; - public String lastName; - public final String nameFound; - - PlayerSearchResult(UUID id, String last, String found) { - uuid = id; - lastName = last; - nameFound = found; - } - - @Override - public boolean equals(Object o) { - if (o == null || !(o instanceof PlayerSearchResult)) return false; - return uuid.equals(((PlayerSearchResult) o).uuid); - } - - @Override - public int hashCode() { - return uuid.hashCode(); - } - } - - public static boolean isValidPlayerName(String name) { - if (name == null) return false; - return name.matches("[0-9a-zA-Z_]{2,16}"); - } - - public static SQLPlayer getDBPlayer(UUID id) throws Exception { - if (id == null) return null; - return ORM.getFirst(SQLPlayer.class, new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, id.toString()), - null); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLContact.java b/src/main/java/fr/pandacube/java/util/db/SQLContact.java deleted file mode 100644 index c95b558..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLContact.java +++ /dev/null @@ -1,43 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLContact extends SQLElement { - - public SQLContact() { - super(); - } - - public SQLContact(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_contact"; - } - - public static final SQLField time = new SQLField<>("time", SQLType.INT, false); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), true, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField userName = new SQLField<>("userName", SQLType.VARCHAR(50), true); - public static final SQLField userMail = new SQLField<>("userMail", SQLType.VARCHAR(50), true); - public static final SQLField titre = new SQLField<>("titre", SQLType.VARCHAR(100), false); - public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); - public static final SQLField hidden = new SQLField<>("hidden", SQLType.BOOLEAN, false, (Boolean) false); - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLForumCategorie.java b/src/main/java/fr/pandacube/java/util/db/SQLForumCategorie.java deleted file mode 100644 index d3a9252..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLForumCategorie.java +++ /dev/null @@ -1,25 +0,0 @@ -package fr.pandacube.java.util.db; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLForumCategorie extends SQLElement { - - public SQLForumCategorie() { - super(); - } - - public SQLForumCategorie(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_forum_categorie"; - } - - public static final SQLField nom = new SQLField<>("nom", SQLType.VARCHAR(100), false); - public static final SQLField ordre = new SQLField<>("ordre", SQLType.INT, false); - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLForumForum.java b/src/main/java/fr/pandacube/java/util/db/SQLForumForum.java deleted file mode 100644 index 6be9eaf..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLForumForum.java +++ /dev/null @@ -1,36 +0,0 @@ -package fr.pandacube.java.util.db; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLForumForum extends SQLElement { - - public SQLForumForum() { - super(); - } - - public SQLForumForum(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_forum_forum"; - } - - public static final SQLFKField catId = SQLFKField.idFK("catId", SQLType.INT, false, - SQLForumCategorie.class); - public static final SQLField nom = new SQLField<>("nom", SQLType.VARCHAR(100), false); - public static final SQLField description = new SQLField<>("description", SQLType.TEXT, false); - public static final SQLField ordre = new SQLField<>("ordre", SQLType.INT, false); - public static final SQLField authView = new SQLField<>("authView", SQLType.INT, false); - public static final SQLField authPost = new SQLField<>("authPost", SQLType.INT, false); - public static final SQLField authThread = new SQLField<>("authThread", SQLType.INT, false); - public static final SQLField authAnchored = new SQLField<>("authAnchored", SQLType.INT, false); - public static final SQLField authModo = new SQLField<>("authModo", SQLType.INT, false); - public static final SQLField nbThreads = new SQLField<>("nbThreads", SQLType.INT, false); - public static final SQLField nbMessages = new SQLField<>("nbMessages", SQLType.INT, false); - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLForumPost.java b/src/main/java/fr/pandacube/java/util/db/SQLForumPost.java deleted file mode 100644 index f606cb2..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLForumPost.java +++ /dev/null @@ -1,41 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLForumPost extends SQLElement { - - public SQLForumPost() { - super(); - } - - public SQLForumPost(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_forum_post"; - } - - public static final SQLField createur = new SQLField<>("createur", SQLType.CHAR(36), false); - public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); - public static final SQLField time = new SQLField<>("time", SQLType.INT, false); - public static final SQLFKField threadId = SQLFKField.idFK("threadId", SQLType.INT, false, - SQLForumThread.class); - public static final SQLField moderated = new SQLField<>("moderated", SQLType.BOOLEAN, false); - - public UUID getCreateurId() { - String id = get(createur); - return (id == null) ? null : UUID.fromString(id); - } - - public void setCreateurId(UUID pName) { - set(createur, (pName == null) ? (String) null : pName.toString()); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLForumThread.java b/src/main/java/fr/pandacube/java/util/db/SQLForumThread.java deleted file mode 100644 index f39dc17..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLForumThread.java +++ /dev/null @@ -1,45 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLForumThread extends SQLElement { - - public SQLForumThread() { - super(); - } - - public SQLForumThread(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_forum_thread"; - } - - public static final SQLFKField forumId = SQLFKField.idFK("forumId", SQLType.INT, false, - SQLForumForum.class); - public static final SQLField titre = new SQLField<>("titre", SQLType.VARCHAR(60), false); - public static final SQLFKField createur = new SQLFKField<>("createur", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField vu = new SQLField<>("vu", SQLType.INT, false); - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLField anchored = new SQLField<>("anchored", SQLType.BOOLEAN, false); - public static final SQLField locked = new SQLField<>("locked", SQLType.BOOLEAN, false); - public static final SQLField nbMessages = new SQLField<>("nbMessages", SQLType.INT, false); - - public UUID getCreateurId() { - String id = get(createur); - return (id == null) ? null : UUID.fromString(id); - } - - public void setCreateurId(UUID pName) { - set(createur, (pName == null) ? (String) null : pName.toString()); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLLoginHistory.java b/src/main/java/fr/pandacube/java/util/db/SQLLoginHistory.java deleted file mode 100644 index 7abd3d8..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLLoginHistory.java +++ /dev/null @@ -1,48 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLLoginHistory extends SQLElement { - - public SQLLoginHistory() { - super(); - } - - public SQLLoginHistory(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_login_history"; - } - - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField ip = new SQLField<>("ip", SQLType.VARCHAR(128), true); - public static final SQLField actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class), - false); - public static final SQLField nbOnline = new SQLField<>("nbOnline", SQLType.INT, false); - public static final SQLField playerName = new SQLField<>("playerName", SQLType.VARCHAR(16), true); - public static final SQLField minecraftVersion = new SQLField<>("minecraftVersion", SQLType.INT, false, 0); - public static final SQLField hostName = new SQLField<>("hostName", SQLType.VARCHAR(128), true); - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } - - public enum ActionType { - LOGIN, LOGOUT - } -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLLoginKickHistory.java b/src/main/java/fr/pandacube/java/util/db/SQLLoginKickHistory.java deleted file mode 100644 index 068caf0..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLLoginKickHistory.java +++ /dev/null @@ -1,42 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLLoginKickHistory extends SQLElement { - - public SQLLoginKickHistory() { - super(); - } - - public SQLLoginKickHistory(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_loginkick_history"; - } - - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField ip = new SQLField<>("ip", SQLType.VARCHAR(128), true); - public static final SQLField playerName = new SQLField<>("playerName", SQLType.VARCHAR(16), true); - public static final SQLField minecraftVersion = new SQLField<>("minecraftVersion", SQLType.INT, false, 0); - public static final SQLField hostName = new SQLField<>("hostName", SQLType.VARCHAR(128), true); - public static final SQLField kickReason = new SQLField<>("kickReason", SQLType.VARCHAR(512), true); - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLMPGroup.java b/src/main/java/fr/pandacube/java/util/db/SQLMPGroup.java deleted file mode 100644 index 7230167..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLMPGroup.java +++ /dev/null @@ -1,41 +0,0 @@ -package fr.pandacube.java.util.db; - -import fr.pandacube.java.util.db.sql_tools.ORM; -import fr.pandacube.java.util.db.sql_tools.ORMException; -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLElementList; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLOrderBy; -import fr.pandacube.java.util.db.sql_tools.SQLType; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; - -public class SQLMPGroup extends SQLElement { - - public SQLMPGroup() { - super(); - } - - public SQLMPGroup(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_mp_group"; - } - - public static final SQLField groupName = new SQLField<>("groupName", SQLType.VARCHAR(16), false); - - public SQLElementList getGroupUsers() throws ORMException { - return ORM.getAll(SQLMPGroupUser.class, new SQLWhereComp(SQLMPGroupUser.groupId, SQLComparator.EQ, getId()), - new SQLOrderBy().addField(ORM.getSQLIdField(SQLMPGroupUser.class)), null, null); - } - - public static SQLMPGroup getByName(String name) throws ORMException { - if (name == null) return null; - - return ORM.getFirst(SQLMPGroup.class, new SQLWhereComp(groupName, SQLComparator.EQ, name), null); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLMPGroupUser.java b/src/main/java/fr/pandacube/java/util/db/SQLMPGroupUser.java deleted file mode 100644 index bfaefd1..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLMPGroupUser.java +++ /dev/null @@ -1,63 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.sql.SQLException; -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.ORM; -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLType; -import fr.pandacube.java.util.db.sql_tools.SQLWhereChain; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; - -public class SQLMPGroupUser extends SQLElement { - - public SQLMPGroupUser() { - super(); - } - - public SQLMPGroupUser(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_mp_group_user"; - } - - public static final SQLFKField groupId = SQLFKField.idFK("groupId", SQLType.INT, false, - SQLMPGroup.class); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - - // TODO ajouter un champ qui dit si le joueur est admin du groupe - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID id) { - set(playerId, (id == null) ? null : id.toString()); - } - - /** - * Retourne l'instance de SQLMPGroupUser correcpondant à la présence d'un - * joueur dans un groupe - * - * @param group le groupe concerné, sous forme d'instance de SQLMPGroup - * @param player l'identifiant du joueur - * @return null si la correspondance n'a pas été trouvée - * @throws SQLException - */ - public static SQLMPGroupUser getPlayerInGroup(SQLMPGroup group, UUID player) throws Exception { - if (player == null || group == null) return null; - return ORM.getFirst(SQLMPGroupUser.class, - new SQLWhereChain(SQLBoolOp.AND).add(new SQLWhereComp(groupId, SQLComparator.EQ, group.getId())) - .add(new SQLWhereComp(playerId, SQLComparator.EQ, player.toString())), - null); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLMPMessage.java b/src/main/java/fr/pandacube/java/util/db/SQLMPMessage.java deleted file mode 100644 index 2fce2e9..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLMPMessage.java +++ /dev/null @@ -1,137 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.PlayerFinder; -import fr.pandacube.java.util.db.sql_tools.ORM; -import fr.pandacube.java.util.db.sql_tools.ORMException; -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLElementList; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLOrderBy; -import fr.pandacube.java.util.db.sql_tools.SQLType; -import fr.pandacube.java.util.db.sql_tools.SQLWhereChain; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereLike; -import fr.pandacube.java.util.db.sql_tools.SQLWhereNull; -import fr.pandacube.java.util.db.sql_tools.SQLOrderBy.Direction; -import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; - -public class SQLMPMessage extends SQLElement { - - public SQLMPMessage() { - super(); - } - - public SQLMPMessage(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_mp_message"; - } - - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLField securityKey = new SQLField<>("securityKey", SQLType.INT, false); - public static final SQLFKField viewerId = new SQLFKField<>("viewerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLFKField sourceId = new SQLFKField<>("sourceId", SQLType.CHAR(36), true, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLFKField destId = new SQLFKField<>("destId", SQLType.CHAR(36), true, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLFKField destGroup = SQLFKField.idFK("destGroup", SQLType.INT, true, - SQLMPGroup.class); - public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(512), false); - public static final SQLField wasRead = new SQLField<>("wasRead", SQLType.BOOLEAN, false); - public static final SQLField deleted = new SQLField<>("deleted", SQLType.BOOLEAN, false, (Boolean) false); - public static final SQLField serverSync = new SQLField<>("serverSync", SQLType.BOOLEAN, false); - - public UUID getViewerId() { - String id = get(viewerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setViewerId(UUID id) { - set(viewerId, (id == null) ? null : id.toString()); - } - - public UUID getSourceId() { - String id = get(sourceId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setSourceId(UUID id) { - set(sourceId, (id == null) ? null : id.toString()); - } - - public UUID getDestId() { - String id = get(destId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setDestId(UUID id) { - set(destId, (id == null) ? null : id.toString()); - } - - public static SQLElementList getAllUnsyncMessage() throws ORMException { - return ORM.getAll(SQLMPMessage.class, new SQLWhereComp(SQLMPMessage.serverSync, SQLComparator.EQ, false), - new SQLOrderBy().addField(SQLMPMessage.time), null, null); - } - - public static SQLElementList getAllUnreadForPlayer(UUID player) throws ORMException { - return getForPlayer(player, true, null, false); - } - - public static SQLElementList getOneDiscussionForPlayer(UUID player, Object discussion, - Integer numberLast, boolean revert) throws ORMException { - if (player == null) return null; - if (discussion != null && !(discussion instanceof String) && !(discussion instanceof UUID)) return null; - if (discussion != null && discussion instanceof String - && !PlayerFinder.isValidPlayerName(discussion.toString())) - return null; - - SQLWhereChain where = new SQLWhereChain(SQLBoolOp.AND) - .add(new SQLWhereComp(SQLMPMessage.viewerId, SQLComparator.EQ, player.toString())); - if (discussion == null) // message de système - where.add(new SQLWhereNull(SQLMPMessage.sourceId, true)) - .add(new SQLWhereNull(SQLMPMessage.destGroup, true)); - else if (discussion instanceof String) { // message de groupe - SQLMPGroup groupEl = ORM.getFirst(SQLMPGroup.class, - new SQLWhereComp(SQLMPGroup.groupName, SQLComparator.EQ, (String) discussion), null); - if (groupEl == null) return null; - where.add(new SQLWhereComp(SQLMPMessage.destGroup, SQLComparator.EQ, groupEl.getId())); - } - else if (discussion instanceof UUID && discussion.equals(player)) // message - // à - // lui - // même - where.add(new SQLWhereLike(SQLMPMessage.destId, discussion.toString())) - .add(new SQLWhereLike(SQLMPMessage.sourceId, discussion.toString())) - .add(new SQLWhereNull(SQLMPMessage.destGroup, true)); - else // discussion instanceof UUID - where.add(new SQLWhereChain(SQLBoolOp.OR).add(new SQLWhereLike(SQLMPMessage.destId, discussion.toString())) - .add(new SQLWhereLike(SQLMPMessage.sourceId, discussion.toString()))) - .add(new SQLWhereNull(SQLMPMessage.destGroup, true)); - - SQLOrderBy orderBy = new SQLOrderBy().addField(SQLMPMessage.time, revert ? Direction.DESC : Direction.ASC); - - return ORM.getAll(SQLMPMessage.class, where, orderBy, numberLast, null); - } - - public static SQLElementList getForPlayer(UUID player, boolean onlyUnread, Integer numberLast, - boolean revert) throws ORMException { - if (player == null) return null; - - SQLWhereChain where = new SQLWhereChain(SQLBoolOp.AND); - where.add(new SQLWhereComp(SQLMPMessage.viewerId, SQLComparator.EQ, player.toString())); - if (onlyUnread) where.add(new SQLWhereComp(SQLMPMessage.wasRead, SQLComparator.EQ, false)); - - SQLOrderBy orderBy = new SQLOrderBy().addField(SQLMPMessage.time, revert ? Direction.DESC : Direction.ASC); - - return ORM.getAll(SQLMPMessage.class, where, orderBy, numberLast, null); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLModoHistory.java b/src/main/java/fr/pandacube/java/util/db/SQLModoHistory.java deleted file mode 100644 index de47b68..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLModoHistory.java +++ /dev/null @@ -1,57 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLModoHistory extends SQLElement { - - public SQLModoHistory() { - super(); - } - - public SQLModoHistory(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_modo_history"; - } - - public static final SQLFKField modoId = new SQLFKField<>("modoId", SQLType.CHAR(36), true, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField actionType = new SQLField<>("actionType", SQLType.ENUM(ActionType.class), - false); - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField value = new SQLField<>("value", SQLType.BIGINT, true); - public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(2048), false); - - public UUID getModoId() { - String id = get(modoId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setModoId(UUID pName) { - set(modoId, (pName == null) ? (String) null : pName.toString()); - } - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } - - public enum ActionType { - BAN, UNBAN, MUTE, UNMUTE, REPORT, KICK - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLOnlineshopHistory.java b/src/main/java/fr/pandacube/java/util/db/SQLOnlineshopHistory.java deleted file mode 100644 index 595ae8d..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLOnlineshopHistory.java +++ /dev/null @@ -1,65 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLOnlineshopHistory extends SQLElement { - - public SQLOnlineshopHistory() { - super(); - } - - public SQLOnlineshopHistory(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_onlineshop_history"; - } - - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLField transactionId = new SQLField<>("transactionId", SQLType.VARCHAR(255), true); - public static final SQLField sourceType = new SQLField<>("sourceType", SQLType.ENUM(SourceType.class), - false); - public static final SQLFKField sourcePlayerId = new SQLFKField<>("sourcePlayerId", - SQLType.CHAR(36), true, SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField sourceQuantity = new SQLField<>("sourceQuantity", SQLType.DOUBLE, false); - public static final SQLField sourceName = new SQLField<>("sourceName", SQLType.VARCHAR(64), false); - public static final SQLField destType = new SQLField<>("destType", SQLType.ENUM(DestType.class), false); - public static final SQLFKField destPlayerId = new SQLFKField<>("destPlayerId", SQLType.CHAR(36), - false, SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField destQuantity = new SQLField<>("destQuantity", SQLType.DOUBLE, false); - public static final SQLField destName = new SQLField<>("destName", SQLType.VARCHAR(64), false); - - public UUID getSourcePlayerId() { - String id = get(sourcePlayerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setSourcePlayerId(UUID pName) { - set(sourcePlayerId, (pName == null) ? (String) null : pName.toString()); - } - - public UUID getDestPlayerId() { - String id = get(destPlayerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setDestPlayerId(UUID pName) { - set(destPlayerId, (pName == null) ? (String) null : pName.toString()); - } - - public static enum SourceType { - REAL_MONEY, BAMBOU - } - - public static enum DestType { - BAMBOU, GRADE - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLPingHistory.java b/src/main/java/fr/pandacube/java/util/db/SQLPingHistory.java deleted file mode 100644 index 8f918f8..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLPingHistory.java +++ /dev/null @@ -1,30 +0,0 @@ -package fr.pandacube.java.util.db; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLPingHistory extends SQLElement { - - public SQLPingHistory() { - super(); - } - - public SQLPingHistory(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_ping_history"; - } - - - - public static final SQLField time = new SQLField<>("time", SQLType.BIGINT, false); - public static final SQLField ip = new SQLField<>("ip", SQLType.VARCHAR(128), true); - public static final SQLField minecraftVersion = new SQLField<>("minecraftVersion", SQLType.INT, false, 0); - public static final SQLField hostName = new SQLField<>("hostName", SQLType.VARCHAR(128), true); - - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLPlayer.java b/src/main/java/fr/pandacube/java/util/db/SQLPlayer.java deleted file mode 100644 index f969432..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLPlayer.java +++ /dev/null @@ -1,119 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.sql.Date; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.ORM; -import fr.pandacube.java.util.db.sql_tools.ORMException; -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLElementList; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; -import fr.pandacube.java.util.db.sql_tools.SQLWhereChain; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; - -public class SQLPlayer extends SQLElement { - - public SQLPlayer() { - super(); - } - - public SQLPlayer(int id) { - super(id); - } - - /* - * Nom de la table - */ - @Override - protected String tableName() { - return "pandacube_player"; - } - - /* - * Champs de la table - */ - public static final SQLField playerId = new SQLField<>("playerId", SQLType.CHAR(36), false); - public static final SQLField token = new SQLField<>("token", SQLType.CHAR(36), true); - public static final SQLField mailCheck = new SQLField<>("mailCheck", SQLType.VARCHAR(255), true); - public static final SQLField password = new SQLField<>("password", SQLType.VARCHAR(255), true); - public static final SQLField mail = new SQLField<>("mail", SQLType.VARCHAR(255), true); - public static final SQLField playerDisplayName = new SQLField<>("playerDisplayName", SQLType.VARCHAR(255), - false); - public static final SQLField firstTimeInGame = new SQLField<>("firstTimeInGame", SQLType.BIGINT, false, 0L); - public static final SQLField timeWebRegister = new SQLField<>("timeWebRegister", SQLType.BIGINT, true); - public static final SQLField lastTimeInGame = new SQLField<>("lastTimeInGame", SQLType.BIGINT, true); - public static final SQLField lastWebActivity = new SQLField<>("lastWebActivity", SQLType.BIGINT, false, 0L); - public static final SQLField onlineInServer = new SQLField<>("onlineInServer", SQLType.VARCHAR(32), true); - public static final SQLField skinURL = new SQLField<>("skinURL", SQLType.VARCHAR(255), true); - public static final SQLField isVanish = new SQLField<>("isVanish", SQLType.BOOLEAN, false, - (Boolean) false); - public static final SQLField birthday = new SQLField<>("birthday", SQLType.DATE, true); - public static final SQLField lastYearCelebBday = new SQLField<>("lastYearCelebratedBirthday", SQLType.INT, - false, 0); - public static final SQLField banTimeout = new SQLField<>("banTimeout", SQLType.BIGINT, true); - public static final SQLField muteTimeout = new SQLField<>("muteTimeout", SQLType.BIGINT, true); - public static final SQLField isWhitelisted = new SQLField<>("isWhitelisted", SQLType.BOOLEAN, false, - (Boolean) false); - public static final SQLField bambou = new SQLField<>("bambou", SQLType.BIGINT, false, 0L); - public static final SQLField grade = new SQLField<>("grade", SQLType.VARCHAR(36), false, "default"); - - /* - * Getteurs spécifique (encapsulation) - */ - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public UUID getToken() { - String id = get(token); - return (id == null) ? null : UUID.fromString(id); - } - - /* - * Setteurs spécifique (encapsulation) - */ - - public void setPlayerId(UUID pName) { - set(playerId, (pName == null) ? (String) null : pName.toString()); - } - - public void setToken(UUID t) { - set(token, (t == null) ? (String) null : t.toString()); - } - - - - - - public static SQLPlayer getPlayerFromUUID(UUID playerId) throws ORMException { - return ORM.getFirst(SQLPlayer.class, - new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, playerId.toString()), null); - } - - - public static SQLElementList getPlayersFromUUIDs(Set playerIds) throws ORMException { - Set uuidsString = new HashSet<>(); - for (UUID id : playerIds) - uuidsString.add(id.toString()); - return getPlayersFromUUIDStr(uuidsString); - } - - public static SQLElementList getPlayersFromUUIDStr(Set playerIds) throws ORMException { - - SQLWhereChain where = new SQLWhereChain(SQLBoolOp.OR); - for (String userId : playerIds) { - where.add(new SQLWhereComp(SQLPlayer.playerId, SQLComparator.EQ, userId)); - } - - return ORM.getAll(SQLPlayer.class, where, null, null, null); - - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLPlayerIgnore.java b/src/main/java/fr/pandacube/java/util/db/SQLPlayerIgnore.java deleted file mode 100644 index 256c3e1..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLPlayerIgnore.java +++ /dev/null @@ -1,91 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.Map; -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.ORM; -import fr.pandacube.java.util.db.sql_tools.ORMException; -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLElementList; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLType; -import fr.pandacube.java.util.db.sql_tools.SQLWhereChain; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; -import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; - -public class SQLPlayerIgnore extends SQLElement { - - public SQLPlayerIgnore() { - super(); - } - - public SQLPlayerIgnore(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_player_ignore"; - } - - public static final SQLFKField ignorer = new SQLFKField<>("ignorer", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLFKField ignored = new SQLFKField<>("ignored", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - - public UUID getIgnorerId() { - String id = get(ignorer); - return (id == null) ? null : UUID.fromString(id); - } - - public void setIgnorerId(UUID pName) { - set(ignorer, (pName == null) ? (String) null : pName.toString()); - } - - public UUID getIgnoredId() { - String id = get(ignored); - return (id == null) ? null : UUID.fromString(id); - } - - public void setIgnoredId(UUID pName) { - set(ignored, (pName == null) ? (String) null : pName.toString()); - } - - public static SQLPlayerIgnore getPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws ORMException { - return ORM.getFirst(SQLPlayerIgnore.class, - new SQLWhereChain(SQLBoolOp.AND) - .add(new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString())) - .add(new SQLWhereComp(SQLPlayerIgnore.ignored, SQLComparator.EQ, ignored.toString())), - null); - } - - public static boolean isPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws ORMException { - return getPlayerIgnoringPlayer(ignorer, ignored) != null; - } - - public static void setPlayerIgnorePlayer(UUID ignorer, UUID ignored, boolean newIgnoreState) throws ORMException { - SQLPlayerIgnore el = getPlayerIgnoringPlayer(ignorer, ignored); - if (el == null && newIgnoreState) { - el = new SQLPlayerIgnore(); - el.setIgnorerId(ignorer); - el.setIgnoredId(ignored); - el.save(); - return; - } - if (el != null && !newIgnoreState) { - el.delete(); - return; - } - - } - - public static Map getIgnoredPlayer(UUID ignorer) throws ORMException { - SQLElementList els = ORM.getAll(SQLPlayerIgnore.class, - new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()), - null, null, null); - - return els.getAllForeign(SQLPlayerIgnore.ignored); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLPlayerTexture.java b/src/main/java/fr/pandacube/java/util/db/SQLPlayerTexture.java deleted file mode 100644 index 8f6ef04..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLPlayerTexture.java +++ /dev/null @@ -1,29 +0,0 @@ -package fr.pandacube.java.util.db; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLPlayerTexture extends SQLElement { - - public SQLPlayerTexture() { - super(); - } - - public SQLPlayerTexture(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_player_texture"; - } - - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField alias = new SQLField<>("alias", SQLType.VARCHAR(64), false); - public static final SQLField textureData = new SQLField<>("textureData", SQLType.TEXT, false); - public static final SQLField textureSignature = new SQLField<>("textureSignature", SQLType.VARCHAR(8192), false); - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLShopStock.java b/src/main/java/fr/pandacube/java/util/db/SQLShopStock.java deleted file mode 100644 index 7536bbd..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLShopStock.java +++ /dev/null @@ -1,27 +0,0 @@ -package fr.pandacube.java.util.db; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLShopStock extends SQLElement { - - public SQLShopStock() { - super(); - } - - public SQLShopStock(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_shop_stock"; - } - - public static final SQLField material = new SQLField<>("material", SQLType.VARCHAR(50), false); - public static final SQLField damage = new SQLField<>("damage", SQLType.INT, false, 0); - public static final SQLField quantity = new SQLField<>("quantity", SQLType.DOUBLE, false); - public static final SQLField server = new SQLField<>("server", SQLType.VARCHAR(50), false); - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLStaffTicket.java b/src/main/java/fr/pandacube/java/util/db/SQLStaffTicket.java deleted file mode 100644 index 02b7666..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLStaffTicket.java +++ /dev/null @@ -1,50 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLStaffTicket extends SQLElement { - - public SQLStaffTicket() { - super(); - } - - public SQLStaffTicket(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_staff_ticket"; - } - - public static final SQLFKField playerId = new SQLFKField<>("playerId", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField message = new SQLField<>("message", SQLType.VARCHAR(1024), false); - public static final SQLField creationTime = new SQLField<>("creationTime", SQLType.BIGINT, false); - public static final SQLFKField staffPlayerId = new SQLFKField<>("staffPlayerId", - SQLType.CHAR(36), true, SQLPlayer.class, SQLPlayer.playerId); - - public UUID getPlayerId() { - String id = get(playerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setPlayerId(UUID id) { - set(playerId, (id == null) ? null : id.toString()); - } - - public UUID getstaffPlayerId() { - String id = get(staffPlayerId); - return (id == null) ? null : UUID.fromString(id); - } - - public void setstaffPlayerId(UUID id) { - set(staffPlayerId, (id == null) ? null : id.toString()); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLStaticPages.java b/src/main/java/fr/pandacube/java/util/db/SQLStaticPages.java deleted file mode 100644 index 807b161..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLStaticPages.java +++ /dev/null @@ -1,28 +0,0 @@ -package fr.pandacube.java.util.db; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLStaticPages extends SQLElement { - - public SQLStaticPages() { - super(); - } - - public SQLStaticPages(int id) { - super(id); - } - - @Override - protected String tableName() { - return "pandacube_static_pages"; - } - - public static final SQLField permalink = new SQLField<>("permalink", SQLType.VARCHAR(128), false); - public static final SQLField titreHead = new SQLField<>("titreHead", SQLType.VARCHAR(128), false); - public static final SQLField titreH2 = new SQLField<>("titreH2", SQLType.VARCHAR(255), false); - public static final SQLField texte = new SQLField<>("texte", SQLType.TEXT, false); - public static final SQLField permissions = new SQLField<>("permissions", SQLType.VARCHAR(255), true); - -} diff --git a/src/main/java/fr/pandacube/java/util/db/SQLUUIDPlayer.java b/src/main/java/fr/pandacube/java/util/db/SQLUUIDPlayer.java deleted file mode 100644 index 9573996..0000000 --- a/src/main/java/fr/pandacube/java/util/db/SQLUUIDPlayer.java +++ /dev/null @@ -1,38 +0,0 @@ -package fr.pandacube.java.util.db; - -import java.util.UUID; - -import fr.pandacube.java.util.db.sql_tools.SQLElement; -import fr.pandacube.java.util.db.sql_tools.SQLFKField; -import fr.pandacube.java.util.db.sql_tools.SQLField; -import fr.pandacube.java.util.db.sql_tools.SQLType; - -public class SQLUUIDPlayer extends SQLElement { - - public SQLUUIDPlayer() { - super(); - } - - public SQLUUIDPlayer(int id) { - super(id); - } - - @Override - protected String tableName() { - return "bungeeperms_uuidplayer"; - } - - public static final SQLFKField uuid = new SQLFKField<>("uuid", SQLType.CHAR(36), false, - SQLPlayer.class, SQLPlayer.playerId); - public static final SQLField player = new SQLField<>("player", SQLType.VARCHAR(16), false); - - public UUID getUUID() { - String id = get(uuid); - return (id == null) ? null : UUID.fromString(id); - } - - public void setUUID(UUID id) { - set(uuid, (id == null) ? null : id.toString()); - } - -} diff --git a/src/main/java/fr/pandacube/java/util/db/sql_tools/ORM.java b/src/main/java/fr/pandacube/java/util/db/sql_tools/ORM.java index efd869a..40719f6 100644 --- a/src/main/java/fr/pandacube/java/util/db/sql_tools/ORM.java +++ b/src/main/java/fr/pandacube/java/util/db/sql_tools/ORM.java @@ -6,29 +6,9 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.logging.Level; import fr.pandacube.java.util.EnumUtil; import fr.pandacube.java.util.Log; -import fr.pandacube.java.util.db.SQLContact; -import fr.pandacube.java.util.db.SQLForumCategorie; -import fr.pandacube.java.util.db.SQLForumForum; -import fr.pandacube.java.util.db.SQLForumPost; -import fr.pandacube.java.util.db.SQLForumThread; -import fr.pandacube.java.util.db.SQLLoginHistory; -import fr.pandacube.java.util.db.SQLLoginKickHistory; -import fr.pandacube.java.util.db.SQLMPGroup; -import fr.pandacube.java.util.db.SQLMPGroupUser; -import fr.pandacube.java.util.db.SQLMPMessage; -import fr.pandacube.java.util.db.SQLModoHistory; -import fr.pandacube.java.util.db.SQLOnlineshopHistory; -import fr.pandacube.java.util.db.SQLPingHistory; -import fr.pandacube.java.util.db.SQLPlayer; -import fr.pandacube.java.util.db.SQLPlayerIgnore; -import fr.pandacube.java.util.db.SQLShopStock; -import fr.pandacube.java.util.db.SQLStaffTicket; -import fr.pandacube.java.util.db.SQLStaticPages; -import fr.pandacube.java.util.db.SQLUUIDPlayer; import fr.pandacube.java.util.db.sql_tools.SQLWhereChain.SQLBoolOp; import fr.pandacube.java.util.db.sql_tools.SQLWhereComp.SQLComparator; import org.javatuples.Pair; @@ -49,43 +29,14 @@ public final class ORM { return connection; } - public synchronized static void init(DBConnection conn) { + public synchronized static > void init(DBConnection conn) { connection = conn; - /* - * Les tables à initialiser - * utile des les initialiser ici, car on peut tout de suite déceler les - * bugs ou erreurs dans la déclaration des SQLFields - */ - - try { - initTable(SQLContact.class); - initTable(SQLForumCategorie.class); - initTable(SQLForumForum.class); - initTable(SQLForumPost.class); - initTable(SQLForumThread.class); - initTable(SQLLoginHistory.class); - initTable(SQLLoginKickHistory.class); - initTable(SQLModoHistory.class); - initTable(SQLMPGroup.class); - initTable(SQLMPGroupUser.class); - initTable(SQLMPMessage.class); - initTable(SQLOnlineshopHistory.class); - initTable(SQLPingHistory.class); - initTable(SQLPlayer.class); - initTable(SQLPlayerIgnore.class); - initTable(SQLShopStock.class); - initTable(SQLStaffTicket.class); - initTable(SQLStaticPages.class); - initTable(SQLUUIDPlayer.class); - } catch (ORMInitTableException e) { - Log.getLogger().log(Level.SEVERE, "Erreur d'initialisation d'une table dans l'ORM", e); - } } - /* package */ static synchronized > void initTable(Class elemClass) throws ORMInitTableException { + public static synchronized > void initTable(Class elemClass) throws ORMInitTableException { if (tables.contains(elemClass)) return; try { tables.add(elemClass);