Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/XeroAlpha/PEWSServer
A WebSocket Server for Minecraft (Bedrock Edition)
https://github.com/XeroAlpha/PEWSServer
Last synced: 3 months ago
JSON representation
A WebSocket Server for Minecraft (Bedrock Edition)
- Host: GitHub
- URL: https://github.com/XeroAlpha/PEWSServer
- Owner: XeroAlpha
- License: gpl-3.0
- Created: 2018-07-09T02:50:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-17T11:15:53.000Z (over 6 years ago)
- Last Synced: 2024-07-28T13:23:16.184Z (3 months ago)
- Language: Java
- Size: 1.29 MB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-minecraft-bedrock - PEWSServer - A WebSocket Server for Minecraft (Bedrock Edition). (Library)
README
# Websocket Server for Minecraft (Bedrock Edition)
## How to use
1. Import `PEWSServer-lite.jar` (You can download it in the Release page.).2. Define you listener factory, this factory creates a listener for every WebSocket connection.
```java
class MyFactory extends MCListenerFactory {
@Override
public MCListener create(WebSocket conn) {
return new MyListener();
}
}class MyListener implements MCListener {
@Override
public void onCreate(MCClient client) {
//when finishing connecting
}@Override
public void onDestroy(MCClient client) {
//when disconnecting
}@Override
public void onError(MCClient client, MCError error) {
//when some error occurs in Minecraft Client
}
}
```3. Create a WebSocket server:
```java
WSServer server = new WSServer(new InetSocketAddress(19131), new MyFactory());
```4. Run your server:
```java
server.start();
```5. Now you can connect to this server by using command '/connect your_ip:port' on your client.
## How to listen to custom Event
1. Extend `com.xero.mcpews.event.Event`.
2. Add a public static field to store the `EventType` of this custom `Event` like this
and override method `getType()`, making it return the `EventType` field before.
```java
public static final EventType TYPE = EventType.registerEventType("CustomEvent", CustomEvent.class);@Override
public EventType getType() {
return TYPE;
}
```3. If you do not want to use Gson to serialize this type of event, you should add a public static
method with the following name and signature:
```java
public static CustomEvent fromJson(JsonElement json, Gson gson) {...}
```
otherwise, WSServer will use {@code gson.fromJson} to serialize it when receiving event with the specific name.4. Finally, you can use `registerReceiver(CustomEvent.TYPE, myReceiver)` to subscribe the custom event.
## Thanks
- [jocopa3/PEWS-API](https://github.com/jocopa3/PEWS-API)
- [LNSSPsd/MyAgent](https://github.com/LNSSPsd/MyAgent)