├── icon.png ├── src ├── test │ ├── resources │ │ ├── plugin.yml │ │ └── i18n │ │ │ ├── en_GB.no-meta.properties │ │ │ ├── fr_FR.yml │ │ │ ├── fr_FR.properties │ │ │ ├── en_US.po │ │ │ └── fr_FR.po │ └── java │ │ └── fr │ │ └── zcraft │ │ └── quartzlib │ │ ├── MockedToasterTest.java │ │ ├── MockedBukkitTest.java │ │ ├── Toaster.java │ │ ├── tools │ │ ├── reflection │ │ │ └── ReflectionTest.java │ │ └── mojang │ │ │ └── MojangHeadTest.java │ │ ├── TestsUtils.java │ │ └── components │ │ └── rawtext │ │ └── ChatColorParserTest.java └── main │ └── java │ └── fr │ └── zcraft │ └── quartzlib │ ├── components │ ├── commands │ │ ├── CommandWorkers.java │ │ ├── CommandInfo.java │ │ ├── WithFlags.java │ │ └── CommandException.java │ ├── worker │ │ ├── WorkerCallback.java │ │ ├── WorkerRunnable.java │ │ ├── WorkerAttributes.java │ │ └── WorkerCallbackManager.java │ ├── scoreboard │ │ ├── SidebarMode.java │ │ ├── SidebarScoreboard.java │ │ └── OnlinePlayersListener.java │ ├── rawtext │ │ └── RawTextSubPart.java │ ├── nbt │ │ └── NBTException.java │ ├── i18n │ │ ├── UnsupportedLocaleException.java │ │ └── translators │ │ │ ├── Translation.java │ │ │ ├── gettext │ │ │ └── GettextPOTranslator.java │ │ │ └── properties │ │ │ └── ZLibResourceBundleControl.java │ ├── configuration │ │ ├── ValueHandler.java │ │ ├── ConfigurationParseException.java │ │ ├── ConfigurationValueHandler.java │ │ ├── Configuration.java │ │ ├── ConfigurationMap.java │ │ ├── ConfigurationSection.java │ │ └── ConfigurationList.java │ ├── gui │ │ ├── GuiAction.java │ │ └── ArrayPromptGui.java │ ├── events │ │ ├── FutureEventHandler.java │ │ └── WrappedEvent.java │ └── attributes │ │ └── AttributeOperation.java │ ├── tools │ ├── Callback.java │ ├── reflection │ │ └── NMSException.java │ ├── items │ │ └── ColorableMaterial.java │ ├── text │ │ ├── ChatColoredString.java │ │ └── ChatColorParser.java │ ├── world │ │ └── WorldUtils.java │ ├── FileUtils.java │ ├── mojang │ │ └── MojangHead.java │ ├── runners │ │ └── RunTask.java │ └── PluginLogger.java │ ├── exceptions │ └── IncompatibleMinecraftVersionException.java │ ├── core │ ├── QuartzComponent.java │ └── QuartzPlugin.java │ └── external │ └── ExternalPluginComponent.java ├── ztoaster ├── src │ ├── main │ │ ├── resources │ │ │ ├── plugin.yml │ │ │ └── i18n │ │ │ │ ├── en_US.po │ │ │ │ └── fr_FR.po │ │ └── java │ │ │ └── fr │ │ │ └── zcraft │ │ │ └── ztoaster │ │ │ ├── commands │ │ │ ├── OpenCommand.java │ │ │ ├── AddCommand.java │ │ │ └── ListCommand.java │ │ │ ├── Toast.java │ │ │ ├── ToastExplorer.java │ │ │ ├── ToasterSidebar.java │ │ │ ├── ToasterWorker.java │ │ │ └── Toaster.java │ └── test │ │ └── java │ │ └── fr │ │ └── zcraft │ │ └── ztoaster │ │ ├── core │ │ └── QuartzLibTest.java │ │ └── MockedToasterTest.java └── pom.xml ├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ ├── docs.yml │ └── release.yml ├── .gitignore ├── pom.xml └── README.md /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zDevelopers/QuartzLib/HEAD/icon.png -------------------------------------------------------------------------------- /src/test/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: zToaster 2 | main: fr.zcraft.quartzlib.Toaster 3 | version: 0.99 4 | 5 | commands: 6 | toaster: 7 | description: Toaster Interface -------------------------------------------------------------------------------- /ztoaster/src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: zToaster 2 | main: fr.zcraft.ztoaster.Toaster 3 | version: 0.0.1 4 | api-version: 1.15 5 | 6 | commands: 7 | toaster: 8 | description: Toaster Interface -------------------------------------------------------------------------------- /src/test/resources/i18n/en_GB.no-meta.properties: -------------------------------------------------------------------------------- 1 | # Project: QuartzLib i18n tests 2 | # Locale: fr-FR, French (France) 3 | 4 | meta-author = Amaury Carrade 5 | meta-team = Amaury Carrade 6 | meta-reports = AmauryCarrade 7 | quartzlib-i18n-no-metadata = true 8 | 9 | sidebar.cook = {darkgreen}{bold}Cook 10 | -------------------------------------------------------------------------------- /src/test/resources/i18n/fr_FR.yml: -------------------------------------------------------------------------------- 1 | author: "Amaury Carrade" 2 | team: "Amaury Carrade" 3 | reports: "AmauryCarrade" 4 | 5 | keys: 6 | greetings: 7 | hi: "Hi there" 8 | how: "How are you?" 9 | toast: "♨ Toaster! ♨" 10 | 11 | other_context: 12 | greetings: 13 | hi: "Hi!" 14 | fine: "Fine?" 15 | toast: "♨ Toaster ♨" 16 | -------------------------------------------------------------------------------- /ztoaster/src/test/java/fr/zcraft/ztoaster/core/QuartzLibTest.java: -------------------------------------------------------------------------------- 1 | package fr.zcraft.ztoaster.core; 2 | 3 | import static org.junit.Assert.assertSame; 4 | 5 | import fr.zcraft.quartzlib.core.QuartzLib; 6 | import fr.zcraft.ztoaster.MockedToasterTest; 7 | import org.junit.Test; 8 | 9 | 10 | public class QuartzLibTest extends MockedToasterTest { 11 | @Test 12 | public void getPluginTest() { 13 | assertSame(plugin, QuartzLib.getPlugin()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/resources/i18n/fr_FR.properties: -------------------------------------------------------------------------------- 1 | # Project: quartzlib i18n tests 2 | # Locale: fr-FR, French (France) 3 | 4 | meta-author = Amaury Carrade 5 | meta-team = Amaury Carrade 6 | meta-reports = AmauryCarrade 7 | 8 | sidebar.cook = {darkgreen}{bold}Cuisinier 9 | 10 | sidebar.inside-the-toaster = {yellow}{bold}Dans le toaster 11 | 12 | sidebar.cooked = {gold}{bold}Cuit 13 | sidebar.toaster-cooking = {red}{bold}\u2668 Toaster \u2668 14 | 15 | sidebar.toaster = {blue}Toaster 16 | 17 | one-toast-added = Un toast ajout\u00E9. 18 | toasts-added = {0} toasts ajout\u00E9s. 19 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [AmauryCarrade] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /src/test/java/fr/zcraft/quartzlib/MockedToasterTest.java: -------------------------------------------------------------------------------- 1 | package fr.zcraft.quartzlib; 2 | 3 | import be.seeseemelk.mockbukkit.MockBukkit; 4 | import be.seeseemelk.mockbukkit.ServerMock; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | 8 | /** 9 | * A base class for tests, that sets up a mock server and enables the Toaster plugin inside it. 10 | */ 11 | public abstract class MockedToasterTest { 12 | protected ServerMock server; 13 | protected Toaster plugin; 14 | 15 | @Before 16 | public void setUp() { 17 | server = MockBukkit.mock(); 18 | plugin = MockBukkit.load(Toaster.class); 19 | } 20 | 21 | @After 22 | public void tearDown() { 23 | MockBukkit.unmock(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ztoaster/src/test/java/fr/zcraft/ztoaster/MockedToasterTest.java: -------------------------------------------------------------------------------- 1 | package fr.zcraft.ztoaster; 2 | 3 | import be.seeseemelk.mockbukkit.MockBukkit; 4 | import be.seeseemelk.mockbukkit.ServerMock; 5 | import fr.zcraft.ztoaster.Toaster; 6 | import org.junit.After; 7 | import org.junit.Before; 8 | 9 | /** 10 | * A base class for tests, that sets up a mock server and enables the Toaster plugin inside it. 11 | */ 12 | public abstract class MockedToasterTest { 13 | protected ServerMock server; 14 | protected Toaster plugin; 15 | 16 | @Before 17 | public void setUp() { 18 | server = MockBukkit.mock(); 19 | plugin = MockBukkit.load(Toaster.class); 20 | } 21 | 22 | @After 23 | public void tearDown() { 24 | MockBukkit.unmock(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/fr/zcraft/quartzlib/MockedBukkitTest.java: -------------------------------------------------------------------------------- 1 | package fr.zcraft.quartzlib; 2 | 3 | import be.seeseemelk.mockbukkit.MockBukkit; 4 | import be.seeseemelk.mockbukkit.ServerMock; 5 | import org.junit.After; 6 | import org.junit.Before; 7 | 8 | /** 9 | * A simple base class for tests that just set up a Mock Bukkit server, without any plugin associated. 10 | *
This is useful for testing simple, non-plugin-related APIs (such as ItemStack) that however require a Server to 11 | * be instantiated.
12 | */ 13 | public abstract class MockedBukkitTest { 14 | protected ServerMock server; 15 | 16 | @Before 17 | public void setup() { 18 | server = MockBukkit.mock(); 19 | } 20 | 21 | @After 22 | public void tearDown() { 23 | MockBukkit.unmock(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | build: 13 | name: Test on Java ${{ matrix.java }} 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | java: [8, 11, 16, 17] 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Set up JDK 1.8 21 | uses: actions/setup-java@v1 22 | with: 23 | java-version: ${{ matrix.java }} 24 | - name: Cache Maven packages 25 | uses: actions/cache@v2 26 | with: 27 | path: ~/.m2 28 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 29 | restore-keys: ${{ runner.os }}-m2 30 | - name: Build with Maven 31 | run: mvn -B test package --file pom.xml 32 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/commands/CommandWorkers.java: -------------------------------------------------------------------------------- 1 | package fr.zcraft.quartzlib.components.commands; 2 | 3 | import fr.zcraft.quartzlib.components.i18n.I; 4 | import fr.zcraft.quartzlib.components.worker.Worker; 5 | import fr.zcraft.quartzlib.components.worker.WorkerAttributes; 6 | import fr.zcraft.quartzlib.components.worker.WorkerCallback; 7 | import fr.zcraft.quartzlib.components.worker.WorkerRunnable; 8 | import fr.zcraft.quartzlib.tools.PluginLogger; 9 | import fr.zcraft.quartzlib.tools.mojang.UUIDFetcher; 10 | import java.util.UUID; 11 | import java.util.function.Consumer; 12 | 13 | @WorkerAttributes(name = "Command's worker", queriesMainThread = true) 14 | public class CommandWorkers extends Worker { 15 | 16 | /** 17 | * Fetches an offline player's UUID by name. 18 | */ 19 | public void offlineNameFetch(final String playerName, final ConsumerThe underlying exception is available through {@link #getCause()}.
38 | */ 39 | public class IncompatibleMinecraftVersionException extends RuntimeException { 40 | 41 | private static final long serialVersionUID = -8022385806817755567L; 42 | 43 | public IncompatibleMinecraftVersionException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | 47 | public IncompatibleMinecraftVersionException(Throwable cause) { 48 | super(cause); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 32 | 33 |The name of the enum item is the name of the material, without the color part.
41 | * 42 | * @see ItemUtils#colorize(ColorableMaterial, DyeColor) Compute a {@link Material} from a {@link ColorableMaterial} 43 | * and a {@link DyeColor}. 44 | * @see ItemUtils#colorize(ColorableMaterial, ChatColor) Compute a {@link Material} from a {@link ColorableMaterial} 45 | * and a {@link ChatColor}. 46 | */ 47 | public enum ColorableMaterial { 48 | BANNER, 49 | BED, 50 | CARPET, 51 | CONCRETE, 52 | CONCRETE_POWDER, 53 | DYE, 54 | GLAZED_TERRACOTTA, 55 | SHULKER_BOX, 56 | STAINED_GLASS, 57 | STAINED_GLASS_PANE, 58 | TERRACOTTA, 59 | WALL_BANNER, 60 | WOOL 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/fr/zcraft/quartzlib/tools/reflection/ReflectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright or © or Copr. QuartzLib contributors (2015 - 2020) 3 | * 4 | * This software is governed by the CeCILL-B license under French law and 5 | * abiding by the rules of distribution of free software. You can use, 6 | * modify and/ or redistribute the software under the terms of the CeCILL-B 7 | * license as circulated by CEA, CNRS and INRIA at the following URL 8 | * "http://www.cecill.info". 9 | * 10 | * As a counterpart to the access to the source code and rights to copy, 11 | * modify and redistribute granted by the license, users are provided only 12 | * with a limited warranty and the software's author, the holder of the 13 | * economic rights, and the successive licensors have only limited 14 | * liability. 15 | * 16 | * In this respect, the user's attention is drawn to the risks associated 17 | * with loading, using, modifying and/or developing or reproducing the 18 | * software by the user in light of its specific status of free software, 19 | * that may mean that it is complicated to manipulate, and that also 20 | * therefore means that it is reserved for developers and experienced 21 | * professionals having in-depth computer knowledge. Users are therefore 22 | * encouraged to load and test the software's suitability as regards their 23 | * requirements in conditions enabling the security of their systems and/or 24 | * data to be ensured and, more generally, to use and operate it in the 25 | * same conditions as regards security. 26 | * 27 | * The fact that you are presently reading this means that you have had 28 | * knowledge of the CeCILL-B license and that you accept its terms. 29 | */ 30 | 31 | package fr.zcraft.quartzlib.tools.reflection; 32 | 33 | import java.util.ArrayList; 34 | import java.util.HashMap; 35 | import java.util.List; 36 | import java.util.Map; 37 | import junit.framework.Assert; 38 | import org.junit.jupiter.api.Test; 39 | 40 | public class ReflectionTest { 41 | @Test 42 | public void testClosestType() { 43 | Class closestType = 44 | Reflection.getClosestType(ArrayList.class, Object.class, String.class, List.class, Map.class); 45 | 46 | Assert.assertEquals(List.class, closestType); 47 | 48 | closestType = Reflection.getClosestType(HashMap.class, Object.class, String.class, List.class, Integer.class); 49 | Assert.assertEquals(Object.class, closestType); 50 | 51 | closestType = Reflection.getClosestType(String.class, Object.class, String.class, List.class, Integer.class); 52 | Assert.assertEquals(String.class, closestType); 53 | 54 | closestType = Reflection.getClosestType(HashMap.class, String.class, List.class, Integer.class); 55 | Assert.assertEquals(null, closestType); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # Publish to GitHub Packages and release the project. 2 | # To trigger, create a tag (not a release) with semantic 3 | # versioning (the tag must start with a v). 4 | # 5 | # git tag -a v0.2 -m "Version 0.2" 6 | # git push --tags 7 | # 8 | # This workflow will automatically: 9 | # - build the project using Maven; 10 | # - publish the built project as a Maven package in the project's 11 | # Maven repository, at https://maven.zcraft.fr/Callbacks are not called when the configuration is reloaded fully.
69 | * 70 | * @param callback The callback. 71 | */ 72 | public static void registerConfigurationUpdateCallback(final CallbackThe listener will be called only if the event is available in the 47 | * server.
48 | * 49 | *This can also be used for other plugins events.
50 | * 51 | *This annotation goes on methods in {@link org.bukkit.event.Listener 52 | * Listeners}; these methods MUST accept one argument of the type {@link 53 | * WrappedEvent}. Listeners with this kind of methods must also be registered 54 | * using {@link FutureEvents#registerFutureEvents(Listener)}.
55 | */ 56 | @Retention(RetentionPolicy.RUNTIME) 57 | @Target(ElementType.METHOD) 58 | public @interface FutureEventHandler { 59 | /** 60 | * The class name of the event to listen to. 61 | * 62 | *The class will be loaded from the raw name at first; then if it fails, 63 | * the class {@code org.bukkit.event.[given name]} will be tried.
64 | */ 65 | String event(); 66 | 67 | /** 68 | * The event's priority. 69 | * 70 | * @see EventHandler#priority() 71 | */ 72 | EventPriority priority() default EventPriority.NORMAL; 73 | 74 | /** 75 | * {@code true} if this listener should not be called if the event was 76 | * cancelled before. 77 | * 78 | * @see EventHandler#ignoreCancelled() 79 | */ 80 | boolean ignoreCancelled() default false; 81 | } 82 | -------------------------------------------------------------------------------- /ztoaster/src/main/java/fr/zcraft/ztoaster/ToasterSidebar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright or © or Copr. ZLib contributors (2015) 3 | * 4 | * This software is governed by the CeCILL-B license under French law and 5 | * abiding by the rules of distribution of free software. You can use, 6 | * modify and/ or redistribute the software under the terms of the CeCILL-B 7 | * license as circulated by CEA, CNRS and INRIA at the following URL 8 | * "http://www.cecill.info". 9 | * 10 | * As a counterpart to the access to the source code and rights to copy, 11 | * modify and redistribute granted by the license, users are provided only 12 | * with a limited warranty and the software's author, the holder of the 13 | * economic rights, and the successive licensors have only limited 14 | * liability. 15 | * 16 | * In this respect, the user's attention is drawn to the risks associated 17 | * with loading, using, modifying and/or developing or reproducing the 18 | * software by the user in light of its specific status of free software, 19 | * that may mean that it is complicated to manipulate, and that also 20 | * therefore means that it is reserved for developers and experienced 21 | * professionals having in-depth computer knowledge. Users are therefore 22 | * encouraged to load and test the software's suitability as regards their 23 | * requirements in conditions enabling the security of their systems and/or 24 | * data to be ensured and, more generally, to use and operate it in the 25 | * same conditions as regards security. 26 | * 27 | * The fact that you are presently reading this means that you have had 28 | * knowledge of the CeCILL-B license and that you accept its terms. 29 | */ 30 | 31 | package fr.zcraft.ztoaster; 32 | 33 | import fr.zcraft.quartzlib.components.i18n.I; 34 | import fr.zcraft.quartzlib.components.i18n.I18n; 35 | import fr.zcraft.quartzlib.components.scoreboard.Sidebar; 36 | import fr.zcraft.quartzlib.components.scoreboard.SidebarMode; 37 | import java.util.Arrays; 38 | import java.util.List; 39 | import java.util.Locale; 40 | import org.bukkit.entity.Player; 41 | 42 | 43 | public class ToasterSidebar extends Sidebar { 44 | private int toastsCount = 0; 45 | private long insideTheToaster = 0; 46 | 47 | public ToasterSidebar() { 48 | setAsync(true); 49 | setContentMode(SidebarMode.PER_PLAYER); 50 | setAutoRefreshDelay(10); 51 | } 52 | 53 | 54 | @Override 55 | public void preRender() { 56 | Toast[] toasts = Toaster.getToasts(); 57 | 58 | toastsCount = toasts.length; 59 | 60 | insideTheToaster = Arrays.stream(toasts) 61 | .filter(toast -> toast.getStatus() != Toast.CookingStatus.COOKED) 62 | .count(); 63 | } 64 | 65 | @Override 66 | public ListIf your listener is called, the class is available and you can use 51 | * reflection without risks.
52 | * 53 | * @return The wrapped event. 54 | * @see fr.zcraft.quartzlib.tools.reflection.Reflection 55 | */ 56 | public Event getEvent() { 57 | return wrappedEvent; 58 | } 59 | 60 | /** 61 | * Checks if the wrapped event is cancellable. 62 | * 63 | * @return {@code true} if cancellable. 64 | */ 65 | public boolean isCancellable() { 66 | return wrappedEvent instanceof Cancellable; 67 | } 68 | 69 | /** 70 | * Checks if the wrapped event is cancelled. 71 | * 72 | * @return {@code true} if cancelled. 73 | * @throws UnsupportedOperationException if the wrapped event is not 74 | * cancellable. 75 | */ 76 | public boolean isCancelled() throws UnsupportedOperationException { 77 | if (wrappedEvent instanceof Cancellable) { 78 | return ((Cancellable) wrappedEvent).isCancelled(); 79 | } else { 80 | throw new UnsupportedOperationException( 81 | "Cannot retrieve the cancellation state of a non-cancellable event"); 82 | } 83 | } 84 | 85 | /** 86 | * Marks the wrapped event as cancelled or not. 87 | * 88 | * @param cancelled {@code true} to cancel it. 89 | * @throws UnsupportedOperationException if the wrapped event is not 90 | * cancellable. 91 | */ 92 | public void setCancelled(boolean cancelled) throws UnsupportedOperationException { 93 | if (wrappedEvent instanceof Cancellable) { 94 | ((Cancellable) wrappedEvent).setCancelled(cancelled); 95 | } else { 96 | throw new UnsupportedOperationException("Cannot set the cancellation state of a non-cancellable event"); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/test/java/fr/zcraft/quartzlib/tools/mojang/MojangHeadTest.java: -------------------------------------------------------------------------------- 1 | package fr.zcraft.quartzlib.tools.mojang; 2 | 3 | import fr.zcraft.quartzlib.MockedBukkitTest; 4 | import java.util.Arrays; 5 | import java.util.HashMap; 6 | import java.util.Objects; 7 | import org.bukkit.Material; 8 | import org.bukkit.inventory.ItemStack; 9 | import org.bukkit.inventory.meta.SkullMeta; 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | class MojangHeadTest extends MockedBukkitTest { 14 | @Test 15 | public void canCreateHeadItems() { 16 | Assert.assertEquals("MHF_Cake", MojangHead.CAKE.getHeadName()); 17 | ItemStack item = MojangHead.CAKE.asItem(); 18 | 19 | Assert.assertEquals(Material.PLAYER_HEAD, item.getType()); 20 | Assert.assertEquals(1, item.getAmount()); 21 | Assert.assertEquals("MHF_Cake", ((SkullMeta) Objects.requireNonNull(item.getItemMeta())).getOwner()); 22 | 23 | ItemStack isbItem = MojangHead.CAKE.asItemBuilder().item(); 24 | 25 | Assert.assertEquals(Material.PLAYER_HEAD, isbItem.getType()); 26 | Assert.assertEquals(1, item.getAmount()); 27 | Assert.assertEquals("MHF_Cake", ((SkullMeta) Objects.requireNonNull(isbItem.getItemMeta())).getOwner()); 28 | } 29 | 30 | @Test 31 | public void headNamesMatch() { 32 | HashMapTo use QuartzLib, you have to use this class instead of {@link JavaPlugin}, 44 | * and to add calls to the {@code super} methods of 45 | * {@link JavaPlugin#onEnable()} and {@link JavaPlugin#onDisable()} (if you use 46 | * them).
47 | */ 48 | public abstract class QuartzPlugin extends JavaPlugin { 49 | protected QuartzPlugin() { 50 | super(); 51 | } 52 | 53 | protected QuartzPlugin(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { 54 | super(loader, description, dataFolder, file); 55 | } 56 | 57 | @Override 58 | public void onLoad() { 59 | QuartzLib.init(this); 60 | } 61 | 62 | /** 63 | * Load the given QuartzLib components. 64 | * 65 | * @param components The base classes of the components to load. 66 | */ 67 | @SafeVarargs 68 | public final void loadComponents(Class extends QuartzComponent>... components) { 69 | for (Class extends QuartzComponent> componentClass : components) { 70 | QuartzLib.loadComponent(componentClass); 71 | } 72 | } 73 | 74 | /** 75 | * Tries to load a given component. 76 | * 77 | * @param69 | * Constructor with no callback argument. Note that you must override 70 | * the onClick method if you use this constructor 71 | *
72 | */ 73 | public ArrayPromptGui(Player player, String title, T[] data, boolean closeOnChoice) { 74 | this(player, title, data, closeOnChoice, null); 75 | } 76 | 77 | /** 78 | * Convert an object to an ItemStack. 79 | * 80 | * @return The ItemStack to display 81 | */ 82 | public abstract ItemStack getViewItem(T data); 83 | 84 | /** 85 | * Called when player made a choice if no callback was provided. 86 | * 87 | * @param data The data given to the callback. 88 | */ 89 | public void onClick(T data) { 90 | throw new NotImplementedException("Override this method or use a callback."); 91 | } 92 | 93 | @Override 94 | protected void onRightClick(T data) { 95 | if (cb != null) { 96 | cb.call(data); 97 | } else { 98 | onClick(data); 99 | } 100 | 101 | if (closeOnChoice) { 102 | close(); 103 | } 104 | } 105 | 106 | @Override 107 | protected void onUpdate() { 108 | setTitle(title); 109 | setMode(Mode.READONLY); 110 | setData(data); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/i18n/translators/properties/ZLibResourceBundleControl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright or © or Copr. QuartzLib contributors (2015 - 2020) 3 | * 4 | * This software is governed by the CeCILL-B license under French law and 5 | * abiding by the rules of distribution of free software. You can use, 6 | * modify and/ or redistribute the software under the terms of the CeCILL-B 7 | * license as circulated by CEA, CNRS and INRIA at the following URL 8 | * "http://www.cecill.info". 9 | * 10 | * As a counterpart to the access to the source code and rights to copy, 11 | * modify and redistribute granted by the license, users are provided only 12 | * with a limited warranty and the software's author, the holder of the 13 | * economic rights, and the successive licensors have only limited 14 | * liability. 15 | * 16 | * In this respect, the user's attention is drawn to the risks associated 17 | * with loading, using, modifying and/or developing or reproducing the 18 | * software by the user in light of its specific status of free software, 19 | * that may mean that it is complicated to manipulate, and that also 20 | * therefore means that it is reserved for developers and experienced 21 | * professionals having in-depth computer knowledge. Users are therefore 22 | * encouraged to load and test the software's suitability as regards their 23 | * requirements in conditions enabling the security of their systems and/or 24 | * data to be ensured and, more generally, to use and operate it in the 25 | * same conditions as regards security. 26 | * 27 | * The fact that you are presently reading this means that you have had 28 | * knowledge of the CeCILL-B license and that you accept its terms. 29 | */ 30 | 31 | package fr.zcraft.quartzlib.components.i18n.translators.properties; 32 | 33 | import java.io.File; 34 | import java.io.FileInputStream; 35 | import java.io.IOException; 36 | import java.io.InputStream; 37 | import java.util.Locale; 38 | import java.util.PropertyResourceBundle; 39 | import java.util.ResourceBundle; 40 | import org.apache.commons.lang.StringUtils; 41 | 42 | 43 | public class ZLibResourceBundleControl extends ResourceBundle.Control { 44 | private final File bundleFile; 45 | private final String resourceReference; 46 | 47 | public ZLibResourceBundleControl(File bundleFile) { 48 | this.bundleFile = bundleFile; 49 | this.resourceReference = null; 50 | } 51 | 52 | public ZLibResourceBundleControl(String resourceReference) { 53 | this.bundleFile = null; 54 | this.resourceReference = resourceReference; 55 | } 56 | 57 | /** 58 | *Uses the file name as the bundle name.
59 | * 60 | *Loads the bundles from the file system instead of the JAR file, to allow modifications by 76 | * the end user, if a file was provided.
77 | * 78 | *The bundles are only loaded on startup, one time, so the cache is not needed.
98 | * Plus, the cache may cause problems if one reloads the plugin to update the translation.
See https://minecraft.gamepedia.com/Head#Mojang_Studios_skins for the complete list.
47 | */ 48 | public enum MojangHead { 49 | /* Mobs */ 50 | ALEX, 51 | BLAZE, 52 | CAVE_SPIDER, 53 | CHICKEN, 54 | COW, 55 | CREEPER, 56 | ENDERMAN, 57 | GHAST, 58 | GOLEM, 59 | HEROBRINE, 60 | LAVA_SLIME, 61 | MUSHROOM_COW, 62 | OCELOT, 63 | PIG, 64 | PIG_ZOMBIE, 65 | SHEEP, 66 | SKELETON, 67 | SLIME, 68 | SPIDER, 69 | SQUID, 70 | STEVE, 71 | VILLAGER, 72 | WITHER_SKELETON("MHF_WSkeleton"), 73 | ZOMBIE, 74 | 75 | /* Blocks */ 76 | CACTUS, 77 | CAKE, 78 | CHEST, 79 | COCONUT_BROWN("MHF_CoconutB"), 80 | COCONUT_GREEN("MHF_CoconutG"), 81 | MELON, 82 | OAK_LOG, 83 | PRESENT("MHF_Present1"), 84 | PRESENT_2, 85 | PUMPKIN, 86 | TNT("MHF_TNT"), 87 | TNT_2("MHF_TNT2"), 88 | 89 | /* Bonus */ 90 | ARROW_UP, 91 | ARROW_DOWN, 92 | ARROW_LEFT, 93 | ARROW_RIGHT, 94 | EXCLAMATION, 95 | QUESTION; 96 | 97 | 98 | private final String headName; 99 | 100 | MojangHead() { 101 | this.headName = "MHF_" + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); 102 | } 103 | 104 | MojangHead(final String headName) { 105 | this.headName = headName; 106 | } 107 | 108 | /** 109 | * Returns the head's name. 110 | * @return The Mojang head's name, to be used as skull owner. 111 | */ 112 | public String getHeadName() { 113 | return headName; 114 | } 115 | 116 | /** 117 | * Returns the head as an ItemStack. 118 | * @return The head as an ItemStack (of type {@link Material#PLAYER_HEAD}). 119 | */ 120 | public ItemStack asItem() { 121 | return asItemBuilder().item(); 122 | } 123 | 124 | /** 125 | * Returns the head as an ItemStackBuilder. 126 | * @return The head as an {@link ItemStackBuilder}, ready to be completed. 127 | */ 128 | // Silence the setOwner deprecation warning, because a string name is the only clean way to get a MHF head. 129 | @SuppressWarnings("deprecation") 130 | public ItemStackBuilder asItemBuilder() { 131 | return new ItemStackBuilder(Material.PLAYER_HEAD) 132 | .withMeta((SkullMeta s) -> s.setOwner(headName)); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/external/ExternalPluginComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright or © or Copr. QuartzLib contributors (2015 - 2020) 3 | * 4 | * This software is governed by the CeCILL-B license under French law and 5 | * abiding by the rules of distribution of free software. You can use, 6 | * modify and/ or redistribute the software under the terms of the CeCILL-B 7 | * license as circulated by CEA, CNRS and INRIA at the following URL 8 | * "http://www.cecill.info". 9 | * 10 | * As a counterpart to the access to the source code and rights to copy, 11 | * modify and redistribute granted by the license, users are provided only 12 | * with a limited warranty and the software's author, the holder of the 13 | * economic rights, and the successive licensors have only limited 14 | * liability. 15 | * 16 | * In this respect, the user's attention is drawn to the risks associated 17 | * with loading, using, modifying and/or developing or reproducing the 18 | * software by the user in light of its specific status of free software, 19 | * that may mean that it is complicated to manipulate, and that also 20 | * therefore means that it is reserved for developers and experienced 21 | * professionals having in-depth computer knowledge. Users are therefore 22 | * encouraged to load and test the software's suitability as regards their 23 | * requirements in conditions enabling the security of their systems and/or 24 | * data to be ensured and, more generally, to use and operate it in the 25 | * same conditions as regards security. 26 | * 27 | * The fact that you are presently reading this means that you have had 28 | * knowledge of the CeCILL-B license and that you accept its terms. 29 | */ 30 | 31 | package fr.zcraft.quartzlib.external; 32 | 33 | import fr.zcraft.quartzlib.core.QuartzComponent; 34 | import fr.zcraft.quartzlib.tools.PluginLogger; 35 | import org.bukkit.Bukkit; 36 | import org.bukkit.plugin.Plugin; 37 | 38 | /** 39 | * This class is a component to interface with other plugins. 40 | * When enabled, the plugin will be looked for using the provided name, and 41 | * casted to the given class. 42 | * If any of this fails, the component will not be enabled. 43 | * Note these components may even fail during instanciation (if the other 44 | * plugin's classes are not found). 45 | * 46 | * @param