Mega gros commit de la mort qui tue

This commit is contained in:
2015-05-11 04:44:19 +02:00
parent 99c8711602
commit dddaa83fe0
33 changed files with 1750 additions and 292 deletions

View File

@@ -1,5 +1,8 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.data_model;
import java.sql.SQLException;
import java.util.List;
public class MPGroupElement extends SQLElement {
private String groupName;
@@ -45,5 +48,12 @@ public class MPGroupElement extends SQLElement {
throw new NullPointerException();
groupName = name;
}
public List<MPGroupUserElement> getUsers() throws SQLException {
return ((MPGroupUserTable)ORM.getTable("mp_group_user"))
.getAll("groupId = "+getId(), "id ASC", null, null);
}
}

View File

@@ -1,5 +1,7 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.data_model;
import java.sql.SQLException;
public class MPGroupUserElement extends SQLElement {
private int groupId;
@@ -51,5 +53,18 @@ public class MPGroupUserElement extends SQLElement {
throw new NullPointerException();
this.playerName = playerName;
}
public MPWebSessionElement getWebSessionData() throws SQLException {
return ((MPWebSessionTable)ORM.getTable("mp_web_session"))
.getFirst("playerName LIKE '"+getPlayerName()+"'", "id ASC");
}
}

View File

@@ -3,6 +3,8 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.data_model;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.mc_pandacraft.java.plugin.pandacraftutils.commands.AbstractCommandExecutor;
public class MPGroupUserTable extends SQLTable<MPGroupUserElement> {
public MPGroupUserTable() throws SQLException {
@@ -24,5 +26,13 @@ public class MPGroupUserTable extends SQLTable<MPGroupUserElement> {
sqlResult.getInt("groupId"),
sqlResult.getString("playerName"));
}
public MPGroupUserElement getPlayerInGroup(MPGroupElement group, String player) throws SQLException {
if (!AbstractCommandExecutor.isValidPlayerName(player))
return null;
return getFirst("groupId = "+group.getId()+" AND playerName = '"+player+"'", "id");
}
}

View File

