From a6bccfc17a4ee46d7b90e5c397bffb4d17f2821f Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Thu, 18 Aug 2016 15:27:46 +0200 Subject: [PATCH] Meilleure gestion ignore list + correctifs divers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Correction d'une cause probable d'un bug : l'arrêt des serveurs spigot se bloque après la sauvegarde des maps (donc logiquement après l'arrêt des plugins). La cause probable est qu'un thread non "daemon" ne s'arrête pas et bloque la fermeture du processus de Spigot. Le retrait de cette cause probable implique que chaque thread créé par le plugin doit être défini en daemon. (Thread#setDaemon()) --- src/fr/pandacube/java/util/db/SQLPlayer.java | 28 +++++++++++++++++++ .../java/util/db/SQLPlayerIgnore.java | 24 ++++++++-------- .../java/util/network/client/TCPClient.java | 1 + .../java/util/network/server/TCPServer.java | 3 ++ .../server/ThreadNAPIExecutionHandler.java | 4 ++- 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/fr/pandacube/java/util/db/SQLPlayer.java b/src/fr/pandacube/java/util/db/SQLPlayer.java index 392ba53..f969432 100644 --- a/src/fr/pandacube/java/util/db/SQLPlayer.java +++ b/src/fr/pandacube/java/util/db/SQLPlayer.java @@ -1,14 +1,19 @@ 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 { @@ -83,9 +88,32 @@ public class SQLPlayer extends SQLElement { 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/fr/pandacube/java/util/db/SQLPlayerIgnore.java b/src/fr/pandacube/java/util/db/SQLPlayerIgnore.java index 2c76b67..256c3e1 100644 --- a/src/fr/pandacube/java/util/db/SQLPlayerIgnore.java +++ b/src/fr/pandacube/java/util/db/SQLPlayerIgnore.java @@ -1,13 +1,13 @@ package fr.pandacube.java.util.db; -import java.util.ArrayList; -import java.util.List; +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.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; @@ -52,7 +52,7 @@ public class SQLPlayerIgnore extends SQLElement { set(ignored, (pName == null) ? (String) null : pName.toString()); } - public static SQLPlayerIgnore getPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws Exception { + 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())) @@ -60,11 +60,11 @@ public class SQLPlayerIgnore extends SQLElement { null); } - public static boolean isPlayerIgnoringPlayer(UUID ignorer, UUID ignored) throws Exception { + 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 Exception { + public static void setPlayerIgnorePlayer(UUID ignorer, UUID ignored, boolean newIgnoreState) throws ORMException { SQLPlayerIgnore el = getPlayerIgnoringPlayer(ignorer, ignored); if (el == null && newIgnoreState) { el = new SQLPlayerIgnore(); @@ -80,14 +80,12 @@ public class SQLPlayerIgnore extends SQLElement { } - public static List getListIgnoredPlayer(UUID ignorer) throws Exception { - List els = ORM.getAll(SQLPlayerIgnore.class, + public static Map getIgnoredPlayer(UUID ignorer) throws ORMException { + SQLElementList els = ORM.getAll(SQLPlayerIgnore.class, new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()), - new SQLOrderBy().addField(ORM.getSQLIdField(SQLPlayerIgnore.class)), null, null); - List ret = new ArrayList<>(els.size()); - for (SQLPlayerIgnore el : els) - ret.add(el.getIgnoredId()); - return ret; + null, null, null); + + return els.getAllForeign(SQLPlayerIgnore.ignored); } } diff --git a/src/fr/pandacube/java/util/network/client/TCPClient.java b/src/fr/pandacube/java/util/network/client/TCPClient.java index 544ad21..fd7e2ef 100644 --- a/src/fr/pandacube/java/util/network/client/TCPClient.java +++ b/src/fr/pandacube/java/util/network/client/TCPClient.java @@ -33,6 +33,7 @@ public class TCPClient extends Thread implements Closeable { public TCPClient(InetSocketAddress a, String connName, TCPClientListener l) throws IOException { super("TCPCl " + connName); + setDaemon(true); if (a == null || l == null) throw new IllegalArgumentException("les arguments ne peuvent pas être null"); socket = new Socket(); socket.setReceiveBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE); diff --git a/src/fr/pandacube/java/util/network/server/TCPServer.java b/src/fr/pandacube/java/util/network/server/TCPServer.java index 3376289..cf31780 100644 --- a/src/fr/pandacube/java/util/network/server/TCPServer.java +++ b/src/fr/pandacube/java/util/network/server/TCPServer.java @@ -49,6 +49,7 @@ public class TCPServer extends Thread implements Closeable { public TCPServer(int port, String sckName, TCPServerListener l) throws IOException { super("TCPSv " + sckName); + setDaemon(true); if (port <= 0 || port > 65535) throw new IllegalArgumentException("le numéro de port est invalide"); socket = new ServerSocket(); socket.setReceiveBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE); @@ -97,6 +98,7 @@ public class TCPServer extends Thread implements Closeable { public TCPServerClientConnection(Socket s, int coId) throws IOException { super("TCPSv " + socketName + " Conn#" + coId + " In"); + setDaemon(true); socket = s; in = socket.getInputStream(); out = socket.getOutputStream(); @@ -189,6 +191,7 @@ public class TCPServer extends Thread implements Closeable { public TCPServerConnectionOutputThread(int coId) { super("TCPSv " + socketName + " Conn#" + coId + " Out"); + setDaemon(true); } private void addPacket(PacketServer packet) { diff --git a/src/fr/pandacube/java/util/network_api/server/ThreadNAPIExecutionHandler.java b/src/fr/pandacube/java/util/network_api/server/ThreadNAPIExecutionHandler.java index 09e7d58..ffdc0bb 100644 --- a/src/fr/pandacube/java/util/network_api/server/ThreadNAPIExecutionHandler.java +++ b/src/fr/pandacube/java/util/network_api/server/ThreadNAPIExecutionHandler.java @@ -4,7 +4,9 @@ public class ThreadNAPIExecutionHandler implements NAPIExecutionHandler { @Override public void handleRun(Runnable executor) { - new Thread(executor).start(); + Thread t = new Thread(executor); + t.setDaemon(true); + t.start(); } }