Archiviert
13
0

Make the clientSide/serverSide builder options additative.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-07-19 19:31:04 +02:00
Ursprung 2756b80ac0
Commit 7b9a5e9db4
2 geänderte Dateien mit 30 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -45,4 +45,30 @@ public enum ConnectionSide {
public boolean isForServer() {
return this == SERVER_SIDE || this == BOTH;
}
/**
* If both connection sides are present, return {@link #BOTH} - otherwise, return the one valud connection side.
* <p>
* NULL is not a valid connection side.
* @param a - the first connection side.
* @param b - the second connection side.
* @return BOTH or the one valid side, or NULL.
*/
public static ConnectionSide add(ConnectionSide a, ConnectionSide b) {
if (a == null)
return b;
if (b == null)
return a;
// Now merge them together
boolean client = a.isForClient() || b.isForClient();
boolean server = a.isForServer() || b.isForServer();
if (client && server)
return BOTH;
else if (client)
return CLIENT_SIDE;
else
return SERVER_SIDE;
}
}

Datei anzeigen

@ -301,19 +301,19 @@ public abstract class PacketAdapter implements PacketListener {
}
/**
* Set this adapter to look for client-side packets only.
* Set this adapter to also look for client-side packets.
* @return This builder, for chaining.
*/
public AdapterParameteters clientSide() {
return connectionSide(ConnectionSide.CLIENT_SIDE);
return connectionSide(ConnectionSide.add(connectionSide, ConnectionSide.CLIENT_SIDE));
}
/**
* Set this adapter to look for client-side packets only.
* Set this adapter to also look for client-side packets.
* @return This builder, for chaining.
*/
public AdapterParameteters serverSide() {
return connectionSide(ConnectionSide.SERVER_SIDE);
return connectionSide(ConnectionSide.add(connectionSide, ConnectionSide.SERVER_SIDE));
}
/**