Code Monkey home page Code Monkey logo

pewsserver's Introduction

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.

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
    }
}
  1. Create a WebSocket server:
WSServer server = new WSServer(new InetSocketAddress(19131), new MyFactory());
  1. Run your server:
server.start();
  1. 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.

public static final EventType TYPE = EventType.registerEventType("CustomEvent", CustomEvent.class);

@Override
public EventType getType() {
    return TYPE;
}
  1. 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:
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.

  1. Finally, you can use registerReceiver(CustomEvent.TYPE, myReceiver) to subscribe the custom event.

Thanks

pewsserver's People

Contributors

xeroalpha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.