├── LICENSE.txt ├── README.md ├── The 5zig API.iml ├── examples ├── basic1 │ ├── core │ │ └── messages │ │ │ └── localhost.properties │ ├── eu.the5zig.api.test │ │ ├── MainTest.java │ │ ├── TestModuleItem.java │ │ ├── TestServer.java │ │ ├── TestServerGameItem.java │ │ ├── TestServerGameListener.java │ │ ├── TestServerInstance.java │ │ └── TestServerListener.java │ ├── lang │ │ ├── language_de_DE.properties │ │ └── language_en_US.properties │ ├── modules.json │ └── plugin.json └── basic2 │ ├── eu │ └── the5zig │ │ └── api │ │ └── test │ │ ├── ActionBarModuleItem.java │ │ ├── MainPlugin.java │ │ ├── MyActionBarListener.java │ │ ├── MyLobbyListener.java │ │ ├── MyServer.java │ │ └── MyServerInstance.java │ └── plugin.json └── src └── eu └── the5zig ├── mod ├── ModAPI.java ├── The5zigAPI.java ├── config │ └── IConfigItem.java ├── event │ ├── ActionBarEvent.java │ ├── Cancelable.java │ ├── ChatEvent.java │ ├── ChatSendEvent.java │ ├── ChestSetSlotEvent.java │ ├── Event.java │ ├── EventHandler.java │ ├── KeyPressEvent.java │ ├── LoadEvent.java │ ├── PayloadEvent.java │ ├── PlayerListEvent.java │ ├── PlayerTeleportEvent.java │ ├── ServerConnectEvent.java │ ├── ServerJoinEvent.java │ ├── ServerQuitEvent.java │ ├── SignEditEvent.java │ ├── TickEvent.java │ ├── TitleEvent.java │ ├── UnloadEvent.java │ └── WorldTickEvent.java ├── gui │ ├── IOverlay.java │ └── ingame │ │ ├── ArmorSlot.java │ │ ├── ItemStack.java │ │ ├── PotionEffect.java │ │ └── Scoreboard.java ├── modules │ ├── AbstractModuleItem.java │ ├── Category.java │ ├── GameModeItem.java │ ├── LargeTextItem.java │ ├── ModuleItemFormatting.java │ ├── ModuleItemProperties.java │ ├── RenderSettings.java │ └── StringItem.java ├── plugin │ ├── Plugin.java │ └── PluginManager.java ├── render │ ├── Formatting.java │ ├── RenderHelper.java │ └── RenderLocation.java ├── server │ ├── AbstractGameListener.java │ ├── GameListenerRegistry.java │ ├── GameMode.java │ ├── GameState.java │ ├── IMultiPatternResult.java │ ├── IPatternResult.java │ └── ServerInstance.java └── util │ ├── IKeybinding.java │ ├── IResourceLocation.java │ ├── NetworkPlayerInfo.java │ ├── PlayerGameMode.java │ └── PluginException.java └── util ├── Callable.java ├── Callback.java └── minecraft └── ChatColor.java /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Official client API of The 5zig Mod! 2 | = 3 | 4 | This is the official client API of The 5zig Mod, which can be used together with the 5zig Mod v3.6 and above. 5 | Build your own 5zig mod plugin, drop it into .minecraft/the5zigmod/plugins and you're ready to go! Create 6 | own module items or server handlers and listen to various mod events! Feel free to create a plugin, suggest 7 | it as a feature to the mod author and it may be implemented in a future version of the 5zig mod. 8 | 9 | The API gives you the perfect start into modding Minecraft and allows you to customize the 5zig mod even more! 10 | If you have got any further suggestions, feel free to create an issue. 11 | 12 | Getting Started 13 | - 14 | If you want to get started, see the examples directory, as there are multiple documented example plugins of the mod. 15 | 16 | Dependencies 17 | - 18 | Required dependencies are: log4j-api 2.0, log4j-core 2.0, netty-4.0.23, lwjgl-2.9.4 and authlib-1.5.17+. All of them can 19 | be found in the libraries folder of your .minecraft directory. 20 | 21 | -------------------------------------------------------------------------------- /The 5zig API.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /examples/basic1/core/messages/localhost.properties: -------------------------------------------------------------------------------- 1 | # This file contains all messages that should be listened on. 2 | # This is accomplished by using regex patterns. When a pattern matches a server message, the 3 | # onMatch() method of all registered AbstractGameListeners will be called, together with the key 4 | # of the pattern and the match result. You can use round brackets to specify a match group that 5 | # will be accessible in this IPatternResult. 6 | # Some expressions are already pre-defined and will be replaced by the mod: %p will match any valid 7 | # Minecraft player name, %d will match any (positive or negative) integer. 8 | 9 | lobby=You are now on server lobby (.+) 10 | 11 | # Messages of the game mode "dummy" prefixed with "dl." 12 | dl.start=The dummy game has started! 13 | dl.end=The dummy game has ended! 14 | -------------------------------------------------------------------------------- /examples/basic1/eu.the5zig.api.test/MainTest.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.The5zigAPI; 4 | import eu.the5zig.mod.event.ChatSendEvent; 5 | import eu.the5zig.mod.event.EventHandler; 6 | import eu.the5zig.mod.event.LoadEvent; 7 | import eu.the5zig.mod.event.WorldTickEvent; 8 | import eu.the5zig.mod.modules.Category; 9 | import eu.the5zig.mod.plugin.Plugin; 10 | import eu.the5zig.mod.util.IKeybinding; 11 | import eu.the5zig.mod.util.NetworkPlayerInfo; 12 | import eu.the5zig.util.minecraft.ChatColor; 13 | import org.lwjgl.input.Keyboard; 14 | 15 | /** 16 | * The main plugin class, as specified in plugin.json. 17 | */ 18 | @Plugin(name = "Test", version = "1.0") // necessary plugin annotation. 19 | public class MainTest { 20 | 21 | /** 22 | * Reference to a registered keybinding. 23 | */ 24 | private IKeybinding keybinding; 25 | 26 | @EventHandler(priority = EventHandler.Priority.LOW) 27 | public void onLoad(LoadEvent event) { // Called when the mod has been loaded. 28 | // log an info message 29 | The5zigAPI.getLogger().info("Hello World, the 5zig mod " + The5zigAPI.getAPI().getModVersion() + "!"); 30 | 31 | // register a new server instance handler. 32 | The5zigAPI.getAPI().registerServerInstance(this, TestServerInstance.class); 33 | 34 | // register a new module item with the id "TEST" in category "Other". 35 | The5zigAPI.getAPI().registerModuleItem(this, "TEST", TestModuleItem.class, Category.OTHER); 36 | // register a new module item that renders only, when both the TestServerInstance and 37 | // the TestServer.TestServerGameMode are active 38 | The5zigAPI.getAPI().registerModuleItem(this, "TEST_MODE", TestServerGameItem.class, Category.SERVER_GENERAL); 39 | 40 | // register a new keybinding and store the result. 41 | keybinding = The5zigAPI.getAPI().registerKeyBiding("Gamemode 1", Keyboard.KEY_G, "OP"); 42 | } 43 | 44 | 45 | @EventHandler(priority = EventHandler.Priority.HIGH) 46 | public void onWorldTick(WorldTickEvent event) { // called every tick, as long as the client is in a world. 47 | if (keybinding.isPressed()) { // check if the keybinding has been pressed. 48 | // if it has been pressed, change the game mode of the player. 49 | The5zigAPI.getAPI().sendPlayerMessage("/gamemode 1"); 50 | } 51 | 52 | // Let's try something different: showing the current ping of all players behind their name in the player list 53 | for (NetworkPlayerInfo networkPlayerInfo : The5zigAPI.getAPI().getServerPlayers()) { // first of all, iterate through the player list 54 | // Not get the current display name (or player name, if the display name has not been set by the server) and append the players ping 55 | String displayName = networkPlayerInfo.getDisplayName(); 56 | if (displayName == null) { 57 | displayName = networkPlayerInfo.getGameProfile().getName(); 58 | } 59 | if (displayName == null) { 60 | continue; 61 | } 62 | int endIndex = displayName.lastIndexOf(" "); 63 | if (endIndex != -1) { 64 | displayName = displayName.substring(0, endIndex); 65 | } 66 | networkPlayerInfo.setDisplayName(displayName + ChatColor.GREEN + " " + ChatColor.ITALIC + networkPlayerInfo.getPing()); 67 | } 68 | } 69 | 70 | @EventHandler 71 | public void onChatSend(ChatSendEvent event) { // called whenever the player wants to send a chat message to the server. 72 | if (event.getMessage().equals("I hate 5zig")) { 73 | event.setMessage("I love 5zig"); 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /examples/basic1/eu.the5zig.api.test/TestModuleItem.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.The5zigAPI; 4 | import eu.the5zig.mod.modules.AbstractModuleItem; 5 | import eu.the5zig.mod.render.RenderLocation; 6 | 7 | /** 8 | * A very simple module item that simply displays "Test", prefixed with "Hello". 9 | */ 10 | public class TestModuleItem extends AbstractModuleItem { 11 | 12 | @Override 13 | public void registerSettings() { 14 | // register a new setting. 15 | getProperties().addSetting("testSetting", true); 16 | } 17 | 18 | @Override 19 | public void render(int x, int y, RenderLocation renderLocation, boolean dummy) { 20 | // render something to the screen. 21 | The5zigAPI.getAPI().getRenderHelper().drawString(getPrefix() + "TEST", x, y); 22 | } 23 | 24 | @Override 25 | public int getWidth(boolean dummy) { 26 | return The5zigAPI.getAPI().getRenderHelper().getStringWidth(getPrefix() + "TEST"); // the width of this item. 27 | } 28 | 29 | @Override 30 | public int getHeight(boolean dummy) { 31 | return 10; // the height of this item. 32 | } 33 | 34 | @Override 35 | public String getName() { 36 | return "Test-Item"; // the name of this item. 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/basic1/eu.the5zig.api.test/TestServer.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.server.GameMode; 4 | 5 | public class TestServer { 6 | 7 | public static class TestServerGameMode extends GameMode { 8 | 9 | @Override 10 | public String getName() { 11 | return "Dummy-Mode"; 12 | } 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic1/eu.the5zig.api.test/TestServerGameItem.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.api.test; 18 | 19 | import eu.the5zig.mod.modules.GameModeItem; 20 | 21 | /** 22 | * This item will be only rendered, when {@link eu.the5zig.api.test.TestServer.TestServerGameMode} is active. 23 | */ 24 | public class TestServerGameItem extends GameModeItem { 25 | 26 | public TestServerGameItem() { 27 | super(TestServer.TestServerGameMode.class); 28 | } 29 | 30 | @Override 31 | protected Object getValue(boolean dummy) { 32 | return getGameMode().getName(); 33 | } 34 | 35 | @Override 36 | public String getName() { 37 | return "Game Mode"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/basic1/eu.the5zig.api.test/TestServerGameListener.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.server.AbstractGameListener; 4 | import eu.the5zig.mod.server.GameState; 5 | import eu.the5zig.mod.server.IPatternResult; 6 | 7 | public class TestServerGameListener extends AbstractGameListener { 8 | 9 | @Override 10 | public Class getGameMode() { 11 | return TestServer.TestServerGameMode.class; 12 | } 13 | 14 | @Override 15 | public boolean matchLobby(String lobby) { 16 | return lobby.startsWith("dl-"); 17 | } 18 | 19 | @Override 20 | public void onMatch(TestServer.TestServerGameMode gameMode, String key, IPatternResult match) { 21 | if (key.equals("dl.start")) { 22 | gameMode.setState(GameState.GAME); 23 | } 24 | if (key.equals("dl.end")) { 25 | gameMode.setState(GameState.FINISHED); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/basic1/eu.the5zig.api.test/TestServerInstance.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.server.ServerInstance; 4 | 5 | public class TestServerInstance extends ServerInstance { 6 | 7 | @Override 8 | public void registerListeners() { 9 | getGameListener().registerListener(new TestServerListener()); 10 | getGameListener().registerListener(new TestServerGameListener()); 11 | } 12 | 13 | @Override 14 | public String getName() { 15 | return "localhost"; 16 | } 17 | 18 | @Override 19 | public String getConfigName() { 20 | return "localhost"; 21 | } 22 | 23 | @Override 24 | public boolean handleServer(String host, int port) { 25 | return host.equals("localhost"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /examples/basic1/eu.the5zig.api.test/TestServerListener.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.server.AbstractGameListener; 4 | import eu.the5zig.mod.server.GameMode; 5 | import eu.the5zig.mod.server.IPatternResult; 6 | 7 | public class TestServerListener extends AbstractGameListener { 8 | 9 | @Override 10 | public Class getGameMode() { 11 | return null; 12 | } 13 | 14 | @Override 15 | public boolean matchLobby(String lobby) { 16 | return false; 17 | } 18 | 19 | @Override 20 | public void onMatch(GameMode gameMode, String key, IPatternResult match) { 21 | if (key.equals("lobby")) { 22 | getGameListener().switchLobby(match.get(0)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/basic1/lang/language_de_DE.properties: -------------------------------------------------------------------------------- 1 | modules.item.test = Test Item 2 | modules.item.test.desc = Das ist ein Test Item. 3 | modules.item.test.test = Test Einstellung 4 | modules.item.test.test.desc = Das ist eine Test Einstellung. 5 | modules.item.test_mode = Test Spielmodus 6 | modules.item.test_mode.desc = Das ist ein Test Spielmodus Item. 7 | -------------------------------------------------------------------------------- /examples/basic1/lang/language_en_US.properties: -------------------------------------------------------------------------------- 1 | modules.item.test = Test Item 2 | modules.item.test.desc = This is a Test Item. 3 | modules.item.test.test = Test Setting 4 | modules.item.test.test.desc = This is a Test Setting. 5 | modules.item.test_mode = Test Game Mode 6 | modules.item.test_mode.desc = This is a Test Game Mode Item. 7 | -------------------------------------------------------------------------------- /examples/basic1/modules.json: -------------------------------------------------------------------------------- 1 | { 2 | "modules": [ 3 | { 4 | "id": "test", 5 | "name": "Hello World", 6 | "items": [ 7 | { 8 | "type": "TEST" 9 | } 10 | ] 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /examples/basic1/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "eu.the5zig.api.test.MainTest" 3 | } -------------------------------------------------------------------------------- /examples/basic2/eu/the5zig/api/test/ActionBarModuleItem.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.modules.GameModeItem; 4 | 5 | public class ActionBarModuleItem extends GameModeItem { 6 | 7 | public ActionBarModuleItem() { 8 | super(MyServer.Main.class /* Only render when MyServer.Main is active */); 9 | } 10 | 11 | @Override 12 | protected Object getValue(boolean dummy) { 13 | if (dummy) { 14 | return "Example Action Bar Message"; 15 | } else { 16 | return getGameMode().lastActionBarMessage; 17 | } 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return "ActionBar"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/basic2/eu/the5zig/api/test/MainPlugin.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.The5zigAPI; 4 | import eu.the5zig.mod.event.EventHandler; 5 | import eu.the5zig.mod.event.LoadEvent; 6 | import eu.the5zig.mod.modules.Category; 7 | import eu.the5zig.mod.plugin.Plugin; 8 | 9 | /** 10 | * Example plugin for displaying the last received action bar message. 11 | */ 12 | @Plugin(name = "Test", version = "1.0") // necessary plugin annotation. 13 | public class MainPlugin { 14 | 15 | @EventHandler(priority = EventHandler.Priority.LOW) 16 | public void onLoad(LoadEvent event) { // Called when the mod has been loaded. 17 | // log an info message 18 | The5zigAPI.getLogger().info("Hello World, the 5zig mod " + The5zigAPI.getAPI().getModVersion() + "! Loading example plugin!"); 19 | 20 | // register a new server instance handler. 21 | The5zigAPI.getAPI().registerServerInstance(this, MyServerInstance.class); 22 | 23 | // register a new module item with the id "ACTION_BAR" in category "Other". 24 | The5zigAPI.getAPI().registerModuleItem(this, "ACTION_BAR", ActionBarModuleItem.class, Category.OTHER); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /examples/basic2/eu/the5zig/api/test/MyActionBarListener.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.server.AbstractGameListener; 4 | import eu.the5zig.util.minecraft.ChatColor; 5 | 6 | /** 7 | * Handle the action bar event 8 | */ 9 | public class MyActionBarListener extends AbstractGameListener { 10 | 11 | @Override 12 | public Class getGameMode() { 13 | return MyServer.Main.class; 14 | } 15 | 16 | /** 17 | * When should this action listener be active? Return {@code true} to be always active. 18 | * @param lobby the new lobby. The lobby can be switched by calling {@link #gameListener} {@link eu.the5zig.mod.server.GameListenerRegistry#switchLobby(String)} 19 | * @return true, if the action handler should be active for the specified lobby. 20 | */ 21 | @Override 22 | public boolean matchLobby(String lobby) { 23 | return true; 24 | } 25 | 26 | /** 27 | * Called whenever we receive an action bar message. 28 | * 29 | * @param gameMode the current game mode instance. 30 | * @param message the message that has been received. 31 | * @return true to cancel. 32 | */ 33 | @Override 34 | public boolean onActionBar(MyServer.Main gameMode, String message) { 35 | gameMode.lastActionBarMessage = ChatColor.stripColor(message); 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/basic2/eu/the5zig/api/test/MyLobbyListener.java: -------------------------------------------------------------------------------- 1 | public class MyLobbyListener extends AbstractGameListener { 2 | @Override 3 | public Class getGameMode() { 4 | return null; 5 | } 6 | 7 | @Override 8 | public boolean matchLobby(String lobby) { 9 | return false; 10 | } 11 | 12 | @Override 13 | public void onServerJoin() { 14 | getGameListener().switchLobby("Lobby"); 15 | } 16 | } -------------------------------------------------------------------------------- /examples/basic2/eu/the5zig/api/test/MyServer.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.server.GameMode; 4 | 5 | public class MyServer { 6 | 7 | public static class Main extends GameMode { 8 | 9 | public String lastActionBarMessage; 10 | 11 | /** 12 | * @return the name of the gamemode (will be displayed to all mod friends). 13 | */ 14 | @Override 15 | public String getName() { 16 | return "Server"; 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/basic2/eu/the5zig/api/test/MyServerInstance.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.api.test; 2 | 3 | import eu.the5zig.mod.server.ServerInstance; 4 | 5 | /** 6 | * Tell the mod what server we want to handle. 7 | */ 8 | public class MyServerInstance extends ServerInstance { 9 | 10 | @Override 11 | public void registerListeners() { 12 | // Register a listener class 13 | getGameListener().registerListener(new MyLobbyListener()); 14 | getGameListener().registerListener(new MyActionBarListener()); 15 | } 16 | 17 | @Override 18 | public String getName() { 19 | return "localhost"; 20 | } 21 | 22 | @Override 23 | public String getConfigName() { 24 | return "localhost"; 25 | } 26 | 27 | @Override 28 | public boolean handleServer(String host, int port) { 29 | return host.equalsIgnoreCase("localhost"); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /examples/basic2/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "main": "eu.the5zig.api.test.MainPlugin" 3 | } -------------------------------------------------------------------------------- /src/eu/the5zig/mod/ModAPI.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; 18 | 19 | import com.mojang.authlib.GameProfile; 20 | import eu.the5zig.mod.gui.IOverlay; 21 | import eu.the5zig.mod.gui.ingame.ArmorSlot; 22 | import eu.the5zig.mod.gui.ingame.ItemStack; 23 | import eu.the5zig.mod.gui.ingame.PotionEffect; 24 | import eu.the5zig.mod.gui.ingame.Scoreboard; 25 | import eu.the5zig.mod.modules.AbstractModuleItem; 26 | import eu.the5zig.mod.modules.Category; 27 | import eu.the5zig.mod.plugin.PluginManager; 28 | import eu.the5zig.mod.render.Formatting; 29 | import eu.the5zig.mod.render.RenderHelper; 30 | import eu.the5zig.mod.server.ServerInstance; 31 | import eu.the5zig.mod.util.IKeybinding; 32 | import eu.the5zig.mod.util.NetworkPlayerInfo; 33 | import eu.the5zig.mod.util.PlayerGameMode; 34 | import io.netty.buffer.ByteBuf; 35 | 36 | import java.util.List; 37 | 38 | /** 39 | * Main API class. 40 | */ 41 | public interface ModAPI { 42 | 43 | /** 44 | * @return the version of the 5zig mod. 45 | */ 46 | String getModVersion(); 47 | 48 | /** 49 | * @return the version of Minecraft. 50 | */ 51 | String getMinecraftVersion(); 52 | 53 | /** 54 | * Use this method to do important checks when in forge environment. Things like 55 | * reflection *may* not work properly then. 56 | * 57 | * @return true, if we are in a forge environment. 58 | */ 59 | boolean isForgeEnvironment(); 60 | 61 | /** 62 | * @return the plugin manager. 63 | */ 64 | PluginManager getPluginManager(); 65 | 66 | /** 67 | * Registers a new ModuleItem. 68 | * 69 | * @param plugin the plugin instance. 70 | * @param key a unique key of the module item. 71 | * @param moduleItem the class of the module item. 72 | * @param category the category of the module item. 73 | */ 74 | void registerModuleItem(Object plugin, String key, Class moduleItem, Category category); 75 | 76 | /** 77 | * Registers a new ModuleItem. 78 | * 79 | * @param plugin the plugin instance. 80 | * @param key a unique key of the module item. 81 | * @param moduleItem the class of the module item. 82 | * @param category the category of the module item. 83 | */ 84 | void registerModuleItem(Object plugin, String key, Class moduleItem, String category); 85 | 86 | /** 87 | * Checks if the specified module item is currently activate. 88 | * 89 | * @param key the key of the module item. 90 | * @return true, if the module item is currently active 91 | */ 92 | boolean isModuleItemActive(String key); 93 | 94 | /** 95 | * Registers a new server instance listener. 96 | * 97 | * @param plugin the plugin instance. 98 | * @param serverInstance the class of the own server instance. 99 | */ 100 | void registerServerInstance(Object plugin, Class serverInstance); 101 | 102 | /** 103 | * @return the active server instance or null, if no server instance is active. 104 | */ 105 | ServerInstance getActiveServer(); 106 | 107 | /** 108 | * Registers a new keybinding. 109 | * 110 | * @param description the name / description of the keybinding. 111 | * @param keyCode the key code of the keybinding. 112 | * @param category the category of the keybinding. 113 | * @return the registered keybinding. 114 | * @see org.lwjgl.input.Keyboard 115 | * @deprecated method misspelled, use {@link #registerKeyBinding(String, int, String)}. 116 | */ 117 | @Deprecated() 118 | IKeybinding registerKeyBiding(String description, int keyCode, String category); 119 | 120 | /** 121 | * Registers a new keybinding. 122 | * 123 | * @param description the name / description of the keybinding. 124 | * @param keyCode the key code of the keybinding. 125 | * @param category the category of the keybinding. 126 | * @return the registered keybinding. 127 | * @see org.lwjgl.input.Keyboard 128 | * @since 1.0.11 129 | */ 130 | IKeybinding registerKeyBinding(String description, int keyCode, String category); 131 | 132 | /** 133 | * @return a class that contains some utility methods for rendering strings and rectangles. 134 | */ 135 | RenderHelper getRenderHelper(); 136 | 137 | /** 138 | * @return the default formatting of all module items. 139 | */ 140 | Formatting getFormatting(); 141 | 142 | /** 143 | * Creates a new overlay message that will appear in the top right corner, simmilar to achievement messages. 144 | * 145 | * @return a new overlay 146 | */ 147 | IOverlay createOverlay(); 148 | 149 | /** 150 | * Translates a key with current Resource Bundle and formats the String. 151 | * 152 | * @param key The key of the Resource. 153 | * @param format The objects to format the String 154 | * @return The formatted, translated value of the key. 155 | */ 156 | String translate(String key, Object... format); 157 | 158 | /** 159 | * @return true, if the player is currently playing in a world. 160 | */ 161 | boolean isInWorld(); 162 | 163 | /** 164 | * Sends a message from the player to the server. Use {@code /} for commands. 165 | * 166 | * @param message the message that should be sent. 167 | */ 168 | void sendPlayerMessage(String message); 169 | 170 | /** 171 | * Sends a message directly to the client / chat window. 172 | * 173 | * @param message the message that should be sent. 174 | */ 175 | void messagePlayer(String message); 176 | 177 | /** 178 | * Sends a message directly to the second chat of the client. 179 | * 180 | * @param message the message that should be sent. 181 | */ 182 | void messagePlayerInSecondChat(String message); 183 | 184 | /** 185 | * Sends a custom payload to the server. 186 | * 187 | * @param channel the channel the payload should be sent on. 188 | * @param payload the payload itself. 189 | */ 190 | void sendPayload(String channel, ByteBuf payload); 191 | 192 | /** 193 | * @return the width of the window. 194 | */ 195 | int getWindowWidth(); 196 | 197 | /** 198 | * @return the height of the window. 199 | */ 200 | int getWindowHeight(); 201 | 202 | /** 203 | * @return the scaled width of the window. 204 | */ 205 | int getScaledWidth(); 206 | 207 | /** 208 | * @return the scaled height of the window. 209 | */ 210 | int getScaledHeight(); 211 | 212 | /** 213 | * @return the scale factor of the window. 214 | */ 215 | int getScaleFactor(); 216 | 217 | /** 218 | * @return the game profile of the current player. 219 | */ 220 | GameProfile getGameProfile(); 221 | 222 | /** 223 | * @return the ip of the server the player is currently playing on. 224 | */ 225 | String getServer(); 226 | 227 | /** 228 | * @return a list containing all entries of the server player list. 229 | * @since 1.0.3 230 | */ 231 | List getServerPlayers(); 232 | 233 | /** 234 | * @return the x-coordinate of the player or of the entity he is currently spectating. 235 | */ 236 | double getPlayerPosX(); 237 | 238 | /** 239 | * @return the y-coordinate of the player or of the entity he is currently spectating. 240 | */ 241 | double getPlayerPosY(); 242 | 243 | /** 244 | * @return the z-coordinate of the player or of the entity he is currently spectating. 245 | */ 246 | double getPlayerPosZ(); 247 | 248 | /** 249 | * @return the current yaw rotation of the player or the entity he is currently spectating. 250 | */ 251 | float getPlayerRotationYaw(); 252 | 253 | /** 254 | * @return the current pitch rotation of the player or the entity he is currently spectating. 255 | */ 256 | float getPlayerRotationPitch(); 257 | 258 | /** 259 | * @return true, if the player is looking at a block and the block is in range. 260 | */ 261 | boolean hasTargetBlock(); 262 | 263 | /** 264 | * @return the x-coordinate of the target block. 265 | */ 266 | int getTargetBlockX(); 267 | 268 | /** 269 | * @return the y-coordinate of the target block. 270 | */ 271 | int getTargetBlockY(); 272 | 273 | /** 274 | * @return the z-coordinate of the target block. 275 | */ 276 | int getTargetBlockZ(); 277 | 278 | /** 279 | * @return the current game mode of the player. 280 | */ 281 | PlayerGameMode getGameMode(); 282 | 283 | /** 284 | * @return a list with all active potion effects of the player. 285 | */ 286 | List getActivePotionEffects(); 287 | 288 | /** 289 | * @return the ItemStack in the main hand of the player. 290 | */ 291 | ItemStack getItemInMainHand(); 292 | 293 | /** 294 | * @return the ItemStack in the off hand of the player. 295 | */ 296 | ItemStack getItemInOffHand(); 297 | 298 | /** 299 | * Gets the ItemStack in the specified armor slot. 300 | * 301 | * @param slot the armor slot. 302 | * @return the ItemStack in the specified armor slot or null, if there is no item. 303 | */ 304 | ItemStack getItemInArmorSlot(ArmorSlot slot); 305 | 306 | /** 307 | * Gets an ItemStack, specified by its resource name. 308 | * 309 | * @param resourceName the resource name of the ItemStack. 310 | * @return the ItemStack or null, if there is no ItemStack for the specified resource name. 311 | */ 312 | ItemStack getItemByName(String resourceName); 313 | 314 | /** 315 | * Gets an ItemStack, specified by its resource name. 316 | * 317 | * @param resourceName the resource name of the ItemStack. 318 | * @param amount the amount of the ItemStack. 319 | * @return the ItemStack or null, if there is no ItemStack for the specified resource name. 320 | */ 321 | ItemStack getItemByName(String resourceName, int amount); 322 | 323 | /** 324 | * Gets the total amount of items in the players inventory by its resource key. 325 | * 326 | * @param key the resource key of the ItemStack. 327 | * @return the total amount of items. 328 | */ 329 | int getItemCount(String key); 330 | 331 | /** 332 | * @return the title of the opened container or {@code null}, if no container is opened. 333 | */ 334 | String getOpenContainerTitle(); 335 | 336 | /** 337 | * @return the selected hotbar item slot 338 | */ 339 | int getSelectedHotbarSlot(); 340 | 341 | /** 342 | * Sets the current hotbar item slot. 343 | * 344 | * @param slot the index of the slot that should be selected. Must be from 0 to 8. 345 | * @throws IndexOutOfBoundsException if the specified slot parameter is either less than zero or greater than 8. 346 | */ 347 | void setSelectedHotbarSlot(int slot); 348 | 349 | /** 350 | * Simulates a right mouse click / use action of the current item 351 | */ 352 | void rightClickItem(); 353 | 354 | /** 355 | * @return a class, representing a sidebar scoreboard. 356 | */ 357 | Scoreboard getSideScoreboard(); 358 | 359 | /** 360 | * @return true, if the player list is currently visible. 361 | */ 362 | boolean isPlayerListShown(); 363 | 364 | /** 365 | * Joins a Minecraft Server. 366 | * 367 | * @param host the host of the server. 368 | * @param port the port of the server. 369 | */ 370 | void joinServer(String host, int port); 371 | 372 | /** 373 | * Plays a sound to the player. Sounds need to be Minecraft vanilla sounds. 374 | * 375 | * @param sound the resource key of the sound. 376 | * @param pitch the pitch value of the sound. 377 | * @since 1.0.2 378 | */ 379 | void playSound(String sound, float pitch); 380 | 381 | /** 382 | * Plays a sound to the player. Sounds need to be either Minecraft vanilla sounds or loaded via an additional resource pack. 383 | * 384 | * @param domain the resource domain of the sound. 385 | * @param sound the resource key of the sound. 386 | * @param pitch the pitch value of the sound. 387 | * @since 1.0.2 388 | */ 389 | void playSound(String domain, String sound, float pitch); 390 | 391 | } 392 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/The5zigAPI.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; 18 | 19 | import org.apache.logging.log4j.Logger; 20 | 21 | /** 22 | * Main class that holds the API instance. 23 | */ 24 | public class The5zigAPI { 25 | 26 | /** 27 | * Set at runtime by the 5zig mod core. 28 | */ 29 | static ModAPI apiInstance; 30 | 31 | /** 32 | * Set at runtime by the 5zig mod core. 33 | */ 34 | static Logger loggerInstance; 35 | 36 | /** 37 | * @return the API instance. 38 | */ 39 | public static ModAPI getAPI() { 40 | return apiInstance; 41 | } 42 | 43 | /** 44 | * @return a logger. 45 | */ 46 | public static Logger getLogger() { 47 | return loggerInstance; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/config/IConfigItem.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.config; 18 | 19 | /** 20 | * Represents a config entry. 21 | * 22 | * @param the (primitive) type of the entry. 23 | */ 24 | public interface IConfigItem { 25 | 26 | /** 27 | * @return the value of the config entry. 28 | */ 29 | T get(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/ActionBarEvent.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.event; 18 | 19 | /** 20 | * Fired, whenever the client receives an action bar message from the server. 21 | */ 22 | public class ActionBarEvent extends Event implements Cancelable { 23 | 24 | /** 25 | * The message of the server. 26 | */ 27 | private String message; 28 | 29 | /** 30 | * Indicates whether this event has been cancelled. 31 | */ 32 | private boolean cancelled; 33 | 34 | public ActionBarEvent(String message) { 35 | this.message = message; 36 | } 37 | 38 | /** 39 | * @return the action bar message that the client has received from the server. 40 | */ 41 | public String getMessage() { 42 | return message; 43 | } 44 | 45 | @Override 46 | public boolean isCancelled() { 47 | return cancelled; 48 | } 49 | 50 | @Override 51 | public void setCancelled(boolean cancelled) { 52 | this.cancelled = cancelled; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/Cancelable.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.event; 18 | 19 | /** 20 | * Indicates that the event can be cancelled. 21 | */ 22 | public interface Cancelable { 23 | 24 | /** 25 | * @return true, if the event has been cancelled. 26 | */ 27 | boolean isCancelled(); 28 | 29 | /** 30 | * Sets the cancellation status of the event. 31 | * 32 | * @param cancelled true, if the event should be cancelled. 33 | */ 34 | void setCancelled(boolean cancelled); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/ChatEvent.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.event; 18 | 19 | /** 20 | * Called, when the client has received a chat message from the server. 21 | */ 22 | public class ChatEvent extends Event implements Cancelable { 23 | 24 | /** 25 | * The message of the server. 26 | */ 27 | private String originalMessage; 28 | /** 29 | * Can be changed by plugins. 30 | */ 31 | private String message; 32 | /** 33 | * An object that represents a minecraft internal chat component. Used internally to send messages to the second chat. 34 | */ 35 | private Object chatComponent; 36 | 37 | /** 38 | * Indicates whether the event has been cancelled. 39 | */ 40 | private boolean cancelled; 41 | 42 | public ChatEvent(String message, Object chatComponent) { 43 | this.originalMessage = message; 44 | this.chatComponent = chatComponent; 45 | } 46 | 47 | /** 48 | * @return the chat message that has been received. 49 | */ 50 | public String getMessage() { 51 | return originalMessage; 52 | } 53 | 54 | /** 55 | * Changes the chat message. The message will be only changed if {@link #isCancelled()} is {@code false}. 56 | * Note, that {@link #getMessage()} still returns the original message to maintain compatibility. 57 | * 58 | * @param message the new message. 59 | */ 60 | public void setMessage(String message) { 61 | if (message == null || !message.equals(originalMessage)) { 62 | this.message = message; 63 | } 64 | } 65 | 66 | /** 67 | * @return the chat message that has been changed by plugins or {@code null}, if the chat message has not been changed. 68 | */ 69 | public String getAlteredMessage() { 70 | return message; 71 | } 72 | 73 | /** 74 | * @return the minecraft internal chat component. 75 | */ 76 | public Object getChatComponent() { 77 | return chatComponent; 78 | } 79 | 80 | @Override 81 | public boolean isCancelled() { 82 | return cancelled; 83 | } 84 | 85 | @Override 86 | public void setCancelled(boolean cancelled) { 87 | this.cancelled = cancelled; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/ChatSendEvent.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.mod.event; 2 | 3 | /** 4 | * Called before a chat message gets sent from the client to the server. 5 | * 6 | * @since 1.0.3 7 | */ 8 | public class ChatSendEvent extends Event implements Cancelable { 9 | 10 | /** 11 | * The message of the event. 12 | */ 13 | private String message; 14 | /** 15 | * Indicates whether the event has been cancelled. 16 | */ 17 | private boolean cancelled; 18 | 19 | public ChatSendEvent(String message) { 20 | this.message = message; 21 | } 22 | 23 | /** 24 | * @return the chat message that will be sent to the server. 25 | */ 26 | public String getMessage() { 27 | return message; 28 | } 29 | 30 | /** 31 | * Alters the message that should be sent. 32 | * 33 | * @param message the new message that should be sent instead. 34 | * @throws NullPointerException if the message is {@code null}. 35 | */ 36 | public void setMessage(String message) { 37 | if (message == null) { 38 | throw new NullPointerException("Message cannot be null."); 39 | } 40 | this.message = message; 41 | } 42 | 43 | @Override 44 | public boolean isCancelled() { 45 | return cancelled; 46 | } 47 | 48 | @Override 49 | public void setCancelled(boolean cancelled) { 50 | this.cancelled = cancelled; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/ChestSetSlotEvent.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.mod.event; 2 | 3 | import eu.the5zig.mod.gui.ingame.ItemStack; 4 | 5 | /** 6 | * This event is called whenever an item gets set into the slot of a chest. 7 | */ 8 | public class ChestSetSlotEvent extends Event { 9 | 10 | /** 11 | * The title of the chest. 12 | */ 13 | private String containerTitle; 14 | /** 15 | * The slot where the {@link #itemStack} has been set to. 16 | */ 17 | private int slot; 18 | /** 19 | * The {@link ItemStack} that has been set. 20 | */ 21 | private ItemStack itemStack; 22 | 23 | public ChestSetSlotEvent(String containerTitle, int slot, ItemStack itemStack) { 24 | this.containerTitle = containerTitle; 25 | this.slot = slot; 26 | this.itemStack = itemStack; 27 | } 28 | 29 | /** 30 | * @return the title of the chest. 31 | */ 32 | public String getContainerTitle() { 33 | return containerTitle; 34 | } 35 | 36 | /** 37 | * @return the slot, whether the {@link ItemStack} has been set to. 38 | */ 39 | public int getSlot() { 40 | return slot; 41 | } 42 | 43 | /** 44 | * @return the {@link ItemStack} that has been set. 45 | */ 46 | public ItemStack getItemStack() { 47 | return itemStack; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/Event.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.event; 18 | 19 | /** 20 | * Represents an event that can be listened to. Extend to create custom events. 21 | */ 22 | public abstract class Event { 23 | } 24 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/EventHandler.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.event; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Indicates that a method is listening on a specific event. 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.METHOD) 29 | public @interface EventHandler { 30 | 31 | /** 32 | * The priority of the event handler. {@link Priority#HIGHEST} will be executed first, {@link Priority#LOWEST} 33 | * will be executed last. 34 | * 35 | * @return the event priority. 36 | */ 37 | Priority priority() default Priority.NORMAL; 38 | 39 | /** 40 | * @return true, if the event handler should not be called if the event has been cancelled before. 41 | */ 42 | boolean ignoreCancelled() default false; 43 | 44 | enum Priority { 45 | LOWEST, LOW, NORMAL, HIGH, HIGHEST 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/KeyPressEvent.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.event; 18 | 19 | /** 20 | * Fired, whenever the client presses a key while in game. 21 | */ 22 | public class KeyPressEvent extends Event { 23 | 24 | /** 25 | * The {@link org.lwjgl.input.Keyboard} key code of the key that has been pressed. 26 | */ 27 | private int keyCode; 28 | 29 | public KeyPressEvent(int keyCode) { 30 | this.keyCode = keyCode; 31 | } 32 | 33 | /** 34 | * @return the {@link org.lwjgl.input.Keyboard} key code of the key that has been pressed. 35 | */ 36 | public int getKeyCode() { 37 | return keyCode; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/LoadEvent.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.event; 18 | 19 | /** 20 | * Fired, when the mod has been loaded. 21 | */ 22 | public class LoadEvent { 23 | } 24 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/PayloadEvent.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.event; 18 | 19 | import io.netty.buffer.ByteBuf; 20 | 21 | /** 22 | * Called, whenever the client receives a custom payload from the server. 23 | */ 24 | public class PayloadEvent extends Event { 25 | 26 | /** 27 | * The channel the payload has been sent on. 28 | */ 29 | private String channel; 30 | /** 31 | * The payload itself. 32 | */ 33 | private ByteBuf payload; 34 | 35 | public PayloadEvent(String channel, ByteBuf payload) { 36 | this.channel = channel; 37 | this.payload = payload; 38 | } 39 | 40 | /** 41 | * @return the channel the payload has been sent on. 42 | */ 43 | public String getChannel() { 44 | return channel; 45 | } 46 | 47 | /** 48 | * @return the custom payload that has been sent. 49 | */ 50 | public ByteBuf getPayload() { 51 | return payload; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/PlayerListEvent.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.event; 18 | 19 | public class PlayerListEvent extends Event { 20 | 21 | private String header; 22 | private String footer; 23 | 24 | public PlayerListEvent(String header, String footer) { 25 | this.header = header; 26 | this.footer = footer; 27 | } 28 | 29 | public String getHeader() { 30 | return header; 31 | } 32 | 33 | public String getFooter() { 34 | return footer; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/PlayerTeleportEvent.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.mod.event; 2 | 3 | /** 4 | * Fired, when the server teleports the client to a new Location 5 | */ 6 | public class PlayerTeleportEvent extends Event { 7 | 8 | /** 9 | * The absolute x-coordinate of the player. 10 | */ 11 | private double x; 12 | /** 13 | * The absolute y-coordinate of the player. 14 | */ 15 | private double y; 16 | /** 17 | * The absolute z-coordinate of the player. 18 | */ 19 | private double z; 20 | /** 21 | * The yaw-rotation of the player. 22 | */ 23 | private float yaw; 24 | /** 25 | * The pitch-rotation of the player. 26 | */ 27 | private float pitch; 28 | 29 | public PlayerTeleportEvent(double x, double y, double z, float yaw, float pitch) { 30 | this.x = x; 31 | this.y = y; 32 | this.z = z; 33 | this.yaw = yaw; 34 | this.pitch = pitch; 35 | } 36 | 37 | /** 38 | * @return the absolute x-coordinate of the player. 39 | */ 40 | public double getX() { 41 | return x; 42 | } 43 | 44 | /** 45 | * @return the absolute y-coordinate of the player. 46 | */ 47 | public double getY() { 48 | return y; 49 | } 50 | 51 | /** 52 | * @return the absolute z-coordinate of the player. 53 | */ 54 | public double getZ() { 55 | return z; 56 | } 57 | 58 | /** 59 | * @return the yaw-rotation of the player. 60 | */ 61 | public float getYaw() { 62 | return yaw; 63 | } 64 | 65 | /** 66 | * @return the pitch-rotation of the player. 67 | */ 68 | public float getPitch() { 69 | return pitch; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/ServerConnectEvent.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.event; 18 | 19 | /** 20 | * Fired, whenever the client connects to a new Minecraft server. This includes switching servers on a BungeeCord network! 21 | */ 22 | public class ServerConnectEvent extends Event { 23 | } 24 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/ServerJoinEvent.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.event; 18 | 19 | /** 20 | * Fired, whenever the client joins a Minecraft server (network). This does not include switching servers on a BungeeCord network. 21 | */ 22 | public class ServerJoinEvent extends Event { 23 | 24 | /** 25 | * The host of the server. 26 | */ 27 | private String host; 28 | /** 29 | * The port of the port. 30 | */ 31 | private int port; 32 | 33 | public ServerJoinEvent(String host, int port) { 34 | this.host = host; 35 | this.port = port; 36 | } 37 | 38 | /** 39 | * @return the host of the server. 40 | */ 41 | public String getHost() { 42 | return host; 43 | } 44 | 45 | /** 46 | * @return the port of the server. 47 | */ 48 | public int getPort() { 49 | return port; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/ServerQuitEvent.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.event; 18 | 19 | /** 20 | * Fired, whenever the client quits a Minecraft server (network). 21 | */ 22 | public class ServerQuitEvent extends Event { 23 | } 24 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/SignEditEvent.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.mod.event; 2 | 3 | /** 4 | * Called when a player finishes editing a sign. 5 | * 6 | * @since 1.0.9 7 | */ 8 | public class SignEditEvent extends Event { 9 | 10 | /** 11 | * The lines of the sign 12 | */ 13 | private String[] lines; 14 | 15 | public SignEditEvent(String[] lines) { 16 | this.lines = lines; 17 | } 18 | 19 | /** 20 | * Gets the text of a specific line. 21 | * 22 | * @param index the index of the line. 23 | * @return the text of a specific line. 24 | */ 25 | public String getLine(int index) { 26 | return lines[index]; 27 | } 28 | 29 | /** 30 | * Changes the text of a specific line. 31 | * 32 | * @param index the index of the line 33 | * @param text the new text 34 | * @throws NullPointerException if the text is {@code null}. 35 | */ 36 | public void setLine(int index, String text) { 37 | if (text == null) { 38 | throw new NullPointerException("Line cannot be null."); 39 | } 40 | this.lines[index] = text; 41 | } 42 | 43 | /** 44 | * @return an array that contains all lines of the sign. 45 | */ 46 | public String[] getLines() { 47 | return lines; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/TickEvent.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.event; 18 | 19 | /** 20 | * Fired every client tick. 21 | */ 22 | public class TickEvent extends Event { 23 | 24 | /** 25 | * Contains a static instance of the event, as we don't want to create a new instance of an "empty" class every tick. 26 | */ 27 | public static final TickEvent INSTANCE = new TickEvent(); 28 | 29 | private TickEvent() { 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/TitleEvent.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.event; 18 | 19 | /** 20 | * Fired, whenever the client should display a new title. 21 | */ 22 | public class TitleEvent extends Event { 23 | 24 | /** 25 | * The title. 26 | */ 27 | private String title; 28 | /** 29 | * The subtitle. 30 | */ 31 | private String subTitle; 32 | 33 | public TitleEvent(String title, String subTitle) { 34 | this.title = title; 35 | this.subTitle = subTitle; 36 | } 37 | 38 | /** 39 | * @return the title. 40 | */ 41 | public String getTitle() { 42 | return title; 43 | } 44 | 45 | /** 46 | * @return the subtitle. 47 | */ 48 | public String getSubTitle() { 49 | return subTitle; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/UnloadEvent.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.mod.event; 2 | 3 | /** 4 | * Called whenever a plugin gets unloaded. 5 | */ 6 | public class UnloadEvent { 7 | } 8 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/event/WorldTickEvent.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.event; 18 | 19 | /** 20 | * Fired every tick, as long as the client is in a world. 21 | */ 22 | public class WorldTickEvent extends Event { 23 | 24 | /** 25 | * Contains a static instance of the event, as we don't want to create a new instance of an "empty" class every tick. 26 | */ 27 | public static final WorldTickEvent INSTANCE = new WorldTickEvent(); 28 | 29 | private WorldTickEvent() { 30 | } 31 | } -------------------------------------------------------------------------------- /src/eu/the5zig/mod/gui/IOverlay.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.gui; 18 | 19 | /** 20 | * Represents an overlay that can display a notification in the top right corner of the screen. 21 | */ 22 | public interface IOverlay { 23 | 24 | /** 25 | * Displays an overlay. 26 | * 27 | * @param title the title of the overlay (will be rendered in yellow, if no other color specified). 28 | * @param subtitle the subtitle of the overlay. 29 | */ 30 | void displayMessage(String title, String subtitle); 31 | 32 | /** 33 | * Displays an overlay. 34 | * 35 | * @param title the title of the overlay (will be rendered in yellow, if no other color specified). 36 | * @param subtitle the subtitle of the overlay. 37 | * @param uniqueReference a unique reference that allows future modification of the overlay. 38 | * @since 1.0.12, Minecraft 1.12 39 | */ 40 | void displayMessage(String title, String subtitle, Object uniqueReference); 41 | 42 | /** 43 | * Displays an overlay. 44 | * 45 | * @param message the subtitle of the overlay. The title will be {@code "The 5zig Mod"} 46 | */ 47 | void displayMessage(String message); 48 | 49 | /** 50 | * Displays an overlay. 51 | * 52 | * @param message the subtitle of the overlay. The title will be {@code "The 5zig Mod"} 53 | * @param uniqueReference a unique reference that allows future modification of the overlay. 54 | * @since 1.0.12, Minecraft 1.12 55 | */ 56 | void displayMessage(String message, Object uniqueReference); 57 | 58 | /** 59 | * Displays an overlay and splits the message into two lines. 60 | * 61 | * @param message the message that should be displayed. 62 | */ 63 | void displayMessageAndSplit(String message); 64 | 65 | /** 66 | * Displays an overlay and splits the message into two lines. 67 | * 68 | * @param message the message that should be displayed. 69 | * @param uniqueReference a unique reference that allows future modification of the overlay. 70 | * @since 1.0.12, Minecraft 1.12 71 | */ 72 | void displayMessageAndSplit(String message, Object uniqueReference); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/gui/ingame/ArmorSlot.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.gui.ingame; 18 | 19 | /** 20 | * Used to get a specific armor slot from the players inventory. 21 | */ 22 | public enum ArmorSlot { 23 | 24 | BOOTS, LEGGINGS, CHESTPLATE, HELMET 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/gui/ingame/ItemStack.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.gui.ingame; 18 | 19 | import java.util.List; 20 | 21 | public interface ItemStack { 22 | 23 | /** 24 | * @return the amount of items in this stack 25 | */ 26 | int getAmount(); 27 | 28 | /** 29 | * @return the maximum durability of the ItemStack. 30 | */ 31 | int getMaxDurability(); 32 | 33 | /** 34 | * @return the current durability of the ItemStack. 35 | */ 36 | int getCurrentDurability(); 37 | 38 | /** 39 | * @return the resource key of the ItemStack. 40 | */ 41 | String getKey(); 42 | 43 | /** 44 | * @return the display name of the ItemStack. 45 | */ 46 | String getDisplayName(); 47 | 48 | /** 49 | * @return the lore of the ItemStack. 50 | */ 51 | List getLore(); 52 | 53 | /** 54 | * @return the food regeneration amount of this item or {@code 0}, if this item is not a food item. 55 | */ 56 | int getHealAmount(); 57 | 58 | /** 59 | * @return the food saturation of this item or {@code 0}, if this item is not a food item. 60 | */ 61 | float getSaturationModifier(); 62 | 63 | /** 64 | * Renders the ItemStack to the screen at given coordinates. 65 | * 66 | * @param x the x-position of the ItemStack. 67 | * @param y the y-position of the ItemStack. 68 | * @param withGenericAttributes true, of the ItemStack should be rendered with generic attributes, indicated by small numbers. 69 | */ 70 | void render(int x, int y, boolean withGenericAttributes); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/gui/ingame/PotionEffect.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.gui.ingame; 18 | 19 | public interface PotionEffect extends Comparable { 20 | 21 | /** 22 | * @return the name of the potion effect. 23 | */ 24 | String getName(); 25 | 26 | /** 27 | * @return the remaining time of the potion effect in ticks. 28 | */ 29 | int getTime(); 30 | 31 | /** 32 | * @return the formatted time string of the potion effect. 33 | */ 34 | String getTimeString(); 35 | 36 | /** 37 | * @return the amplifier of the potion effect, starting from 0. 38 | */ 39 | int getAmplifier(); 40 | 41 | /** 42 | * @return the icon index of the potion effect or -1, if it has no item. 43 | */ 44 | int getIconIndex(); 45 | 46 | /** 47 | * @return true, if the potion effect is good. 48 | */ 49 | boolean isGood(); 50 | 51 | /** 52 | * @return true, if the potion effect emits particles. 53 | */ 54 | boolean hasParticles(); 55 | 56 | /** 57 | * @return the color of the liquid for this potion. 58 | */ 59 | int getLiquidColor(); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/gui/ingame/Scoreboard.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.gui.ingame; 18 | 19 | import java.util.HashMap; 20 | 21 | /** 22 | * A class that represents a sidebar scoreboard. 23 | */ 24 | public interface Scoreboard { 25 | 26 | /** 27 | * @return the title of the scoreboard. 28 | */ 29 | String getTitle(); 30 | 31 | /** 32 | * @return a map, containing all scores together with their name. 33 | */ 34 | HashMap getLines(); 35 | } 36 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/modules/AbstractModuleItem.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.modules; 18 | 19 | import eu.the5zig.mod.render.RenderHelper; 20 | import eu.the5zig.mod.render.RenderLocation; 21 | 22 | /** 23 | * A module item that can be rendered onto the ingame screen. 24 | */ 25 | public abstract class AbstractModuleItem { 26 | 27 | /** 28 | * Some properties of the module item, like settings and the formatting of it. 29 | */ 30 | ModuleItemProperties properties; 31 | 32 | RenderSettings renderSettings; 33 | 34 | /** 35 | * @return the properties of this module item. 36 | */ 37 | public final ModuleItemProperties getProperties() { 38 | return properties; 39 | } 40 | 41 | /** 42 | * Override this method to register new settings. 43 | */ 44 | public void registerSettings() { 45 | } 46 | 47 | /** 48 | * Called, whenever the module item should be rendered. 49 | * 50 | * @param x the x-position of the item. 51 | * @param y the y-position of the item. 52 | * @param renderLocation the {@link RenderLocation} of the item. 53 | * @param dummy true, if the item should render dummy values. 54 | */ 55 | public abstract void render(int x, int y, RenderLocation renderLocation, boolean dummy); 56 | 57 | /** 58 | * Implement to return the width of the module item. Usually {@link RenderHelper#getStringWidth(String)}. 59 | * 60 | * @param dummy true, if the item should render dummy values. 61 | * @return the width of the module item. 62 | */ 63 | public abstract int getWidth(boolean dummy); 64 | 65 | /** 66 | * Implement to return the height of the module item. Usually {@code 10}. 67 | * 68 | * @param dummy true, if the item should render dummy values. 69 | * @return the height of the module item. 70 | */ 71 | public abstract int getHeight(boolean dummy); 72 | 73 | /** 74 | * Override to specify, when the module item should be rendered. 75 | * 76 | * @param dummy true, if the item should render dummy values. 77 | * @return true, if the item should be rendered. 78 | */ 79 | public boolean shouldRender(boolean dummy) { 80 | return true; 81 | } 82 | 83 | /** 84 | * Override to return a display name. 85 | * 86 | * @return the name of the module item. 87 | * @see #getTranslation() getTranslation(): use this method instead, if you want to return different names for different languages. 88 | */ 89 | public String getName() { 90 | return null; 91 | } 92 | 93 | /** 94 | * @return the translation key of the module item. 95 | */ 96 | public String getTranslation() { 97 | return null; 98 | } 99 | 100 | /** 101 | * Builds a prefix according to the specified text. 102 | * 103 | * @param prefixText the prefix. 104 | * @return a formatted prefix string. 105 | */ 106 | protected final String getPrefix(String prefixText) { 107 | return properties.buildPrefix(prefixText); 108 | } 109 | 110 | /** 111 | * Builds a prefix according to the current display name of the item. 112 | * 113 | * @return a formatted prefix string. 114 | */ 115 | protected final String getPrefix() { 116 | return properties.buildPrefix(); 117 | } 118 | 119 | /** 120 | * Shortens the decimals of a double. 121 | * 122 | * @param d the double that should be shortened. 123 | * @return a shortened string of the double. 124 | */ 125 | protected final String shorten(double d) { 126 | return properties.shorten(d); 127 | } 128 | 129 | /** 130 | * Shortens the decimals of a float. 131 | * 132 | * @param f the float that should be shortened. 133 | * @return a shortened string of the float. 134 | */ 135 | protected final String shorten(float f) { 136 | return properties.shorten(f); 137 | } 138 | 139 | /** 140 | * @return a class that contains various additional settings for the current render pass. The result of this method 141 | * is changed each time before {@link AbstractModuleItem#render(int, int, RenderLocation, boolean)} is called. 142 | */ 143 | protected RenderSettings getRenderSettings() { 144 | return renderSettings; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/modules/Category.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.modules; 18 | 19 | /** 20 | * All categories that a module can have. 21 | */ 22 | public enum Category { 23 | 24 | GENERAL("GENERAL"), EQUIP("EQUIP"), SERVER_GENERAL("SERVER_GENERAL"), SERVER_TIMOLIA("SERVER_TIMOLIA"), SERVER_GOMMEHD("SERVER_GOMMEHD"), SERVER_PLAYMINITY("SERVER_PLAYMINITY"), 25 | SERVER_BERGWERK("SERVER_BERGWERK"), SERVER_HYPIXEL("SERVER_HYPIXEL"), SERVER_VENICRAFT("SERVER_VENICRAFT"), SERVER_CYTOOXIEN("SERVER_CYTOOXIEN"), SERVER_SIMPLEHG("SERVER_SIMPLEHG"), 26 | SYSTEM("SYSTEM"), OTHER("OTHER"); 27 | 28 | private String name; 29 | 30 | Category(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/modules/GameModeItem.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.modules; 18 | 19 | import eu.the5zig.mod.The5zigAPI; 20 | import eu.the5zig.mod.server.GameMode; 21 | import eu.the5zig.mod.server.GameState; 22 | import eu.the5zig.mod.server.ServerInstance; 23 | 24 | /** 25 | * A module item that renders only whenever the client is playing on the specified game mode. 26 | * 27 | * @param the game mode. 28 | */ 29 | public abstract class GameModeItem extends StringItem { 30 | 31 | /** 32 | * The class of the game mode. 33 | */ 34 | private Class modeClass; 35 | /** 36 | * The game states in which the game mode should be rendered or {@code null} if the item should be rendered 37 | * in all game states. 38 | */ 39 | private GameState[] state; 40 | 41 | /** 42 | * Creates a new game mode item. 43 | * 44 | * @param modeClass the class of the game mode. 45 | * @param state the game states when the item should be rendered or none, if the item should be rendered 46 | * in all game states. 47 | */ 48 | public GameModeItem(Class modeClass, GameState... state) { 49 | this.modeClass = modeClass; 50 | this.state = state; 51 | } 52 | 53 | /** 54 | * The item will be only rendered, if the Minecraft client is playing on the specified game mode and either 55 | * no specific game states have been specified or one of the specified game states is active. 56 | * 57 | * @param dummy true, if the item should render dummy values. 58 | * @return true, if the item should be rendered. 59 | */ 60 | @Override 61 | public boolean shouldRender(boolean dummy) { 62 | if (dummy) { 63 | return true; 64 | } 65 | ServerInstance activeServer = The5zigAPI.getAPI().getActiveServer(); 66 | if (activeServer != null && activeServer.getGameListener().getCurrentGameMode() != null 67 | && modeClass.isAssignableFrom(activeServer.getGameListener().getCurrentGameMode().getClass())) { 68 | if (state != null && state.length != 0) { 69 | for (GameState gameState : state) { 70 | if (getGameMode().getState() == gameState) { 71 | return getValue(false) != null; 72 | } 73 | } 74 | return false; 75 | } 76 | return getValue(false) != null; 77 | } 78 | return false; 79 | } 80 | 81 | /** 82 | * @return the active game mode instance. 83 | */ 84 | protected T getGameMode() { 85 | return modeClass.cast(The5zigAPI.getAPI().getActiveServer().getGameListener().getCurrentGameMode()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/modules/LargeTextItem.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.modules; 18 | 19 | import eu.the5zig.mod.The5zigAPI; 20 | import eu.the5zig.mod.render.RenderLocation; 21 | import eu.the5zig.mod.server.GameMode; 22 | import eu.the5zig.mod.server.GameState; 23 | 24 | public abstract class LargeTextItem extends GameModeItem { 25 | 26 | public LargeTextItem(Class modeClass, GameState... state) { 27 | super(modeClass, state); 28 | } 29 | 30 | @Override 31 | public void render(int x, int y, RenderLocation renderLocation, boolean dummy) { 32 | if (dummy) { 33 | return; 34 | } 35 | The5zigAPI.getAPI().getRenderHelper().drawLargeText(The5zigAPI.getAPI().getFormatting().getPrefixFormatting() + getText()); 36 | } 37 | 38 | protected abstract String getText(); 39 | 40 | @Override 41 | protected Object getValue(boolean dummy) { 42 | return getText(); 43 | } 44 | 45 | @Override 46 | public int getWidth(boolean dummy) { 47 | return 0; 48 | } 49 | 50 | @Override 51 | public int getHeight(boolean dummy) { 52 | return 0; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/modules/ModuleItemFormatting.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.modules; 18 | 19 | import eu.the5zig.util.minecraft.ChatColor; 20 | 21 | /** 22 | * Stores the formatting of a module item. 23 | */ 24 | public interface ModuleItemFormatting { 25 | 26 | /** 27 | * @return the formatting of the prefix (either {@link ChatColor#RESET}, {@link ChatColor#BOLD}, 28 | * {@link ChatColor#ITALIC}, {@link ChatColor#UNDERLINE} or {@link ChatColor#STRIKETHROUGH}). 29 | */ 30 | ChatColor getPrefixFormatting(); 31 | 32 | /** 33 | * @return the color of the prefix. 34 | */ 35 | ChatColor getPrefixColor(); 36 | 37 | /** 38 | * @return the main formatting (either {@link ChatColor#RESET}, {@link ChatColor#BOLD}, 39 | * {@link ChatColor#ITALIC}, {@link ChatColor#UNDERLINE} or {@link ChatColor#STRIKETHROUGH}). 40 | */ 41 | ChatColor getMainFormatting(); 42 | 43 | /** 44 | * @return the main color. 45 | */ 46 | ChatColor getMainColor(); 47 | 48 | } -------------------------------------------------------------------------------- /src/eu/the5zig/mod/modules/ModuleItemProperties.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.modules; 18 | 19 | import eu.the5zig.mod.config.IConfigItem; 20 | import eu.the5zig.util.Callable; 21 | 22 | public interface ModuleItemProperties { 23 | 24 | /** 25 | * Adds a setting to the module item. 26 | * 27 | * @param key the identifier of the setting. 28 | * @param defaultValue the default value of the setting. 29 | * @param maxValue the maximum value for the setting. When reaching it, the setting will start at zero again. 30 | * @see #getSetting(String) 31 | */ 32 | void addSetting(String key, int defaultValue, int maxValue); 33 | 34 | /** 35 | * Adds a setting to the module item. 36 | * 37 | * @param key the identifier of the setting. 38 | * @param defaultValue the default value of the setting. 39 | * @param maxValue the maximum value for the setting. When reaching it, the setting will start at zero again. 40 | * @param customValue a {@link Callable} that is used to display a custom value. 41 | * @see #getSetting(String) 42 | */ 43 | void addSetting(String key, int defaultValue, int maxValue, Callable customValue); 44 | 45 | /** 46 | * Adds a setting to the module item. 47 | * 48 | * @param key the identifier of the setting. 49 | * @param defaultValue the default value of the setting. 50 | * @param maxValue the maximum value for the setting. When reaching it, the setting will start at zero again. 51 | * @see #getSetting(String) 52 | */ 53 | void addSetting(String key, float defaultValue, float maxValue); 54 | 55 | /** 56 | * Adds a setting to the module item. Will be displayed as slider. 57 | * 58 | * @param key the identifier of the setting. 59 | * @param suffix the suffix of the setting. 60 | * @param defaultValue the default value of the setting. 61 | * @param minValue the minimum value of the setting. 62 | * @param maxValue the maximum value of the setting. 63 | * @param steps the amount of steps or {@code -1} if the value should not be clamped. 64 | * @see #getSetting(String) 65 | */ 66 | void addSetting(String key, String suffix, float defaultValue, float minValue, float maxValue, int steps); 67 | 68 | /** 69 | * Adds a setting to the module item. 70 | * 71 | * @param key the identifier of the setting. 72 | * @param defaultValue the default value of the setting. 73 | * @see #getSetting(String) 74 | */ 75 | void addSetting(String key, boolean defaultValue); 76 | 77 | /** 78 | * Adds a setting to the module item. 79 | * 80 | * @param key the identifier of the setting. 81 | * @param defaultValue the default value of the setting. 82 | * @param enumClass the class of the Enum. 83 | * @see #getSetting(String) 84 | */ 85 | void addSetting(String key, E defaultValue, Class enumClass); 86 | 87 | IConfigItem getSetting(String key); 88 | 89 | /** 90 | * @return the formatting of the module item or {@code null}, if the default mod formatting 91 | * should be used. 92 | * @see #setFormatting(ModuleItemFormatting) 93 | */ 94 | ModuleItemFormatting getFormatting(); 95 | 96 | /** 97 | * Sets the formatting of the module item. 98 | * 99 | * @param formatting the formatting or {@code null}, if the default mod formatting should 100 | * be used. 101 | * @see #getFormatting() 102 | */ 103 | void setFormatting(ModuleItemFormatting formatting); 104 | 105 | /** 106 | * @return true, if the prefix of the module item is currently visible. 107 | * @see #setShowPrefix(boolean) 108 | */ 109 | boolean isShowPrefix(); 110 | 111 | /** 112 | * Sets the visibility of the prefix. 113 | * 114 | * @param showPrefix true, if the prefix of the module item should be shown. 115 | * @see #isShowPrefix() 116 | */ 117 | void setShowPrefix(boolean showPrefix); 118 | 119 | /** 120 | * @return the display name of the module name. Either {@link AbstractModuleItem#getName()} 121 | * or {@link AbstractModuleItem#getTranslation()}, depending whether the method returns {@code null} 122 | * or not. 123 | */ 124 | String getDisplayName(); 125 | 126 | /** 127 | * Builds a prefix according to the specified prefix. The formatting that will be used is 128 | * either {@link #getFormatting()} or the default mod formatting. 129 | * 130 | * @param prefixText the prefix. 131 | * @return a formatted prefix string. 132 | * @see #buildPrefix() 133 | */ 134 | String buildPrefix(String prefixText); 135 | 136 | /** 137 | * Builds a prefix according to the current display name. The formatting that will be used is 138 | * either {@link #getFormatting()} or the default mod formatting. 139 | * 140 | * @return a formatted prefix string. 141 | * @see #buildPrefix(String) 142 | */ 143 | String buildPrefix(); 144 | 145 | /** 146 | * Shortens the decimals of a double. 147 | * 148 | * @param d the double that should be shortened. 149 | * @return a shortened string of the double. 150 | */ 151 | String shorten(double d); 152 | 153 | /** 154 | * Shortens the decimals of a float. 155 | * 156 | * @param f the float that should be shortened. 157 | * @return a shortened string of the float. 158 | */ 159 | String shorten(float f); 160 | 161 | } 162 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/modules/RenderSettings.java: -------------------------------------------------------------------------------- 1 | package eu.the5zig.mod.modules; 2 | 3 | public interface RenderSettings { 4 | 5 | /** 6 | * @return the scale factor of the calling module. 7 | */ 8 | float getScale(); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/modules/StringItem.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.modules; 18 | 19 | import eu.the5zig.mod.The5zigAPI; 20 | import eu.the5zig.mod.render.RenderLocation; 21 | 22 | /** 23 | * A module item that renders a simple text to the screen. Simply extend this class and 24 | * override {@link #getValue(boolean)}. 25 | */ 26 | public abstract class StringItem extends AbstractModuleItem { 27 | 28 | /** 29 | * Renders a simple text as item onto the screen. The text needs to be returned from an extending class. 30 | * 31 | * @param x the x-position of the item. 32 | * @param y the y-position of the item. 33 | * @param renderLocation the {@link RenderLocation} of the item. 34 | * @param dummy true, if the item should render dummy values. 35 | */ 36 | @Override 37 | public void render(int x, int y, RenderLocation renderLocation, boolean dummy) { 38 | String text = getText(dummy); 39 | 40 | The5zigAPI.getAPI().getRenderHelper().drawString(text, x, y); 41 | } 42 | 43 | /** 44 | * Only renders the item when {@link #getValue(boolean)} is not {@code null}. 45 | * 46 | * @param dummy true, if the item should render dummy values. 47 | * @return true, if the item should be rendered. 48 | */ 49 | @Override 50 | public boolean shouldRender(boolean dummy) { 51 | return getValue(dummy) != null; 52 | } 53 | 54 | /** 55 | * The actual text that will be rendered. 56 | * 57 | * @param dummy true, if the item should render dummy values. 58 | * @return the actual text that will be rendered. 59 | */ 60 | private String getText(boolean dummy) { 61 | return getPrefix() + String.valueOf(getValue(dummy)); 62 | } 63 | 64 | /** 65 | * The width of the text. 66 | * 67 | * @param dummy true, if the item should render dummy values. 68 | * @return the width of the module item. 69 | */ 70 | @Override 71 | public int getWidth(boolean dummy) { 72 | return The5zigAPI.getAPI().getRenderHelper().getStringWidth(getText(dummy)); 73 | } 74 | 75 | /** 76 | * The height of the text. 77 | * 78 | * @param dummy true, if the item should render dummy values. 79 | * @return the height of the module item. 80 | */ 81 | @Override 82 | public int getHeight(boolean dummy) { 83 | return 10; 84 | } 85 | 86 | /** 87 | * Needs to be implemented to return a custom value. 88 | * 89 | * @param dummy true, if the method should return dummy values. 90 | * @return a value that should be rendered or {@code null} if the item should not be rendered to the screen. 91 | */ 92 | protected abstract Object getValue(boolean dummy); 93 | } 94 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/plugin/Plugin.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.plugin; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Needs to be used in the main class of a plugin. 26 | */ 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Target(ElementType.TYPE) 29 | public @interface Plugin { 30 | 31 | /** 32 | * @return the name of the module. 33 | */ 34 | String name(); 35 | 36 | /** 37 | * @return the version of the module. 38 | */ 39 | String version(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/plugin/PluginManager.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.plugin; 18 | 19 | import eu.the5zig.mod.event.Event; 20 | 21 | public interface PluginManager { 22 | 23 | /** 24 | * Registers a class as a listener. This method scans through all methods of the specified class and registers all methods 25 | * that are annotated by the {@link eu.the5zig.mod.event.EventHandler} annotation. 26 | * 27 | * @param plugin the plugin instance. 28 | * @param listener an instance of the listener class that should be registered. 29 | */ 30 | void registerListener(Object plugin, Object listener); 31 | 32 | /** 33 | * Unregisters a listener class instance. 34 | * 35 | * @param plugin the plugin instance. 36 | * @param listener the listener class instance that should be unregistered. 37 | */ 38 | void unregisterListener(Object plugin, Object listener); 39 | 40 | /** 41 | * Unregisters all listeners of a plugin. 42 | * 43 | * @param plugin the plugin instance. 44 | */ 45 | void unregisterListener(Object plugin); 46 | 47 | /** 48 | * Fires an event and calls all methods that are listening on it. 49 | * 50 | * @param event the event that should be fired. 51 | * @return the fired event (for convenience). 52 | */ 53 | T fireEvent(T event); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/render/Formatting.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.render; 18 | 19 | public interface Formatting { 20 | 21 | /** 22 | * @return the default formatting of the prefixes of all module items. 23 | */ 24 | String getPrefixFormatting(); 25 | 26 | /** 27 | * @return the default formatting of all module items. 28 | */ 29 | String getMainFormatting(); 30 | 31 | /** 32 | * @return the default formatting of the brackets of all module items. 33 | */ 34 | String getBracketFormatting(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/render/RenderHelper.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.render; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * A class that contains various render utility methods. 23 | */ 24 | public interface RenderHelper { 25 | 26 | /** 27 | * Draws a String at given position with shadow. 28 | * 29 | * @param string The String 30 | * @param x The x Coordinate 31 | * @param y The y Coordinate 32 | * @param format Arguments referenced by the format specifiers in the format string 33 | */ 34 | void drawString(String string, int x, int y, Object... format); 35 | 36 | /** 37 | * Draws a String at given position with shadow. 38 | * 39 | * @param string The String 40 | * @param x The x Coordinate 41 | * @param y The y Coordinate 42 | */ 43 | void drawString(String string, int x, int y); 44 | 45 | /** 46 | * Draws a centered String at given position with shadow. 47 | * 48 | * @param string The String 49 | * @param x The x Coordinate/the middle of the rendered text. 50 | * @param y The y Coordinate 51 | */ 52 | void drawCenteredString(String string, int x, int y); 53 | 54 | /** 55 | * Draws a centered String at given position. 56 | * 57 | * @param string The String 58 | * @param x The x Coordinate/the middle of the rendered text. 59 | * @param y The y Coordinate 60 | * @param color The hex-color the rendered text should have. 61 | */ 62 | void drawCenteredString(String string, int x, int y, int color); 63 | 64 | /** 65 | * Draws a String at given position with color and shadow. 66 | * 67 | * @param string The String 68 | * @param x The y Coordinate 69 | * @param y The x Coordinate 70 | * @param color The color of the String 71 | * @param format Arguments referenced by the format specifiers in the format string 72 | */ 73 | void drawString(String string, int x, int y, int color, Object... format); 74 | 75 | /** 76 | * Draws a String at given position with color and shadow. 77 | * 78 | * @param string The String 79 | * @param x The y Coordinate 80 | * @param y The x Coordinate 81 | * @param color The color of the String 82 | */ 83 | void drawString(String string, int x, int y, int color); 84 | 85 | /** 86 | * Draws a String at given position with color. 87 | * 88 | * @param string The String 89 | * @param x The y Coordinate 90 | * @param y The x Coordinate 91 | * @param color The color of the String 92 | * @param withShadow True, if the String should have a shadow. 93 | */ 94 | void drawString(String string, int x, int y, int color, boolean withShadow); 95 | 96 | /** 97 | * Splits the input string into parts that are not longer than the specified max width. 98 | * 99 | * @param string The string that should be split. 100 | * @param maxWidth The maximum width the split parts should be long. 101 | * @return a list containing all split parts of the String. 102 | */ 103 | List splitStringToWidth(String string, int maxWidth); 104 | 105 | /** 106 | * @param string The String whose width should be calculated. 107 | * @return the width of the String. 108 | */ 109 | int getStringWidth(String string); 110 | 111 | /** 112 | * Shortens a String to a specified width. 113 | * 114 | * @param string The String that should be shortened. 115 | * @param width The maximum width the String should have. 116 | * @return a String that is not longer than the specified width. 117 | */ 118 | String shortenToWidth(String string, int width); 119 | 120 | /** 121 | * Draws a rectangle at given position. 122 | * 123 | * @param left the left x-coordinate of the rectangle. 124 | * @param top the top y-coordinate of the rectangle. 125 | * @param right the right x-coordinate of the rectangle. 126 | * @param bottom the bottom y-coordinate of the rectangle. 127 | * @param color the color of the rectangle, as hexadecimal argb-value. 128 | * Eg. red: {@code 0xFFFF0000}, blue: {@code 0xFF0000FF}, 50% opaque green: {@code 0x8800FF00}. 129 | */ 130 | void drawRect(double left, double top, double right, double bottom, int color); 131 | 132 | /** 133 | * Draws a rectangle with a gradient at given position. 134 | * 135 | * @param left the left x-coordinate of the rectangle. 136 | * @param top the top y-coordinate of the rectangle. 137 | * @param right the right x-coordinate of the rectangle. 138 | * @param bottom the bottom y-coordinate of the rectangle. 139 | * @param startColor the start color of the rectangle, as hexadecimal argb-value. 140 | * Eg. red: {@code 0xFFFF0000}, blue: {@code 0xFF0000FF}, 50% opaque green: {@code 0x8800FF00}. 141 | * @param endColor the end color of the rectangle, as hexadecimal argb-value. 142 | * Eg. red: {@code 0xFFFF0000}, blue: {@code 0xFF0000FF}, 50% opaque green: {@code 0x8800FF00}. 143 | * @param verticalGradient true, if the gradient should be on the vertical axis, false, if the gradient 144 | * should be on the vertical axis. 145 | */ 146 | void drawGradientRect(double left, double top, double right, double bottom, int startColor, int endColor, boolean verticalGradient); 147 | 148 | /** 149 | * Draws the outline of a rectangle at given position. 150 | * 151 | * @param left the left x-coordinate of the rectangle. 152 | * @param top the top y-coordinate of the rectangle. 153 | * @param right the right x-coordinate of the rectangle. 154 | * @param bottom the bottom y-coordinate of the rectangle. 155 | * @param color the color of the rectangle, as hexadecimal argb-value. 156 | * Eg. red: {@code 0xFFFF0000}, blue: {@code 0xFF0000FF}, 50% opaque green: {@code 0x8800FF00}. 157 | */ 158 | void drawRectOutline(int left, int top, int right, int bottom, int color); 159 | 160 | /** 161 | * Draws the inline of a rectangle at given position. 162 | * 163 | * @param left the left x-coordinate of the rectangle. 164 | * @param top the top y-coordinate of the rectangle. 165 | * @param right the right x-coordinate of the rectangle. 166 | * @param bottom the bottom y-coordinate of the rectangle. 167 | * @param color the color of the rectangle, as hexadecimal argb-value. 168 | * Eg. red: {@code 0xFFFF0000}, blue: {@code 0xFF0000FF}, 50% opaque green: {@code 0x8800FF00}. 169 | */ 170 | void drawRectInline(int left, int top, int right, int bottom, int color); 171 | 172 | /** 173 | * Draws a centered, scaled string at given position. 174 | * 175 | * @param string the string that should be rendered. 176 | * @param x the center of the horizontal axis of the string. 177 | * @param y the y-position of the string. 178 | * @param scale the scale of the string. 179 | */ 180 | void drawScaledCenteredString(String string, int x, int y, float scale); 181 | 182 | /** 183 | * Draws a scaled string at given position. 184 | * 185 | * @param string the string that should be rendered. 186 | * @param x the x-position of the string. 187 | * @param y the y-position of the string. 188 | * @param scale the scale of the string. 189 | */ 190 | void drawScaledString(String string, int x, int y, float scale); 191 | 192 | /** 193 | * Draws a large text to the center of the screen. Only one large text will be rendered at once. 194 | * 195 | * @param string the string that should be drawn. 196 | */ 197 | void drawLargeText(String string); 198 | 199 | } 200 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/render/RenderLocation.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.render; 18 | 19 | /** 20 | * Indicates the location, where a module item is bound to. 21 | */ 22 | public enum RenderLocation { 23 | 24 | LEFT, RIGHT, CENTERED 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/server/AbstractGameListener.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 | import eu.the5zig.mod.gui.ingame.ItemStack; 20 | import io.netty.buffer.ByteBuf; 21 | 22 | /** 23 | * Extend to handle a specific game mode of a server. 24 | * 25 | * @param the game mode this listener is listining on. 26 | */ 27 | public abstract class AbstractGameListener { 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 | * @return the class of the game mode this listener is listening on or {@code null}, if this listener 36 | * should listen on all game modes. 37 | */ 38 | public abstract Class getGameMode(); 39 | 40 | /** 41 | * Called whenever the Minecraft client changes a server lobby. 42 | * 43 | * @param lobby the new lobby. 44 | * @return true, if the listener listens on this server lobby. 45 | */ 46 | public abstract boolean matchLobby(String lobby); 47 | 48 | /** 49 | * Called, whenever a message from the supplied message property file matched a server chat message. 50 | * 51 | * @param gameMode the current game mode instance. 52 | * @param key the message key. 53 | * @param match the match result. 54 | */ 55 | public void onMatch(T gameMode, String key, IPatternResult match) { 56 | } 57 | 58 | /** 59 | * Called, whenever the Minecraft client joins the server of this server instance. 60 | */ 61 | public void onServerJoin() { 62 | } 63 | 64 | /** 65 | * Called, whenever the Minecraft client joins this game mode. 66 | * 67 | * @param gameMode the current game mode instance. 68 | */ 69 | public void onGameModeJoin(T gameMode) { 70 | } 71 | 72 | /** 73 | * Called every tick, as long as the client plays on this game mode. 74 | * 75 | * @param gameMode the current game mode instance. 76 | */ 77 | public void onTick(T gameMode) { 78 | } 79 | 80 | /** 81 | * Called, whenever a key has been pressed, while the client is playing on this game mode. 82 | * 83 | * @param gameMode the current game mode instance. 84 | * @param code the {@link org.lwjgl.input.Keyboard} key code. 85 | */ 86 | public void onKeyPress(T gameMode, int code) { 87 | } 88 | 89 | /** 90 | * Called, when the client joins a new server while playing a game mode. 91 | * 92 | * @param gameMode the current game mode instance. 93 | */ 94 | public void onServerConnect(T gameMode) { 95 | } 96 | 97 | /** 98 | * Called, when the client leaves a server while playing a game mode. 99 | * 100 | * @param gameMode the current game mode instance. 101 | */ 102 | public void onServerDisconnect(T gameMode) { 103 | } 104 | 105 | /** 106 | * Called, when the client receives a custom payload from the server while playing a game mode. 107 | * 108 | * @param gameMode the current game mode instance. 109 | * @param channel the channel, the payload has been sent on. 110 | * @param packetData the payload data. 111 | */ 112 | public void onPayloadReceive(T gameMode, String channel, ByteBuf packetData) { 113 | } 114 | 115 | /** 116 | * Called, whenever the client receives a chat message from the server while playing this game mode. 117 | * 118 | * @param gameMode the current game mode instance. 119 | * @param message the message that has been received. 120 | * @return true, if the message should be ignored by the Minecraft client. 121 | */ 122 | public boolean onServerChat(T gameMode, String message) { 123 | return false; 124 | } 125 | 126 | /** 127 | * Called, whenever the client receives an action bar message from the server while playing this game mode. 128 | * 129 | * @param gameMode the current game mode instance. 130 | * @param message the message that has been received. 131 | * @return true, if the message should be ignored by the Minecraft client. 132 | */ 133 | public boolean onActionBar(T gameMode, String message) { 134 | return false; 135 | } 136 | 137 | /** 138 | * Called, whenever the player list header and/or footer have been updated while playing on this game mode. 139 | * 140 | * @param gameMode the current game mode instance. 141 | * @param header the header of the player list. 142 | * @param footer the footer of the player list. 143 | */ 144 | public void onPlayerListHeaderFooter(T gameMode, String header, String footer) { 145 | } 146 | 147 | /** 148 | * Called, whenever the client receives a title from the server while playing on this game mode. 149 | * 150 | * @param gameMode the current game mode instance. 151 | * @param title the title. 152 | * @param subTitle the subtitle. 153 | */ 154 | public void onTitle(T gameMode, String title, String subTitle) { 155 | } 156 | 157 | /** 158 | * Called, whenever the server teleports the client to a new location. 159 | * 160 | * @param gameMode the current game mode instance. 161 | * @param x the absolute x-coordinate of the player. 162 | * @param y the absolute y-coordinate of the player. 163 | * @param z the absolute z-coordinate of the player. 164 | * @param yaw the yaw-rotation of the player. 165 | * @param pitch the pitch-rotation of the player. 166 | */ 167 | public void onTeleport(T gameMode, double x, double y, double z, float yaw, float pitch) { 168 | } 169 | 170 | /** 171 | * Called, whenever an {@link ItemStack} gets set into a chest slot. 172 | * 173 | * @param gameMode the current game mode instance. 174 | * @param containerTitle the title of the chest. 175 | * @param slot the slot. 176 | * @param itemStack the item stack. 177 | */ 178 | public void onChestSetSlot(T gameMode, String containerTitle, int slot, ItemStack itemStack) { 179 | } 180 | 181 | /** 182 | * @return an utility class that holds all registered listeners. 183 | */ 184 | public final GameListenerRegistry getGameListener() { 185 | return gameListener; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/eu/the5zig/mod/server/GameListenerRegistry.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 | import eu.the5zig.util.Callback; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | * Utility class that holds all game mode listeners and contains util methods to send & ignore server messages. 25 | */ 26 | public interface GameListenerRegistry { 27 | 28 | /** 29 | * Registers a listener that listens on a game mode. 30 | * 31 | * @param listener the listener that should be registered. 32 | */ 33 | void registerListener(AbstractGameListener listener); 34 | 35 | /** 36 | * Switches the lobby of a server and tries to match a new game mode by iterating through all listeners 37 | * and calling {@link AbstractGameListener#matchLobby(String)}. 38 | * 39 | * @param newLobby the new lobby. 40 | */ 41 | void switchLobby(String newLobby); 42 | 43 | /** 44 | * @return the current lobby name or {@code null}, if there is no current lobby name. 45 | */ 46 | String getCurrentLobby(); 47 | 48 | /** 49 | * @return the current nick name of the player or {@code null}, if the player is not nicked. 50 | */ 51 | String getCurrentNick(); 52 | 53 | /** 54 | * Sets a new nick name for the player. 55 | * 56 | * @param nickname the new nick name or {@code null}, if the player is not nicked. 57 | */ 58 | void setCurrentNick(String nickname); 59 | 60 | /** 61 | * Sends a message from the player and ignores the result of it. 62 | * 63 | * @param message the message that should be sent. 64 | * @param key the message key that should be ignored, specified in the messages property file. 65 | */ 66 | void sendAndIgnore(String message, String key); 67 | 68 | /** 69 | * Sends a message from the player and ignores multiple results of it. 70 | * 71 | * @param message the message that should be sent. 72 | * @param start the first message that should be ignored, key specified in the messages property file. 73 | * @param end the last message that should be ignored, key specified in the messages property file. 74 | * @param callback a callback that will be called, after the last message has been ignored. This callback will 75 | * contain all ignored messages. 76 | */ 77 | void sendAndIgnoreMultiple(String message, String start, String end, Callback callback); 78 | 79 | /** 80 | * Sends a message from the player and ignores multiple results of it. 81 | * 82 | * @param message the message that should be sent. 83 | * @param startKey the first message that should be ignored, key specified in the messages property file. 84 | * @param numberOfMessages the number of messages that should be ignored. 85 | * @param abortKey a message that will cancel ignoring further messages. 86 | * @param callback a callback that will be called, after {@code numberOfMessages} messages have been ignored or 87 | * the abort message has been received. This callback will contain all ignored messages. 88 | */ 89 | void sendAndIgnoreMultiple(String message, String startKey, int numberOfMessages, String abortKey, Callback callback); 90 | 91 | /** 92 | * @return the current game mode or {@code null}, if the client does not play on this server instance. 93 | */ 94 | GameMode getCurrentGameMode(); 95 | 96 | /** 97 | * @return a set containing all friends. You can add friends to that list in order to update the online friends module item. 98 | */ 99 | Set getOnlineFriends(); 100 | 101 | /** 102 | * @return a set containing all party members. 103 | */ 104 | Set 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 | --------------------------------------------------------------------------------