diff --git a/make_jar.jardesc b/make_jar.jardesc index 258e062..0aa0889 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/plugin.yml b/resources/plugin.yml index 0a9011d..7b24f2a 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 4.1 +version: 4.2 diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java index 9bcfa37..4e92901 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java @@ -4,7 +4,7 @@ import java.sql.SQLException; import net.mc_pandacraft.java.plugin.pandacraftutils.commands.PandacraftUtilsCommandsManager; import net.mc_pandacraft.java.plugin.pandacraftutils.config.ConfigManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.SQLManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.ORM; import net.mc_pandacraft.java.plugin.pandacraftutils.listener.BlockListener; import net.mc_pandacraft.java.plugin.pandacraftutils.listener.EntityListener; import net.mc_pandacraft.java.plugin.pandacraftutils.listener.PlayerListener; @@ -119,7 +119,7 @@ public class PandacraftUtils extends JavaPlugin { ConfigManager.loadNewInstance(); - SQLManager.loadNewInstance(); + ORM.init(); OnlinePlayerManager.loadNewInstance(); PandacraftUtilsCommandsManager.loadNewInstance(); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSystem.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSystem.java index 94c4f64..6c26682 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSystem.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandSystem.java @@ -107,22 +107,51 @@ public class CommandSystem extends AbstractCommandExecutor { } else if (args.length > 0 && (args[0].equalsIgnoreCase("thread") || args[0].equalsIgnoreCase("threads"))) { - sender.sendMessage(decoration_color+"------------- Threads chargés -------------"); try { ThreadInfo[] threadsInfo = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false); - int count = 0; - for(ThreadInfo thrd : threadsInfo) + ThreadInfo threadInfoSelected = null; + + if (args.length > 1) { - if (thrd == null) - continue; - count++; - - sender.sendMessage("#"+thrd.getThreadId()+" §7"+thrd.getThreadName()+"§r : "+thrd.getThreadState().toString().toLowerCase()); + String threadName = getLastParam(args, 1); + for (ThreadInfo th : threadsInfo) + if (th != null && th.getThreadName().equalsIgnoreCase(threadName)) + threadInfoSelected = th; + } + + if (threadInfoSelected != null) { + sender.sendMessage(decoration_color+"--------------- Info Thread ---------------"); + sender.sendMessage("#"+threadInfoSelected.getThreadId()+" §7"+threadInfoSelected.getThreadName()+"§r : "+threadInfoSelected.getThreadState().toString()); + StackTraceElement[] stack = threadInfoSelected.getStackTrace(); + sender.sendMessage("StackTrace : ("+stack.length+" element(s))"); + for (StackTraceElement stEl : stack) { + sender.sendMessage(ChatColor.GRAY+" - "+stEl.toString()); + } + sender.sendMessage(decoration_color+"-------------------------------------------"); } - sender.sendMessage(decoration_color+"Total : §7"+count+" thread"+((count>1)?"s":"")); + else { + + sender.sendMessage(decoration_color+"------------- Threads chargés -------------"); + int count = 0; + for(ThreadInfo thrd : threadsInfo) + { + if (thrd == null) + continue; + count++; + + sender.sendMessage("#"+thrd.getThreadId()+" §7"+thrd.getThreadName()+"§r : "+thrd.getThreadState().toString()); + + } + sender.sendMessage(decoration_color+"Total : §7"+count+" thread"+((count>1)?"s":"")); + + } + + + + } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupElement.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupElement.java new file mode 100644 index 0000000..9a802d7 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupElement.java @@ -0,0 +1,49 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +public class MPGroupElement extends SQLElement { + + private String groupName; + + + + public MPGroupElement(String name) { + super("pandacraft_mp_group"); + setGroupName(name); + } + + protected MPGroupElement(int id, String name) { + super("pandacraft_mp_group", id); + setGroupName(name); + } + + + + + + + + @Override + protected String[] getValues() { + return new String[] { + groupName + }; + } + + @Override + protected String[] getFieldsName() { + return new String[] { + "groupName" + }; + } + + + + public String getGroupName() { return groupName; } + + public void setGroupName(String name) { + if (name == null) + throw new NullPointerException(); + groupName = name; + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupTable.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupTable.java new file mode 100644 index 0000000..8d2676a --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupTable.java @@ -0,0 +1,26 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MPGroupTable extends SQLTable { + + public MPGroupTable() throws SQLException { + super("pandacraft_mp_group"); + } + + @Override + protected String createTableParameters() { + return "id INT AUTO_INCREMENT PRIMARY KEY," + + "groupName VARCHAR(16) NOT NULL"; + } + + @Override + protected MPGroupElement getElementInstance(ResultSet sqlResult) + throws SQLException { + return new MPGroupElement( + sqlResult.getInt("id"), + sqlResult.getString("groupName")); + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserElement.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserElement.java new file mode 100644 index 0000000..16bf76e --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserElement.java @@ -0,0 +1,55 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +public class MPGroupUserElement extends SQLElement { + + private int groupId; + private String playerName; + + + public MPGroupUserElement(int gId, String pName) { + super("pandacraft_mp_group_user"); + setGroupId(gId); + setPlayerName(pName); + } + + protected MPGroupUserElement(int id, int gId, String pName) { + super("pandacraft_mp_group_user", id); + setGroupId(gId); + setPlayerName(pName); + } + + + + @Override + protected String[] getValues() { + return new String[] { + Integer.toString(groupId), + playerName + }; + } + + @Override + protected String[] getFieldsName() { + return new String[] { + "groupId", + "playerName" + }; + } + + + + + + + + public int getGroupId() { return groupId; } + public String getPlayerName() { return playerName; } + + public void setGroupId(int gId) { groupId = gId; } + public void setPlayerName(String playerName) { + if (playerName == null) + throw new NullPointerException(); + this.playerName = playerName; + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserTable.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserTable.java new file mode 100644 index 0000000..6d2f79b --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPGroupUserTable.java @@ -0,0 +1,28 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MPGroupUserTable extends SQLTable { + + public MPGroupUserTable() throws SQLException { + super("pandacraft_mp_group_user"); + } + + @Override + protected String createTableParameters() { + return "id INT AUTO_INCREMENT PRIMARY KEY," + + "groupId INT NOT NULL," + + "playerName VARCHAR(16) NOT NULL"; + } + + @Override + protected MPGroupUserElement getElementInstance(ResultSet sqlResult) + throws SQLException { + return new MPGroupUserElement( + sqlResult.getInt("id"), + sqlResult.getInt("groupId"), + sqlResult.getString("playerName")); + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageElement.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageElement.java new file mode 100644 index 0000000..41e09e5 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageElement.java @@ -0,0 +1,153 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +/** + * Représente un message dans la base de donnée
+ *
+ * Les propriétés suivantes doivent être complétés hors constructeur (par défaut null) : + *
    + *
  • destNick
  • + *
  • ou destGroup
  • + *
+ * La propriété deleted est défini par défaut à Faux. + * @author Marc Baloup + * + */ +public class MPMessageElement extends SQLElement { + + private long time; + private int securityKey; // permet de différencier deux message, dans le cas où 2 messages ont exactement la même valeur time + private String viewerNick; + private String sourceNick; + private String destNick = null; + private Integer destGroup = null; + private String message; + private boolean read; + private boolean deleted = false; + private boolean serverSync; + + + + public MPMessageElement(long t, int secKey, String viewNick, String srcNick, String msg, boolean r, boolean sync) { + super("pandacraft_mp_message"); + setTime(t); + setSecurityKey(secKey); + setViewerNick(viewNick); + setSourceNick(srcNick); + setMessage(msg); + setRead(r); + setServerSync(sync); + } + + + protected MPMessageElement(int id, long t, int secKey, String viewNick, String srcNick, String msg, boolean r, boolean sync) { + super("pandacraft_mp_message", id); + setTime(t); + setSecurityKey(secKey); + setViewerNick(viewNick); + setSourceNick(srcNick); + setMessage(msg); + setRead(r); + setServerSync(sync); + } + + + + + + + + + + + + + + + + + + + @Override + protected String[] getValues() { + return new String[] { + Long.toString(time), + Integer.toString(securityKey), + viewerNick, + sourceNick, + destNick, + (destGroup==null)?null:destGroup.toString(), + message, + (read)?"1":"0", + (deleted)?"1":"0", + (serverSync)?"1":"0" + }; + } + + + + + @Override + protected String[] getFieldsName() { + return new String[] { + "time", + "securityKey", + "viewerNick", + "sourceNick", + "destNick", + "destGroup", + "message", + "read", + "deleted", + "serverSync" + }; + } + + + public long getTime() { return time; } + public int getSecurityKey() { return securityKey; } + public String getViewerNick() { return viewerNick; } + public String getSourceNick() { return sourceNick; } + public String getDestNick() { return destNick; } + public Integer getDestGroup() { return destGroup; } + public String getMessage() { return message; } + public boolean isRead() { return read; } + public boolean isDeleted() { return deleted; } + public boolean isServerSync() { return serverSync; } + + + + + public void setTime(long t) { time = t; } + public void setSecurityKey(int secKey) { securityKey = secKey; } + + public void setViewerNick(String viewNick) { + if (viewNick == null) + throw new NullPointerException(); + viewerNick = viewNick; + } + + public void setSourceNick(String srcNick) { sourceNick = srcNick; } + + public void setDestNick(String destNick) { + this.destNick = destNick; + if (destNick != null) + destGroup = null; + } + + public void setDestGroup(Integer destGroup) { + this.destGroup = destGroup; + if (destGroup != null) + destNick = null; + } + + public void setMessage(String msg) { + if (msg == null) + throw new NullPointerException(); + message = msg; + } + + public void setRead(boolean r) { read = r; } + public void setDeleted(boolean del) { deleted = del; } + public void setServerSync(boolean sync) { serverSync = sync; } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageTable.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageTable.java new file mode 100644 index 0000000..049f7cc --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageTable.java @@ -0,0 +1,52 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MPMessageTable extends SQLTable { + + public MPMessageTable() throws SQLException { + super("pandacraft_mp_message"); + } + + @Override + protected String createTableParameters() { + return "id INT AUTO_INCREMENT PRIMARY KEY," + + "time BIGINT NOT NULL," + + "securityKey INT NOT NULL," + + "viewerNick VARCHAR(16) NOT NULL," + + "sourceNick VARCHAR(16) NULL," // Null si la source est la console ou une autre entité qu'un joueur + + "destNick VARCHAR(16) NULL," + + "destGroup INT NULL," + + "message VARCHAR(512) NOT NULL," + + "read TINYINT NOT NULL," + + "deleted TINYINT NOT NULL," + + "serverSync TINYINT NOT NULL"; + } + + @Override + protected MPMessageElement getElementInstance(ResultSet sqlResult) + throws SQLException { + MPMessageElement el = new MPMessageElement( + sqlResult.getInt("id"), + sqlResult.getLong("time"), + sqlResult.getInt("securityKey"), + sqlResult.getString("viewerNick"), + sqlResult.getString("sourceNick"), + sqlResult.getString("message"), + sqlResult.getBoolean("read"), + sqlResult.getBoolean("serverSync")); + el.setDestNick(sqlResult.getString("destNick")); + + int group = sqlResult.getInt("destGroup"); + el.setDestGroup(sqlResult.wasNull()?null:group); + + el.setDestNick(sqlResult.getString("destNick")); + + return el; + } + + + + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPWebSessionElement.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPWebSessionElement.java new file mode 100644 index 0000000..c75f603 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPWebSessionElement.java @@ -0,0 +1,69 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +public class MPWebSessionElement extends SQLElement { + + private String playerName; + private long lastWebActivity; + private boolean isInGameOnline; + private String playerDisplayName; + + public MPWebSessionElement(String pName, long lastWebAct, boolean onlineIG, String dispName) { + super("pandacraft_mp_web_session"); + setPlayerName(pName); + setLastWebActivity(lastWebAct); + setInGameOnline(onlineIG); + setPlayerDisplayName(dispName); + } + + protected MPWebSessionElement(int id, String pName, long lastWebAct, boolean onlineIG, String dispName) { + super("pandacraft_mp_web_session", id); + setPlayerName(pName); + setLastWebActivity(lastWebAct); + setInGameOnline(onlineIG); + setPlayerDisplayName(dispName); + } + + @Override + protected String[] getValues() { + return new String[] { + playerName, + Long.toString(lastWebActivity), + (isInGameOnline)?"1":"0", + playerDisplayName + }; + } + + @Override + protected String[] getFieldsName() { + return new String[] { + "playerName", + "lastWebActivity", + "isInGameOnline", + "playerDisplayName" + }; + } + + public String getPlayerName() { return playerName; } + public long getLastWebActivity() { return lastWebActivity; } + public boolean isInGameOnline() { return isInGameOnline; } + public String getPlayerDisplayName() { return playerDisplayName; } + + + + public void setPlayerName(String pName) { + if (pName == null) + throw new NullPointerException(); + playerName = pName; + } + + public void setLastWebActivity(long lastWebAct) { lastWebActivity = lastWebAct; } + + public void setInGameOnline(boolean onlineIG) { isInGameOnline = onlineIG; } + + public void setPlayerDisplayName(String dispName) { + if (dispName == null) + throw new NullPointerException(); + playerDisplayName = dispName; + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPWebSessionTable.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPWebSessionTable.java new file mode 100644 index 0000000..327f0af --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPWebSessionTable.java @@ -0,0 +1,32 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MPWebSessionTable extends SQLTable { + + public MPWebSessionTable() throws SQLException { + super("pandacraft_mp_web_session"); + } + + @Override + protected String createTableParameters() { + return "id INT AUTO_INCREMENT PRIMARY KEY," + + "playerName VARCHAR(16) NOT NULL," + + "lastWebActivity BIGINT NOT NULL," + + "isInGameOnline TINYINT NOT NULL," + + "playerDisplayName VARCHAR(255) NOT NULL"; + } + + @Override + protected MPWebSessionElement getElementInstance(ResultSet sqlResult) + throws SQLException { + return new MPWebSessionElement( + sqlResult.getInt("id"), + sqlResult.getString("playerName"), + sqlResult.getLong("lastWebActivity"), + sqlResult.getBoolean("isInGameOnline"), + sqlResult.getString("playerDisplayName")); + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/ORM.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/ORM.java new file mode 100644 index 0000000..68e7a60 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/ORM.java @@ -0,0 +1,59 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +/** + * ORM = Object-Relational Mapping + * @author Marc Baloup + * + */ +public final class ORM { + + @SuppressWarnings("rawtypes") + private static Map tables = new HashMap(); + + + public synchronized static void init() { + try { + + /* + * Les tables SQL sont à instancier ici ! + */ + + tables.put("modo_history", new ModoHistoryTable()); + + tables.put("mp_message", new MPMessageTable()); + tables.put("mp_group", new MPGroupTable()); + tables.put("mp_group_user", new MPGroupUserTable()); + tables.put("mp_web_session", new MPWebSessionTable()); + + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + + + + + + @SuppressWarnings("rawtypes") + public synchronized static SQLTable getTable(String name) { + return tables.get(name); + } + + + + + + + + + private ORM() { } // rend la classe non instanciable + + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLManager.java deleted file mode 100644 index 6e749ea..0000000 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLManager.java +++ /dev/null @@ -1,51 +0,0 @@ -package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; - -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - -public class SQLManager { - - private static SQLManager instance; - - /** - * Retourne l'unique instance de la classe. Si elle n'existe pas, on tente de créer - * @return L'unique instance de la classe - */ - - public synchronized static SQLManager getInstance() { - if (instance == null) - loadNewInstance(); - return instance; - } - - public synchronized static void loadNewInstance() { - instance = new SQLManager(); - } - - - - - @SuppressWarnings("rawtypes") - private Map tables = new HashMap(); - - - public SQLManager() { - try { - - /* - * Les tables SQL sont à instancier ici ! - */ - - tables.put("modo_history", new ModoHistoryTable()); - - - } catch (SQLException e) { - e.printStackTrace(); - } - - - } - - -} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLTable.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLTable.java index 59a5f16..38b40a6 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLTable.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLTable.java @@ -73,10 +73,27 @@ public abstract class SQLTable { public List getAll() throws SQLException { + + return getAll(null, null, null, null); + } + + + public List getAll(String where, String orderBy, Integer limit, Integer offset) throws SQLException { Statement stmt = db.getConnection().createStatement(); - String sql = "SELECT * FROM "+tableName+";"; + String sql = "SELECT * FROM "+tableName; + + if (where != null) + sql += " WHERE "+where; + if (orderBy != null) + sql += " ORDER BY "+orderBy; + if (limit != null) + sql += " LIMIT "+limit; + if (offset != null) + sql += " OFFSET "+offset; + sql += ";"; ResultSet set = stmt.executeQuery(sql); + List elmts = new ArrayList(); while (set.next()) elmts.add(getElementInstance(set)); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/VanillaMessageManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/VanillaMessageManager.java index db7a899..a3980f0 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/VanillaMessageManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/VanillaMessageManager.java @@ -26,7 +26,7 @@ public class VanillaMessageManager { if (OnlinePlayerManager.get(event.getPlayer()).isVanished()) return; - plugin.getServer().broadcastMessage(ChatColor.YELLOW+event.getPlayer().getDisplayName()+ChatColor.YELLOW+" vient de se connecter"); + plugin.broadcast(ChatColor.YELLOW+event.getPlayer().getDisplayName()+ChatColor.YELLOW+" vient de se connecter", false); } @@ -38,8 +38,8 @@ public class VanillaMessageManager { // on affiche le message que si le joueur n'est pas vanish if (OnlinePlayerManager.get(event.getPlayer()).isVanished()) return; - - plugin.getServer().broadcastMessage(ChatColor.YELLOW+event.getPlayer().getDisplayName()+ChatColor.YELLOW+" a quitté le jeu"); + + plugin.broadcast(ChatColor.YELLOW+event.getPlayer().getDisplayName()+ChatColor.YELLOW+" a quitté le jeu", false); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java index 27136a2..bd31c1d 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java @@ -342,7 +342,7 @@ public class OnlinePlayer extends OffPlayer { * gère cette foncionnalitée */ public boolean isVanished() { - return EssentialsInterface.isPlayerVanished(player); + return getEssentialsUser().isVanished(); }