Meilleure gestion ignore list + correctifs divers
- 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())
This commit is contained in:
parent
0c1ac240f8
commit
a6bccfc17a
@ -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<SQLPlayer> {
|
||||
@ -83,9 +88,32 @@ public class SQLPlayer extends SQLElement<SQLPlayer> {
|
||||
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<SQLPlayer> getPlayersFromUUIDs(Set<UUID> playerIds) throws ORMException {
|
||||
Set<String> uuidsString = new HashSet<>();
|
||||
for (UUID id : playerIds)
|
||||
uuidsString.add(id.toString());
|
||||
return getPlayersFromUUIDStr(uuidsString);
|
||||
}
|
||||
|
||||
public static SQLElementList<SQLPlayer> getPlayersFromUUIDStr(Set<String> 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<SQLPlayerIgnore> {
|
||||
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<SQLPlayerIgnore> {
|
||||
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<SQLPlayerIgnore> {
|
||||
|
||||
}
|
||||
|
||||
public static List<UUID> getListIgnoredPlayer(UUID ignorer) throws Exception {
|
||||
List<SQLPlayerIgnore> els = ORM.getAll(SQLPlayerIgnore.class,
|
||||
public static Map<String, SQLPlayer> getIgnoredPlayer(UUID ignorer) throws ORMException {
|
||||
SQLElementList<SQLPlayerIgnore> els = ORM.getAll(SQLPlayerIgnore.class,
|
||||
new SQLWhereComp(SQLPlayerIgnore.ignorer, SQLComparator.EQ, ignorer.toString()),
|
||||
new SQLOrderBy().addField(ORM.getSQLIdField(SQLPlayerIgnore.class)), null, null);
|
||||
List<UUID> ret = new ArrayList<>(els.size());
|
||||
for (SQLPlayerIgnore el : els)
|
||||
ret.add(el.getIgnoredId());
|
||||
return ret;
|
||||
null, null, null);
|
||||
|
||||
return els.getAllForeign(SQLPlayerIgnore.ignored);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user