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); } }