-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,51 @@ | ||
# ServersHandler | ||
Handling servers with Redis | ||
# ServersHandler 2.0 | ||
A complete rewrite of a 2 year old project. | ||
|
||
## Example | ||
```java | ||
public class Example extends JavaPlugin { | ||
|
||
private ServersHandler serversHandler; | ||
|
||
@Override | ||
public void onEnable() { | ||
serversHandler = ServersHandler.initialize(this, "Lobby", new JedisPoolBuilder() | ||
.withDefaultConfig() | ||
.hostname("localhost") | ||
.port(6379) | ||
); | ||
|
||
serversHandler.registerListener(synchronizedServer -> { | ||
System.out.printf( | ||
"Server %s was updated! (%s/%s)%n", | ||
synchronizedServer.getName(), | ||
synchronizedServer.getOnlinePlayers(), | ||
synchronizedServer.getMaxPlayers() | ||
); | ||
|
||
Map<String, Object> data = synchronizedServer.getData(); | ||
System.out.println("value: " + data.get("key")); | ||
}); | ||
|
||
Map<String, SynchronizedServer> servers = serversHandler.getServers(); | ||
System.out.println("Servers: " + servers.size()); | ||
|
||
SynchronizedServer local = serversHandler.local(); | ||
System.out.println("Local server: " + local.getName()); | ||
|
||
SynchronizedServer server = serversHandler.getServers().get("Lobby"); | ||
System.out.println("Lobby players: " + server.getOnlinePlayers()); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
serversHandler.shutdown(); | ||
} | ||
|
||
public void setKeyValue() { | ||
SynchronizedServer local = serversHandler.local(); | ||
local.getData().put("key", "value"); | ||
serversHandler.publish(local); | ||
} | ||
} | ||
``` |