Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Core extends JavaPlugin {
- private ExecutorService executorService = Executors.newCachedThreadPool();
- private boolean EPOLL = Epoll.isAvailable();
- private EventLoopGroup eventLoopGroup;
- private static Core instance;
- private Channel channel;
- @Override
- public void onEnable() {
- eventLoopGroup = EPOLL ? new EpollEventLoopGroup() : new NioEventLoopGroup();
- try {
- newConnection();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onDisable() {
- eventLoopGroup.shutdownGracefully();
- }
- private void newConnection() throws InterruptedException {
- PacketHandler.registerPacket(PacketOutPing.class, PacketType.OUT);
- PacketHandler.registerPacket(PacketInPing.class, PacketType.IN);
- EventLoopGroup eventLoopGroup = EPOLL ? new EpollEventLoopGroup() : new NioEventLoopGroup();
- try {
- channel = new Bootstrap()
- .group(eventLoopGroup)
- .channel(EPOLL ? EpollSocketChannel.class : NioSocketChannel.class)
- .handler(new ChannelInitializer<Channel>() {
- @Override
- protected void initChannel(Channel channel) throws Exception {
- channel.pipeline()
- .addFirst(new PacketEncoder())
- .addLast(new PacketDecoder())
- .addLast(new NetworkHandler());
- }
- })
- .connect("127.0.0.1", 8000).sync().channel();
- } finally {
- eventLoopGroup.shutdownGracefully();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement