Compare commits
327 Commits
Minecraft-
...
Minecraft-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
edc5b4dc91 | ||
![]() |
220a95aece | ||
![]() |
4685099808 | ||
![]() |
6c14f40108 | ||
![]() |
b041d84063 | ||
![]() |
a9d3d9461f | ||
![]() |
3fc7064997 | ||
![]() |
80001aa1f0 | ||
![]() |
a0d94282f6 | ||
![]() |
33e11f4c44 | ||
![]() |
b541e7aa76 | ||
![]() |
dd06937a3b | ||
![]() |
891dc87b16 | ||
![]() |
8e77cb35ff | ||
![]() |
59b32a8621 | ||
![]() |
02324206e3 | ||
![]() |
73ce828e6e | ||
![]() |
79d04bec2e | ||
![]() |
cbcd874d47 | ||
![]() |
09f123ce9a | ||
![]() |
0a5f8556fe | ||
![]() |
103a509f26 | ||
![]() |
32a5271dc3 | ||
![]() |
14389eb370 | ||
![]() |
a8b6a6b4aa | ||
![]() |
8133304cce | ||
![]() |
3e8c21a485 | ||
![]() |
f12dcc72d9 | ||
![]() |
a7a32509c7 | ||
![]() |
703a393888 | ||
![]() |
3c961cd5d9 | ||
![]() |
12ee68a315 | ||
![]() |
db5510cc4e | ||
![]() |
5ed5c71aea | ||
![]() |
38a8469ab4 | ||
![]() |
9538dcf4d4 | ||
![]() |
33f654ce6f | ||
![]() |
c108e4e1ce | ||
![]() |
e998faeec1 | ||
![]() |
d67acd7bc9 | ||
![]() |
702f434db1 | ||
![]() |
47b5631562 | ||
![]() |
80e23d6646 | ||
![]() |
1dca12cffb | ||
![]() |
29c897c9cf | ||
![]() |
042f47cbb9 | ||
![]() |
422e97f495 | ||
![]() |
08789d8f9f | ||
![]() |
96444ae304 | ||
![]() |
af58db8a67 | ||
![]() |
49cffebd9b | ||
![]() |
ffdb917f2c | ||
![]() |
9c9657e36d | ||
![]() |
1342baed47 | ||
![]() |
e3a7490bcd | ||
![]() |
3e8693793c | ||
![]() |
bb47aba682 | ||
![]() |
d0e5ee4e09 | ||
![]() |
07e330b005 | ||
![]() |
024288e587 | ||
![]() |
53a6bb1dee | ||
![]() |
0f06b2c4e0 | ||
![]() |
d3c1acce83 | ||
![]() |
eaea090d37 | ||
![]() |
7384e797fc | ||
![]() |
d4d93ddbb9 | ||
![]() |
ccdf2a89d8 | ||
![]() |
89edb00c05 | ||
![]() |
00a0277a13 | ||
![]() |
68f11e46f7 | ||
![]() |
c352e854ee | ||
![]() |
d8c92cd311 | ||
![]() |
99f361ca77 | ||
![]() |
738ed99d54 | ||
![]() |
ad0da59267 | ||
![]() |
1dcc8d6a4b | ||
![]() |
0840a77153 | ||
![]() |
61a93a54a9 | ||
![]() |
da0281508e | ||
![]() |
51e92de2dd | ||
![]() |
f948acd634 | ||
![]() |
773ce089c1 | ||
![]() |
a07eba7965 | ||
![]() |
b68b6a76c7 | ||
![]() |
332033bb02 | ||
![]() |
172b8bc75b | ||
![]() |
db5a147491 | ||
![]() |
f083e27649 | ||
![]() |
b64a7be19b | ||
![]() |
c4d60a8fa9 | ||
![]() |
f07cfe0cf7 | ||
![]() |
4463b0c1b2 | ||
![]() |
ee8f33c196 | ||
![]() |
14ac2dd308 | ||
![]() |
fb94612315 | ||
![]() |
4c96880580 | ||
![]() |
4c4cdd51a1 | ||
![]() |
1f38152530 | ||
![]() |
911f08d52c | ||
![]() |
8f961c9d4e | ||
![]() |
8a5d8a57f7 | ||
![]() |
c54553d0f9 | ||
![]() |
600a1b4ff5 | ||
![]() |
09e592295f | ||
![]() |
fa0ee02beb | ||
![]() |
b23b54d9e4 | ||
![]() |
b3e8feb4cb | ||
![]() |
d0d1562155 | ||
![]() |
f510ab2a0b | ||
![]() |
fb1cab499d | ||
![]() |
58ca63e2b1 | ||
![]() |
499337c98e | ||
![]() |
526137be7b | ||
![]() |
47839cb11c | ||
![]() |
55a6cc56ef | ||
![]() |
8c2bea5be2 | ||
![]() |
daa58ffe58 | ||
![]() |
0189ad9c17 | ||
![]() |
9adcb05d45 | ||
![]() |
10e81041b2 | ||
![]() |
0c56945ffd | ||
![]() |
0a36cbd5bc | ||
![]() |
61b4777177 | ||
![]() |
7d1904584b | ||
![]() |
475571986c | ||
![]() |
55c2bcd634 | ||
![]() |
db4abfe486 | ||
![]() |
9424bdedca | ||
![]() |
52b3c6b77c | ||
![]() |
be29799f5a | ||
![]() |
c0d581d41f | ||
![]() |
6b50c7c599 | ||
![]() |
b4101874cc | ||
![]() |
66de4c95ef | ||
![]() |
927a295add | ||
![]() |
2cbea83c02 | ||
![]() |
87884ad084 | ||
![]() |
94cc2412e7 | ||
![]() |
924b90e325 | ||
![]() |
3f476a30b4 | ||
![]() |
f579b31bca | ||
![]() |
cac35116c3 | ||
![]() |
bd42fb23a0 | ||
![]() |
ffbebaff69 | ||
![]() |
b741722e5d | ||
![]() |
07288c722c | ||
![]() |
85e82a2e34 | ||
![]() |
3aef35ccbb | ||
![]() |
d1760dad93 | ||
![]() |
d3d11cf283 | ||
![]() |
d3bada58d4 | ||
![]() |
23517a9a97 | ||
![]() |
fdc87e88f5 | ||
![]() |
12941ffe62 | ||
![]() |
06e732d8c7 | ||
![]() |
5c4ea3c7a0 | ||
![]() |
632fa8bd94 | ||
![]() |
8732904bfd | ||
![]() |
788b96dc0a | ||
![]() |
1296783d9b | ||
![]() |
a9603a6372 | ||
![]() |
b15ed87ad5 | ||
![]() |
3e816f628b | ||
![]() |
7bfc4bf819 | ||
![]() |
f8d15f4c88 | ||
![]() |
a73b06eee3 | ||
![]() |
2069679140 | ||
![]() |
9a173968f1 | ||
![]() |
13f1fa7443 | ||
![]() |
0f7da279ef | ||
![]() |
a6ba661a32 | ||
![]() |
22133bc8d2 | ||
![]() |
f9c9517958 | ||
![]() |
7a79bd0816 | ||
![]() |
6a60376033 | ||
![]() |
4ce0eee232 | ||
![]() |
72f3a79759 | ||
![]() |
dbb6aebf58 | ||
![]() |
54040ec48d | ||
![]() |
8c4ddf458c | ||
![]() |
07fb6490f8 | ||
![]() |
d9eb8c66b8 | ||
![]() |
7fab3ba372 | ||
![]() |
92c3ef1989 | ||
![]() |
fbf2d8969e | ||
![]() |
1881507712 | ||
![]() |
fd2a72477f | ||
![]() |
d4cbac1bdf | ||
![]() |
fa0671ab2a | ||
![]() |
184154a8b3 | ||
![]() |
cbec4e836a | ||
![]() |
3ce7982778 | ||
![]() |
b55944e2fb | ||
![]() |
12cba14657 | ||
![]() |
78e67283cc | ||
![]() |
f0f1e71c93 | ||
![]() |
3c1a5aabfd | ||
![]() |
f0d4e8c24a | ||
![]() |
ba8bd7faf0 | ||
![]() |
787692070e | ||
![]() |
523e991018 | ||
![]() |
7733fbfb28 | ||
![]() |
44ac36941f | ||
![]() |
0235c4a01e | ||
![]() |
b4220e9229 | ||
![]() |
9b9addfccd | ||
![]() |
b75a2b5060 | ||
![]() |
b5aecd5dcc | ||
![]() |
4d51d16512 | ||
![]() |
05a9342854 | ||
![]() |
483fede234 | ||
![]() |
ce8f1b44b6 | ||
![]() |
b1e3f6a75b | ||
![]() |
33d315b719 | ||
![]() |
d11e130d61 | ||
![]() |
45a93c8cfc | ||
![]() |
fd411edddb | ||
![]() |
ac5e8dbaff | ||
![]() |
340d82812a | ||
![]() |
eaf99cf4a6 | ||
![]() |
4baae5a230 | ||
![]() |
aa1a871967 | ||
![]() |
18f5ed3102 | ||
![]() |
d1dd7379b1 | ||
![]() |
0b0d09427d | ||
![]() |
dce0f6b408 | ||
![]() |
c5307c4451 | ||
![]() |
4f2b98188e | ||
![]() |
d5eb37c7a6 | ||
![]() |
2a421cdd8d | ||
![]() |
757f8f0cb9 | ||
![]() |
388d2620db | ||
![]() |
3ba52cb98b | ||
![]() |
e652214071 | ||
![]() |
0821404f92 | ||
![]() |
11b90b91b7 | ||
![]() |
aa3989db19 | ||
![]() |
76c914db14 | ||
![]() |
639e5f3c1d | ||
![]() |
9fd69068ae | ||
![]() |
9c35cad824 | ||
![]() |
d82b29e15a | ||
![]() |
9b0c827c37 | ||
![]() |
125d3f07f7 | ||
![]() |
2f45f0d578 | ||
![]() |
ad4c143ce4 | ||
![]() |
835e4e332c | ||
![]() |
0578f94522 | ||
![]() |
0cd4c9030c | ||
![]() |
0d666168f0 | ||
![]() |
cfb823f077 | ||
![]() |
36a5e89ff9 | ||
![]() |
bb4e8e29a5 | ||
![]() |
8e34e038d6 | ||
![]() |
d1950389cc | ||
![]() |
9d841bb91a | ||
![]() |
828cebcc4b | ||
![]() |
12fec2fcdd | ||
![]() |
8b6b134662 | ||
![]() |
538beb33a6 | ||
![]() |
97338cbfad | ||
![]() |
3e28decef2 | ||
![]() |
f93b647df3 | ||
![]() |
775ffdc998 | ||
![]() |
80c22027de | ||
![]() |
122987dd83 | ||
![]() |
ac4bab2425 | ||
![]() |
a51ffb1f4c | ||
![]() |
77e0dcc7f8 | ||
![]() |
ddb93fd988 | ||
![]() |
7eac22d362 | ||
![]() |
185dc97ca6 | ||
![]() |
e0d19cf305 | ||
![]() |
0e9002091b | ||
![]() |
9fdcded97f | ||
![]() |
32fdc83841 | ||
![]() |
1bf126d4f8 | ||
![]() |
56533c6259 | ||
![]() |
4cb46c6e5c | ||
![]() |
6decf860c9 | ||
![]() |
29f22f9be9 | ||
![]() |
98860ffd02 | ||
![]() |
2c225a05e7 | ||
![]() |
c1dfd0fb7b | ||
![]() |
9be44d51a6 | ||
![]() |
2a2c2717d5 | ||
![]() |
3f994a1c4c | ||
![]() |
9a0da50e6c | ||
![]() |
67fdc830c2 | ||
![]() |
64e8a79551 | ||
![]() |
afc387ce0d | ||
![]() |
8a70af5293 | ||
![]() |
57793e93f0 | ||
![]() |
a48ef137bd | ||
![]() |
ff32d29e09 | ||
![]() |
9f3359f8fa | ||
![]() |
539fccb873 | ||
![]() |
b25c81daf3 | ||
![]() |
21a354fa75 | ||
![]() |
aefe3333a9 | ||
![]() |
0afefa8f61 | ||
![]() |
834ac24b38 | ||
![]() |
c465eca03b | ||
![]() |
beb0bf9836 | ||
![]() |
688c42219c | ||
![]() |
1ea53f01aa | ||
![]() |
202dab5c98 | ||
![]() |
49ea7f908f | ||
![]() |
9d3bddedb6 | ||
![]() |
332bdaaec0 | ||
![]() |
904a1bfaa3 | ||
![]() |
5eb7a6eba7 | ||
![]() |
8e262cf428 | ||
![]() |
125df5c22d | ||
![]() |
7b631092f5 | ||
![]() |
d3c1339cc9 | ||
![]() |
679bf2fca9 | ||
![]() |
7436621481 | ||
![]() |
6236cff658 | ||
![]() |
6b504d9160 | ||
![]() |
d1124ca70b | ||
![]() |
779582d441 | ||
![]() |
b91564f77a | ||
![]() |
30b2e5008b | ||
![]() |
140830efe0 | ||
![]() |
5f8e76c61c | ||
![]() |
b7511abfda |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,12 +1,11 @@
|
|||||||
# Eclipse stuff
|
# Eclipse stuff
|
||||||
.classpath/
|
.classpath
|
||||||
.project/
|
.project
|
||||||
.settings/
|
.settings/
|
||||||
|
|
||||||
# netbeans
|
# netbeans
|
||||||
nbproject/
|
nbproject/
|
||||||
nbactions.xml
|
nbactions.xml
|
||||||
nb-configuration.xml
|
|
||||||
|
|
||||||
# we use maven!
|
# we use maven!
|
||||||
build.xml
|
build.xml
|
||||||
|
31
api/nb-configuration.xml
Normal file
31
api/nb-configuration.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
22
api/pom.xml
22
api/pom.xml
@@ -6,13 +6,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-parent</artifactId>
|
<artifactId>bungeecord-parent</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-api</artifactId>
|
<artifactId>bungeecord-api</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>BungeeCord-API</name>
|
<name>BungeeCord-API</name>
|
||||||
@@ -26,15 +26,21 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ning</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>async-http-client</artifactId>
|
<artifactId>bungeecord-config</artifactId>
|
||||||
<version>1.7.14</version>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.yaml</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>snakeyaml</artifactId>
|
<artifactId>bungeecord-event</artifactId>
|
||||||
<version>1.12</version>
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-protocol</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@@ -1,111 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2007 The Guava Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.google.common.eventbus;
|
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.cache.LoadingCache;
|
|
||||||
import com.google.common.collect.HashMultimap;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.common.reflect.TypeToken;
|
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link HandlerFindingStrategy} for collecting all event handler methods that are marked with
|
|
||||||
* the {@link Subscribe} annotation.
|
|
||||||
*
|
|
||||||
* @author Cliff Biffle
|
|
||||||
* @author Louis Wasserman
|
|
||||||
*/
|
|
||||||
class AnnotatedHandlerFinder implements HandlerFindingStrategy {
|
|
||||||
/**
|
|
||||||
* A thread-safe cache that contains the mapping from each class to all methods in that class and
|
|
||||||
* all super-classes, that are annotated with {@code @Subscribe}. The cache is shared across all
|
|
||||||
* instances of this class; this greatly improves performance if multiple EventBus instances are
|
|
||||||
* created and objects of the same class are registered on all of them.
|
|
||||||
*/
|
|
||||||
private static final LoadingCache<Class<?>, ImmutableList<Method>> handlerMethodsCache =
|
|
||||||
CacheBuilder.newBuilder()
|
|
||||||
.weakKeys()
|
|
||||||
.build(new CacheLoader<Class<?>, ImmutableList<Method>>() {
|
|
||||||
@Override
|
|
||||||
public ImmutableList<Method> load(Class<?> concreteClass) throws Exception {
|
|
||||||
return getAnnotatedMethodsInternal(concreteClass);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* This implementation finds all methods marked with a {@link Subscribe} annotation.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Multimap<Class<?>, EventHandler> findAllHandlers(Object listener) {
|
|
||||||
Multimap<Class<?>, EventHandler> methodsInListener = HashMultimap.create();
|
|
||||||
Class<?> clazz = listener.getClass();
|
|
||||||
for (Method method : getAnnotatedMethods(clazz)) {
|
|
||||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
|
||||||
Class<?> eventType = parameterTypes[0];
|
|
||||||
EventHandler handler = new EventHandler(listener, method);
|
|
||||||
methodsInListener.put(eventType, handler);
|
|
||||||
}
|
|
||||||
return methodsInListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ImmutableList<Method> getAnnotatedMethods(Class<?> clazz) {
|
|
||||||
try {
|
|
||||||
return handlerMethodsCache.getUnchecked(clazz);
|
|
||||||
} catch (UncheckedExecutionException e) {
|
|
||||||
throw Throwables.propagate(e.getCause());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ImmutableList<Method> getAnnotatedMethodsInternal(Class<?> clazz) {
|
|
||||||
Set<? extends Class<?>> supers = TypeToken.of(clazz).getTypes().rawTypes();
|
|
||||||
ImmutableList.Builder<Method> result = ImmutableList.builder();
|
|
||||||
for (Method method : clazz.getMethods()) {
|
|
||||||
/*
|
|
||||||
* Iterate over each distinct method of {@code clazz}, checking if it is annotated with
|
|
||||||
* @Subscribe by any of the superclasses or superinterfaces that declare it.
|
|
||||||
*/
|
|
||||||
for (Class<?> c : supers) {
|
|
||||||
try {
|
|
||||||
Method m = c.getMethod(method.getName(), method.getParameterTypes());
|
|
||||||
if (m.isAnnotationPresent(Subscribe.class)) {
|
|
||||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
|
||||||
if (parameterTypes.length != 1) {
|
|
||||||
throw new IllegalArgumentException("Method " + method
|
|
||||||
+ " has @Subscribe annotation, but requires " + parameterTypes.length
|
|
||||||
+ " arguments. Event handler methods must require a single argument.");
|
|
||||||
}
|
|
||||||
Class<?> eventType = parameterTypes[0];
|
|
||||||
result.add(method);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (NoSuchMethodException ignored) {
|
|
||||||
// Move on.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.build();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,46 @@
|
|||||||
|
package net.md_5.bungee.api;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
public abstract class AbstractReconnectHandler implements ReconnectHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerInfo getServer(ProxiedPlayer player)
|
||||||
|
{
|
||||||
|
ServerInfo server = getForcedHost( player.getPendingConnection() );
|
||||||
|
if ( server == null )
|
||||||
|
{
|
||||||
|
server = getStoredServer( player );
|
||||||
|
if ( server == null )
|
||||||
|
{
|
||||||
|
server = ProxyServer.getInstance().getServerInfo( player.getPendingConnection().getListener().getDefaultServer() );
|
||||||
|
}
|
||||||
|
|
||||||
|
Preconditions.checkState( server != null, "Default server not defined" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ServerInfo getForcedHost(PendingConnection con)
|
||||||
|
{
|
||||||
|
if ( con.getVirtualHost() == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String forced = con.getListener().getForcedHosts().get( con.getVirtualHost().getHostString() );
|
||||||
|
|
||||||
|
if ( forced == null && con.getListener().isForceDefault() )
|
||||||
|
{
|
||||||
|
forced = con.getListener().getDefaultServer();
|
||||||
|
}
|
||||||
|
return ProxyServer.getInstance().getServerInfo( forced );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract ServerInfo getStoredServer(ProxiedPlayer player);
|
||||||
|
}
|
@@ -2,7 +2,6 @@ package net.md_5.bungee.api;
|
|||||||
|
|
||||||
import net.md_5.bungee.api.plugin.PluginManager;
|
import net.md_5.bungee.api.plugin.PluginManager;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.ning.http.client.AsyncHttpClient;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -12,9 +11,9 @@ import lombok.Getter;
|
|||||||
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.connection.Server;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.api.scheduler.TaskScheduler;
|
import net.md_5.bungee.api.scheduler.TaskScheduler;
|
||||||
|
import net.md_5.bungee.api.tab.CustomTabList;
|
||||||
|
|
||||||
public abstract class ProxyServer
|
public abstract class ProxyServer
|
||||||
{
|
{
|
||||||
@@ -49,6 +48,13 @@ public abstract class ProxyServer
|
|||||||
*/
|
*/
|
||||||
public abstract String getVersion();
|
public abstract String getVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a localized string from the .properties file.
|
||||||
|
*
|
||||||
|
* @return the localized string
|
||||||
|
*/
|
||||||
|
public abstract String getTranslation(String name, Object... args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the main logger which can be used as a suitable replacement for
|
* Gets the main logger which can be used as a suitable replacement for
|
||||||
* {@link System#out} and {@link System#err}.
|
* {@link System#out} and {@link System#err}.
|
||||||
@@ -72,20 +78,6 @@ public abstract class ProxyServer
|
|||||||
*/
|
*/
|
||||||
public abstract ProxiedPlayer getPlayer(String name);
|
public abstract ProxiedPlayer getPlayer(String name);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a server by its name. The instance returned will be taken from a
|
|
||||||
* player currently on that server to facilitate abstract proxy -> server
|
|
||||||
* actions.
|
|
||||||
*
|
|
||||||
* @param name the name to lookup
|
|
||||||
* @return the associated server
|
|
||||||
* @deprecated in most cases the {@link #getServerInfo(java.lang.String)}
|
|
||||||
* method should be used, as it will return a server even when no players
|
|
||||||
* are online.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract Server getServer(String name);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all servers registered to this proxy, keyed by name. Unlike the
|
* Return all servers registered to this proxy, keyed by name. Unlike the
|
||||||
* methods in {@link ConfigurationAdapter#getServers()}, this will not
|
* methods in {@link ConfigurationAdapter#getServers()}, this will not
|
||||||
@@ -127,21 +119,6 @@ public abstract class ProxyServer
|
|||||||
*/
|
*/
|
||||||
public abstract void setConfigurationAdapter(ConfigurationAdapter adapter);
|
public abstract void setConfigurationAdapter(ConfigurationAdapter adapter);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the currently in use tab list handle.
|
|
||||||
*
|
|
||||||
* @return the tab list handler
|
|
||||||
*/
|
|
||||||
public abstract TabListHandler getTabListHandler();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the used tab list handler, should not be changed once players have
|
|
||||||
* connected
|
|
||||||
*
|
|
||||||
* @param handler the tab list handler to set
|
|
||||||
*/
|
|
||||||
public abstract void setTabListHandler(TabListHandler handler);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently in use reconnect handler.
|
* Get the currently in use reconnect handler.
|
||||||
*
|
*
|
||||||
@@ -211,10 +188,11 @@ public abstract class ProxyServer
|
|||||||
*
|
*
|
||||||
* @param name name of the server
|
* @param name name of the server
|
||||||
* @param address connectable Minecraft address + port of the server
|
* @param address connectable Minecraft address + port of the server
|
||||||
|
* @param motd the motd when used as a forced server
|
||||||
* @param restricted whether the server info restricted property will be set
|
* @param restricted whether the server info restricted property will be set
|
||||||
* @return the constructed instance
|
* @return the constructed instance
|
||||||
*/
|
*/
|
||||||
public abstract ServerInfo constructServerInfo(String name, InetSocketAddress address, boolean restricted);
|
public abstract ServerInfo constructServerInfo(String name, InetSocketAddress address, String motd, boolean restricted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the console overlord for this proxy. Being the console, this
|
* Returns the console overlord for this proxy. Being the console, this
|
||||||
@@ -240,11 +218,33 @@ public abstract class ProxyServer
|
|||||||
public abstract TaskScheduler getScheduler();
|
public abstract TaskScheduler getScheduler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the the web client used by this proxy to facilitate making web
|
* Get the current number of connected users. The default implementation is
|
||||||
* requests. Care should be taken to ensure that all operations are non
|
* more efficient than {@link #getPlayers()} as it does not take a lock or
|
||||||
* blocking where applicable.
|
* make a copy.
|
||||||
*
|
*
|
||||||
* @return the server's {@link AsyncHttpClient} instance
|
* @return the current number of connected players
|
||||||
*/
|
*/
|
||||||
public abstract AsyncHttpClient getHttpClient();
|
public abstract int getOnlineCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the specified message to the console and all connected players.
|
||||||
|
*
|
||||||
|
* @param message the message to broadcast
|
||||||
|
*/
|
||||||
|
public abstract void broadcast(String message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a new instance of this proxies custom tab list.
|
||||||
|
*
|
||||||
|
* @param player the player to generate this list in the context of
|
||||||
|
* @return a new {@link CustomTabList} instance
|
||||||
|
*/
|
||||||
|
public abstract CustomTabList customTabList(ProxiedPlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the commands which are disabled and will not be run on this proxy.
|
||||||
|
*
|
||||||
|
* @return the set of disabled commands
|
||||||
|
*/
|
||||||
|
public abstract Collection<String> getDisabledCommands();
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ public interface ReconnectHandler
|
|||||||
* @param player the connecting player
|
* @param player the connecting player
|
||||||
* @return the server to connect to
|
* @return the server to connect to
|
||||||
*/
|
*/
|
||||||
public ServerInfo getServer(ProxiedPlayer player);
|
ServerInfo getServer(ProxiedPlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the server of this player before they disconnect so it can be
|
* Save the server of this player before they disconnect so it can be
|
||||||
@@ -20,12 +20,20 @@ public interface ReconnectHandler
|
|||||||
*
|
*
|
||||||
* @param player the player to save
|
* @param player the player to save
|
||||||
*/
|
*/
|
||||||
public void setServer(ProxiedPlayer player);
|
void setServer(ProxiedPlayer player); // TOOD: String + String arguments?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save all pending reconnect locations. Whilst not used for database
|
* Save all pending reconnect locations. Whilst not used for database
|
||||||
* connections, this method will be called at a predefined interval to allow
|
* connections, this method will be called at a predefined interval to allow
|
||||||
* the saving of reconnect files.
|
* the saving of reconnect files.
|
||||||
*/
|
*/
|
||||||
public void save();
|
void save();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close all connections indicating that the proxy is about to shutdown and
|
||||||
|
* all data should be saved. No new requests will be made after this method
|
||||||
|
* has been called.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void close();
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,15 @@ public interface ConfigurationAdapter
|
|||||||
*/
|
*/
|
||||||
public boolean getBoolean(String path, boolean def);
|
public boolean getBoolean(String path, boolean def);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list from the specified path.
|
||||||
|
*
|
||||||
|
* @param path the path to retrieve the list form.
|
||||||
|
* @param def the default value
|
||||||
|
* @return the retrieved list
|
||||||
|
*/
|
||||||
|
public Collection<?> getList(String path, Collection<?> def);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the configuration all servers which may be accessible via the proxy.
|
* Get the configuration all servers which may be accessible via the proxy.
|
||||||
*
|
*
|
||||||
|
@@ -3,6 +3,7 @@ package net.md_5.bungee.api.config;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.md_5.bungee.api.tab.TabListHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing the configuration of a server listener. Used for allowing
|
* Class representing the configuration of a server listener. Used for allowing
|
||||||
@@ -48,8 +49,24 @@ public class ListenerInfo
|
|||||||
*/
|
*/
|
||||||
private final Map<String, String> forcedHosts;
|
private final Map<String, String> forcedHosts;
|
||||||
/**
|
/**
|
||||||
* Get the texture pack used for servers connected to this proxy. May be
|
* Class used to build tab lists for this player.
|
||||||
* null.
|
|
||||||
*/
|
*/
|
||||||
private final TexturePackInfo texturePack;
|
private final Class<? extends TabListHandler> tabList;
|
||||||
|
/**
|
||||||
|
* Whether to set the local address when connecting to servers.
|
||||||
|
*/
|
||||||
|
private final boolean setLocalAddress;
|
||||||
|
/**
|
||||||
|
* Whether to pass the ping through when we can reliably get the target
|
||||||
|
* server (force default server).
|
||||||
|
*/
|
||||||
|
private final boolean pingPassthrough;
|
||||||
|
/**
|
||||||
|
* What port to run udp query on.
|
||||||
|
*/
|
||||||
|
private final int queryPort;
|
||||||
|
/**
|
||||||
|
* Whether to enable udp query.
|
||||||
|
*/
|
||||||
|
private final boolean queryEnabled;
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,13 @@ public interface ServerInfo
|
|||||||
*/
|
*/
|
||||||
Collection<ProxiedPlayer> getPlayers();
|
Collection<ProxiedPlayer> getPlayers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the MOTD which should be used when this server is a forced host.
|
||||||
|
*
|
||||||
|
* @return the motd
|
||||||
|
*/
|
||||||
|
String getMotd();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the player can access this server. It will only return false when
|
* Whether the player can access this server. It will only return false when
|
||||||
* the player has no permission and this server is restricted.
|
* the player has no permission and this server is restricted.
|
||||||
|
@@ -1,17 +0,0 @@
|
|||||||
package net.md_5.bungee.api.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class TexturePackInfo
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The URL of the texture pack.
|
|
||||||
*/
|
|
||||||
private final String url;
|
|
||||||
/**
|
|
||||||
* The square dimension of this texture pack.
|
|
||||||
*/
|
|
||||||
private final int size;
|
|
||||||
}
|
|
@@ -1,6 +1,7 @@
|
|||||||
package net.md_5.bungee.api.connection;
|
package net.md_5.bungee.api.connection;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A proxy connection is defined as a connection directly connected to a socket.
|
* A proxy connection is defined as a connection directly connected to a socket.
|
||||||
@@ -15,7 +16,7 @@ public interface Connection
|
|||||||
*
|
*
|
||||||
* @return the remote address
|
* @return the remote address
|
||||||
*/
|
*/
|
||||||
public InetSocketAddress getAddress();
|
InetSocketAddress getAddress();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnects this end of the connection for the specified reason. If this
|
* Disconnects this end of the connection for the specified reason. If this
|
||||||
@@ -25,5 +26,23 @@ public interface Connection
|
|||||||
* @param reason the reason shown to the player / sent to the server on
|
* @param reason the reason shown to the player / sent to the server on
|
||||||
* disconnect
|
* disconnect
|
||||||
*/
|
*/
|
||||||
public void disconnect(String reason);
|
void disconnect(String reason);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the unsafe methods of this class.
|
||||||
|
*
|
||||||
|
* @return the unsafe method interface
|
||||||
|
*/
|
||||||
|
Unsafe unsafe();
|
||||||
|
|
||||||
|
interface Unsafe
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a packet to this connection.
|
||||||
|
*
|
||||||
|
* @param packet the packet to send
|
||||||
|
*/
|
||||||
|
void sendPacket(DefinedPacket packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,26 +14,26 @@ public interface PendingConnection extends Connection
|
|||||||
*
|
*
|
||||||
* @return the requested username, or null if not set
|
* @return the requested username, or null if not set
|
||||||
*/
|
*/
|
||||||
public String getName();
|
String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the numerical client version of the player attempting to log in.
|
* Get the numerical client version of the player attempting to log in.
|
||||||
*
|
*
|
||||||
* @return the protocol version of the remote client
|
* @return the protocol version of the remote client
|
||||||
*/
|
*/
|
||||||
public byte getVersion();
|
byte getVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the requested virtual host that the client tried to connect to.
|
* Get the requested virtual host that the client tried to connect to.
|
||||||
*
|
*
|
||||||
* @return request virtual host or null if invalid / not specified.
|
* @return request virtual host or null if invalid / not specified.
|
||||||
*/
|
*/
|
||||||
public InetSocketAddress getVirtualHost();
|
InetSocketAddress getVirtualHost();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the listener that accepted this connection.
|
* Get the listener that accepted this connection.
|
||||||
*
|
*
|
||||||
* @return the accepting listener
|
* @return the accepting listener
|
||||||
*/
|
*/
|
||||||
public ListenerInfo getListener();
|
ListenerInfo getListener();
|
||||||
}
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package net.md_5.bungee.api.connection;
|
|||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.tab.TabListHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a player who's connection is being connected to somewhere else,
|
* Represents a player who's connection is being connected to somewhere else,
|
||||||
@@ -15,7 +16,7 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
|||||||
*
|
*
|
||||||
* @return the players current display name
|
* @return the players current display name
|
||||||
*/
|
*/
|
||||||
public String getDisplayName();
|
String getDisplayName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this players display name to be used as their nametag and tab list
|
* Sets this players display name to be used as their nametag and tab list
|
||||||
@@ -23,7 +24,7 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
|||||||
*
|
*
|
||||||
* @param name the name to set
|
* @param name the name to set
|
||||||
*/
|
*/
|
||||||
public void setDisplayName(String name);
|
void setDisplayName(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects / transfers this user to the specified connection, gracefully
|
* Connects / transfers this user to the specified connection, gracefully
|
||||||
@@ -32,21 +33,21 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
|||||||
*
|
*
|
||||||
* @param target the new server to connect to
|
* @param target the new server to connect to
|
||||||
*/
|
*/
|
||||||
public void connect(ServerInfo target);
|
void connect(ServerInfo target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the server this player is connected to.
|
* Gets the server this player is connected to.
|
||||||
*
|
*
|
||||||
* @return the server this player is connected to
|
* @return the server this player is connected to
|
||||||
*/
|
*/
|
||||||
public Server getServer();
|
Server getServer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ping time between the proxy and this connection.
|
* Gets the ping time between the proxy and this connection.
|
||||||
*
|
*
|
||||||
* @return the current ping time
|
* @return the current ping time
|
||||||
*/
|
*/
|
||||||
public int getPing();
|
int getPing();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a plugin message to this player.
|
* Send a plugin message to this player.
|
||||||
@@ -54,19 +55,48 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
|||||||
* @param channel the channel to send this data via
|
* @param channel the channel to send this data via
|
||||||
* @param data the data to send
|
* @param data the data to send
|
||||||
*/
|
*/
|
||||||
public void sendData(String channel, byte[] data);
|
void sendData(String channel, byte[] data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the pending connection that belongs to this player.
|
* Get the pending connection that belongs to this player.
|
||||||
*
|
*
|
||||||
* @return the pending connection that this player used
|
* @return the pending connection that this player used
|
||||||
*/
|
*/
|
||||||
public PendingConnection getPendingConnection();
|
PendingConnection getPendingConnection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make this player chat (say something), to the server he is currently on.
|
* Make this player chat (say something), to the server he is currently on.
|
||||||
*
|
*
|
||||||
* @param message the message to say
|
* @param message the message to say
|
||||||
*/
|
*/
|
||||||
public void chat(String message);
|
void chat(String message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the new tab list for the user. At this stage it is not advisable to
|
||||||
|
* change after the user has logged in!
|
||||||
|
*
|
||||||
|
* @param list the new list
|
||||||
|
*/
|
||||||
|
void setTabList(TabListHandler list);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current tab list.
|
||||||
|
*
|
||||||
|
* @return the tab list in use by this user
|
||||||
|
*/
|
||||||
|
TabListHandler getTabList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the server which this player will be sent to next time the log in.
|
||||||
|
*
|
||||||
|
* @return the server, or null if default
|
||||||
|
*/
|
||||||
|
ServerInfo getReconnectServer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the server which this player will be sent to next time the log in.
|
||||||
|
*
|
||||||
|
* @param server the server to set
|
||||||
|
*/
|
||||||
|
void setReconnectServer(ServerInfo server);
|
||||||
}
|
}
|
||||||
|
@@ -67,7 +67,7 @@ public class AsyncEvent<T> extends Event
|
|||||||
{
|
{
|
||||||
Preconditions.checkState( intents.contains( plugin ), "Plugin %s has not registered intent for event %s", plugin, this );
|
Preconditions.checkState( intents.contains( plugin ), "Plugin %s has not registered intent for event %s", plugin, this );
|
||||||
intents.remove( plugin );
|
intents.remove( plugin );
|
||||||
if ( latch.decrementAndGet() == 0 )
|
if ( latch.decrementAndGet() == 0 && fired.get() )
|
||||||
{
|
{
|
||||||
done.done( (T) this, null );
|
done.done( (T) this, null );
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,34 @@
|
|||||||
|
package net.md_5.bungee.api.event;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
|
import net.md_5.bungee.protocol.packet.Packet2Handshake;
|
||||||
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event called to represent a player first making their presence and username
|
||||||
|
* known.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = false)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PlayerHandshakeEvent extends Event
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection attempting to login.
|
||||||
|
*/
|
||||||
|
private final PendingConnection connection;
|
||||||
|
/**
|
||||||
|
* The handshake.
|
||||||
|
*/
|
||||||
|
private final Packet2Handshake handshake;
|
||||||
|
|
||||||
|
public PlayerHandshakeEvent(PendingConnection connection, Packet2Handshake handshake)
|
||||||
|
{
|
||||||
|
this.connection = connection;
|
||||||
|
this.handshake = handshake;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,18 +1,18 @@
|
|||||||
package net.md_5.bungee.api.event;
|
package net.md_5.bungee.api.event;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NonNull;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Cancellable;
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
|
||||||
@ToString(callSuper = false)
|
@ToString(callSuper = false)
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class ServerConnectEvent extends Event
|
public class ServerConnectEvent extends Event implements Cancellable
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,5 +22,16 @@ public class ServerConnectEvent extends Event
|
|||||||
/**
|
/**
|
||||||
* Server the player will be connected to.
|
* Server the player will be connected to.
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
private ServerInfo target;
|
private ServerInfo target;
|
||||||
|
/**
|
||||||
|
* Cancelled state.
|
||||||
|
*/
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public ServerConnectEvent(ProxiedPlayer player, ServerInfo target)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,11 +33,27 @@ public class ServerKickEvent extends Event implements Cancellable
|
|||||||
* Server to send player to if this event is cancelled.
|
* Server to send player to if this event is cancelled.
|
||||||
*/
|
*/
|
||||||
private ServerInfo cancelServer;
|
private ServerInfo cancelServer;
|
||||||
|
/**
|
||||||
|
* State in which the kick occured.
|
||||||
|
*/
|
||||||
|
private State state;
|
||||||
|
|
||||||
|
public enum State
|
||||||
|
{
|
||||||
|
|
||||||
|
CONNECTING, CONNECTED, UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
public ServerKickEvent(ProxiedPlayer player, String kickReason, ServerInfo cancelServer)
|
public ServerKickEvent(ProxiedPlayer player, String kickReason, ServerInfo cancelServer)
|
||||||
|
{
|
||||||
|
this( player, kickReason, cancelServer, State.UNKNOWN );
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerKickEvent(ProxiedPlayer player, String kickReason, ServerInfo cancelServer, State state)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.kickReason = kickReason;
|
this.kickReason = kickReason;
|
||||||
this.cancelServer = cancelServer;
|
this.cancelServer = cancelServer;
|
||||||
|
this.state = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,22 @@
|
|||||||
|
package net.md_5.bungee.api.event;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player has changed servers.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = false)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class ServerSwitchEvent extends Event
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Player whom the server is for.
|
||||||
|
*/
|
||||||
|
private final ProxiedPlayer player;
|
||||||
|
}
|
@@ -2,6 +2,7 @@ package net.md_5.bungee.api.plugin;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
||||||
@@ -19,6 +20,8 @@ public class Plugin
|
|||||||
private ProxyServer proxy;
|
private ProxyServer proxy;
|
||||||
@Getter
|
@Getter
|
||||||
private File file;
|
private File file;
|
||||||
|
@Getter
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the plugin has just been loaded. Most of the proxy will not
|
* Called when the plugin has just been loaded. Most of the proxy will not
|
||||||
@@ -73,10 +76,11 @@ public class Plugin
|
|||||||
* @param description the description that describes this plugin
|
* @param description the description that describes this plugin
|
||||||
* @param jarfile this plugins jar or container
|
* @param jarfile this plugins jar or container
|
||||||
*/
|
*/
|
||||||
final void init(ProxyServer proxy, PluginDescription description, File file)
|
final void init(ProxyServer proxy, PluginDescription description)
|
||||||
{
|
{
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.file = file;
|
this.file = description.getFile();
|
||||||
|
this.logger = new PluginLogger( this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,13 +2,18 @@ package net.md_5.bungee.api.plugin;
|
|||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
public class PluginClassloader extends URLClassLoader
|
public class PluginClassloader extends URLClassLoader
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final Set<PluginClassloader> allLoaders = new HashSet<>();
|
private static final Set<PluginClassloader> allLoaders = new CopyOnWriteArraySet<>();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
ClassLoader.registerAsParallelCapable();
|
||||||
|
}
|
||||||
|
|
||||||
public PluginClassloader(URL[] urls)
|
public PluginClassloader(URL[] urls)
|
||||||
{
|
{
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package net.md_5.bungee.api.plugin;
|
package net.md_5.bungee.api.plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -35,4 +36,8 @@ public class PluginDescription
|
|||||||
* Plugin hard dependencies.
|
* Plugin hard dependencies.
|
||||||
*/
|
*/
|
||||||
private Set<String> depends = new HashSet<>();
|
private Set<String> depends = new HashSet<>();
|
||||||
|
/**
|
||||||
|
* File we were loaded from.
|
||||||
|
*/
|
||||||
|
private File file = null;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
package net.md_5.bungee.api.plugin;
|
||||||
|
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
|
||||||
|
public class PluginLogger extends Logger
|
||||||
|
{
|
||||||
|
|
||||||
|
private String pluginName;
|
||||||
|
|
||||||
|
protected PluginLogger(Plugin plugin)
|
||||||
|
{
|
||||||
|
super( plugin.getClass().getCanonicalName(), null );
|
||||||
|
pluginName = "[" + plugin.getDescription().getName() + "] ";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log(LogRecord logRecord)
|
||||||
|
{
|
||||||
|
logRecord.setMessage( pluginName + logRecord.getMessage() );
|
||||||
|
ProxyServer.getInstance().getLogger().log( logRecord );
|
||||||
|
}
|
||||||
|
}
|
@@ -1,15 +1,20 @@
|
|||||||
package net.md_5.bungee.api.plugin;
|
package net.md_5.bungee.api.plugin;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
@@ -20,7 +25,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.event.LoginEvent;
|
import net.md_5.bungee.event.EventBus;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,9 +42,19 @@ public class PluginManager
|
|||||||
private final ProxyServer proxy;
|
private final ProxyServer proxy;
|
||||||
/*========================================================================*/
|
/*========================================================================*/
|
||||||
private final Yaml yaml = new Yaml();
|
private final Yaml yaml = new Yaml();
|
||||||
private final EventBus eventBus = new EventBus();
|
private final EventBus eventBus;
|
||||||
private final Map<String, Plugin> plugins = new HashMap<>();
|
private final Map<String, Plugin> plugins = new LinkedHashMap<>();
|
||||||
private final Map<String, Command> commandMap = new HashMap<>();
|
private final Map<String, Command> commandMap = new HashMap<>();
|
||||||
|
private Map<String, PluginDescription> toLoad = new HashMap<>();
|
||||||
|
private Multimap<Plugin, Command> commandsByPlugin = ArrayListMultimap.create();
|
||||||
|
private Multimap<Plugin, Listener> listenersByPlugin = ArrayListMultimap.create();
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public PluginManager(ProxyServer proxy)
|
||||||
|
{
|
||||||
|
this.proxy = proxy;
|
||||||
|
eventBus = new EventBus( proxy.getLogger() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a command so that it may be executed.
|
* Register a command so that it may be executed.
|
||||||
@@ -53,6 +69,7 @@ public class PluginManager
|
|||||||
{
|
{
|
||||||
commandMap.put( alias.toLowerCase(), command );
|
commandMap.put( alias.toLowerCase(), command );
|
||||||
}
|
}
|
||||||
|
commandsByPlugin.put( plugin, command );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,6 +80,26 @@ public class PluginManager
|
|||||||
public void unregisterCommand(Command command)
|
public void unregisterCommand(Command command)
|
||||||
{
|
{
|
||||||
commandMap.values().remove( command );
|
commandMap.values().remove( command );
|
||||||
|
commandsByPlugin.values().remove( command );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister all commands owned by a {@link Plugin}
|
||||||
|
*
|
||||||
|
* @param plugin the plugin to register the commands of
|
||||||
|
*/
|
||||||
|
public void unregisterCommands(Plugin plugin)
|
||||||
|
{
|
||||||
|
for ( Iterator<Command> it = commandsByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
commandMap.values().remove( it.next() );
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean dispatchCommand(CommandSender sender, String commandLine)
|
||||||
|
{
|
||||||
|
return dispatchCommand( sender, commandLine, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,10 +110,21 @@ public class PluginManager
|
|||||||
* arguments
|
* arguments
|
||||||
* @return whether the command was handled
|
* @return whether the command was handled
|
||||||
*/
|
*/
|
||||||
public boolean dispatchCommand(CommandSender sender, String commandLine)
|
public boolean dispatchCommand(CommandSender sender, String commandLine, List<String> tabResults)
|
||||||
{
|
{
|
||||||
String[] split = argsSplit.split( commandLine );
|
String[] split = argsSplit.split( commandLine );
|
||||||
Command command = commandMap.get( split[0].toLowerCase() );
|
// Check for chat that only contains " "
|
||||||
|
if ( split.length == 0 )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String commandName = split[0].toLowerCase();
|
||||||
|
if ( proxy.getDisabledCommands().contains( commandName ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Command command = commandMap.get( commandName );
|
||||||
if ( command == null )
|
if ( command == null )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -85,14 +133,23 @@ public class PluginManager
|
|||||||
String permission = command.getPermission();
|
String permission = command.getPermission();
|
||||||
if ( permission != null && !permission.isEmpty() && !sender.hasPermission( permission ) )
|
if ( permission != null && !permission.isEmpty() && !sender.hasPermission( permission ) )
|
||||||
{
|
{
|
||||||
sender.sendMessage( ChatColor.RED + "You do not have permission to execute this command!" );
|
sender.sendMessage( proxy.getTranslation( "no_permission" ) );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] args = Arrays.copyOfRange( split, 1, split.length );
|
String[] args = Arrays.copyOfRange( split, 1, split.length );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.execute( sender, args );
|
if ( tabResults == null )
|
||||||
|
{
|
||||||
|
command.execute( sender, args );
|
||||||
|
} else if ( command instanceof TabExecutor )
|
||||||
|
{
|
||||||
|
for ( String s : ( (TabExecutor) command ).onTabComplete( sender, args ) )
|
||||||
|
{
|
||||||
|
tabResults.add( s );
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch ( Exception ex )
|
} catch ( Exception ex )
|
||||||
{
|
{
|
||||||
sender.sendMessage( ChatColor.RED + "An internal error occurred whilst executing this command, please check the console log for details." );
|
sender.sendMessage( ChatColor.RED + "An internal error occurred whilst executing this command, please check the console log for details." );
|
||||||
@@ -122,23 +179,37 @@ public class PluginManager
|
|||||||
return plugins.get( name );
|
return plugins.get( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void loadAndEnablePlugins()
|
||||||
* Enable all plugins by calling the {@link Plugin#onEnable()} method.
|
|
||||||
*/
|
|
||||||
public void enablePlugins()
|
|
||||||
{
|
{
|
||||||
Map<Plugin, Boolean> pluginStatuses = new HashMap<>();
|
Map<PluginDescription, Boolean> pluginStatuses = new HashMap<>();
|
||||||
for ( Map.Entry<String, Plugin> entry : plugins.entrySet() )
|
for ( Map.Entry<String, PluginDescription> entry : toLoad.entrySet() )
|
||||||
{
|
{
|
||||||
Plugin plugin = entry.getValue();
|
PluginDescription plugin = entry.getValue();
|
||||||
if ( !this.enablePlugin( pluginStatuses, new Stack<Plugin>(), plugin ) )
|
if ( !enablePlugin( pluginStatuses, new Stack<PluginDescription>(), plugin ) )
|
||||||
{
|
{
|
||||||
ProxyServer.getInstance().getLogger().warning( "Failed to enable " + entry.getKey() );
|
ProxyServer.getInstance().getLogger().warning( "Failed to enable " + entry.getKey() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
toLoad.clear();
|
||||||
|
toLoad = null;
|
||||||
|
|
||||||
|
for ( Plugin plugin : plugins.values() )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
plugin.onEnable();
|
||||||
|
ProxyServer.getInstance().getLogger().log( Level.INFO, "Enabled plugin {0} version {1} by {2}", new Object[]
|
||||||
|
{
|
||||||
|
plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getAuthor()
|
||||||
|
} );
|
||||||
|
} catch ( Throwable t )
|
||||||
|
{
|
||||||
|
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Exception encountered when loading plugin: " + plugin.getDescription().getName(), t );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean enablePlugin(Map<Plugin, Boolean> pluginStatuses, Stack<Plugin> dependStack, Plugin plugin)
|
private boolean enablePlugin(Map<PluginDescription, Boolean> pluginStatuses, Stack<PluginDescription> dependStack, PluginDescription plugin)
|
||||||
{
|
{
|
||||||
if ( pluginStatuses.containsKey( plugin ) )
|
if ( pluginStatuses.containsKey( plugin ) )
|
||||||
{
|
{
|
||||||
@@ -149,21 +220,21 @@ public class PluginManager
|
|||||||
boolean status = true;
|
boolean status = true;
|
||||||
|
|
||||||
// try to load dependencies first
|
// try to load dependencies first
|
||||||
for ( String dependName : plugin.getDescription().getDepends() )
|
for ( String dependName : plugin.getDepends() )
|
||||||
{
|
{
|
||||||
Plugin depend = this.plugins.get( dependName );
|
PluginDescription depend = toLoad.get( dependName );
|
||||||
Boolean dependStatus = depend != null ? pluginStatuses.get( depend ) : Boolean.FALSE;
|
Boolean dependStatus = ( depend != null ) ? pluginStatuses.get( depend ) : Boolean.FALSE;
|
||||||
|
|
||||||
if ( dependStatus == null )
|
if ( dependStatus == null )
|
||||||
{
|
{
|
||||||
if ( dependStack.contains( depend ) )
|
if ( dependStack.contains( depend ) )
|
||||||
{
|
{
|
||||||
StringBuilder dependencyGraph = new StringBuilder();
|
StringBuilder dependencyGraph = new StringBuilder();
|
||||||
for ( Plugin element : dependStack )
|
for ( PluginDescription element : dependStack )
|
||||||
{
|
{
|
||||||
dependencyGraph.append( element.getDescription().getName() ).append( " -> " );
|
dependencyGraph.append( element.getName() ).append( " -> " );
|
||||||
}
|
}
|
||||||
dependencyGraph.append( plugin.getDescription().getName() ).append( " -> " ).append( dependName );
|
dependencyGraph.append( plugin.getName() ).append( " -> " ).append( dependName );
|
||||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Circular dependency detected: " + dependencyGraph );
|
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Circular dependency detected: " + dependencyGraph );
|
||||||
status = false;
|
status = false;
|
||||||
} else
|
} else
|
||||||
@@ -178,7 +249,7 @@ public class PluginManager
|
|||||||
{
|
{
|
||||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} (required by {1}) is unavailable", new Object[]
|
ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} (required by {1}) is unavailable", new Object[]
|
||||||
{
|
{
|
||||||
depend.getDescription().getName(), plugin.getDescription().getName()
|
String.valueOf( depend.getName() ), plugin.getName()
|
||||||
} );
|
} );
|
||||||
status = false;
|
status = false;
|
||||||
}
|
}
|
||||||
@@ -194,15 +265,23 @@ public class PluginManager
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin.onEnable();
|
URLClassLoader loader = new PluginClassloader( new URL[]
|
||||||
ProxyServer.getInstance().getLogger().log( Level.INFO, "Enabled plugin {0} version {1} by {2}", new Object[]
|
|
||||||
{
|
{
|
||||||
plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getAuthor()
|
plugin.getFile().toURI().toURL()
|
||||||
|
} );
|
||||||
|
Class<?> main = loader.loadClass( plugin.getMain() );
|
||||||
|
Plugin clazz = (Plugin) main.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
clazz.init( proxy, plugin );
|
||||||
|
plugins.put( plugin.getName(), clazz );
|
||||||
|
clazz.onLoad();
|
||||||
|
ProxyServer.getInstance().getLogger().log( Level.INFO, "Loaded plugin {0} version {1} by {2}", new Object[]
|
||||||
|
{
|
||||||
|
plugin.getName(), plugin.getVersion(), plugin.getAuthor()
|
||||||
} );
|
} );
|
||||||
} catch ( Throwable t )
|
} catch ( Throwable t )
|
||||||
{
|
{
|
||||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Exception encountered when loading plugin: " + plugin.getDescription().getName(), t );
|
proxy.getLogger().log( Level.WARNING, "Error enabling plugin " + plugin.getName(), t );
|
||||||
status = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,51 +289,12 @@ public class PluginManager
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a plugin from the specified file. This file must be in jar format.
|
|
||||||
* This will not enable plugins, {@link #enablePlugins()} must be called.
|
|
||||||
*
|
|
||||||
* @param file the file to load from
|
|
||||||
* @throws Exception Any exceptions encountered when loading a plugin from
|
|
||||||
* this file.
|
|
||||||
*/
|
|
||||||
public void loadPlugin(File file) throws Exception
|
|
||||||
{
|
|
||||||
Preconditions.checkNotNull( file, "file" );
|
|
||||||
Preconditions.checkArgument( file.isFile(), "Must load from file" );
|
|
||||||
|
|
||||||
try ( JarFile jar = new JarFile( file ) )
|
|
||||||
{
|
|
||||||
JarEntry pdf = jar.getJarEntry( "plugin.yml" );
|
|
||||||
Preconditions.checkNotNull( pdf, "Plugin must have a plugin.yml" );
|
|
||||||
|
|
||||||
try ( InputStream in = jar.getInputStream( pdf ) )
|
|
||||||
{
|
|
||||||
PluginDescription desc = yaml.loadAs( in, PluginDescription.class );
|
|
||||||
URLClassLoader loader = new PluginClassloader( new URL[]
|
|
||||||
{
|
|
||||||
file.toURI().toURL()
|
|
||||||
} );
|
|
||||||
Class<?> main = loader.loadClass( desc.getMain() );
|
|
||||||
Plugin plugin = (Plugin) main.getDeclaredConstructor().newInstance();
|
|
||||||
|
|
||||||
plugin.init( proxy, desc, file );
|
|
||||||
plugins.put( desc.getName(), plugin );
|
|
||||||
plugin.onLoad();
|
|
||||||
ProxyServer.getInstance().getLogger().log( Level.INFO, "Loaded plugin {0} version {1} by {2}", new Object[]
|
|
||||||
{
|
|
||||||
desc.getName(), desc.getVersion(), desc.getAuthor()
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load all plugins from the specified folder.
|
* Load all plugins from the specified folder.
|
||||||
*
|
*
|
||||||
* @param folder the folder to search for plugins in
|
* @param folder the folder to search for plugins in
|
||||||
*/
|
*/
|
||||||
public void loadPlugins(File folder)
|
public void detectPlugins(File folder)
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull( folder, "folder" );
|
Preconditions.checkNotNull( folder, "folder" );
|
||||||
Preconditions.checkArgument( folder.isDirectory(), "Must load from a directory" );
|
Preconditions.checkArgument( folder.isDirectory(), "Must load from a directory" );
|
||||||
@@ -263,9 +303,17 @@ public class PluginManager
|
|||||||
{
|
{
|
||||||
if ( file.isFile() && file.getName().endsWith( ".jar" ) )
|
if ( file.isFile() && file.getName().endsWith( ".jar" ) )
|
||||||
{
|
{
|
||||||
try
|
try ( JarFile jar = new JarFile( file ) )
|
||||||
{
|
{
|
||||||
loadPlugin( file );
|
JarEntry pdf = jar.getJarEntry( "plugin.yml" );
|
||||||
|
Preconditions.checkNotNull( pdf, "Plugin must have a plugin.yml" );
|
||||||
|
|
||||||
|
try ( InputStream in = jar.getInputStream( pdf ) )
|
||||||
|
{
|
||||||
|
PluginDescription desc = yaml.loadAs( in, PluginDescription.class );
|
||||||
|
desc.setFile( file );
|
||||||
|
toLoad.put( desc.getName(), desc );
|
||||||
|
}
|
||||||
} catch ( Exception ex )
|
} catch ( Exception ex )
|
||||||
{
|
{
|
||||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not load plugin from file " + file, ex );
|
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not load plugin from file " + file, ex );
|
||||||
@@ -304,13 +352,44 @@ public class PluginManager
|
|||||||
/**
|
/**
|
||||||
* Register a {@link Listener} for receiving called events. Methods in this
|
* Register a {@link Listener} for receiving called events. Methods in this
|
||||||
* Object which wish to receive events must be annotated with the
|
* Object which wish to receive events must be annotated with the
|
||||||
* {@link Subscribe} annotation.
|
* {@link EventHandler} annotation.
|
||||||
*
|
*
|
||||||
* @param plugin the owning plugin
|
* @param plugin the owning plugin
|
||||||
* @param listener the listener to register events for
|
* @param listener the listener to register events for
|
||||||
*/
|
*/
|
||||||
public void registerListener(Plugin plugin, Listener listener)
|
public void registerListener(Plugin plugin, Listener listener)
|
||||||
{
|
{
|
||||||
|
for ( Method method : listener.getClass().getDeclaredMethods() )
|
||||||
|
{
|
||||||
|
Preconditions.checkArgument( !method.isAnnotationPresent( Subscribe.class ),
|
||||||
|
"Listener %s has registered using deprecated subscribe annotation! Please update to @EventHandler.", listener );
|
||||||
|
}
|
||||||
eventBus.register( listener );
|
eventBus.register( listener );
|
||||||
|
listenersByPlugin.put( plugin, listener );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister a {@link Listener} so that the events do not reach it anymore.
|
||||||
|
*
|
||||||
|
* @param listener the listener to unregister
|
||||||
|
*/
|
||||||
|
public void unregisterListener(Listener listener)
|
||||||
|
{
|
||||||
|
eventBus.unregister( listener );
|
||||||
|
listenersByPlugin.values().remove( listener );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister all of a Plugin's listener.
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
*/
|
||||||
|
public void unregisterListeners(Plugin plugin)
|
||||||
|
{
|
||||||
|
for ( Iterator<Listener> it = listenersByPlugin.get( plugin ).iterator(); it.hasNext(); )
|
||||||
|
{
|
||||||
|
eventBus.unregister( it.next() );
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,10 @@
|
|||||||
|
package net.md_5.bungee.api.plugin;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
|
||||||
|
|
||||||
|
public interface TabExecutor
|
||||||
|
{
|
||||||
|
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args);
|
||||||
|
}
|
@@ -1,6 +1,5 @@
|
|||||||
package net.md_5.bungee.api.scheduler;
|
package net.md_5.bungee.api.scheduler;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,11 +30,7 @@ public interface ScheduledTask
|
|||||||
Runnable getTask();
|
Runnable getTask();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the delay in the specified unit before this task will next be
|
* Cancel this task to suppress subsequent executions.
|
||||||
* executed.
|
|
||||||
*
|
|
||||||
* @param unit the unit to get the delay in
|
|
||||||
* @return the time before the next execution of this task
|
|
||||||
*/
|
*/
|
||||||
long getDelay(TimeUnit unit);
|
void cancel();
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package net.md_5.bungee.api.scoreboard;
|
package net.md_5.bungee.api.score;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package net.md_5.bungee.api.scoreboard;
|
package net.md_5.bungee.api.score;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents locations for a scoreboard to be displayed.
|
* Represents locations for a scoreboard to be displayed.
|
@@ -1,4 +1,4 @@
|
|||||||
package net.md_5.bungee.api.scoreboard;
|
package net.md_5.bungee.api.score;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package net.md_5.bungee.api.scoreboard;
|
package net.md_5.bungee.api.score;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -59,7 +59,6 @@ public class Scoreboard
|
|||||||
public void addScore(Score score)
|
public void addScore(Score score)
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull( score, "score" );
|
Preconditions.checkNotNull( score, "score" );
|
||||||
Preconditions.checkArgument( !scores.containsKey( score.getItemName() ), "Score %s already exists in this scoreboard", score.getItemName() );
|
|
||||||
scores.put( score.getItemName(), score );
|
scores.put( score.getItemName(), score );
|
||||||
}
|
}
|
||||||
|
|
@@ -1,20 +1,22 @@
|
|||||||
package net.md_5.bungee.api.scoreboard;
|
package net.md_5.bungee.api.score;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Team
|
public class Team
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final String name;
|
private final String name;
|
||||||
private String displayName;
|
private String displayName;
|
||||||
private String prefix;
|
private String prefix;
|
||||||
private String suffix;
|
private String suffix;
|
||||||
private byte friendlyMode;
|
private boolean friendlyFire;
|
||||||
private Set<String> players = new HashSet<>();
|
private Set<String> players = new HashSet<>();
|
||||||
|
|
||||||
public Collection<String> getPlayers()
|
public Collection<String> getPlayers()
|
60
api/src/main/java/net/md_5/bungee/api/tab/CustomTabList.java
Normal file
60
api/src/main/java/net/md_5/bungee/api/tab/CustomTabList.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package net.md_5.bungee.api.tab;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a custom tab list, which may have slots manipulated.
|
||||||
|
*/
|
||||||
|
public interface CustomTabList extends TabListHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blank out this tab list and update immediately.
|
||||||
|
*/
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the columns in this list.
|
||||||
|
*
|
||||||
|
* @return the width of this list
|
||||||
|
*/
|
||||||
|
int getColumns();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the rows in this list.
|
||||||
|
*
|
||||||
|
* @return the height of this list
|
||||||
|
*/
|
||||||
|
int getRows();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the total size of this list.
|
||||||
|
*
|
||||||
|
* @return {@link #getRows()} * {@link #getColumns()}
|
||||||
|
*/
|
||||||
|
int getSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the text in the specified slot and update immediately.
|
||||||
|
*
|
||||||
|
* @param row the row to set
|
||||||
|
* @param column the column to set
|
||||||
|
* @param text the text to set
|
||||||
|
* @return the padded text
|
||||||
|
*/
|
||||||
|
String setSlot(int row, int column, String text);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the text in the specified slot.
|
||||||
|
*
|
||||||
|
* @param row the row to set
|
||||||
|
* @param column the column to set
|
||||||
|
* @param text the text to set
|
||||||
|
* @param update whether or not to invoke {@link #update()} upon completion
|
||||||
|
* @return the padded text
|
||||||
|
*/
|
||||||
|
String setSlot(int row, int column, String text, boolean update);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush all queued changes to the user.
|
||||||
|
*/
|
||||||
|
void update();
|
||||||
|
}
|
@@ -0,0 +1,39 @@
|
|||||||
|
package net.md_5.bungee.api.tab;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
public abstract class TabListAdapter implements TabListHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private ProxiedPlayer player;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(ProxiedPlayer player)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnect()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisconnect()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServerChange()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPingChange(int ping)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@@ -1,23 +1,30 @@
|
|||||||
package net.md_5.bungee.api;
|
package net.md_5.bungee.api.tab;
|
||||||
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
public interface TabListHandler
|
public interface TabListHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called so that this class may set member fields to keep track of its
|
||||||
|
* internal state. You should not do any packet sending or manipulation of
|
||||||
|
* the passed player, other than storing it.
|
||||||
|
*
|
||||||
|
* @param player the player to be associated with this list
|
||||||
|
*/
|
||||||
|
void init(ProxiedPlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when this player first connects to the proxy.
|
||||||
|
*/
|
||||||
|
void onConnect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player first connects to the proxy.
|
* Called when a player first connects to the proxy.
|
||||||
*
|
*
|
||||||
* @param player the connecting player
|
* @param player the connecting player
|
||||||
*/
|
*/
|
||||||
public void onConnect(ProxiedPlayer player);
|
void onServerChange();
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a player changes their connected server.
|
|
||||||
*
|
|
||||||
* @param player the player who changed servers
|
|
||||||
*/
|
|
||||||
public void onServerChange(ProxiedPlayer player);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a players ping changes. The new ping will have not updated in
|
* Called when a players ping changes. The new ping will have not updated in
|
||||||
@@ -26,14 +33,14 @@ public interface TabListHandler
|
|||||||
* @param player the player who's ping changed
|
* @param player the player who's ping changed
|
||||||
* @param ping the player's new ping.
|
* @param ping the player's new ping.
|
||||||
*/
|
*/
|
||||||
public void onPingChange(ProxiedPlayer player, int ping);
|
void onPingChange(int ping);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player disconnects.
|
* Called when a player disconnects.
|
||||||
*
|
*
|
||||||
* @param player the disconnected player
|
* @param player the disconnected player
|
||||||
*/
|
*/
|
||||||
public void onDisconnect(ProxiedPlayer player);
|
void onDisconnect();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a list update packet is sent from server to client.
|
* Called when a list update packet is sent from server to client.
|
||||||
@@ -44,5 +51,5 @@ public interface TabListHandler
|
|||||||
* @param ping ping of the subject player
|
* @param ping ping of the subject player
|
||||||
* @return whether to send the packet to the client
|
* @return whether to send the packet to the client
|
||||||
*/
|
*/
|
||||||
public boolean onListUpdate(ProxiedPlayer player, String name, boolean online, int ping);
|
boolean onListUpdate(String name, boolean online, int ping);
|
||||||
}
|
}
|
31
bootstrap/nb-configuration.xml
Normal file
31
bootstrap/nb-configuration.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
97
bootstrap/pom.xml
Normal file
97
bootstrap/pom.xml
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-parent</artifactId>
|
||||||
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-bootstrap</artifactId>
|
||||||
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>BungeeCord-Bootstrap</name>
|
||||||
|
<description>Java 1.6 loader for BungeeCord</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-proxy</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sf.jopt-simple</groupId>
|
||||||
|
<artifactId>jopt-simple</artifactId>
|
||||||
|
<version>4.5</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>BungeeCord</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>2.5.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.6</source>
|
||||||
|
<target>1.6</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<!-- Don't deploy proxy to maven repo, only APIs -->
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifestEntries>
|
||||||
|
<Main-Class>net.md_5.bungee.Bootstrap</Main-Class>
|
||||||
|
<Implementation-Version>${describe}</Implementation-Version>
|
||||||
|
<Specification-Version>${maven.build.timestamp}</Specification-Version>
|
||||||
|
</manifestEntries>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
<exclude>**/*.SF</exclude>
|
||||||
|
<exclude>**/*.DSA</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
81
bootstrap/src/main/java/net/md_5/bungee/Bootstrap.java
Normal file
81
bootstrap/src/main/java/net/md_5/bungee/Bootstrap.java
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package net.md_5.bungee;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import joptsimple.OptionParser;
|
||||||
|
import joptsimple.OptionSet;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.command.ConsoleCommandSender;
|
||||||
|
|
||||||
|
public class Bootstrap
|
||||||
|
{
|
||||||
|
|
||||||
|
private static List<String> list(String... params)
|
||||||
|
{
|
||||||
|
return Arrays.asList( params );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a new instance of BungeeCord.
|
||||||
|
*
|
||||||
|
* @param args command line arguments, currently none are used
|
||||||
|
* @throws Exception when the server cannot be started
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) throws Exception
|
||||||
|
{
|
||||||
|
OptionParser parser = new OptionParser();
|
||||||
|
parser.allowsUnrecognizedOptions();
|
||||||
|
parser.acceptsAll( list( "v", "version" ) );
|
||||||
|
|
||||||
|
OptionSet options = parser.parse( args );
|
||||||
|
|
||||||
|
if ( options.has( "version" ) )
|
||||||
|
{
|
||||||
|
System.out.println( Bootstrap.class.getPackage().getImplementationVersion() );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !System.getProperty( "java.version" ).startsWith( "1.7" ) )
|
||||||
|
{
|
||||||
|
System.err.println( "*** ERROR *** BungeeCord requires Java 7 to function!" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( BungeeCord.class.getPackage().getSpecificationVersion() != null )
|
||||||
|
{
|
||||||
|
Calendar deadline = Calendar.getInstance();
|
||||||
|
deadline.add( Calendar.WEEK_OF_YEAR, 2 );
|
||||||
|
if ( Calendar.getInstance().after( new SimpleDateFormat( "yyyyMMdd" ).parse( BungeeCord.class.getPackage().getSpecificationVersion() ) ) )
|
||||||
|
{
|
||||||
|
System.err.println( "*** Warning, this build is outdated ***" );
|
||||||
|
System.err.println( "*** Please download a new build from http://ci.md-5.net/job/BungeeCord ***" );
|
||||||
|
System.err.println( "*** You will get NO support regarding this build ***" );
|
||||||
|
System.err.println( "*** Server will start in 30 seconds ***" );
|
||||||
|
Thread.sleep( TimeUnit.SECONDS.toMillis( 30 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.setProperty( "java.net.preferIPv4Stack", "true" );
|
||||||
|
|
||||||
|
BungeeCord bungee = new BungeeCord();
|
||||||
|
ProxyServer.setInstance( bungee );
|
||||||
|
bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() );
|
||||||
|
bungee.start();
|
||||||
|
|
||||||
|
while ( bungee.isRunning )
|
||||||
|
{
|
||||||
|
String line = bungee.getConsoleReader().readLine( ">" );
|
||||||
|
if ( line != null )
|
||||||
|
{
|
||||||
|
if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) )
|
||||||
|
{
|
||||||
|
bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
config/nb-configuration.xml
Normal file
31
config/nb-configuration.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
@@ -6,29 +6,24 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-parent</artifactId>
|
<artifactId>bungeecord-parent</artifactId>
|
||||||
<version>1.4.7-SNAPSHOT</version>
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-config</artifactId>
|
<artifactId>bungeecord-config</artifactId>
|
||||||
<version>1.4.7-SNAPSHOT</version>
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>BungeeCord-Config</name>
|
<name>BungeeCord-Config</name>
|
||||||
<description>Generic java configuration API intended for use with BungeeCord</description>
|
<description>Generic java configuration API intended for use with BungeeCord</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.11</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.yaml</groupId>
|
<groupId>org.yaml</groupId>
|
||||||
<artifactId>snakeyaml</artifactId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
<version>1.11</version>
|
<version>1.13</version>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -2,7 +2,7 @@ package net.md_5.bungee.config;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
@@ -13,36 +13,53 @@ public final class Configuration
|
|||||||
{
|
{
|
||||||
|
|
||||||
private static final char SEPARATOR = '.';
|
private static final char SEPARATOR = '.';
|
||||||
private final Map<String, Object> self;
|
final Map<String, Object> self;
|
||||||
private Map<String, Object> comments = new HashMap<>();
|
|
||||||
private final Configuration defaults;
|
private final Configuration defaults;
|
||||||
|
|
||||||
private Map<String, Object> getHolder(String path, Map<String, Object> parent, boolean create)
|
private Configuration getSectionFor(String path)
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object get(String path, Map<String, Object> holder)
|
|
||||||
{
|
{
|
||||||
int index = path.indexOf( SEPARATOR );
|
int index = path.indexOf( SEPARATOR );
|
||||||
String first, second;
|
|
||||||
if ( index == -1 )
|
if ( index == -1 )
|
||||||
{
|
{
|
||||||
second = path;
|
return this;
|
||||||
} else
|
|
||||||
{
|
|
||||||
first = path.substring( 0, index );
|
|
||||||
second = path.substring( index + 1, path.length() );
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
String root = path.substring( 0, index );
|
||||||
|
Object section = self.get( root );
|
||||||
|
if ( section == null )
|
||||||
|
{
|
||||||
|
section = new LinkedHashMap<>();
|
||||||
|
self.put( root, section );
|
||||||
|
}
|
||||||
|
if ( section instanceof Configuration )
|
||||||
|
{
|
||||||
|
return (Configuration) section;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Configuration( (Map) section, ( defaults == null ) ? null : defaults.getSectionFor( path ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getChild(String path)
|
||||||
|
{
|
||||||
|
int index = path.indexOf( SEPARATOR );
|
||||||
|
return ( index == -1 ) ? path : path.substring( index + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T get(String path, T def)
|
public <T> T get(String path, T def)
|
||||||
{
|
{
|
||||||
Object val = get( path, self );
|
Configuration section = getSectionFor( path );
|
||||||
return ( val != null && val.getClass().isInstance( def ) ) ? (T) val : (T) defaults.get( path );
|
Object val;
|
||||||
|
if ( section == this )
|
||||||
|
{
|
||||||
|
val = self.get( path );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
val = section.get( getChild( path ), def );
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( val != null ) ? (T) val : def;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(String path)
|
public Object get(String path)
|
||||||
@@ -52,19 +69,26 @@ public final class Configuration
|
|||||||
|
|
||||||
public Object getDefault(String path)
|
public Object getDefault(String path)
|
||||||
{
|
{
|
||||||
return defaults.get( path );
|
return ( defaults == null ) ? null : defaults.get( path );
|
||||||
}
|
|
||||||
|
|
||||||
public void set(String path, Object value, String comment)
|
|
||||||
{
|
|
||||||
String child = path.substring( path.indexOf( SEPARATOR ) + 1 );
|
|
||||||
getHolder( path, self, true ).put( child, value );
|
|
||||||
getHolder( path, comments, true ).put( child, value );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String path, Object value)
|
public void set(String path, Object value)
|
||||||
{
|
{
|
||||||
set( path, value, null );
|
Configuration section = getSectionFor( path );
|
||||||
|
if ( section == this )
|
||||||
|
{
|
||||||
|
self.put( path, value );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
section.set( getChild( path ), value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
public Configuration getSection(String path)
|
||||||
|
{
|
||||||
|
Object def = getDefault( path );
|
||||||
|
return new Configuration( (Map) ( get( path, ( def instanceof Map ) ? def : Collections.EMPTY_MAP ) ), ( defaults == null ) ? null : defaults.getSection( path ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package net.md_5.bungee.config;
|
package net.md_5.bungee.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -15,13 +17,17 @@ public abstract class ConfigurationProvider
|
|||||||
providers.put( YamlConfiguration.class, new YamlConfiguration() );
|
providers.put( YamlConfiguration.class, new YamlConfiguration() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationProvider getProvider(Class<? extends ConfigurationProvider> provider)
|
public static ConfigurationProvider getProvider(Class<? extends ConfigurationProvider> provider)
|
||||||
{
|
{
|
||||||
return providers.get( provider );
|
return providers.get( provider );
|
||||||
}
|
}
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
public abstract Configuration load(File file);
|
public abstract void save(Configuration config, File file) throws IOException;
|
||||||
|
|
||||||
|
public abstract void save(Configuration config, Writer writer);
|
||||||
|
|
||||||
|
public abstract Configuration load(File file) throws IOException;
|
||||||
|
|
||||||
public abstract Configuration load(Reader reader);
|
public abstract Configuration load(Reader reader);
|
||||||
|
|
||||||
|
@@ -1,14 +1,18 @@
|
|||||||
package net.md_5.bungee.config;
|
package net.md_5.bungee.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PACKAGE)
|
||||||
public class YamlConfiguration extends ConfigurationProvider
|
public class YamlConfiguration extends ConfigurationProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -24,14 +28,26 @@ public class YamlConfiguration extends ConfigurationProvider
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Configuration load(File file)
|
public void save(Configuration config, File file) throws IOException
|
||||||
|
{
|
||||||
|
try ( FileWriter writer = new FileWriter( file ) )
|
||||||
|
{
|
||||||
|
save( config, writer );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(Configuration config, Writer writer)
|
||||||
|
{
|
||||||
|
yaml.get().dump( config.self, writer );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Configuration load(File file) throws IOException
|
||||||
{
|
{
|
||||||
try ( FileReader reader = new FileReader( file ) )
|
try ( FileReader reader = new FileReader( file ) )
|
||||||
{
|
{
|
||||||
return load( reader );
|
return load( reader );
|
||||||
} catch ( IOException ex )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,61 @@
|
|||||||
|
package net.md_5.bungee.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class YamlConfigurationTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private String docuement = ""
|
||||||
|
+ "receipt: Oz-Ware Purchase Invoice\n"
|
||||||
|
+ "date: 2012-08-06\n"
|
||||||
|
+ "customer:\n"
|
||||||
|
+ " given: Dorothy\n"
|
||||||
|
+ " family: Gale\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "items:\n"
|
||||||
|
+ " - part_no: A4786\n"
|
||||||
|
+ " descrip: Water Bucket (Filled)\n"
|
||||||
|
+ " price: 1.47\n"
|
||||||
|
+ " quantity: 4\n"
|
||||||
|
+ "\n"
|
||||||
|
+ " - part_no: E1628\n"
|
||||||
|
+ " descrip: High Heeled \"Ruby\" Slippers\n"
|
||||||
|
+ " size: 8\n"
|
||||||
|
+ " price: 100.27\n"
|
||||||
|
+ " quantity: 1\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "bill-to: &id001\n"
|
||||||
|
+ " street: |\n"
|
||||||
|
+ " 123 Tornado Alley\n"
|
||||||
|
+ " Suite 16\n"
|
||||||
|
+ " city: East Centerville\n"
|
||||||
|
+ " state: KS\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "ship-to: *id001\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "specialDelivery: >\n"
|
||||||
|
+ " Follow the Yellow Brick\n"
|
||||||
|
+ " Road to the Emerald City.\n"
|
||||||
|
+ " Pay no attention to the\n"
|
||||||
|
+ " man behind the curtain.";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRead() throws Exception
|
||||||
|
{
|
||||||
|
Configuration conf = ConfigurationProvider.getProvider( YamlConfiguration.class ).load( docuement );
|
||||||
|
|
||||||
|
Assert.assertEquals( "receipt", "Oz-Ware Purchase Invoice", conf.getString( "receipt" ) );
|
||||||
|
// Assert.assertEquals( "date", "2012-08-06", conf.get( "date" ).toString() );
|
||||||
|
|
||||||
|
Configuration customer = conf.getSection( "customer" );
|
||||||
|
Assert.assertEquals( "customer.given", "Dorothy", customer.getString( "given" ) );
|
||||||
|
Assert.assertEquals( "customer.given", "Dorothy", conf.getString( "customer.given" ) );
|
||||||
|
|
||||||
|
List items = conf.getList( "items" );
|
||||||
|
Map item = (Map) items.get( 0 );
|
||||||
|
Assert.assertEquals( "items[0].part_no", "A4786", item.get( "part_no" ) );
|
||||||
|
}
|
||||||
|
}
|
31
event/nb-configuration.xml
Normal file
31
event/nb-configuration.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
20
event/pom.xml
Normal file
20
event/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-parent</artifactId>
|
||||||
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-event</artifactId>
|
||||||
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>BungeeCord-Event</name>
|
||||||
|
<description>Generic java event dispatching API intended for use with BungeeCord</description>
|
||||||
|
</project>
|
202
event/src/main/java/net/md_5/bungee/event/EventBus.java
Normal file
202
event/src/main/java/net/md_5/bungee/event/EventBus.java
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
package net.md_5.bungee.event;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class EventBus
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Map<Class<?>, Map<Byte, Map<Object, Method[]>>> byListenerAndPriority = new HashMap<>();
|
||||||
|
private final Map<Class<?>, EventHandlerMethod[]> byEventBaked = new HashMap<>();
|
||||||
|
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
public EventBus()
|
||||||
|
{
|
||||||
|
this( null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public EventBus(Logger logger)
|
||||||
|
{
|
||||||
|
this.logger = ( logger == null ) ? Logger.getGlobal() : logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void post(Object event)
|
||||||
|
{
|
||||||
|
lock.readLock().lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
EventHandlerMethod[] handlers = byEventBaked.get( event.getClass() );
|
||||||
|
if ( handlers != null )
|
||||||
|
{
|
||||||
|
for ( EventHandlerMethod method : handlers )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
method.invoke( event );
|
||||||
|
} catch ( IllegalAccessException ex )
|
||||||
|
{
|
||||||
|
throw new Error( "Method became inaccessible: " + event, ex );
|
||||||
|
} catch ( IllegalArgumentException ex )
|
||||||
|
{
|
||||||
|
throw new Error( "Method rejected target/argument: " + event, ex );
|
||||||
|
} catch ( InvocationTargetException ex )
|
||||||
|
{
|
||||||
|
logger.log( Level.WARNING, MessageFormat.format( "Error dispatching event {0} to listener {1}", event, method.getListener() ), ex.getCause() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally
|
||||||
|
{
|
||||||
|
lock.readLock().unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Class<?>, Map<Byte, Set<Method>>> findHandlers(Object listener)
|
||||||
|
{
|
||||||
|
Map<Class<?>, Map<Byte, Set<Method>>> handler = new HashMap<>();
|
||||||
|
for ( Method m : listener.getClass().getDeclaredMethods() )
|
||||||
|
{
|
||||||
|
EventHandler annotation = m.getAnnotation( EventHandler.class );
|
||||||
|
if ( annotation != null )
|
||||||
|
{
|
||||||
|
Class<?>[] params = m.getParameterTypes();
|
||||||
|
if ( params.length != 1 )
|
||||||
|
{
|
||||||
|
logger.log( Level.INFO, "Method {0} in class {1} annotated with {2} does not have single argument", new Object[]
|
||||||
|
{
|
||||||
|
m, listener.getClass(), annotation
|
||||||
|
} );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Map<Byte, Set<Method>> prioritiesMap = handler.get( params[0] );
|
||||||
|
if ( prioritiesMap == null )
|
||||||
|
{
|
||||||
|
prioritiesMap = new HashMap<>();
|
||||||
|
handler.put( params[0], prioritiesMap );
|
||||||
|
}
|
||||||
|
Set<Method> priority = prioritiesMap.get( annotation.priority() );
|
||||||
|
if ( priority == null )
|
||||||
|
{
|
||||||
|
priority = new HashSet<>();
|
||||||
|
prioritiesMap.put( annotation.priority(), priority );
|
||||||
|
}
|
||||||
|
priority.add( m );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(Object listener)
|
||||||
|
{
|
||||||
|
Map<Class<?>, Map<Byte, Set<Method>>> handler = findHandlers( listener );
|
||||||
|
lock.writeLock().lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for ( Map.Entry<Class<?>, Map<Byte, Set<Method>>> e : handler.entrySet() )
|
||||||
|
{
|
||||||
|
Map<Byte, Map<Object, Method[]>> prioritiesMap = byListenerAndPriority.get( e.getKey() );
|
||||||
|
if ( prioritiesMap == null )
|
||||||
|
{
|
||||||
|
prioritiesMap = new HashMap<>();
|
||||||
|
byListenerAndPriority.put( e.getKey(), prioritiesMap );
|
||||||
|
}
|
||||||
|
for ( Map.Entry<Byte, Set<Method>> entry : e.getValue().entrySet() )
|
||||||
|
{
|
||||||
|
Map<Object, Method[]> currentPriorityMap = prioritiesMap.get( entry.getKey() );
|
||||||
|
if ( currentPriorityMap == null )
|
||||||
|
{
|
||||||
|
currentPriorityMap = new HashMap<>();
|
||||||
|
prioritiesMap.put( entry.getKey(), currentPriorityMap );
|
||||||
|
}
|
||||||
|
Method[] baked = new Method[ entry.getValue().size() ];
|
||||||
|
currentPriorityMap.put( listener, entry.getValue().toArray( baked ) );
|
||||||
|
}
|
||||||
|
bakeHandlers( e.getKey() );
|
||||||
|
}
|
||||||
|
} finally
|
||||||
|
{
|
||||||
|
lock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregister(Object listener)
|
||||||
|
{
|
||||||
|
Map<Class<?>, Map<Byte, Set<Method>>> handler = findHandlers( listener );
|
||||||
|
lock.writeLock().lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for ( Map.Entry<Class<?>, Map<Byte, Set<Method>>> e : handler.entrySet() )
|
||||||
|
{
|
||||||
|
Map<Byte, Map<Object, Method[]>> prioritiesMap = byListenerAndPriority.get( e.getKey() );
|
||||||
|
if ( prioritiesMap != null )
|
||||||
|
{
|
||||||
|
for ( Byte priority : e.getValue().keySet() )
|
||||||
|
{
|
||||||
|
Map<Object, Method[]> currentPriority = prioritiesMap.get( priority );
|
||||||
|
if ( currentPriority != null )
|
||||||
|
{
|
||||||
|
currentPriority.remove( listener );
|
||||||
|
if ( currentPriority.isEmpty() )
|
||||||
|
{
|
||||||
|
prioritiesMap.remove( priority );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( prioritiesMap.isEmpty() )
|
||||||
|
{
|
||||||
|
byListenerAndPriority.remove( e.getKey() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bakeHandlers( e.getKey() );
|
||||||
|
}
|
||||||
|
} finally
|
||||||
|
{
|
||||||
|
lock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shouldn't be called without first locking the writeLock; intended for use
|
||||||
|
* only inside {@link #register(java.lang.Object) register(Object)} or
|
||||||
|
* {@link #unregister(java.lang.Object) unregister(Object)}.
|
||||||
|
*/
|
||||||
|
private void bakeHandlers(Class<?> eventClass)
|
||||||
|
{
|
||||||
|
Map<Byte, Map<Object, Method[]>> handlersByPriority = byListenerAndPriority.get( eventClass );
|
||||||
|
if ( handlersByPriority != null )
|
||||||
|
{
|
||||||
|
List<EventHandlerMethod> handlersList = new ArrayList<>( handlersByPriority.size() * 2 );
|
||||||
|
for ( byte value = Byte.MIN_VALUE; value < Byte.MAX_VALUE; value++ )
|
||||||
|
{
|
||||||
|
Map<Object, Method[]> handlersByListener = handlersByPriority.get( value );
|
||||||
|
if ( handlersByListener != null )
|
||||||
|
{
|
||||||
|
for ( Map.Entry<Object, Method[]> listenerHandlers : handlersByListener.entrySet() )
|
||||||
|
{
|
||||||
|
for ( Method method : listenerHandlers.getValue() )
|
||||||
|
{
|
||||||
|
EventHandlerMethod ehm = new EventHandlerMethod( listenerHandlers.getKey(), method );
|
||||||
|
handlersList.add( ehm );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
byEventBaked.put( eventClass, handlersList.toArray( new EventHandlerMethod[ handlersList.size() ] ) );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
byEventBaked.put( eventClass, null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
event/src/main/java/net/md_5/bungee/event/EventHandler.java
Normal file
26
event/src/main/java/net/md_5/bungee/event/EventHandler.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package net.md_5.bungee.event;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
public @interface EventHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the priority of the event handler.
|
||||||
|
* <p>
|
||||||
|
* Event handlers are called in order of priority:
|
||||||
|
* <ol>
|
||||||
|
* <li>LOWEST</li>
|
||||||
|
* <li>LOW</li>
|
||||||
|
* <li>NORMAL</li>
|
||||||
|
* <li>HIGH</li>
|
||||||
|
* <li>HIGHEST</li>
|
||||||
|
* </ol>
|
||||||
|
*/
|
||||||
|
byte priority() default EventPriority.NORMAL;
|
||||||
|
}
|
@@ -0,0 +1,21 @@
|
|||||||
|
package net.md_5.bungee.event;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class EventHandlerMethod
|
||||||
|
{
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Object listener;
|
||||||
|
@Getter
|
||||||
|
private final Method method;
|
||||||
|
|
||||||
|
public void invoke(Object event) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
|
||||||
|
{
|
||||||
|
method.invoke( listener, event );
|
||||||
|
}
|
||||||
|
}
|
19
event/src/main/java/net/md_5/bungee/event/EventPriority.java
Normal file
19
event/src/main/java/net/md_5/bungee/event/EventPriority.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package net.md_5.bungee.event;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Importance of the {@link EventHandler}. When executing an Event, the handlers
|
||||||
|
* are called in order of their Priority.
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class EventPriority
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final byte LOWEST = -64;
|
||||||
|
public static final byte LOW = -32;
|
||||||
|
public static final byte NORMAL = 0;
|
||||||
|
public static final byte HIGH = 32;
|
||||||
|
public static final byte HIGHEST = 64;
|
||||||
|
}
|
42
event/src/test/java/net/md_5/bungee/event/EventBusTest.java
Normal file
42
event/src/test/java/net/md_5/bungee/event/EventBusTest.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package net.md_5.bungee.event;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class EventBusTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private final EventBus bus = new EventBus();
|
||||||
|
private final CountDownLatch latch = new CountDownLatch( 2 );
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNestedEvents()
|
||||||
|
{
|
||||||
|
bus.register( this );
|
||||||
|
bus.post( new FirstEvent() );
|
||||||
|
Assert.assertEquals( 0, latch.getCount() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void firstListener(FirstEvent event)
|
||||||
|
{
|
||||||
|
bus.post( new SecondEvent() );
|
||||||
|
Assert.assertEquals( 1, latch.getCount() );
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void secondListener(SecondEvent event)
|
||||||
|
{
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FirstEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SecondEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,64 @@
|
|||||||
|
package net.md_5.bungee.event;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class EventPriorityTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private final EventBus bus = new EventBus();
|
||||||
|
private final CountDownLatch latch = new CountDownLatch( 5 );
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPriority()
|
||||||
|
{
|
||||||
|
bus.register( this );
|
||||||
|
bus.register( new EventPriorityListenerPartner() );
|
||||||
|
bus.post( new PriorityTestEvent() );
|
||||||
|
Assert.assertEquals( 0, latch.getCount() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onLowestPriority(PriorityTestEvent event)
|
||||||
|
{
|
||||||
|
Assert.assertEquals( 5, latch.getCount() );
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onNormalPriority(PriorityTestEvent event)
|
||||||
|
{
|
||||||
|
Assert.assertEquals( 3, latch.getCount() );
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onHighestPriority(PriorityTestEvent event)
|
||||||
|
{
|
||||||
|
Assert.assertEquals( 1, latch.getCount() );
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PriorityTestEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EventPriorityListenerPartner
|
||||||
|
{
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
|
public void onHighPriority(PriorityTestEvent event)
|
||||||
|
{
|
||||||
|
Assert.assertEquals( 2, latch.getCount() );
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onLowPriority(PriorityTestEvent event)
|
||||||
|
{
|
||||||
|
Assert.assertEquals( 4, latch.getCount() );
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
package net.md_5.bungee.event;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class UnregisteringListenerTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private final EventBus bus = new EventBus();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPriority()
|
||||||
|
{
|
||||||
|
bus.register( this );
|
||||||
|
bus.unregister( this );
|
||||||
|
bus.post( new TestEvent() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEvent(TestEvent evt)
|
||||||
|
{
|
||||||
|
Assert.fail( "Event listener wasn't unregistered" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestEvent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
31
nb-configuration.xml
Normal file
31
nb-configuration.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
28
pom.xml
28
pom.xml
@@ -11,16 +11,16 @@
|
|||||||
|
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-parent</artifactId>
|
<artifactId>bungeecord-parent</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>BungeeCord</name>
|
<name>BungeeCord</name>
|
||||||
<description>Parent project for all BungeeCord modules.</description>
|
<description>Parent project for all BungeeCord modules.</description>
|
||||||
<url>https://github.com/ElasticPortalSuite/BungeeCord</url>
|
<url>https://github.com/SpigotMC/BungeeCord</url>
|
||||||
<inceptionYear>2012</inceptionYear>
|
<inceptionYear>2012</inceptionYear>
|
||||||
<organization>
|
<organization>
|
||||||
<name>Elastic Portal Suite</name>
|
<name>Elastic Portal Suite</name>
|
||||||
<url>https://github.com/ElasticPortalSuite</url>
|
<url>https://github.com/SpigotMC</url>
|
||||||
</organization>
|
</organization>
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
@@ -38,18 +38,22 @@
|
|||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>api</module>
|
<module>api</module>
|
||||||
|
<module>bootstrap</module>
|
||||||
|
<module>config</module>
|
||||||
|
<module>event</module>
|
||||||
<module>protocol</module>
|
<module>protocol</module>
|
||||||
<module>proxy</module>
|
<module>proxy</module>
|
||||||
|
<module>query</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git@github.com:ElasticPortalSuite/BungeeCord.git</connection>
|
<connection>scm:git:git@github.com:SpigotMC/BungeeCord.git</connection>
|
||||||
<developerConnection>scm:git:git@github.com:ElasticPortalSuite/BungeeCord.git</developerConnection>
|
<developerConnection>scm:git:git@github.com:SpigotMC/BungeeCord.git</developerConnection>
|
||||||
<url>git@github.com:ElasticPortalSuite/BungeeCord.git</url>
|
<url>git@github.com:SpigotMC/BungeeCord.git</url>
|
||||||
</scm>
|
</scm>
|
||||||
<issueManagement>
|
<issueManagement>
|
||||||
<system>GitHub</system>
|
<system>GitHub</system>
|
||||||
<url>https://github.com/ElasticPortalSuite/BungeeCord/issues</url>
|
<url>https://github.com/SpigotMC/BungeeCord/issues</url>
|
||||||
</issueManagement>
|
</issueManagement>
|
||||||
<ciManagement>
|
<ciManagement>
|
||||||
<system>jenkins</system>
|
<system>jenkins</system>
|
||||||
@@ -58,15 +62,21 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<build.number>unknown</build.number>
|
<build.number>unknown</build.number>
|
||||||
<netty.version>4.0.0.CR1</netty.version>
|
<netty.version>4.0.9.Final</netty.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>0.11.8</version>
|
<version>0.12.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
31
protocol/nb-configuration.xml
Normal file
31
protocol/nb-configuration.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<org-netbeans-modules-editor-indent.CodeStyle.usedProfile>project</org-netbeans-modules-editor-indent.CodeStyle.usedProfile>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.otherBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>NEW_LINE</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.methodDeclBracePlacement>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinMethodCallParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSwitchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinCatchParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinTryParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinSynchronizedParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinArrayInitBrackets>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinWhileParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinIfParens>
|
||||||
|
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.spaceWithinForParens>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
@@ -6,13 +6,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-parent</artifactId>
|
<artifactId>bungeecord-parent</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-protocol</artifactId>
|
<artifactId>bungeecord-protocol</artifactId>
|
||||||
<version>1.5-SNAPSHOT</version>
|
<version>1.6.4-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>BungeeCord-Protocol</name>
|
<name>BungeeCord-Protocol</name>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
<artifactId>netty-buffer</artifactId>
|
<artifactId>netty-buffer</artifactId>
|
||||||
<version>${netty.version}</version>
|
<version>${netty.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -0,0 +1,10 @@
|
|||||||
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
|
public class BadPacketException extends RuntimeException
|
||||||
|
{
|
||||||
|
|
||||||
|
public BadPacketException(String message)
|
||||||
|
{
|
||||||
|
super( message );
|
||||||
|
}
|
||||||
|
}
|
33
protocol/src/main/java/net/md_5/bungee/protocol/Forge.java
Normal file
33
protocol/src/main/java/net/md_5/bungee/protocol/Forge.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.packet.forge.Forge1Login;
|
||||||
|
import net.md_5.bungee.protocol.skip.PacketReader;
|
||||||
|
|
||||||
|
public class Forge extends Vanilla
|
||||||
|
{
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static final Forge instance = new Forge();
|
||||||
|
|
||||||
|
public Forge()
|
||||||
|
{
|
||||||
|
classes[0x01] = Forge1Login.class;
|
||||||
|
skipper = new PacketReader( this ); // TODO: :(
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefinedPacket read(short packetId, ByteBuf buf)
|
||||||
|
{
|
||||||
|
int start = buf.readerIndex();
|
||||||
|
DefinedPacket packet = read( packetId, buf, this );
|
||||||
|
if ( buf.readerIndex() == start )
|
||||||
|
{
|
||||||
|
packet = super.read( packetId, buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MinecraftInput
|
||||||
|
{
|
||||||
|
|
||||||
|
private final ByteBuf buf;
|
||||||
|
|
||||||
|
public byte readByte()
|
||||||
|
{
|
||||||
|
return buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
public short readUnisgnedByte()
|
||||||
|
{
|
||||||
|
return buf.readUnsignedByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int readInt()
|
||||||
|
{
|
||||||
|
return buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String readString()
|
||||||
|
{
|
||||||
|
short len = buf.readShort();
|
||||||
|
char[] c = new char[ len ];
|
||||||
|
for ( int i = 0; i < c.length; i++ )
|
||||||
|
{
|
||||||
|
c[i] = buf.readChar();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String( c );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class MinecraftOutput
|
||||||
|
{
|
||||||
|
|
||||||
|
private final ByteBuf buf;
|
||||||
|
|
||||||
|
public MinecraftOutput()
|
||||||
|
{
|
||||||
|
buf = Unpooled.buffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] toArray()
|
||||||
|
{
|
||||||
|
if ( buf.hasArray() )
|
||||||
|
{
|
||||||
|
return Arrays.copyOfRange( buf.array(), buf.arrayOffset(), buf.arrayOffset() + buf.writerIndex() );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
byte[] b = new byte[ buf.writerIndex() ];
|
||||||
|
buf.readBytes( b );
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinecraftOutput writeByte(byte b)
|
||||||
|
{
|
||||||
|
buf.writeByte( b );
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeInt(int i)
|
||||||
|
{
|
||||||
|
buf.writeInt( i );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeString(String s)
|
||||||
|
{
|
||||||
|
char[] cc = s.toCharArray();
|
||||||
|
buf.writeShort( cc.length );
|
||||||
|
for ( char c : cc )
|
||||||
|
{
|
||||||
|
buf.writeChar( c );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket(String s)
|
||||||
|
{
|
||||||
|
buf.writeBytes( s.getBytes( Charset.forName( "UTF-8" ) ) );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
|
public enum OpCode
|
||||||
|
{
|
||||||
|
|
||||||
|
BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, USHORT_BYTE, OPTIONAL_WINDOW
|
||||||
|
}
|
@@ -0,0 +1,20 @@
|
|||||||
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.skip.PacketReader;
|
||||||
|
|
||||||
|
public interface Protocol
|
||||||
|
{
|
||||||
|
|
||||||
|
PacketReader getSkipper();
|
||||||
|
|
||||||
|
DefinedPacket read(short packetId, ByteBuf buf);
|
||||||
|
|
||||||
|
OpCode[][] getOpCodes();
|
||||||
|
|
||||||
|
Class<? extends DefinedPacket>[] getClasses();
|
||||||
|
|
||||||
|
Constructor<? extends DefinedPacket>[] getConstructors();
|
||||||
|
}
|
@@ -1,38 +1,131 @@
|
|||||||
package net.md_5.bungee.protocol;
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
import static net.md_5.bungee.protocol.PacketDefinitions.OpCode.*;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import lombok.Getter;
|
||||||
|
import static net.md_5.bungee.protocol.OpCode.*;
|
||||||
|
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.packet.Packet0KeepAlive;
|
||||||
|
import net.md_5.bungee.protocol.packet.Packet1Login;
|
||||||
|
import net.md_5.bungee.protocol.packet.Packet2CEntityProperties;
|
||||||
|
import net.md_5.bungee.protocol.packet.Packet2Handshake;
|
||||||
|
import net.md_5.bungee.protocol.packet.Packet3Chat;
|
||||||
|
import net.md_5.bungee.protocol.packet.Packet9Respawn;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketCBTabComplete;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketCCSettings;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketCDClientStatus;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketCFScoreboardScore;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketD0DisplayScoreboard;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketD1Team;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketFEPing;
|
||||||
|
import net.md_5.bungee.protocol.packet.PacketFFKick;
|
||||||
|
import net.md_5.bungee.protocol.skip.PacketReader;
|
||||||
|
|
||||||
public class PacketDefinitions
|
public class Vanilla implements Protocol
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final OpCode[][] opCodes = new OpCode[ 512 ][];
|
public static final byte PROTOCOL_VERSION = 78;
|
||||||
public static final int VANILLA_PROTOCOL = 0;
|
public static final String GAME_VERSION = "1.6.4";
|
||||||
public static final int FORGE_PROTOCOL = 256;
|
@Getter
|
||||||
|
private static final Vanilla instance = new Vanilla();
|
||||||
|
/*========================================================================*/
|
||||||
|
@Getter
|
||||||
|
private final OpCode[][] opCodes = new OpCode[ 256 ][];
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Getter
|
||||||
|
protected Class<? extends DefinedPacket>[] classes = new Class[ 256 ];
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Getter
|
||||||
|
private Constructor<? extends DefinedPacket>[] constructors = new Constructor[ 256 ];
|
||||||
|
@Getter
|
||||||
|
protected PacketReader skipper;
|
||||||
|
/*========================================================================*/
|
||||||
|
|
||||||
public enum OpCode
|
public Vanilla()
|
||||||
{
|
{
|
||||||
|
classes[0x00] = Packet0KeepAlive.class;
|
||||||
BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SCORE, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, TEAM, USHORT_BYTE
|
classes[0x01] = Packet1Login.class;
|
||||||
|
classes[0x02] = Packet2Handshake.class;
|
||||||
|
classes[0x03] = Packet3Chat.class;
|
||||||
|
classes[0x09] = Packet9Respawn.class;
|
||||||
|
classes[0xC9] = PacketC9PlayerListItem.class;
|
||||||
|
classes[0x2C] = Packet2CEntityProperties.class;
|
||||||
|
classes[0xCC] = PacketCCSettings.class;
|
||||||
|
classes[0xCB] = PacketCBTabComplete.class;
|
||||||
|
classes[0xCD] = PacketCDClientStatus.class;
|
||||||
|
classes[0xCE] = PacketCEScoreboardObjective.class;
|
||||||
|
classes[0xCF] = PacketCFScoreboardScore.class;
|
||||||
|
classes[0xD0] = PacketD0DisplayScoreboard.class;
|
||||||
|
classes[0xD1] = PacketD1Team.class;
|
||||||
|
classes[0xFA] = PacketFAPluginMessage.class;
|
||||||
|
classes[0xFC] = PacketFCEncryptionResponse.class;
|
||||||
|
classes[0xFD] = PacketFDEncryptionRequest.class;
|
||||||
|
classes[0xFE] = PacketFEPing.class;
|
||||||
|
classes[0xFF] = PacketFFKick.class;
|
||||||
|
skipper = new PacketReader( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
@Override
|
||||||
|
public DefinedPacket read(short packetId, ByteBuf buf)
|
||||||
{
|
{
|
||||||
opCodes[0x00] = new OpCode[]
|
int start = buf.readerIndex();
|
||||||
|
DefinedPacket packet = read( packetId, buf, this );
|
||||||
|
if ( buf.readerIndex() == start )
|
||||||
{
|
{
|
||||||
INT
|
throw new BadPacketException( "Unknown packet id " + packetId );
|
||||||
};
|
}
|
||||||
opCodes[0x01] = new OpCode[]
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DefinedPacket read(short id, ByteBuf buf, Protocol protocol)
|
||||||
|
{
|
||||||
|
DefinedPacket packet = packet( id, protocol );
|
||||||
|
if ( packet != null )
|
||||||
{
|
{
|
||||||
INT, STRING, BYTE, BYTE, BYTE, BYTE, BYTE
|
packet.read( buf );
|
||||||
};
|
return packet;
|
||||||
opCodes[0x02] = new OpCode[]
|
}
|
||||||
|
protocol.getSkipper().tryRead( id, buf );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DefinedPacket packet(short id, Protocol protocol)
|
||||||
|
{
|
||||||
|
DefinedPacket ret = null;
|
||||||
|
Class<? extends DefinedPacket> clazz = protocol.getClasses()[id];
|
||||||
|
|
||||||
|
if ( clazz != null )
|
||||||
{
|
{
|
||||||
BYTE, STRING, STRING, INT
|
try
|
||||||
};
|
{
|
||||||
opCodes[0x03] = new OpCode[]
|
Constructor<? extends DefinedPacket> constructor = protocol.getConstructors()[id];
|
||||||
{
|
if ( constructor == null )
|
||||||
STRING
|
{
|
||||||
};
|
constructor = clazz.getDeclaredConstructor();
|
||||||
|
constructor.setAccessible( true );
|
||||||
|
protocol.getConstructors()[id] = constructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( constructor != null )
|
||||||
|
{
|
||||||
|
ret = constructor.newInstance();
|
||||||
|
}
|
||||||
|
} catch ( NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
opCodes[0x04] = new OpCode[]
|
opCodes[0x04] = new OpCode[]
|
||||||
{
|
{
|
||||||
LONG, LONG
|
LONG, LONG
|
||||||
@@ -51,11 +144,7 @@ public class PacketDefinitions
|
|||||||
};
|
};
|
||||||
opCodes[0x08] = new OpCode[]
|
opCodes[0x08] = new OpCode[]
|
||||||
{
|
{
|
||||||
SHORT, SHORT, FLOAT
|
FLOAT, SHORT, FLOAT
|
||||||
};
|
|
||||||
opCodes[0x09] = new OpCode[]
|
|
||||||
{
|
|
||||||
INT, BYTE, BYTE, SHORT, STRING
|
|
||||||
};
|
};
|
||||||
opCodes[0x0A] = new OpCode[]
|
opCodes[0x0A] = new OpCode[]
|
||||||
{
|
{
|
||||||
@@ -95,7 +184,7 @@ public class PacketDefinitions
|
|||||||
};
|
};
|
||||||
opCodes[0x13] = new OpCode[]
|
opCodes[0x13] = new OpCode[]
|
||||||
{
|
{
|
||||||
INT, BYTE
|
INT, BYTE, INT
|
||||||
};
|
};
|
||||||
opCodes[0x14] = new OpCode[]
|
opCodes[0x14] = new OpCode[]
|
||||||
{
|
{
|
||||||
@@ -121,6 +210,10 @@ public class PacketDefinitions
|
|||||||
{
|
{
|
||||||
INT, INT, INT, INT, SHORT
|
INT, INT, INT, INT, SHORT
|
||||||
};
|
};
|
||||||
|
opCodes[0x1B] = new OpCode[]
|
||||||
|
{
|
||||||
|
FLOAT, FLOAT, BOOLEAN, BOOLEAN
|
||||||
|
};
|
||||||
opCodes[0x1C] = new OpCode[]
|
opCodes[0x1C] = new OpCode[]
|
||||||
{
|
{
|
||||||
INT, SHORT, SHORT, SHORT
|
INT, SHORT, SHORT, SHORT
|
||||||
@@ -159,7 +252,7 @@ public class PacketDefinitions
|
|||||||
};
|
};
|
||||||
opCodes[0x27] = new OpCode[]
|
opCodes[0x27] = new OpCode[]
|
||||||
{
|
{
|
||||||
INT, INT
|
INT, INT, BOOLEAN
|
||||||
};
|
};
|
||||||
opCodes[0x28] = new OpCode[]
|
opCodes[0x28] = new OpCode[]
|
||||||
{
|
{
|
||||||
@@ -227,7 +320,7 @@ public class PacketDefinitions
|
|||||||
};
|
};
|
||||||
opCodes[0x64] = new OpCode[]
|
opCodes[0x64] = new OpCode[]
|
||||||
{
|
{
|
||||||
BYTE, BYTE, STRING, BYTE, BOOLEAN
|
OPTIONAL_WINDOW
|
||||||
};
|
};
|
||||||
opCodes[0x65] = new OpCode[]
|
opCodes[0x65] = new OpCode[]
|
||||||
{
|
{
|
||||||
@@ -273,74 +366,21 @@ public class PacketDefinitions
|
|||||||
{
|
{
|
||||||
INT, SHORT, INT, BYTE, SHORT_BYTE
|
INT, SHORT, INT, BYTE, SHORT_BYTE
|
||||||
};
|
};
|
||||||
|
opCodes[0x85] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, INT, INT, INT
|
||||||
|
};
|
||||||
opCodes[0xC3] = new OpCode[]
|
opCodes[0xC3] = new OpCode[]
|
||||||
{
|
{
|
||||||
SHORT, SHORT, INT_BYTE
|
SHORT, SHORT, INT_BYTE
|
||||||
};
|
};
|
||||||
opCodes[0xC8] = new OpCode[]
|
opCodes[0xC8] = new OpCode[]
|
||||||
{
|
{
|
||||||
INT, BYTE
|
INT, INT
|
||||||
};
|
|
||||||
opCodes[0xC9] = new OpCode[]
|
|
||||||
{
|
|
||||||
STRING, BOOLEAN, SHORT
|
|
||||||
};
|
};
|
||||||
opCodes[0xCA] = new OpCode[]
|
opCodes[0xCA] = new OpCode[]
|
||||||
{
|
{
|
||||||
BYTE, BYTE, BYTE
|
BYTE, FLOAT, FLOAT
|
||||||
};
|
|
||||||
opCodes[0xCB] = new OpCode[]
|
|
||||||
{
|
|
||||||
STRING
|
|
||||||
};
|
|
||||||
opCodes[0xCC] = new OpCode[]
|
|
||||||
{
|
|
||||||
STRING, BYTE, BYTE, BYTE, BOOLEAN
|
|
||||||
};
|
|
||||||
opCodes[0xCD] = new OpCode[]
|
|
||||||
{
|
|
||||||
BYTE
|
|
||||||
};
|
|
||||||
opCodes[0xCE] = new OpCode[]
|
|
||||||
{
|
|
||||||
STRING, STRING, BYTE
|
|
||||||
};
|
|
||||||
opCodes[0xCF] = new OpCode[]
|
|
||||||
{
|
|
||||||
SCORE
|
|
||||||
};
|
|
||||||
opCodes[0xD0] = new OpCode[]
|
|
||||||
{
|
|
||||||
BYTE, STRING
|
|
||||||
};
|
|
||||||
opCodes[0xD1] = new OpCode[]
|
|
||||||
{
|
|
||||||
TEAM
|
|
||||||
};
|
|
||||||
opCodes[0xFA] = new OpCode[]
|
|
||||||
{
|
|
||||||
STRING, SHORT_BYTE
|
|
||||||
};
|
|
||||||
opCodes[0xFC] = new OpCode[]
|
|
||||||
{
|
|
||||||
SHORT_BYTE, SHORT_BYTE
|
|
||||||
};
|
|
||||||
opCodes[0xFD] = new OpCode[]
|
|
||||||
{
|
|
||||||
STRING, SHORT_BYTE, SHORT_BYTE
|
|
||||||
};
|
|
||||||
opCodes[0xFE] = new OpCode[]
|
|
||||||
{
|
|
||||||
BYTE
|
|
||||||
};
|
|
||||||
opCodes[0xFF] = new OpCode[]
|
|
||||||
{
|
|
||||||
STRING
|
|
||||||
};
|
|
||||||
/*========================== Minecraft Forge ===========================*/
|
|
||||||
opCodes[0x01 + FORGE_PROTOCOL] = new OpCode[]
|
|
||||||
{
|
|
||||||
INT, STRING, BYTE, INT, BYTE, BYTE, BYTE
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,19 +0,0 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class Score extends Instruction
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void read(ByteBuf in) throws IOException
|
|
||||||
{
|
|
||||||
STRING.read( in );
|
|
||||||
if ( in.readByte() == 0 )
|
|
||||||
{
|
|
||||||
STRING.read( in );
|
|
||||||
INT.read( in );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class Team extends Instruction
|
|
||||||
{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void read(ByteBuf in) throws IOException
|
|
||||||
{
|
|
||||||
STRING.read( in );
|
|
||||||
byte mode = in.readByte();
|
|
||||||
if ( mode == 0 || mode == 2 )
|
|
||||||
{
|
|
||||||
STRING.read( in );
|
|
||||||
STRING.read( in );
|
|
||||||
STRING.read( in );
|
|
||||||
BYTE.read( in );
|
|
||||||
}
|
|
||||||
if ( mode == 0 || mode == 3 || mode == 4 )
|
|
||||||
{
|
|
||||||
STRING_ARRAY.read( in );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,29 +1,8 @@
|
|||||||
package net.md_5.bungee.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
import net.md_5.bungee.netty.ChannelWrapper;
|
public abstract class AbstractPacketHandler
|
||||||
|
|
||||||
public abstract class PacketHandler
|
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract String toString();
|
|
||||||
|
|
||||||
public void connected(ChannelWrapper channel) throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnected(ChannelWrapper channel) throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exception(Throwable t) throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(byte[] buf) throws Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle(Packet0KeepAlive alive) throws Exception
|
public void handle(Packet0KeepAlive alive) throws Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -44,6 +23,10 @@ public abstract class PacketHandler
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handle(Packet2CEntityProperties properties) throws Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public void handle(PacketC9PlayerListItem playerList) throws Exception
|
public void handle(PacketC9PlayerListItem playerList) throws Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -91,4 +74,8 @@ public abstract class PacketHandler
|
|||||||
public void handle(PacketFFKick kick) throws Exception
|
public void handle(PacketFFKick kick) throws Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handle(PacketCBTabComplete tabComplete) throws Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,69 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public abstract class DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
|
||||||
|
public final int getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeString(String s, ByteBuf buf)
|
||||||
|
{
|
||||||
|
// TODO: Check len - use Guava?
|
||||||
|
buf.writeShort( s.length() );
|
||||||
|
for ( char c : s.toCharArray() )
|
||||||
|
{
|
||||||
|
buf.writeChar( c );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String readString(ByteBuf buf)
|
||||||
|
{
|
||||||
|
// TODO: Check len - use Guava?
|
||||||
|
short len = buf.readShort();
|
||||||
|
char[] chars = new char[ len ];
|
||||||
|
for ( int i = 0; i < len; i++ )
|
||||||
|
{
|
||||||
|
chars[i] = buf.readChar();
|
||||||
|
}
|
||||||
|
return new String( chars );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeArray(byte[] b, ByteBuf buf)
|
||||||
|
{
|
||||||
|
// TODO: Check len - use Guava?
|
||||||
|
buf.writeShort( b.length );
|
||||||
|
buf.writeBytes( b );
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] readArray(ByteBuf buf)
|
||||||
|
{
|
||||||
|
// TODO: Check len - use Guava?
|
||||||
|
short len = buf.readShort();
|
||||||
|
byte[] ret = new byte[ len ];
|
||||||
|
buf.readBytes( ret );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void read(ByteBuf buf);
|
||||||
|
|
||||||
|
public abstract void write(ByteBuf buf);
|
||||||
|
|
||||||
|
public abstract void handle(AbstractPacketHandler handler) throws Exception;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract boolean equals(Object obj);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract int hashCode();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract String toString();
|
||||||
|
}
|
@@ -0,0 +1,38 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Packet0KeepAlive extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private int randomId;
|
||||||
|
|
||||||
|
private Packet0KeepAlive()
|
||||||
|
{
|
||||||
|
super( 0x00 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
randomId = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeInt( randomId );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,73 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Packet1Login extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
protected int entityId;
|
||||||
|
protected String levelType;
|
||||||
|
protected byte gameMode;
|
||||||
|
protected int dimension;
|
||||||
|
protected byte difficulty;
|
||||||
|
protected byte unused;
|
||||||
|
protected byte maxPlayers;
|
||||||
|
|
||||||
|
protected Packet1Login()
|
||||||
|
{
|
||||||
|
super( 0x01 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Packet1Login(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers)
|
||||||
|
{
|
||||||
|
this( entityId, levelType, gameMode, (int) dimension, difficulty, unused, maxPlayers );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Packet1Login(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.entityId = entityId;
|
||||||
|
this.levelType = levelType;
|
||||||
|
this.gameMode = gameMode;
|
||||||
|
this.dimension = dimension;
|
||||||
|
this.difficulty = difficulty;
|
||||||
|
this.unused = unused;
|
||||||
|
this.maxPlayers = maxPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
entityId = buf.readInt();
|
||||||
|
levelType = readString( buf );
|
||||||
|
gameMode = buf.readByte();
|
||||||
|
dimension = buf.readByte();
|
||||||
|
difficulty = buf.readByte();
|
||||||
|
unused = buf.readByte();
|
||||||
|
maxPlayers = buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeInt( entityId );
|
||||||
|
writeString( levelType, buf );
|
||||||
|
buf.writeByte( gameMode );
|
||||||
|
buf.writeByte( dimension );
|
||||||
|
buf.writeByte( difficulty );
|
||||||
|
buf.writeByte( unused );
|
||||||
|
buf.writeByte( maxPlayers );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,47 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Packet2CEntityProperties extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
public Packet2CEntityProperties()
|
||||||
|
{
|
||||||
|
super( 0x2C );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.readInt();
|
||||||
|
int recordCount = buf.readInt();
|
||||||
|
for ( int i = 0; i < recordCount; i++ )
|
||||||
|
{
|
||||||
|
readString( buf );
|
||||||
|
buf.readDouble();
|
||||||
|
short size = buf.readShort();
|
||||||
|
for ( short s = 0; s < size; s++ )
|
||||||
|
{
|
||||||
|
buf.skipBytes( 25 ); // long, long, double, byte
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,49 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Packet2Handshake extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private byte protocolVersion;
|
||||||
|
private String username;
|
||||||
|
private String host;
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
private Packet2Handshake()
|
||||||
|
{
|
||||||
|
super( 0x02 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
protocolVersion = buf.readByte();
|
||||||
|
username = readString( buf );
|
||||||
|
host = readString( buf );
|
||||||
|
port = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte( protocolVersion );
|
||||||
|
writeString( username, buf );
|
||||||
|
writeString( host, buf );
|
||||||
|
buf.writeInt( port );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Packet3Chat extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private Packet3Chat()
|
||||||
|
{
|
||||||
|
super( 0x03 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Packet3Chat(String message)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
message = readString( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( message, buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Packet9Respawn extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private int dimension;
|
||||||
|
private byte difficulty;
|
||||||
|
private byte gameMode;
|
||||||
|
private short worldHeight;
|
||||||
|
private String levelType;
|
||||||
|
|
||||||
|
private Packet9Respawn()
|
||||||
|
{
|
||||||
|
super( 0x09 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Packet9Respawn(int dimension, byte difficulty, byte gameMode, short worldHeight, String levelType)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.dimension = dimension;
|
||||||
|
this.difficulty = difficulty;
|
||||||
|
this.gameMode = gameMode;
|
||||||
|
this.worldHeight = worldHeight;
|
||||||
|
this.levelType = levelType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
dimension = buf.readInt();
|
||||||
|
difficulty = buf.readByte();
|
||||||
|
gameMode = buf.readByte();
|
||||||
|
worldHeight = buf.readShort();
|
||||||
|
levelType = readString( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeInt( dimension );
|
||||||
|
buf.writeByte( difficulty );
|
||||||
|
buf.writeByte( gameMode );
|
||||||
|
buf.writeShort( worldHeight );
|
||||||
|
writeString( levelType, buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,52 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketC9PlayerListItem extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
private boolean online;
|
||||||
|
private short ping;
|
||||||
|
|
||||||
|
private PacketC9PlayerListItem()
|
||||||
|
{
|
||||||
|
super( 0xC9 );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketC9PlayerListItem(String username, boolean online, short ping)
|
||||||
|
{
|
||||||
|
super( 0xC9 );
|
||||||
|
this.username = username;
|
||||||
|
this.online = online;
|
||||||
|
this.ping = ping;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
username = readString( buf );
|
||||||
|
online = buf.readBoolean();
|
||||||
|
ping = buf.readShort();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( username, buf );
|
||||||
|
buf.writeBoolean( online );
|
||||||
|
buf.writeShort( ping );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,51 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketCBTabComplete extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String cursor;
|
||||||
|
private String[] commands;
|
||||||
|
|
||||||
|
private PacketCBTabComplete()
|
||||||
|
{
|
||||||
|
super( 0xCB );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketCBTabComplete(String[] alternatives)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
commands = alternatives;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
cursor = readString( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
StringBuilder tab = new StringBuilder();
|
||||||
|
for ( String alternative : commands )
|
||||||
|
{
|
||||||
|
tab.append( alternative );
|
||||||
|
tab.append( "\00" );
|
||||||
|
}
|
||||||
|
writeString( tab.substring( 0, tab.length() - 1 ), buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,48 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketCCSettings extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String locale;
|
||||||
|
private byte viewDistance;
|
||||||
|
private byte chatFlags;
|
||||||
|
private byte difficulty;
|
||||||
|
private boolean showCape;
|
||||||
|
|
||||||
|
private PacketCCSettings()
|
||||||
|
{
|
||||||
|
super( 0xCC );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
locale = readString( buf );
|
||||||
|
viewDistance = buf.readByte();
|
||||||
|
chatFlags = buf.readByte();
|
||||||
|
difficulty = buf.readByte();
|
||||||
|
showCape = buf.readBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( locale, buf );
|
||||||
|
buf.writeByte( viewDistance );
|
||||||
|
buf.writeByte( chatFlags );
|
||||||
|
buf.writeByte( difficulty );
|
||||||
|
buf.writeBoolean( showCape );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,42 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketCDClientStatus extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private byte payload;
|
||||||
|
|
||||||
|
private PacketCDClientStatus()
|
||||||
|
{
|
||||||
|
super( 0xCD );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketCDClientStatus(byte payload)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.payload = payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
payload = buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte( payload );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,55 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketCEScoreboardObjective extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String text;
|
||||||
|
/**
|
||||||
|
* 0 to create, 1 to remove.
|
||||||
|
*/
|
||||||
|
private byte action;
|
||||||
|
|
||||||
|
private PacketCEScoreboardObjective()
|
||||||
|
{
|
||||||
|
super( 0xCE );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketCEScoreboardObjective(String name, String text, byte action)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.name = name;
|
||||||
|
this.text = text;
|
||||||
|
this.action = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
name = readString( buf );
|
||||||
|
text = readString( buf );
|
||||||
|
action = buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( name, buf );
|
||||||
|
writeString( text, buf );
|
||||||
|
buf.writeByte( action );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketCFScoreboardScore extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String itemName;
|
||||||
|
/**
|
||||||
|
* 0 = create / update, 1 = remove.
|
||||||
|
*/
|
||||||
|
private byte action;
|
||||||
|
private String scoreName;
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
private PacketCFScoreboardScore()
|
||||||
|
{
|
||||||
|
super( 0xCF );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
itemName = readString( buf );
|
||||||
|
action = buf.readByte();
|
||||||
|
if ( action != 1 )
|
||||||
|
{
|
||||||
|
scoreName = readString( buf );
|
||||||
|
value = buf.readInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( itemName, buf );
|
||||||
|
buf.writeByte( action );
|
||||||
|
if ( action != 1 )
|
||||||
|
{
|
||||||
|
writeString( scoreName, buf );
|
||||||
|
buf.writeInt( value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,44 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketD0DisplayScoreboard extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0 = list, 1 = side, 2 = below.
|
||||||
|
*/
|
||||||
|
private byte position;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private PacketD0DisplayScoreboard()
|
||||||
|
{
|
||||||
|
super( 0xD0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
position = buf.readByte();
|
||||||
|
name = readString( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte( position );
|
||||||
|
writeString( name, buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,92 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketD1Team extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 0 - create, 1 remove, 2 info update, 3 player add, 4 player remove.
|
||||||
|
*/
|
||||||
|
private byte mode;
|
||||||
|
private String displayName;
|
||||||
|
private String prefix;
|
||||||
|
private String suffix;
|
||||||
|
private boolean friendlyFire;
|
||||||
|
private short playerCount;
|
||||||
|
private String[] players;
|
||||||
|
|
||||||
|
private PacketD1Team()
|
||||||
|
{
|
||||||
|
super( 0xD1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Packet to destroy a team.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public PacketD1Team(String name)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.name = name;
|
||||||
|
this.mode = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
name = readString( buf );
|
||||||
|
mode = buf.readByte();
|
||||||
|
if ( mode == 0 || mode == 2 )
|
||||||
|
{
|
||||||
|
displayName = readString( buf );
|
||||||
|
prefix = readString( buf );
|
||||||
|
suffix = readString( buf );
|
||||||
|
friendlyFire = buf.readBoolean();
|
||||||
|
}
|
||||||
|
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||||
|
{
|
||||||
|
players = new String[ buf.readShort() ];
|
||||||
|
for ( int i = 0; i < getPlayers().length; i++ )
|
||||||
|
{
|
||||||
|
players[i] = readString( buf );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( name, buf );
|
||||||
|
buf.writeByte( mode );
|
||||||
|
if ( mode == 0 || mode == 2 )
|
||||||
|
{
|
||||||
|
writeString( displayName, buf );
|
||||||
|
writeString( prefix, buf );
|
||||||
|
writeString( suffix, buf );
|
||||||
|
buf.writeBoolean( friendlyFire );
|
||||||
|
}
|
||||||
|
if ( mode == 0 || mode == 3 || mode == 4 )
|
||||||
|
{
|
||||||
|
buf.writeShort( players.length );
|
||||||
|
for ( int i = 0; i < players.length; i++ )
|
||||||
|
{
|
||||||
|
writeString( players[i], buf );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,64 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import net.md_5.bungee.protocol.MinecraftInput;
|
||||||
|
import net.md_5.bungee.protocol.MinecraftOutput;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketFAPluginMessage extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String tag;
|
||||||
|
private byte[] data;
|
||||||
|
|
||||||
|
private PacketFAPluginMessage()
|
||||||
|
{
|
||||||
|
super( 0xFA );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketFAPluginMessage(String tag, byte[] data)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.tag = tag;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
tag = readString( buf );
|
||||||
|
data = readArray( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( tag, buf );
|
||||||
|
writeArray( data, buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataInput getStream()
|
||||||
|
{
|
||||||
|
return new DataInputStream( new ByteArrayInputStream( data ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinecraftInput getMCStream()
|
||||||
|
{
|
||||||
|
return new MinecraftInput( Unpooled.wrappedBuffer( data ) );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,48 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketFCEncryptionResponse extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private byte[] sharedSecret;
|
||||||
|
private byte[] verifyToken;
|
||||||
|
|
||||||
|
private PacketFCEncryptionResponse()
|
||||||
|
{
|
||||||
|
super( 0xFC );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketFCEncryptionResponse(byte[] sharedSecret, byte[] verifyToken)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.sharedSecret = sharedSecret;
|
||||||
|
this.verifyToken = verifyToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
sharedSecret = readArray( buf );
|
||||||
|
verifyToken = readArray( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeArray( sharedSecret, buf );
|
||||||
|
writeArray( verifyToken, buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,52 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketFDEncryptionRequest extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String serverId;
|
||||||
|
private byte[] publicKey;
|
||||||
|
private byte[] verifyToken;
|
||||||
|
|
||||||
|
private PacketFDEncryptionRequest()
|
||||||
|
{
|
||||||
|
super( 0xFD );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketFDEncryptionRequest(String serverId, byte[] publicKey, byte[] verifyToken)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.serverId = serverId;
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
this.verifyToken = verifyToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
serverId = readString( buf );
|
||||||
|
publicKey = readArray( buf );
|
||||||
|
verifyToken = readArray( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( serverId, buf );
|
||||||
|
writeArray( publicKey, buf );
|
||||||
|
writeArray( verifyToken, buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,36 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketFEPing extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private byte version;
|
||||||
|
|
||||||
|
private PacketFEPing()
|
||||||
|
{
|
||||||
|
super( 0xFE );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
version = buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeByte( version );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,44 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PacketFFKick extends DefinedPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private PacketFFKick()
|
||||||
|
{
|
||||||
|
super( 0xFF );
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketFFKick(String message)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
message = readString( buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
writeString( message, buf );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,52 @@
|
|||||||
|
package net.md_5.bungee.protocol.packet.forge;
|
||||||
|
|
||||||
|
import net.md_5.bungee.protocol.packet.*;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Forge1Login extends Packet1Login
|
||||||
|
{
|
||||||
|
|
||||||
|
private Forge1Login()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Forge1Login(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers)
|
||||||
|
{
|
||||||
|
super( entityId, levelType, gameMode, dimension, difficulty, unused, maxPlayers );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ByteBuf buf)
|
||||||
|
{
|
||||||
|
entityId = buf.readInt();
|
||||||
|
levelType = readString( buf );
|
||||||
|
gameMode = buf.readByte();
|
||||||
|
dimension = buf.readInt();
|
||||||
|
difficulty = buf.readByte();
|
||||||
|
unused = buf.readByte();
|
||||||
|
maxPlayers = buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ByteBuf buf)
|
||||||
|
{
|
||||||
|
buf.writeInt( entityId );
|
||||||
|
writeString( levelType, buf );
|
||||||
|
buf.writeByte( gameMode );
|
||||||
|
buf.writeInt( dimension );
|
||||||
|
buf.writeByte( difficulty );
|
||||||
|
buf.writeByte( unused );
|
||||||
|
buf.writeByte( maxPlayers );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(AbstractPacketHandler handler) throws Exception
|
||||||
|
{
|
||||||
|
handler.handle( this );
|
||||||
|
}
|
||||||
|
}
|
@@ -1,13 +1,12 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class BulkChunk extends Instruction
|
public class BulkChunk extends Instruction
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
short count = in.readShort();
|
short count = in.readShort();
|
||||||
int size = in.readInt();
|
int size = in.readInt();
|
@@ -1,7 +1,6 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class ByteHeader extends Instruction
|
class ByteHeader extends Instruction
|
||||||
{
|
{
|
||||||
@@ -14,7 +13,7 @@ class ByteHeader extends Instruction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
byte size = in.readByte();
|
byte size = in.readByte();
|
||||||
for ( byte b = 0; b < size; b++ )
|
for ( byte b = 0; b < size; b++ )
|
@@ -1,7 +1,6 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
abstract class Instruction
|
abstract class Instruction
|
||||||
{
|
{
|
||||||
@@ -19,17 +18,16 @@ abstract class Instruction
|
|||||||
static final Instruction LONG = new Jump( 8 );
|
static final Instruction LONG = new Jump( 8 );
|
||||||
static final Instruction METADATA = new MetaData();
|
static final Instruction METADATA = new MetaData();
|
||||||
static final Instruction OPTIONAL_MOTION = new OptionalMotion();
|
static final Instruction OPTIONAL_MOTION = new OptionalMotion();
|
||||||
static final Instruction SCORE = new Score();
|
|
||||||
static final Instruction SHORT = new Jump( 2 );
|
static final Instruction SHORT = new Jump( 2 );
|
||||||
static final Instruction SHORT_BYTE = new ShortHeader( BYTE );
|
static final Instruction SHORT_BYTE = new ShortHeader( BYTE );
|
||||||
static final Instruction SHORT_ITEM = new ShortHeader( ITEM );
|
static final Instruction SHORT_ITEM = new ShortHeader( ITEM );
|
||||||
static final Instruction STRING = new ShortHeader( new Jump( 2 ) );
|
static final Instruction STRING = new ShortHeader( new Jump( 2 ) );
|
||||||
static final Instruction TEAM = new Team();
|
|
||||||
static final Instruction USHORT_BYTE = new UnsignedShortByte();
|
static final Instruction USHORT_BYTE = new UnsignedShortByte();
|
||||||
|
static final Instruction OPTIONAL_WINDOW = new OptionalWindow();
|
||||||
// Illegal forward references below this line
|
// Illegal forward references below this line
|
||||||
static final Instruction BYTE_INT = new ByteHeader( INT );
|
static final Instruction BYTE_INT = new ByteHeader( INT );
|
||||||
// Custom instructions
|
// Custom instructions
|
||||||
static final Instruction STRING_ARRAY = new ShortHeader( STRING );
|
static final Instruction STRING_ARRAY = new ShortHeader( STRING );
|
||||||
|
|
||||||
abstract void read(ByteBuf in) throws IOException;
|
abstract void read(ByteBuf in);
|
||||||
}
|
}
|
@@ -1,7 +1,6 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class IntHeader extends Instruction
|
class IntHeader extends Instruction
|
||||||
{
|
{
|
||||||
@@ -14,7 +13,7 @@ class IntHeader extends Instruction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
int size = in.readInt();
|
int size = in.readInt();
|
||||||
for ( int i = 0; i < size; i++ )
|
for ( int i = 0; i < size; i++ )
|
@@ -1,13 +1,12 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class Item extends Instruction
|
class Item extends Instruction
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
short type = in.readShort();
|
short type = in.readShort();
|
||||||
if ( type >= 0 )
|
if ( type >= 0 )
|
@@ -1,7 +1,6 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class Jump extends Instruction
|
class Jump extends Instruction
|
||||||
{
|
{
|
||||||
@@ -18,7 +17,7 @@ class Jump extends Instruction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
in.skipBytes( len );
|
in.skipBytes( len );
|
||||||
}
|
}
|
@@ -1,13 +1,12 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class MetaData extends Instruction
|
class MetaData extends Instruction
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
int x = in.readUnsignedByte();
|
int x = in.readUnsignedByte();
|
||||||
while ( x != 127 )
|
while ( x != 127 )
|
@@ -1,13 +1,12 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class OptionalMotion extends Instruction
|
class OptionalMotion extends Instruction
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
int data = in.readInt();
|
int data = in.readInt();
|
||||||
if ( data > 0 )
|
if ( data > 0 )
|
@@ -0,0 +1,21 @@
|
|||||||
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class OptionalWindow extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void read(ByteBuf in)
|
||||||
|
{
|
||||||
|
BYTE.read( in );
|
||||||
|
byte type = in.readByte();
|
||||||
|
STRING.read( in );
|
||||||
|
BYTE.read( in );
|
||||||
|
BOOLEAN.read( in );
|
||||||
|
if ( type == 11 )
|
||||||
|
{
|
||||||
|
INT.read( in );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,24 +1,24 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.md_5.bungee.protocol.PacketDefinitions;
|
import net.md_5.bungee.protocol.OpCode;
|
||||||
import net.md_5.bungee.protocol.PacketDefinitions.OpCode;
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
|
|
||||||
public class PacketReader
|
public class PacketReader
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final Instruction[][] instructions = new Instruction[ PacketDefinitions.opCodes.length ][];
|
private final Instruction[][] instructions;
|
||||||
|
|
||||||
static
|
public PacketReader(Protocol protocol)
|
||||||
{
|
{
|
||||||
|
instructions = new Instruction[ protocol.getOpCodes().length ][];
|
||||||
for ( int i = 0; i < instructions.length; i++ )
|
for ( int i = 0; i < instructions.length; i++ )
|
||||||
{
|
{
|
||||||
List<Instruction> output = new ArrayList<>();
|
List<Instruction> output = new ArrayList<>();
|
||||||
|
|
||||||
OpCode[] enums = PacketDefinitions.opCodes[i];
|
OpCode[] enums = protocol.getOpCodes()[i];
|
||||||
if ( enums != null )
|
if ( enums != null )
|
||||||
{
|
{
|
||||||
for ( OpCode struct : enums )
|
for ( OpCode struct : enums )
|
||||||
@@ -59,35 +59,16 @@ public class PacketReader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readPacket(int packetId, ByteBuf in, int protocol) throws IOException
|
public void tryRead(short packetId, ByteBuf in)
|
||||||
{
|
{
|
||||||
Instruction[] packetDef = null;
|
Instruction[] packetDef = instructions[packetId];
|
||||||
if ( packetId + protocol < instructions.length )
|
|
||||||
{
|
|
||||||
packetDef = instructions[packetId + protocol];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( packetDef == null )
|
if ( packetDef != null )
|
||||||
{
|
{
|
||||||
if ( protocol == PacketDefinitions.VANILLA_PROTOCOL )
|
for ( Instruction instruction : packetDef )
|
||||||
{
|
{
|
||||||
throw new IOException( "Unknown packet id " + packetId );
|
instruction.read( in );
|
||||||
} else
|
|
||||||
{
|
|
||||||
readPacket( packetId, in, PacketDefinitions.VANILLA_PROTOCOL );
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( Instruction instruction : packetDef )
|
|
||||||
{
|
|
||||||
instruction.read( in );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void readPacket(ByteBuf in, int protocol) throws IOException
|
|
||||||
{
|
|
||||||
int packetId = in.readUnsignedByte();
|
|
||||||
readPacket( packetId, in, protocol );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,6 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class ShortHeader extends Instruction
|
class ShortHeader extends Instruction
|
||||||
{
|
{
|
||||||
@@ -14,7 +13,7 @@ class ShortHeader extends Instruction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
short size = in.readShort();
|
short size = in.readShort();
|
||||||
for ( short s = 0; s < size; s++ )
|
for ( short s = 0; s < size; s++ )
|
@@ -1,13 +1,12 @@
|
|||||||
package net.md_5.bungee.protocol.netty;
|
package net.md_5.bungee.protocol.skip;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class UnsignedShortByte extends Instruction
|
class UnsignedShortByte extends Instruction
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(ByteBuf in) throws IOException
|
void read(ByteBuf in)
|
||||||
{
|
{
|
||||||
int size = in.readUnsignedShort();
|
int size = in.readUnsignedShort();
|
||||||
in.skipBytes( size );
|
in.skipBytes( size );
|
@@ -0,0 +1,45 @@
|
|||||||
|
package net.md_5.bungee.protocol;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import net.md_5.bungee.protocol.packet.AbstractPacketHandler;
|
||||||
|
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class PacketTest
|
||||||
|
{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPackets() throws Exception
|
||||||
|
{
|
||||||
|
AbstractPacketHandler handler = new AbstractPacketHandler()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
for ( short i = 0; i < 256; i++ )
|
||||||
|
{
|
||||||
|
Class<? extends DefinedPacket> clazz = Vanilla.getInstance().getClasses()[ i];
|
||||||
|
if ( clazz != null )
|
||||||
|
{
|
||||||
|
Assert.assertTrue( "Packet " + clazz + " is not public", Modifier.isPublic( clazz.getModifiers() ) );
|
||||||
|
DefinedPacket packet = Vanilla.packet( i, Vanilla.getInstance() );
|
||||||
|
Assert.assertTrue( "Could not create packet with id " + i + " and class " + clazz, packet != null );
|
||||||
|
Assert.assertTrue( "Packet with id " + i + " does not have correct class (expected " + clazz + " but got " + packet.getClass(), packet.getClass() == clazz );
|
||||||
|
Assert.assertTrue( "Packet " + clazz + " does not report correct id", packet.getId() == i );
|
||||||
|
Assert.assertTrue( "Packet " + clazz + " does not have custom hash code", packet.hashCode() != System.identityHashCode( packet ) );
|
||||||
|
Assert.assertTrue( "Packet " + clazz + " does not have custom toString", packet.toString().indexOf( '@' ) == -1 );
|
||||||
|
// TODO: Enable this test again in v2
|
||||||
|
// Assert.assertTrue( "Packet " + clazz + " does not have private no args constructor", Modifier.isPrivate( clazz.getDeclaredConstructor().getModifiers() ) );
|
||||||
|
|
||||||
|
for ( Field field : clazz.getDeclaredFields() )
|
||||||
|
{
|
||||||
|
// TODO: Enable this test again in v2
|
||||||
|
// Assert.assertTrue( "Packet " + clazz + " has non private field " + field, Modifier.isPrivate( field.getModifiers() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
packet.handle( handler ); // Make sure there are no exceptions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user