@@ -1,5 +1,7 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.data_model;
import java.sql.SQLException;
/**
* Représente un message dans la base de donnée<br/>
* <br/>
@@ -21,7 +23,7 @@ public class MPMessageElement extends SQLElement {
private String destNick = null;
private Integer destGroup = null;
private String message;
private boolean read;
private boolean wasRead;
private boolean deleted = false;
private boolean serverSync;
@@ -77,7 +79,7 @@ public class MPMessageElement extends SQLElement {
destNick,
(destGroup==null)?null:destGroup.toString(),
message,
(read)?"1":"0",
(wasRead)?"1":"0",
(deleted)?"1":"0",
(serverSync)?"1":"0"
};
@@ -96,7 +98,7 @@ public class MPMessageElement extends SQLElement {
"destNick",
"destGroup",
"message",
"read",
"wasRead",
"deleted",
"serverSync"
};
@@ -110,7 +112,7 @@ public class MPMessageElement extends SQLElement {
public String getDestNick() { return destNick; }
public Integer getDestGroup() { return destGroup; }
public String getMessage() { return message; }
public boolean isRead() { return read; }
public boolean isRead() { return wasRead; }
public boolean isDeleted() { return deleted; }
public boolean isServerSync() { return serverSync; }
@@ -146,8 +148,18 @@ public class MPMessageElement extends SQLElement {
message = msg;
}
public void setRead(boolean r) { read = r; }
public void setRead(boolean r) { wasRead = r; }
public void setDeleted(boolean del) { deleted = del; }
public void setServerSync(boolean sync) { serverSync = sync; }
public MPGroupElement getDestGroupElement() throws SQLException {
if (getDestGroup() == null) return null;
return ((MPGroupTable)ORM.getTable("mp_group")).get(getDestGroup());
}
}

View File

@@ -2,6 +2,9 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.data_model;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import net.mc_pandacraft.java.plugin.pandacraftutils.commands.AbstractCommandExecutor;
public class MPMessageTable extends SQLTable<MPMessageElement> {
@@ -19,7 +22,7 @@ public class MPMessageTable extends SQLTable<MPMessageElement> {
+ "destNick VARCHAR(16) NULL,"
+ "destGroup INT NULL,"
+ "message VARCHAR(512) NOT NULL,"
+ "read TINYINT NOT NULL,"
+ "wasRead TINYINT NOT NULL,"
+ "deleted TINYINT NOT NULL,"
+ "serverSync TINYINT NOT NULL";
}
@@ -34,19 +37,33 @@ public class MPMessageTable extends SQLTable<MPMessageElement> {
sqlResult.getString("viewerNick"),
sqlResult.getString("sourceNick"),
sqlResult.getString("message"),
sqlResult.getBoolean("read"),
sqlResult.getBoolean("wasRead"),
sqlResult.getBoolean("serverSync"));
el.setDestNick(sqlResult.getString("destNick"));
int group = sqlResult.getInt("destGroup");
el.setDestGroup(sqlResult.wasNull()?null:group);
el.setDestNick(sqlResult.getString("destNick"));
el.setDeleted(sqlResult.getBoolean("deleted"));
return el;
}
public List<MPMessageElement> getAllUnsyncMessage() throws SQLException {
return getAll("serverSync = 0", "time ASC", null, null);
}
public List<MPMessageElement> getAllUnreadForPlayer(String player) throws SQLException {
if (!AbstractCommandExecutor.isValidPlayerName(player)) return null;
return getAll("viewerNick = "+player+" AND read = 0", "time ASC", null, null);
}
}

View File

@@ -5,7 +5,16 @@ import java.util.HashMap;
import java.util.Map;
/**
* ORM = Object-Relational Mapping
* <b>ORM = Object-Relational Mapping</b><br/>
* Liste des tables avec leur classes :
* <ul>
* <li><code>"modo_history" : ModoHistoryTable</code></li>
* <li><code>"staff_ticket" : StaffTicketTable</code></li>
* <li><code>"mp_message" : MPMessageTable</code></li>
* <li><code>"mp_group" : MPGroupTable</code></li>
* <li><code>"mp_group_user" : MPGroupUserTable</code></li>
* <li><code>"mp_web_session" : MPWebSessionTable</code></li>
* </ul>
* @author Marc Baloup
*
*/
@@ -23,6 +32,8 @@ public final class ORM {
*/
tables.put("modo_history", new ModoHistoryTable());
tables.put("staff_ticket", new StaffTicketTable());
tables.put("mp_message", new MPMessageTable());
tables.put("mp_group", new MPGroupTable());
@@ -40,7 +51,12 @@ public final class ORM {
/**
* Récupère l'instance de la classe associé à la table demandé en paramètre.<br/>
* <b>Il est conseillé de caster le retour de cette méthode par la classe associé à la table demandé.</b>
* @param name nom de la table telle qu'elle est enregistrée dans la classe ORM
* @return ta table dont le nom est passé en paramètre
*/
@SuppressWarnings("rawtypes")
public synchronized static SQLTable getTable(String name) {
return tables.get(name);

View File

@@ -59,6 +59,13 @@ public abstract class SQLTable<T extends SQLElement> {
public String getTableName() {
return tableName;
}
public T get(int id) throws SQLException {
Statement stmt = db.getConnection().createStatement();
String sql = "SELECT * FROM "+tableName+" WHERE id = "+id+";";
@@ -73,11 +80,17 @@ public abstract class SQLTable<T extends SQLElement> {
public List<T> getAll() throws SQLException {
return getAll(null, null, null, null);
}
public T getFirst(String where, String orderBy) throws SQLException {
List<T> elts = getAll(where, orderBy, 1, null);
return (elts.size() == 0)? null : elts.get(0);
}
public List<T> getAll(String where, String orderBy, Integer limit, Integer offset) throws SQLException {
Statement stmt = db.getConnection().createStatement();
String sql = "SELECT * FROM "+tableName;

View File

@@ -0,0 +1,104 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.data_model;
import org.apache.commons.lang.NullArgumentException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
public class StaffTicketElement extends SQLElement {
private String playerName;
private String message;
private long creationTime;
private String staffPlayer = null;
private String locWorld;
private double locX;
private double locY;
private double locZ;
public StaffTicketElement(String pName, String m, long creaTime, Location loc) {
super("pandacraft_staff_ticket");
setPlayerName(pName);
setMessage(m);
setCreationTime(creaTime);
setLocation(loc);
}
protected StaffTicketElement(int id, String pName, String m, long creaTime, String locW, double x, double y, double z) {
super("pandacraft_staff_ticket", id);
setPlayerName(pName);
setMessage(m);
setCreationTime(creaTime);
locWorld = locW;
locX = x;
locY = y;
locZ = z;
}
@Override
protected String[] getValues() {
return new String[] {
playerName,
message,
Long.toString(creationTime),
staffPlayer,
locWorld,
Double.toString(locX),
Double.toString(locY),
Double.toString(locZ)
};
}
@Override
protected String[] getFieldsName() {
return new String[] {
"playerName",
"message",
"creationTime",
"staffPlayer",
"locWorld",
"locX",
"locY",
"locZ"
};
}
public String getPlayerName() {
return playerName;
}
public void setPlayerName(String playerName) {
if (playerName == null) throw new NullArgumentException("playerName");
this.playerName = playerName;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
if (message == null) throw new NullArgumentException("message");
this.message = message;
}
public long getCreationTime() {
return creationTime;
}
public void setCreationTime(long creationTime) {
this.creationTime = creationTime;
}
public String getStaffPlayer() {
return staffPlayer;
}
public void setStaffPlayer(String staffPlayer) {
this.staffPlayer = staffPlayer;
}
public Location getLocation() {
return new Location(Bukkit.getWorld(locWorld), locX, locY, locZ);
}
public void setLocation(Location loc) {
if (loc == null) throw new NullArgumentException("loc");
locWorld = loc.getWorld().getName();
locX = loc.getX();
locY = loc.getY();
locZ = loc.getZ();
}
}

View File

@@ -0,0 +1,43 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.data_model;
import java.sql.ResultSet;
import java.sql.SQLException;
public class StaffTicketTable extends SQLTable<StaffTicketElement> {
public StaffTicketTable() throws SQLException {
super("pandacraft_staff_ticket");
}
@Override
protected String createTableParameters() {
return "id INT AUTO_INCREMENT PRIMARY KEY,"
+ "playerName VARCHAR(16) NOT NULL,"
+ "message VARCHAR(1024) NOT NULL,"
+ "creationTime BIGINT NOT NULL,"
+ "staffPlayer VARCHAR(16) NULL,"
+ "locWorld VARCHAR(64) NOT NULL,"
+ "locX DOUBLE NOT NULL,"
+ "locY DOUBLE NOT NULL,"
+ "locZ DOUBLE NOT NULL";
}
@Override
protected StaffTicketElement getElementInstance(ResultSet sqlResult)
throws SQLException {
StaffTicketElement el = new StaffTicketElement(
sqlResult.getInt("id"),
sqlResult.getString("playerName"),
sqlResult.getString("message"),
sqlResult.getLong("creationTime"),
sqlResult.getString("locWorld"),
sqlResult.getDouble("locX"),
sqlResult.getDouble("locY"),
sqlResult.getDouble("locZ"));
el.setStaffPlayer(sqlResult.getString("staffPlayer"));
return el;
}
}