Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. package de.skyxocuts.multicrafting.bungee.gamesmanager.server;
  2.  
  3. import de.skyxocuts.multicrafting.bungee.Main;
  4. import io.netty.bootstrap.ServerBootstrap;
  5. import io.netty.channel.ChannelInitializer;
  6. import io.netty.channel.ChannelPipeline;
  7. import io.netty.channel.EventLoopGroup;
  8. import io.netty.channel.nio.NioEventLoopGroup;
  9. import io.netty.channel.socket.SocketChannel;
  10. import io.netty.channel.socket.nio.NioServerSocketChannel;
  11. import io.netty.handler.codec.DelimiterBasedFrameDecoder;
  12. import io.netty.handler.codec.Delimiters;
  13. import io.netty.handler.codec.string.StringDecoder;
  14. import io.netty.handler.codec.string.StringEncoder;
  15.  
  16. /**
  17. * Created by Till on 01.06.2015.
  18. */
  19. public class BungeeServer {
  20.  
  21. private int port;
  22.  
  23. public BungeeServer() {
  24. this.port = 13494;
  25.  
  26. Main.plugin.getProxy().getScheduler().runAsync(Main.plugin, new Runnable() {
  27. @Override
  28. public void run() {
  29. init();
  30. }
  31. });
  32. }
  33.  
  34. public void init() {
  35. EventLoopGroup bossGroup = new NioEventLoopGroup();
  36. EventLoopGroup workerGroup = new NioEventLoopGroup();
  37.  
  38. try {
  39. ServerBootstrap bootstrap = new ServerBootstrap()
  40. .group(bossGroup, workerGroup)
  41. .channel(NioServerSocketChannel.class)
  42. .childHandler(new ChannelInitializer<SocketChannel>() {
  43. @Override
  44. public void initChannel(SocketChannel socketChannel) throws Exception {
  45. Main.plugin.getLogger().info("TEst");
  46. ChannelPipeline pipeline = socketChannel.pipeline();
  47. pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
  48. pipeline.addLast("decoder", new StringDecoder());
  49. pipeline.addLast("encoder", new StringEncoder());
  50.  
  51. pipeline.addLast("handler", new BungeeServerHandler());
  52. }
  53. });
  54.  
  55. bootstrap.bind(port).sync().channel().closeFuture().sync();
  56. } catch (InterruptedException e) {
  57. e.printStackTrace();
  58. } finally {
  59. bossGroup.shutdownGracefully();
  60. workerGroup.shutdownGracefully();
  61. }
  62.  
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement