getPartyMembers();
105 |
106 | /**
107 | * @return true, if the Minecraft client currently plays on the server instance.
108 | */
109 | boolean isOnServer();
110 | }
111 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/server/GameMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.mod.server;
18 |
19 | /**
20 | * An abstract class that represents a server game mode. Override to store custom values for each specific game mode.
21 | */
22 | public abstract class GameMode {
23 |
24 | /**
25 | * Stores a unix time stamp that is either used to display the remaining time or current time, depending
26 | * on the {@link #state}.
27 | */
28 | protected long time;
29 | /**
30 | * The current game state.
31 | */
32 | protected GameState state;
33 |
34 | // Preset fields.
35 | protected int kills;
36 | protected int killStreak;
37 | protected long killStreakTime;
38 | protected int killstreakDuration = 1000 * 20;
39 | protected int deaths;
40 | protected String winner;
41 | protected boolean respawnable;
42 |
43 | public GameMode() {
44 | this.time = -1;
45 | killStreakTime = -1;
46 | this.state = GameState.LOBBY;
47 | this.respawnable = false;
48 | }
49 |
50 | public long getTime() {
51 | return time;
52 | }
53 |
54 | public void setTime(long time) {
55 | this.time = time;
56 | }
57 |
58 | public GameState getState() {
59 | return state;
60 | }
61 |
62 | public void setState(GameState state) {
63 | this.state = state;
64 | if (state == GameState.FINISHED) {
65 | time = System.currentTimeMillis() - time;
66 | } else {
67 | this.time = -1;
68 | }
69 | }
70 |
71 | public int getKills() {
72 | return kills;
73 | }
74 |
75 | public void setKills(int kills) {
76 | this.kills = kills;
77 | }
78 |
79 | public int getKillStreak() {
80 | if (killStreakTime != -1 && System.currentTimeMillis() - killStreakTime > 0) {
81 | killStreakTime = -1;
82 | killStreak = 0;
83 | }
84 | return killStreak;
85 | }
86 |
87 | public void setKillStreak(int killStreak) {
88 | this.killStreak = killStreak;
89 | this.killStreakTime = System.currentTimeMillis() + killstreakDuration;
90 | }
91 |
92 | public int getDeaths() {
93 | return deaths;
94 | }
95 |
96 | public void setDeaths(int deaths) {
97 | this.deaths = deaths;
98 | }
99 |
100 | public String getWinner() {
101 | return winner;
102 | }
103 |
104 | public void setWinner(String winner) {
105 | this.winner = winner;
106 | }
107 |
108 | public boolean isRespawnable() {
109 | return respawnable;
110 | }
111 |
112 | public void setRespawnable(boolean canRespawn) {
113 | this.respawnable = canRespawn;
114 | }
115 |
116 | public abstract String getName();
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/server/GameState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.mod.server;
18 |
19 | public enum GameState {
20 |
21 | /**
22 | * Lobby state.
23 | */
24 | LOBBY,
25 |
26 | /**
27 | * Game is Starting. All players have been teleported and are now freezed.
28 | */
29 | STARTING,
30 |
31 | /**
32 | * Pre game. All players can move, invincibility is on.
33 | */
34 | PREGAME,
35 |
36 | /**
37 | * Game.
38 | */
39 | GAME,
40 |
41 | /**
42 | * EndGame, eg. Deathmatch
43 | */
44 | ENDGAME,
45 |
46 | /**
47 | * Finished, stops the current time counter.
48 | */
49 | FINISHED
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/server/IMultiPatternResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.mod.server;
18 |
19 | /**
20 | * Represents multiple messages that have been ignored.
21 | */
22 | public interface IMultiPatternResult {
23 |
24 | /**
25 | * Tries to find a message that messages a specific pattern, specified by the messages file resource key, and
26 | * removes it from the ignored messages list.
27 | *
28 | * @param key the resource key of the pattern.
29 | * @return a pattern result or null, if no such message has been ignored.
30 | */
31 | IPatternResult parseKey(String key);
32 |
33 | /**
34 | * @return the amount of messages that have not yet been handled.
35 | */
36 | int getRemainingMessageCount();
37 |
38 | /**
39 | * Gets a message at a specific index.
40 | *
41 | * @param index the index of the message.
42 | * @return the message at the specified index.
43 | */
44 | String getMessage(int index);
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/server/IPatternResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.mod.server;
18 |
19 | /**
20 | * Represents the result of a matched pattern.
21 | */
22 | public interface IPatternResult {
23 |
24 | /**
25 | * @return the size of the result.
26 | */
27 | int size();
28 |
29 | /**
30 | * Gets a matched group at the specified index.
31 | *
32 | * @param index the index.
33 | * @return a matched group at the specified index or an empty string, in the index exceeds the total group count.
34 | */
35 | String get(int index);
36 |
37 | /**
38 | * Allows you to ignore the matched message.
39 | *
40 | * @param ignore true, if the matched message should be ignored.
41 | * @since 1.0.1
42 | */
43 | void ignoreMessage(boolean ignore);
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/server/ServerInstance.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.mod.server;
18 |
19 | /**
20 | * Represents a custom server handler. Extend to create a custom server handler.
21 | *
22 | * Create optionally a message resource file that is located in {@code core/servers}
23 | * of your plugin and called like {@link #getConfigName()} and ends with
24 | * {@code .properties}. This file should contain all messages that the mod should listen on. When
25 | * matched, the active {@link AbstractGameListener} will be called with the message key.
26 | */
27 | public abstract class ServerInstance {
28 |
29 | /**
30 | * Utility class that holds all game mode listeners and contains util methods to send & ignore server messages.
31 | */
32 | GameListenerRegistry gameListener;
33 |
34 | /**
35 | * Register all your game mode listeners in this method, using {@link #getGameListener()}
36 | * and {@link GameListenerRegistry#registerListener(AbstractGameListener)}
37 | */
38 | public abstract void registerListeners();
39 |
40 | /**
41 | * @return the display name of the server instance.
42 | */
43 | public abstract String getName();
44 |
45 | /**
46 | * @return the config name of the server instance, used for modules and the message property file.
47 | */
48 | public abstract String getConfigName();
49 |
50 | /**
51 | * Called, whenever the client joins a Minecraft server to check, whether the server
52 | * is handled by any registered server instance.
53 | *
54 | * @param host the host of the Minecraft server.
55 | * @param port the port of the Minecraft server.
56 | * @return true, if the server should be handled by this server instance.
57 | */
58 | public abstract boolean handleServer(String host, int port);
59 |
60 | /**
61 | * @return an utility class that holds all registered listeners.
62 | */
63 | public final GameListenerRegistry getGameListener() {
64 | return gameListener;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/util/IKeybinding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.mod.util;
18 |
19 | /**
20 | * Represents a keybinding.
21 | *
22 | * @see eu.the5zig.mod.ModAPI#registerKeyBiding(String, int, String)
23 | */
24 | public interface IKeybinding {
25 |
26 | /**
27 | * @return true, if the keybinding has been pressed.
28 | */
29 | boolean isPressed();
30 |
31 | /**
32 | * @return the key code of the keybinding.
33 | */
34 | int getKeyCode();
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/util/IResourceLocation.java:
--------------------------------------------------------------------------------
1 | package eu.the5zig.mod.util;
2 |
3 | /**
4 | * Represents a Minecraft resource location.
5 | */
6 | public interface IResourceLocation {
7 |
8 | /**
9 | * @return the resource path.
10 | */
11 | String getResourcePath();
12 |
13 | /**
14 | * @return the resource domain (Eg. minecraft).
15 | */
16 | String getResourceDomain();
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/util/NetworkPlayerInfo.java:
--------------------------------------------------------------------------------
1 | package eu.the5zig.mod.util;
2 |
3 | import com.mojang.authlib.GameProfile;
4 |
5 | /**
6 | * A class that represents an entry of the network player list.
7 | */
8 | public interface NetworkPlayerInfo {
9 |
10 | /**
11 | * @return the {@link GameProfile} of this player.
12 | */
13 | GameProfile getGameProfile();
14 |
15 | /**
16 | * @return the display name of this player or {@code null}, if no special display name has been set.
17 | */
18 | String getDisplayName();
19 |
20 | /**
21 | * Sets a new display name for this player. If the unformatted string does not equal {@link GameProfile#getName()} of this player, a yellow star (*) will be added in front of the name.
22 | *
23 | * Setting a display name will also override any scoreboard assigned team color.
24 | *
25 | * @param displayName the new display name for this player.
26 | */
27 | void setDisplayName(String displayName);
28 |
29 | /**
30 | * @return the player response time to server in milliseconds.
31 | */
32 | int getPing();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/util/PlayerGameMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.mod.util;
18 |
19 | import eu.the5zig.mod.ModAPI;
20 |
21 | /**
22 | * Indicates the current GameMode of a player.
23 | *
24 | * @see ModAPI#getGameMode()
25 | */
26 | public enum PlayerGameMode {
27 |
28 | SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/eu/the5zig/mod/util/PluginException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.mod.util;
18 |
19 | /**
20 | * Thrown, if there was any problem when loading a plugin.
21 | */
22 | public class PluginException extends Exception {
23 |
24 | public PluginException() {
25 | super();
26 | }
27 |
28 | public PluginException(String message) {
29 | super(message);
30 | }
31 |
32 | public PluginException(String message, Throwable cause) {
33 | super(message, cause);
34 | }
35 |
36 | public PluginException(Throwable cause) {
37 | super(cause);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/eu/the5zig/util/Callable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.util;
18 |
19 | public interface Callable {
20 |
21 | /**
22 | * Computes a result, or throws an exception if unable to do so.
23 | *
24 | * @return computed result
25 | */
26 | V call();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/eu/the5zig/util/Callback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.util;
18 |
19 | public interface Callback {
20 |
21 | /**
22 | * Override to listen for a call in the future.
23 | *
24 | * @param callback a value.
25 | */
26 | void call(V callback);
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/eu/the5zig/util/minecraft/ChatColor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 5zig
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package eu.the5zig.util.minecraft;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 | import java.util.regex.Pattern;
22 |
23 | public enum ChatColor {
24 |
25 | /**
26 | * Represents black.
27 | */
28 | BLACK('0', "black", 0x000000),
29 | /**
30 | * Represents dark blue.
31 | */
32 | DARK_BLUE('1', "dark_blue", 0x0000AA),
33 | /**
34 | * Represents dark green.
35 | */
36 | DARK_GREEN('2', "dark_green", 0x00AA00),
37 | /**
38 | * Represents dark blue (aqua).
39 | */
40 | DARK_AQUA('3', "dark_aqua", 0x00AAAA),
41 | /**
42 | * Represents dark red.
43 | */
44 | DARK_RED('4', "dark_red", 0xAA0000),
45 | /**
46 | * Represents dark purple.
47 | */
48 | DARK_PURPLE('5', "dark_purple", 0xAA00AA),
49 | /**
50 | * Represents gold.
51 | */
52 | GOLD('6', "gold", 0xFFAA00),
53 | /**
54 | * Represents gray.
55 | */
56 | GRAY('7', "gray", 0xAAAAAA),
57 | /**
58 | * Represents dark gray.
59 | */
60 | DARK_GRAY('8', "dark_gray", 0x555555),
61 | /**
62 | * Represents blue.
63 | */
64 | BLUE('9', "blue", 0x5555FF),
65 | /**
66 | * Represents green.
67 | */
68 | GREEN('a', "green", 0x55FF55),
69 | /**
70 | * Represents aqua.
71 | */
72 | AQUA('b', "aqua", 0x55FFFF),
73 | /**
74 | * Represents red.
75 | */
76 | RED('c', "red", 0xFF5555),
77 | /**
78 | * Represents light purple.
79 | */
80 | LIGHT_PURPLE('d', "light_purple", 0xFF55FF),
81 | /**
82 | * Represents yellow.
83 | */
84 | YELLOW('e', "yellow", 0xFFFF55),
85 | /**
86 | * Represents white.
87 | */
88 | WHITE('f', "white", 0xFFFFFF),
89 | /**
90 | * Represents magical characters that change around randomly.
91 | */
92 | MAGIC('k', "obfuscated"),
93 | /**
94 | * Makes the text bold.
95 | */
96 | BOLD('l', "bold"),
97 | /**
98 | * Makes a line appear through the text.
99 | */
100 | STRIKETHROUGH('m', "strikethrough"),
101 | /**
102 | * Makes the text appear underlined.
103 | */
104 | UNDERLINE('n', "underline"),
105 | /**
106 | * Makes the text italic.
107 | */
108 | ITALIC('o', "italic"),
109 | /**
110 | * Resets all previous chat colors or formats.
111 | */
112 | RESET('r', "reset");
113 | /**
114 | * The special character which prefixes all chat colour codes. Use this if
115 | * you need to dynamically convert colour codes from your custom format.
116 | */
117 | public static final char COLOR_CHAR = '\u00A7';
118 | public static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRr";
119 | /**
120 | * Pattern to remove all colour codes.
121 | */
122 | public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf(COLOR_CHAR) + "[0-9A-FK-OR]");
123 | /**
124 | * Colour instances keyed by their active character.
125 | */
126 | private static final Map BY_CHAR = new HashMap();
127 |
128 | static {
129 | for (ChatColor colour : values()) {
130 | BY_CHAR.put(colour.code, colour);
131 | }
132 | }
133 |
134 | /**
135 | * The code appended to {@link #COLOR_CHAR} to make usable colour.
136 | */
137 | private final char code;
138 | /**
139 | * This colour's colour char prefixed by the {@link #COLOR_CHAR}.
140 | */
141 | private final String toString;
142 | private final String name;
143 |
144 | private final int color;
145 |
146 | ChatColor(char code, String name) {
147 | this(code, name, -1);
148 | }
149 |
150 | ChatColor(char code, String name, int color) {
151 | this.code = code;
152 | this.name = name;
153 | this.color = color;
154 | this.toString = new String(new char[]{COLOR_CHAR, code});
155 | }
156 |
157 | /**
158 | * Strips the given message of all color codes
159 | *
160 | * @param input String to strip of color
161 | * @return A copy of the input string, without any coloring
162 | */
163 | public static String stripColor(final String input) {
164 | if (input == null) {
165 | return null;
166 | }
167 |
168 | return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
169 | }
170 |
171 | public static String translateAlternateColorCodes(char altColorChar, String textToTranslate) {
172 | char[] b = textToTranslate.toCharArray();
173 | for (int i = 0; i < b.length - 1; i++) {
174 | if (b[i] == altColorChar && ALL_CODES.indexOf(b[i + 1]) > -1) {
175 | b[i] = ChatColor.COLOR_CHAR;
176 | b[i + 1] = Character.toLowerCase(b[i + 1]);
177 | }
178 | }
179 | return new String(b);
180 | }
181 |
182 | /**
183 | * Get the colour represented by the specified code.
184 | *
185 | * @param code the code to search for
186 | * @return the mapped colour, or null if non exists
187 | */
188 | public static ChatColor getByChar(char code) {
189 | return BY_CHAR.get(code);
190 | }
191 |
192 | public String getName() {
193 | return name;
194 | }
195 |
196 | public char getCode() {
197 | return code;
198 | }
199 |
200 | public int getColor() {
201 | return color;
202 | }
203 |
204 | @Override
205 | public String toString() {
206 | return toString;
207 | }
208 |
209 | }
210 |
--------------------------------------------------------------------------------