Some code improvement
This commit is contained in:
parent
8bc32aaa30
commit
5832e5270d
2
pom.xml
2
pom.xml
@ -24,7 +24,7 @@
|
||||
<dependency>
|
||||
<groupId>fr.pandacube.bungeecord</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.11-SNAPSHOT</version>
|
||||
<version>1.12-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -57,5 +57,9 @@ public class BiMap<K, V> implements Iterable<Entry<K, V>> {
|
||||
c.accept(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ public class PacketD0ServerException extends PacketServer {
|
||||
}
|
||||
|
||||
|
||||
public void setException(Exception e) {
|
||||
public void setException(Throwable t) {
|
||||
StringWriter sw = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(sw));
|
||||
t.printStackTrace(new PrintWriter(sw));
|
||||
exception = sw.toString();
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,6 @@ public class TCPServer extends Thread implements Closeable {
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
@SuppressWarnings("resource")
|
||||
Socket socketClient = socket.accept();
|
||||
socketClient.setSendBufferSize(Pandacube.NETWORK_TCP_BUFFER_SIZE);
|
||||
socketClient.setSoTimeout(Pandacube.NETWORK_TIMEOUT);
|
||||
@ -156,11 +155,13 @@ public class TCPServer extends Thread implements Closeable {
|
||||
|
||||
executeCallbacks(pc, callbacks);
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
Log.severe("Exception while handling packet. This exception will be sent to the client with PacketServerException packet.", e);
|
||||
PacketD0ServerException packet = new PacketD0ServerException();
|
||||
packet.setException(e);
|
||||
send(packet);
|
||||
if (e instanceof InterruptedException || e instanceof Error)
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,6 @@ public class NetworkAPIListener implements Runnable {
|
||||
try {
|
||||
// réception des connexion client
|
||||
while (!serverSocket.isClosed()) {
|
||||
@SuppressWarnings("resource")
|
||||
Socket socketClient = serverSocket.accept();
|
||||
nAPIExecutionHandler.handleRun(new PacketExecutor(socketClient, this));
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ public abstract class SQLElement<E extends SQLElement<E>> {
|
||||
return modifiedSinceLastSave.contains(field.name);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "resource" })
|
||||
@SuppressWarnings("unchecked")
|
||||
public void save() throws ORMException {
|
||||
if (!isValidForSave())
|
||||
throw new IllegalStateException(toString() + " has at least one undefined value and can't be saved.");
|
||||
|
@ -9,6 +9,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
|
||||
@ -45,10 +46,10 @@ public class SQLElementList<E extends SQLElement<E>> extends ArrayList<E> {
|
||||
* @param value la valeur à lui appliquer
|
||||
*/
|
||||
public synchronized <T> void setCommon(SQLField<E, T> field, T value) {
|
||||
if (field != null && field.name == "id")
|
||||
throw new IllegalArgumentException("Can't modify id field in a SQLElementList");
|
||||
if (field == null)
|
||||
throw new IllegalArgumentException("field can't be null");
|
||||
if (field.name == "id")
|
||||
throw new IllegalArgumentException("Can't modify id field in a SQLElementList");
|
||||
|
||||
Class<E> elemClass = field.getSQLElementType();
|
||||
try {
|
||||
@ -132,11 +133,7 @@ public class SQLElementList<E extends SQLElement<E>> extends ArrayList<E> {
|
||||
}
|
||||
|
||||
private List<E> getStoredEl() {
|
||||
List<E> listStored = new ArrayList<>();
|
||||
forEach(el -> {
|
||||
if (el.isStored()) listStored.add(el);
|
||||
});
|
||||
return listStored;
|
||||
return stream().filter(SQLElement::isStored).collect(Collectors.toCollection(() -> new ArrayList<>()));
|
||||
}
|
||||
|
||||
public synchronized void removeFromDB() {
|
||||
|
Loading…
Reference in New Issue
Block a user