@@ 63-103 (lines=41) @@ | ||
60 | // Converting the byte array into a byte buffer |
|
61 | ByteBuf buf = Unpooled.wrappedBuffer( event.getData() ); |
|
62 | ||
63 | try { |
|
64 | // Reading the message key |
|
65 | final String messageKey = LabyModPlugin.getInstance().getApi().readString( buf, Short.MAX_VALUE ); |
|
66 | final String messageContents = LabyModPlugin.getInstance().getApi().readString( buf, Short.MAX_VALUE ); |
|
67 | final JsonElement jsonMessage = jsonParser.parse( messageContents ); |
|
68 | ||
69 | // Calling the event synchronously |
|
70 | ProxyServer.getInstance().getScheduler().schedule( LabyModPlugin.getInstance(), new Runnable() { |
|
71 | @Override |
|
72 | public void run() { |
|
73 | // Listening to the INFO (join) message |
|
74 | if ( messageKey.equals( "INFO" ) && jsonMessage.isJsonObject() ) { |
|
75 | JsonObject jsonObject = jsonMessage.getAsJsonObject(); |
|
76 | String version = jsonObject.has( "version" ) |
|
77 | && jsonObject.get( "version" ).isJsonPrimitive() |
|
78 | && jsonObject.get( "version" ).getAsJsonPrimitive().isString() ? jsonObject.get( "version" ).getAsString() : "Unknown"; |
|
79 | ||
80 | boolean chunkCachingEnabled = false; |
|
81 | int chunkCachingVersion = 0; |
|
82 | ||
83 | if ( jsonObject.has( "ccp" ) && jsonObject.get( "ccp" ).isJsonObject() ) { |
|
84 | JsonObject chunkCachingObject = jsonObject.get( "ccp" ).getAsJsonObject(); |
|
85 | ||
86 | if ( chunkCachingObject.has( "enabled" ) ) |
|
87 | chunkCachingEnabled = chunkCachingObject.get( "enabled" ).getAsBoolean(); |
|
88 | ||
89 | if ( chunkCachingObject.has( "version" ) ) |
|
90 | chunkCachingVersion = chunkCachingObject.get( "version" ).getAsInt(); |
|
91 | } |
|
92 | ||
93 | ProxyServer.getInstance().getPluginManager().callEvent( new LabyModPlayerJoinEvent( player, version, |
|
94 | chunkCachingEnabled, chunkCachingVersion, Addon.getAddons( jsonObject ) ) ); |
|
95 | return; |
|
96 | } |
|
97 | ||
98 | // Calling the LabyModPlayerJoinEvent |
|
99 | ProxyServer.getInstance().getPluginManager().callEvent( new MessageReceiveEvent( player, messageKey, jsonMessage ) ); |
|
100 | } |
|
101 | }, 0L, TimeUnit.SECONDS ); |
|
102 | } catch ( RuntimeException ex ) { |
|
103 | ex.printStackTrace(); |
|
104 | } |
|
105 | } |
|
106 | } |
@@ 101-144 (lines=44) @@ | ||
98 | // Converting the byte array into a byte buffer |
|
99 | ByteBuf buf = Unpooled.wrappedBuffer( bytes ); |
|
100 | ||
101 | try { |
|
102 | // Reading the message key |
|
103 | final String messageKey = api.readString( buf, Short.MAX_VALUE ); |
|
104 | final String messageContents = api.readString( buf, Short.MAX_VALUE ); |
|
105 | final JsonElement jsonMessage = JSON_PARSER.parse( messageContents ); |
|
106 | ||
107 | // Calling the event synchronously |
|
108 | Bukkit.getScheduler().runTask( LabyModPlugin.this, new Runnable() { |
|
109 | @Override |
|
110 | public void run() { |
|
111 | // Checking whether the player is still online |
|
112 | if ( !player.isOnline() ) |
|
113 | return; |
|
114 | ||
115 | // Listening to the INFO (join) message |
|
116 | if ( messageKey.equals( "INFO" ) && jsonMessage.isJsonObject() ) { |
|
117 | JsonObject jsonObject = jsonMessage.getAsJsonObject(); |
|
118 | String version = jsonObject.has( "version" ) |
|
119 | && jsonObject.get( "version" ).isJsonPrimitive() |
|
120 | && jsonObject.get( "version" ).getAsJsonPrimitive().isString() ? jsonObject.get( "version" ).getAsString() : "Unknown"; |
|
121 | ||
122 | boolean chunkCachingEnabled = false; |
|
123 | int chunkCachingVersion = 0; |
|
124 | ||
125 | if ( jsonObject.has( "ccp" ) && jsonObject.get( "ccp" ).isJsonObject() ) { |
|
126 | JsonObject chunkCachingObject = jsonObject.get( "ccp" ).getAsJsonObject(); |
|
127 | ||
128 | if ( chunkCachingObject.has( "enabled" ) ) |
|
129 | chunkCachingEnabled = chunkCachingObject.get( "enabled" ).getAsBoolean(); |
|
130 | ||
131 | if ( chunkCachingObject.has( "version" ) ) |
|
132 | chunkCachingVersion = chunkCachingObject.get( "version" ).getAsInt(); |
|
133 | } |
|
134 | ||
135 | Bukkit.getPluginManager().callEvent( new LabyModPlayerJoinEvent( player, version, |
|
136 | chunkCachingEnabled, chunkCachingVersion, Addon.getAddons( jsonObject ) ) ); |
|
137 | return; |
|
138 | } |
|
139 | ||
140 | // Calling the MessageReceiveEvent |
|
141 | Bukkit.getPluginManager().callEvent( new MessageReceiveEvent( player, messageKey, jsonMessage ) ); |
|
142 | } |
|
143 | } ); |
|
144 | } catch ( RuntimeException ignored ) { |
|
145 | } |
|
146 | } |
|
147 | } ); |