Make the clientSide/serverSide builder options additative.

This commit is contained in:
Kristian S. Stangeland 2013-07-19 19:31:04 +02:00
parent 2756b80ac0
commit 7b9a5e9db4
2 changed files with 30 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -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));
}
/**