File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
helpers/test-client/src/sc
sdk/src/server-api/sc/api/plugins Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 4242public class TestClient extends XStreamClient {
4343 private static final Logger logger = (Logger ) LoggerFactory .getLogger (TestClient .class );
4444
45- private static final String gameType = ServiceLoader . load ( IGamePlugin .class ). iterator (). next (). id ();
45+ private static final String gameType = IGamePlugin .loadPluginId ();
4646 private static final ClientPlayer [] players = {new ClientPlayer (), new ClientPlayer ()};
4747 private static final File logDir = new File ("log" ).getAbsoluteFile ();
4848
Original file line number Diff line number Diff line change @@ -2,13 +2,27 @@ package sc.api.plugins
22
33import sc.plugins.IPlugin
44import sc.shared.ScoreDefinition
5- import java.io.File
5+ import java.util.ServiceLoader
66
77interface IGamePlugin : IPlugin {
8- fun id (): String?
8+ fun id (): String
99 /* * @return eine neues Spiel dieses Typs. */
1010 fun createGame (): IGameInstance
1111 fun createGameFromState (state : IGameState ): IGameInstance
1212
1313 val scoreDefinition: ScoreDefinition
14+
15+ companion object {
16+ @JvmStatic
17+ fun loadPlugin (): IGamePlugin {
18+ val iter = ServiceLoader .load(IGamePlugin ::class .java).iterator()
19+ if (! iter.hasNext())
20+ throw RuntimeException (" Couldn't find a plugin!" )
21+ return iter.next()
22+ }
23+
24+ @JvmStatic
25+ fun loadPluginId (): String =
26+ loadPlugin().id()
27+ }
1428}
You can’t perform that action at this time.
0 commit comments