Birthday stuff in SQLPlayer and IOffPlayer
This commit is contained in:
parent
6ef8557c34
commit
f73c07bea3
@ -1,5 +1,6 @@
|
|||||||
package fr.pandacube.lib.core.players;
|
package fr.pandacube.lib.core.players;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import fr.pandacube.lib.core.chat.ChatColorUtil;
|
import fr.pandacube.lib.core.chat.ChatColorUtil;
|
||||||
@ -304,6 +305,30 @@ public interface IOffPlayer {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Birthday
|
||||||
|
*/
|
||||||
|
|
||||||
|
public default void setBirthday(int day, int month, Integer year) {
|
||||||
|
try {
|
||||||
|
SQLPlayer dbPlayer = getDbPlayer();
|
||||||
|
dbPlayer.setBirthday(day, month, year);
|
||||||
|
dbPlayer.save();
|
||||||
|
} catch (DBException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public default Calendar getBirthday() {
|
||||||
|
try {
|
||||||
|
return getDbPlayer().getBirthday();
|
||||||
|
} catch (DBException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -145,7 +145,7 @@ public class PlayerFinder {
|
|||||||
return name.matches("[0-9a-zA-Z_.]{2,20}");
|
return name.matches("[0-9a-zA-Z_.]{2,20}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SQLPlayer getDBPlayer(UUID id) throws Exception {
|
public static SQLPlayer getDBPlayer(UUID id) throws DBException {
|
||||||
if (id == null) return null;
|
if (id == null) return null;
|
||||||
return SQLPlayer.getPlayerFromUUID(id);
|
return SQLPlayer.getPlayerFromUUID(id);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package fr.pandacube.lib.core.players;
|
package fr.pandacube.lib.core.players;
|
||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -9,8 +11,15 @@ import fr.pandacube.lib.core.db.DBException;
|
|||||||
import fr.pandacube.lib.core.db.SQLElement;
|
import fr.pandacube.lib.core.db.SQLElement;
|
||||||
import fr.pandacube.lib.core.db.SQLElementList;
|
import fr.pandacube.lib.core.db.SQLElementList;
|
||||||
import fr.pandacube.lib.core.db.SQLField;
|
import fr.pandacube.lib.core.db.SQLField;
|
||||||
|
import fr.pandacube.lib.core.util.Log;
|
||||||
|
|
||||||
public class SQLPlayer extends SQLElement<SQLPlayer> {
|
public class SQLPlayer extends SQLElement<SQLPlayer> {
|
||||||
|
|
||||||
|
/** If the player birth year is internally 1800, it is considered as a non disclosed age.
|
||||||
|
* All player with an age below 13 should have their age automatically hidden.
|
||||||
|
*/
|
||||||
|
public static final int UNDISCLOSED_AGE_YEAR = 1800;
|
||||||
|
|
||||||
|
|
||||||
public SQLPlayer() {
|
public SQLPlayer() {
|
||||||
super();
|
super();
|
||||||
@ -59,6 +68,38 @@ public class SQLPlayer extends SQLElement<SQLPlayer> {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Calendar getBirthday() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Date birthday = get(SQLPlayer.birthday);
|
||||||
|
if (birthday == null) // le joueur n'a pas de date d'anniversaire
|
||||||
|
return null;
|
||||||
|
GregorianCalendar cal = new GregorianCalendar();
|
||||||
|
cal.setTime(birthday);
|
||||||
|
return cal;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.severe(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBirthday(int day, int month, Integer year) {
|
||||||
|
if (year == null)
|
||||||
|
year = UNDISCLOSED_AGE_YEAR;
|
||||||
|
|
||||||
|
GregorianCalendar cal = new GregorianCalendar();
|
||||||
|
cal.set(year, month, day, 0, 0, 0);
|
||||||
|
|
||||||
|
set(SQLPlayer.birthday, new java.sql.Date(cal.getTimeInMillis()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static SQLPlayer getPlayerFromUUID(UUID pId) throws DBException {
|
public static SQLPlayer getPlayerFromUUID(UUID pId) throws DBException {
|
||||||
if (pId == null)
|
if (pId == null)
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user