├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ ├── docs.yml │ └── release.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── checkstyle.xml ├── icon.png ├── pom.xml ├── quartzlib └── pom.xml ├── src ├── main │ └── java │ │ └── fr │ │ └── zcraft │ │ └── quartzlib │ │ ├── components │ │ ├── attributes │ │ │ ├── Attribute.java │ │ │ ├── AttributeOperation.java │ │ │ └── Attributes.java │ │ ├── commands │ │ │ ├── Command.java │ │ │ ├── CommandException.java │ │ │ ├── CommandGroup.java │ │ │ ├── CommandInfo.java │ │ │ ├── CommandWorkers.java │ │ │ ├── Commands.java │ │ │ ├── HelpCommand.java │ │ │ └── WithFlags.java │ │ ├── configuration │ │ │ ├── Configuration.java │ │ │ ├── ConfigurationInstance.java │ │ │ ├── ConfigurationItem.java │ │ │ ├── ConfigurationList.java │ │ │ ├── ConfigurationMap.java │ │ │ ├── ConfigurationParseException.java │ │ │ ├── ConfigurationSection.java │ │ │ ├── ConfigurationValueHandler.java │ │ │ ├── ConfigurationValueHandlers.java │ │ │ └── ValueHandler.java │ │ ├── events │ │ │ ├── FutureEventHandler.java │ │ │ ├── FutureEvents.java │ │ │ └── WrappedEvent.java │ │ ├── gui │ │ │ ├── ActionGui.java │ │ │ ├── ArrayPromptGui.java │ │ │ ├── ExplorerGui.java │ │ │ ├── Gui.java │ │ │ ├── GuiAction.java │ │ │ ├── GuiBase.java │ │ │ ├── GuiUtils.java │ │ │ ├── InventoryGui.java │ │ │ └── PromptGui.java │ │ ├── i18n │ │ │ ├── I.java │ │ │ ├── I18n.java │ │ │ ├── UnsupportedLocaleException.java │ │ │ └── translators │ │ │ │ ├── Translation.java │ │ │ │ ├── Translator.java │ │ │ │ ├── gettext │ │ │ │ ├── GettextPOTranslator.java │ │ │ │ ├── POFile.java │ │ │ │ └── PluralForms.java │ │ │ │ ├── properties │ │ │ │ ├── PropertiesTranslator.java │ │ │ │ └── ZLibResourceBundleControl.java │ │ │ │ └── yaml │ │ │ │ └── YAMLTranslator.java │ │ ├── nbt │ │ │ ├── NBT.java │ │ │ ├── NBTCompound.java │ │ │ ├── NBTException.java │ │ │ ├── NBTList.java │ │ │ └── NBTType.java │ │ ├── rawtext │ │ │ ├── RawText.java │ │ │ ├── RawTextPart.java │ │ │ └── RawTextSubPart.java │ │ ├── scoreboard │ │ │ ├── OnlinePlayersListener.java │ │ │ ├── Sidebar.java │ │ │ ├── SidebarMode.java │ │ │ ├── SidebarScoreboard.java │ │ │ └── sender │ │ │ │ ├── ObjectiveSender.java │ │ │ │ └── SidebarObjective.java │ │ └── worker │ │ │ ├── Worker.java │ │ │ ├── WorkerAttributes.java │ │ │ ├── WorkerCallback.java │ │ │ ├── WorkerCallbackManager.java │ │ │ ├── WorkerMainThreadExecutor.java │ │ │ └── WorkerRunnable.java │ │ ├── core │ │ ├── QuartzComponent.java │ │ ├── QuartzLib.java │ │ └── QuartzPlugin.java │ │ ├── exceptions │ │ └── IncompatibleMinecraftVersionException.java │ │ ├── external │ │ └── ExternalPluginComponent.java │ │ └── tools │ │ ├── Callback.java │ │ ├── FileUtils.java │ │ ├── PluginLogger.java │ │ ├── UpdateChecker.java │ │ ├── commands │ │ └── PaginatedTextView.java │ │ ├── items │ │ ├── ColorableMaterial.java │ │ ├── CraftingRecipes.java │ │ ├── GlowEffect.java │ │ ├── InventoryUtils.java │ │ ├── ItemStackBuilder.java │ │ ├── ItemUtils.java │ │ └── TextualBanners.java │ │ ├── mojang │ │ ├── MojangHead.java │ │ └── UUIDFetcher.java │ │ ├── players │ │ └── ReducedDebugInfo.java │ │ ├── reflection │ │ ├── NMSException.java │ │ ├── NMSNetwork.java │ │ └── Reflection.java │ │ ├── runners │ │ ├── RunAsyncTask.java │ │ └── RunTask.java │ │ ├── text │ │ ├── ActionBar.java │ │ ├── ChatColorParser.java │ │ ├── ChatColoredString.java │ │ ├── ListHeaderFooter.java │ │ ├── MessageSender.java │ │ ├── RawMessage.java │ │ └── Titles.java │ │ └── world │ │ ├── FlatLocation.java │ │ └── WorldUtils.java └── test │ ├── java │ └── fr │ │ └── zcraft │ │ └── quartzlib │ │ ├── MockedBukkitTest.java │ │ ├── MockedToasterTest.java │ │ ├── TestsUtils.java │ │ ├── Toaster.java │ │ ├── components │ │ ├── commands │ │ │ └── CommandFlagsTest.java │ │ ├── gui │ │ │ └── GuiUtilsTest.java │ │ └── rawtext │ │ │ ├── ChatColorParserTest.java │ │ │ └── RawTextTest.java │ │ ├── i18n │ │ ├── PoParserTest.java │ │ ├── PoTranslatorTest.java │ │ ├── PropertiesTranslatorTest.java │ │ └── YamlTranslatorTest.java │ │ └── tools │ │ ├── items │ │ ├── CraftingRecipesTest.java │ │ ├── ItemStackBuilderTest.java │ │ └── ItemUtilsTest.java │ │ ├── mojang │ │ └── MojangHeadTest.java │ │ └── reflection │ │ └── ReflectionTest.java │ └── resources │ ├── i18n │ ├── en_GB.no-meta.properties │ ├── en_US.po │ ├── fr_FR.po │ ├── fr_FR.properties │ └── fr_FR.yml │ └── plugin.yml └── ztoaster ├── pom.xml └── src ├── main ├── java │ └── fr │ │ └── zcraft │ │ └── ztoaster │ │ ├── Toast.java │ │ ├── ToastExplorer.java │ │ ├── Toaster.java │ │ ├── ToasterSidebar.java │ │ ├── ToasterWorker.java │ │ └── commands │ │ ├── AddCommand.java │ │ ├── ListCommand.java │ │ └── OpenCommand.java └── resources │ ├── i18n │ ├── en_US.po │ └── fr_FR.po │ └── plugin.yml └── test └── java └── fr └── zcraft └── ztoaster ├── MockedToasterTest.java └── core └── QuartzLibTest.java /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Build documentation 2 | on: 3 | push: 4 | branches: [master] 5 | jobs: 6 | javadoc: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v2 11 | - name: Setup Java 12 | uses: actions/setup-java@v1 13 | with: 14 | java-version: 8 15 | - name: Cache all the things 16 | uses: actions/cache@v2 17 | with: 18 | path: ~/.m2 19 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 20 | restore-keys: ${{ runner.os }}-m2 21 | - name: Build JavaDoc 22 | run: mvn -B javadoc:javadoc -pl quartzlib --file pom.xml 23 | - name: Checkout website repository 24 | uses: actions/checkout@v2 25 | with: 26 | repository: zDevelopers/zdevelopers.github.io 27 | path: web 28 | branch: master 29 | persist-credentials: false 30 | - name: Push built documentation to website repository 31 | shell: bash 32 | run: | 33 | # Extract project name 34 | PROJECT_NAME=${GITHUB_REPOSITORY##*/} 35 | PROJECT_NAME_LOWER=${PROJECT_NAME,,} 36 | 37 | # Create dir if needed, cleanup old doc and copy new one 38 | mkdir -p web/static/docs/ 39 | rm -rf web/static/docs/$PROJECT_NAME_LOWER 40 | cp -r quartzlib/target/site/apidocs web/static/docs/$PROJECT_NAME_LOWER 41 | 42 | # Go to website repository 43 | cd web 44 | 45 | # Configure git to push to this repository 46 | git config --global user.name QuartzBot 47 | git config --global user.email moriplay@zcraft.fr 48 | git config --global user.password ${{ secrets.QUARTZ_BOT_TOKEN }} 49 | 50 | # Add files 51 | echo ::group::Commit 52 | git add . 53 | git commit -m "Updated documentation for $PROJECT_NAME" 54 | echo ::endgroup:: 55 | 56 | # Push 57 | echo ::group::Push 58 | git push https://QuartzBot:${{ secrets.QUARTZ_BOT_TOKEN }}@github.com/zDevelopers/zdevelopers.github.io.git 59 | echo ::endgroup:: 60 | -------------------------------------------------------------------------------- /.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/; 12 | # - create a new draft release; 13 | # - attach the built project to the release. 14 | 15 | name: Publish new release 16 | 17 | on: 18 | push: 19 | tags: 20 | - 'v*' 21 | 22 | jobs: 23 | publish: 24 | runs-on: ubuntu-latest 25 | steps: 26 | - name: Checkout 27 | uses: actions/checkout@v2 28 | 29 | - name: Setup Java 30 | uses: actions/setup-java@v1 31 | with: 32 | java-version: 8 33 | 34 | - uses: actions/cache@v2 35 | with: 36 | path: ~/.m2 37 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 38 | restore-keys: ${{ runner.os }}-m2 39 | 40 | - name: Extract project name 41 | id: project-name 42 | uses: actions/github-script@v3 43 | with: 44 | script: return context.repo.repo 45 | result-encoding: string 46 | 47 | - name: Publish to GitHub Packages 48 | id: maven-publish 49 | run: | 50 | TAG_NAME=${GIT_REF_NAME##*/} 51 | REVISION_NAME=${TAG_NAME:1} 52 | 53 | mvn -B deploy -pl quartzlib -am "-Drevision=$REVISION_NAME" 54 | 55 | JAR_PATH=$(ls ./quartzlib/target/*.jar | tail -n 1) 56 | JAR_NAME=$(basename $JAR_PATH) 57 | echo "::set-output name=jar_path::$JAR_PATH" 58 | echo "::set-output name=jar_name::$JAR_NAME" 59 | env: 60 | GIT_REF_NAME: ${{ github.ref }} 61 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 62 | 63 | - name: Create new GitHub Release 64 | id: create-release 65 | uses: actions/create-release@v1 66 | env: 67 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 68 | with: 69 | tag_name: ${{ github.ref }} 70 | release_name: ${{ steps.project-name.outputs.result }} ${{ github.ref }} 71 | draft: true 72 | prerelease: false 73 | 74 | - name: Upload GitHub Release Asset 75 | uses: actions/upload-release-asset@v1 76 | env: 77 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 78 | with: 79 | upload_url: ${{ steps.create-release.outputs.upload_url }} 80 | asset_path: ${{ steps.maven-publish.outputs.jar_path }} 81 | asset_name: ${{ steps.maven-publish.outputs.jar_name }} 82 | asset_content_type: application/java-archive 83 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Java ### 2 | *.class 3 | 4 | # Mobile Tools for Java (J2ME) 5 | .mtj.tmp/ 6 | 7 | # Package Files # 8 | *.jar 9 | *.war 10 | *.ear 11 | 12 | # virtual machine crash logs 13 | hs_err_pid* 14 | 15 | 16 | ### Maven ### 17 | target/ 18 | pom.xml.tag 19 | pom.xml.releaseBackup 20 | pom.xml.versionsBackup 21 | pom.xml.next 22 | release.properties 23 | dependency-reduced-pom.xml 24 | buildNumber.properties 25 | 26 | 27 | ### Intellij ### 28 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 29 | 30 | *.iml 31 | 32 | ## Directory-based project format: 33 | .idea/ 34 | 35 | ## File-based project format: 36 | *.ipr 37 | *.iws 38 | 39 | ## Plugin-specific files: 40 | 41 | # IntelliJ 42 | /out/ 43 | 44 | # mpeltonen/sbt-idea plugin 45 | .idea_modules/ 46 | 47 | # JIRA plugin 48 | atlassian-ide-plugin.xml 49 | 50 | # Crashlytics plugin (for Android Studio and IntelliJ) 51 | com_crashlytics_export_strings.xml 52 | crashlytics.properties 53 | crashlytics-build.properties 54 | 55 | 56 | ### NetBeans ### 57 | nbproject/private/ 58 | build/ 59 | nbbuild/ 60 | dist/ 61 | nbdist/ 62 | nbactions.xml 63 | nb-configuration.xml 64 | .nb-gradle/ 65 | 66 | 67 | ### Eclipse ### 68 | *.pydevproject 69 | .metadata 70 | .gradle 71 | bin/ 72 | tmp/ 73 | *.tmp 74 | *.bak 75 | *.swp 76 | *~.nib 77 | local.properties 78 | .settings/ 79 | .loadpath 80 | 81 | # Eclipse Core 82 | .project 83 | 84 | # External tool builders 85 | .externalToolBuilders/ 86 | 87 | # Locally stored "Eclipse launch configurations" 88 | *.launch 89 | 90 | # CDT-specific 91 | .cproject 92 | 93 | # JDT-specific (Eclipse Java Development Tools) 94 | .classpath 95 | 96 | # PDT-specific 97 | .buildpath 98 | 99 | # sbteclipse plugin 100 | .target 101 | 102 | # TeXlipse plugin 103 | .texlipse 104 | 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | QuartzLib 2 | ========== 3 | 4 | Helper library for Bukkit plugins development. 5 | ---- 6 | 7 | ###### (Formerly known as zLib) 8 | 9 | ### How to use this library in your plugin? 10 | 11 | If you are using Maven to build your plugin, follow these simple steps. Other builds methods are not supported (but you can use them of course). 12 | Currently, QuartzLib requires **Java 8** or later and **Bukkit 1.15** or later. 13 | 14 | #### I'm starting a new plugin 15 | 16 | Either create a plugin as usual and add the QuartzLib as explained below, or use [the plugin bootstrap generator](https://github.com/zDevelopers/zLib-CodeGen-Utils#plugins-bootstrap-generator) and answer “yes” when the tool asks if you want to use QuartzLib. 17 | 18 | #### I want to add QuartzLib to an existing project 19 | 20 | 1. Add our Maven repository to your `pom.xml` file. 21 | 22 | ```xml 23 | 24 | QuartzLib 25 | https://maven.zcraft.fr/QuartzLib 26 | 27 | ``` 28 | 29 | 2. Add QuartzLib as a dependency. 30 | 31 | ```xml 32 | 33 | fr.zcraft 34 | quartzlib 35 | 0.0.3 36 | 37 | ``` 38 | 39 | 3. Add the shading plugin to the build. Replace **`YOUR.OWN.PACKAGE`** with your own package. 40 | 41 | ```xml 42 | 43 | ... 44 | 45 | ... 46 | 47 | org.apache.maven.plugins 48 | maven-shade-plugin 49 | 2.4 50 | 51 | 52 | 53 | fr.zcraft:quartzlib 54 | 55 | 56 | 57 | 58 | fr.zcraft.quartzlib 59 | YOUR.OWN.PACKAGE 60 | 61 | 62 | 63 | 64 | 65 | package 66 | 67 | shade 68 | 69 | 70 | 71 | 72 | ... 73 | 74 | ... 75 | 76 | ``` 77 | 78 | 4. Build your project as usual, as example with the following command from your working directory, or using an integrated tool from your IDE. 79 | 80 | ```bash 81 | mvn clean install 82 | ``` 83 | 84 | You should also update your code, so your main class extends [`QuartzPlugin`](https://zdevelopers.github.io/QuartzLib/?fr/zcraft/quartzlib/core/QuartzPlugin.html) instead of `JavaPlugin`. No other changes are required. This will allow you to use directly some useful methods to load your plugin's components. 85 | Check out [the wiki](https://github.com/zDevelopers/QuartzLib/wiki/Installation) for more information. 86 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zDevelopers/QuartzLib/95f7c5d0a61e5d82e8ea1396e7a715507fa804a0/icon.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 32 | 33 | 36 | 4.0.0 37 | 38 | fr.zcraft 39 | quartz 40 | 0.0.5 41 | 42 | pom 43 | 44 | 45 | 1.8 46 | UTF-8 47 | 1.8 48 | 1.8 49 | 50 | 51 | 52 | quartzlib 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/attributes/AttributeOperation.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.attributes; 32 | 33 | /** 34 | * This enum represents the possible values for an item attribute operation. 35 | */ 36 | public enum AttributeOperation { 37 | /** 38 | * Operation 0: Additive. Adds all of the modifiers' amounts to the current value of the attribute. 39 | */ 40 | ADDITIVE(0), 41 | /** 42 | * Operation 1: Multiplicative. Multiplies the current value of the attribute by (1 + x), 43 | * where x is the sum of the modifiers' amounts. 44 | */ 45 | MULTIPLY(1), 46 | /** 47 | * Operation 2: Multiplicative. For every modifier, multiplies the current value of the attribute by (1 + x), 48 | * where x is the amount of the particular modifier. 49 | * Functions the same as Operation 1 if there is only a single modifier with operation 1 or 2. 50 | * However, for multiple modifiers it will multiply the modifiers rather than adding them. 51 | */ 52 | MULTIPLY_ALL(2); 53 | 54 | private final int code; 55 | 56 | AttributeOperation(int code) { 57 | this.code = code; 58 | } 59 | 60 | /** 61 | * Gets an AttributeOperation from its code. 62 | * 63 | * @param code The attribute code. 64 | * @return the corresponding attribute operation. 65 | * @throws IllegalArgumentException if the code is invalid. 66 | */ 67 | public static AttributeOperation fromCode(int code) throws IllegalArgumentException { 68 | for (AttributeOperation operation : values()) { 69 | if (operation.code == code) { 70 | return operation; 71 | } 72 | } 73 | 74 | throw new IllegalArgumentException("Illegal Attribute operation code : " + code); 75 | } 76 | 77 | /** 78 | * Gets the operation's code. 79 | * @return the operation's code. 80 | */ 81 | public int getCode() { 82 | return code; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return String.valueOf(code); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/commands/CommandException.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.commands; 32 | 33 | import fr.zcraft.quartzlib.components.gui.GuiUtils; 34 | import fr.zcraft.quartzlib.tools.PluginLogger; 35 | import org.bukkit.ChatColor; 36 | 37 | 38 | public class CommandException extends Exception { 39 | private final Reason reason; 40 | private final Command command; 41 | private final String extra; 42 | 43 | /** 44 | * A new CommandException. 45 | * @param command The command that raised the exception. 46 | * @param reason The reason code. 47 | * @param extra Any extra message. 48 | */ 49 | public CommandException(Command command, Reason reason, String extra) { 50 | this.command = command; 51 | this.reason = reason; 52 | this.extra = extra; 53 | } 54 | 55 | public CommandException(Command command, Reason reason) { 56 | this(command, reason, ""); 57 | } 58 | 59 | public Reason getReason() { 60 | return reason; 61 | } 62 | 63 | /** 64 | * Builds the "reason" string for this command exception. 65 | * @return The reason string. 66 | */ 67 | public String getReasonString() { 68 | switch (reason) { 69 | case COMMANDSENDER_EXPECTED_PLAYER: 70 | return "You must be a player to use this command."; 71 | case INVALID_PARAMETERS: 72 | final String prefix = ChatColor.GOLD + Commands.CHAT_PREFIX + " " + ChatColor.RESET; 73 | return "\n" 74 | + ChatColor.RED + Commands.CHAT_PREFIX + ' ' + ChatColor.BOLD + "Invalid argument" + '\n' 75 | + GuiUtils.generatePrefixedFixedLengthString(ChatColor.RED + Commands.CHAT_PREFIX + " ", extra) 76 | + '\n' 77 | + GuiUtils.generatePrefixedFixedLengthString(prefix, "Usage: " + command.getUsageString()) 78 | + '\n' 79 | + GuiUtils.generatePrefixedFixedLengthString(prefix, 80 | "For more information, use /" + command.getCommandGroup().getUsualName() 81 | + " help " + command.getName()); 82 | case COMMAND_ERROR: 83 | return extra.isEmpty() ? "An unknown error suddenly happened." : extra; 84 | case SENDER_NOT_AUTHORIZED: 85 | return "You do not have the permission to use this command."; 86 | default: 87 | PluginLogger.warning("Unknown CommandException caught", this); 88 | return "An unknown error suddenly happened."; 89 | } 90 | } 91 | 92 | public enum Reason { 93 | COMMANDSENDER_EXPECTED_PLAYER, 94 | INVALID_PARAMETERS, 95 | COMMAND_ERROR, 96 | SENDER_NOT_AUTHORIZED 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/commands/CommandInfo.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.commands; 32 | 33 | import java.lang.annotation.ElementType; 34 | import java.lang.annotation.Retention; 35 | import java.lang.annotation.RetentionPolicy; 36 | import java.lang.annotation.Target; 37 | 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Target({ElementType.TYPE}) 40 | public @interface CommandInfo { 41 | /** 42 | * The name of the command. 43 | */ 44 | String name(); 45 | 46 | /** 47 | * The "usage" description. 48 | */ 49 | String usageParameters() default ""; 50 | 51 | /** 52 | * Aliases for this command. 53 | */ 54 | String[] aliases() default {}; 55 | } 56 | -------------------------------------------------------------------------------- /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 Consumer callback) { 20 | final WorkerCallback wCallback = new WorkerCallback() { 21 | @Override 22 | public void finished(UUID result) { 23 | callback.accept(result); // Si tout va bien on passe l'UUID au callback 24 | } 25 | 26 | @Override 27 | public void errored(Throwable exception) { 28 | PluginLogger.warning(I.t("Error while getting player UUID")); 29 | callback.accept(null); // En cas d'erreur on envoie `null` au callback 30 | } 31 | }; 32 | WorkerRunnable wr = new WorkerRunnable() { 33 | @Override 34 | public UUID run() throws Throwable { 35 | return UUIDFetcher.fetch(playerName); 36 | } 37 | }; 38 | submitQuery(wr, wCallback); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/commands/WithFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright or © or Copr. AmauryCarrade (2015) 3 | * 4 | * http://amaury.carrade.eu 5 | * 6 | * This software is governed by the CeCILL-B license under French law and 7 | * abiding by the rules of distribution of free software. You can use, 8 | * modify and/ or redistribute the software under the terms of the CeCILL-B 9 | * license as circulated by CEA, CNRS and INRIA at the following URL 10 | * "http://www.cecill.info". 11 | * 12 | * As a counterpart to the access to the source code and rights to copy, 13 | * modify and redistribute granted by the license, users are provided only 14 | * with a limited warranty and the software's author, the holder of the 15 | * economic rights, and the successive licensors have only limited 16 | * liability. 17 | * 18 | * In this respect, the user's attention is drawn to the risks associated 19 | * with loading, using, modifying and/or developing or reproducing the 20 | * software by the user in light of its specific status of free software, 21 | * that may mean that it is complicated to manipulate, and that also 22 | * therefore means that it is reserved for developers and experienced 23 | * professionals having in-depth computer knowledge. Users are therefore 24 | * encouraged to load and test the software's suitability as regards their 25 | * requirements in conditions enabling the security of their systems and/or 26 | * data to be ensured and, more generally, to use and operate it in the 27 | * same conditions as regards security. 28 | * 29 | * The fact that you are presently reading this means that you have had 30 | * knowledge of the CeCILL-B license and that you accept its terms. 31 | */ 32 | 33 | package fr.zcraft.quartzlib.components.commands; 34 | 35 | import java.lang.annotation.ElementType; 36 | import java.lang.annotation.Retention; 37 | import java.lang.annotation.RetentionPolicy; 38 | import java.lang.annotation.Target; 39 | 40 | 41 | /** 42 | * Adds this annotation to a command class to make it accept flags, 43 | * i.e. parameters prefixed with - or -- extracted from the args 44 | * array and made available through {@link Command#hasFlag(String)}. 45 | */ 46 | @Retention(RetentionPolicy.RUNTIME) 47 | @Target({ElementType.TYPE}) 48 | public @interface WithFlags { 49 | 50 | /** 51 | * The name of the flags. 52 | */ 53 | String[] value() default {}; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/configuration/Configuration.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.configuration; 32 | 33 | import fr.zcraft.quartzlib.core.QuartzComponent; 34 | import fr.zcraft.quartzlib.core.QuartzLib; 35 | import fr.zcraft.quartzlib.tools.Callback; 36 | 37 | 38 | public abstract class Configuration extends QuartzComponent { 39 | /* ===== Static API ===== */ 40 | private static ConfigurationInstance instance; 41 | 42 | /** 43 | * Initializes the configuration based on a given class. 44 | */ 45 | public static void init(final Class configurationClass) { 46 | instance = new ConfigurationInstance(QuartzLib.getPlugin().getConfig()); 47 | instance.init(configurationClass); 48 | instance.onEnable(); 49 | } 50 | 51 | /** 52 | * Saves the config.yml configuration to the disk. 53 | */ 54 | public static void save() { 55 | instance.save(true); 56 | } 57 | 58 | /** 59 | * Reloads the config.yml configuration from the disk. 60 | */ 61 | public static void reload() { 62 | instance.reload(true); 63 | } 64 | 65 | /** 66 | * Registers a callback called when the configuration is updated someway. 67 | * 68 | *

Callbacks are not called when the configuration is reloaded fully.

69 | * 70 | * @param callback The callback. 71 | */ 72 | public static void registerConfigurationUpdateCallback(final Callback> callback) { 73 | instance.registerConfigurationUpdateCallback(callback); 74 | } 75 | 76 | @Override 77 | protected void onEnable() { 78 | init(this.getClass()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/configuration/ConfigurationList.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.configuration; 32 | 33 | import java.util.Collection; 34 | import java.util.Collections; 35 | import java.util.Iterator; 36 | import java.util.List; 37 | import java.util.ListIterator; 38 | 39 | public class ConfigurationList extends ConfigurationItem> implements List { 40 | private final Class itemType; 41 | 42 | public ConfigurationList(String fieldName, List defaultValue, Class itemType, String... deprecatedNames) { 43 | super(fieldName, defaultValue, deprecatedNames); 44 | this.itemType = itemType; 45 | } 46 | 47 | @Override 48 | protected List getValue(Object value) throws ConfigurationParseException { 49 | if (value == null) { 50 | return null; 51 | } 52 | 53 | return ConfigurationValueHandlers.handleListValue(value, itemType); 54 | } 55 | 56 | @Override 57 | public int size() { 58 | return get().size(); 59 | } 60 | 61 | @Override 62 | public boolean isEmpty() { 63 | return get().isEmpty(); 64 | } 65 | 66 | @Override 67 | public boolean contains(Object o) { 68 | return get().contains(o); 69 | } 70 | 71 | @Override 72 | public Iterator iterator() { 73 | return get().iterator(); 74 | } 75 | 76 | @Override 77 | public T[] toArray() { 78 | return (T[]) get().toArray(); 79 | } 80 | 81 | @Override 82 | public T[] toArray(T[] a) { 83 | return get().toArray(a); 84 | } 85 | 86 | @Override 87 | public boolean add(T e) { 88 | throw new UnsupportedOperationException(); 89 | } 90 | 91 | @Override 92 | public void add(int index, T element) { 93 | throw new UnsupportedOperationException(); 94 | } 95 | 96 | @Override 97 | public boolean remove(Object o) { 98 | throw new UnsupportedOperationException(); 99 | } 100 | 101 | @Override 102 | public T remove(int index) { 103 | throw new UnsupportedOperationException(); 104 | } 105 | 106 | @Override 107 | public boolean containsAll(Collection c) { 108 | return get().containsAll(c); 109 | } 110 | 111 | @Override 112 | public boolean addAll(Collection c) { 113 | throw new UnsupportedOperationException(); 114 | } 115 | 116 | @Override 117 | public boolean addAll(int index, Collection c) { 118 | throw new UnsupportedOperationException(); 119 | } 120 | 121 | @Override 122 | public boolean removeAll(Collection c) { 123 | throw new UnsupportedOperationException(); 124 | } 125 | 126 | @Override 127 | public boolean retainAll(Collection c) { 128 | throw new UnsupportedOperationException(); 129 | } 130 | 131 | @Override 132 | public void clear() { 133 | throw new UnsupportedOperationException(); 134 | } 135 | 136 | @Override 137 | public T get(int index) { 138 | return get().get(index); 139 | } 140 | 141 | @Override 142 | public T set(int index, T element) { 143 | throw new UnsupportedOperationException(); 144 | } 145 | 146 | @Override 147 | public int indexOf(Object o) { 148 | return get().indexOf(o); 149 | } 150 | 151 | @Override 152 | public int lastIndexOf(Object o) { 153 | return get().lastIndexOf(o); 154 | } 155 | 156 | @Override 157 | public ListIterator listIterator() { 158 | return Collections.unmodifiableList(get()).listIterator(); 159 | } 160 | 161 | @Override 162 | public ListIterator listIterator(int index) { 163 | return Collections.unmodifiableList(get()).listIterator(index); 164 | } 165 | 166 | @Override 167 | public List subList(int fromIndex, int toIndex) { 168 | return get().subList(fromIndex, toIndex); 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/configuration/ConfigurationMap.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.configuration; 32 | 33 | import java.util.Collection; 34 | import java.util.Collections; 35 | import java.util.Iterator; 36 | import java.util.Map; 37 | import java.util.Map.Entry; 38 | import java.util.Set; 39 | 40 | public class ConfigurationMap extends ConfigurationItem> implements Map, Iterable> { 41 | private final Class keyType; 42 | private final Class valueType; 43 | 44 | /** 45 | * Creates a new configuration map. 46 | */ 47 | public ConfigurationMap(String name, Map defaultValue, Class keyType, Class valueType, 48 | String... deprecatedNames) { 49 | super(name, defaultValue, deprecatedNames); 50 | this.keyType = keyType; 51 | this.valueType = valueType; 52 | } 53 | 54 | @Override 55 | protected Map getValue(Object value) throws ConfigurationParseException { 56 | if (value == null) { 57 | return null; 58 | } 59 | 60 | return ConfigurationValueHandlers.handleMapValue(value, keyType, valueType, this); 61 | } 62 | 63 | @Override 64 | boolean validate() { 65 | boolean isValid = super.validate(); 66 | 67 | if (ConfigurationSection.class.isAssignableFrom(valueType)) { 68 | for (Object value : values()) { 69 | if (!((ConfigurationSection) value).validate()) { 70 | isValid = false; 71 | } 72 | } 73 | } 74 | 75 | return isValid; 76 | } 77 | 78 | @Override 79 | public int size() { 80 | return get().size(); 81 | } 82 | 83 | @Override 84 | public boolean isEmpty() { 85 | return get().isEmpty(); 86 | } 87 | 88 | @Override 89 | public boolean containsKey(Object key) { 90 | return get().containsKey(key); 91 | } 92 | 93 | @Override 94 | public boolean containsValue(Object value) { 95 | return get().containsValue(value); 96 | } 97 | 98 | @Override 99 | public V get(Object key) { 100 | return get().get(key); 101 | } 102 | 103 | @Override 104 | public V put(K key, V value) { 105 | throw new UnsupportedOperationException(); 106 | } 107 | 108 | @Override 109 | public V remove(Object key) { 110 | throw new UnsupportedOperationException(); 111 | } 112 | 113 | @Override 114 | public void putAll(Map m) { 115 | throw new UnsupportedOperationException(); 116 | } 117 | 118 | @Override 119 | public void clear() { 120 | throw new UnsupportedOperationException(); 121 | } 122 | 123 | @Override 124 | public Set keySet() { 125 | return Collections.unmodifiableSet(get().keySet()); 126 | } 127 | 128 | @Override 129 | public Collection values() { 130 | return Collections.unmodifiableCollection(get().values()); 131 | } 132 | 133 | @Override 134 | public Set> entrySet() { 135 | return Collections.unmodifiableSet(get().entrySet()); 136 | } 137 | 138 | @Override 139 | public Iterator> iterator() { 140 | return entrySet().iterator(); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/configuration/ConfigurationParseException.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.configuration; 32 | 33 | public class ConfigurationParseException extends Exception { 34 | private static final long serialVersionUID = 5461007750484876641L; 35 | private final Object value; 36 | 37 | public ConfigurationParseException(String message, Object value) { 38 | super(message); 39 | this.value = value; 40 | } 41 | 42 | public Object getValue() { 43 | return value; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/configuration/ConfigurationSection.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.configuration; 32 | 33 | import java.lang.reflect.Field; 34 | import java.util.Collection; 35 | import java.util.Collections; 36 | import java.util.HashMap; 37 | import java.util.Iterator; 38 | import java.util.Map; 39 | import java.util.Set; 40 | 41 | public class ConfigurationSection 42 | extends ConfigurationItem 43 | implements Map, 44 | Iterable { 45 | private final HashMap items = new HashMap(); 46 | 47 | protected ConfigurationSection() { 48 | this(null); 49 | } 50 | 51 | private ConfigurationSection(String fieldName, String... deprecatedNames) { 52 | super(fieldName, null, Map.class, deprecatedNames); 53 | } 54 | 55 | @Override 56 | void init() { 57 | super.init(); 58 | for (Field field : this.getClass().getFields()) { 59 | if (ConfigurationItem.class.isAssignableFrom(field.getType())) { 60 | try { 61 | ConfigurationItem item = (ConfigurationItem) field.get(this); 62 | item.setParent(this); 63 | item.init(); 64 | items.put(field.getName().toUpperCase(), item); 65 | } catch (Exception ignored) { } 66 | } 67 | } 68 | } 69 | 70 | @Override 71 | boolean validate() { 72 | boolean isValid = true; 73 | 74 | for (ConfigurationItem item : items.values()) { 75 | if (!item.validate()) { 76 | isValid = false; 77 | } 78 | } 79 | 80 | return isValid; 81 | } 82 | 83 | 84 | @Override 85 | public Map get() { 86 | return getConfig().getConfigurationSection(getFieldName()).getValues(true); 87 | } 88 | 89 | @Override 90 | public ConfigurationItem get(Object key) { 91 | return items.get(key.toString().toUpperCase()); 92 | } 93 | 94 | @Override 95 | public int size() { 96 | return items.size(); 97 | } 98 | 99 | @Override 100 | public boolean isEmpty() { 101 | return items.isEmpty(); 102 | } 103 | 104 | @Override 105 | public boolean containsKey(Object key) { 106 | return items.containsKey(key.toString().toUpperCase()); 107 | } 108 | 109 | @Override 110 | public boolean containsValue(Object value) { 111 | return items.containsValue(value); 112 | } 113 | 114 | @Override 115 | public ConfigurationItem put(String key, ConfigurationItem value) { 116 | throw new UnsupportedOperationException(); 117 | } 118 | 119 | @Override 120 | public ConfigurationItem remove(Object key) { 121 | throw new UnsupportedOperationException(); 122 | } 123 | 124 | @Override 125 | public void putAll(Map m) { 126 | throw new UnsupportedOperationException(); 127 | } 128 | 129 | @Override 130 | public void clear() { 131 | throw new UnsupportedOperationException(); 132 | } 133 | 134 | @Override 135 | public Set keySet() { 136 | return Collections.unmodifiableSet(items.keySet()); 137 | } 138 | 139 | @Override 140 | public Collection values() { 141 | return Collections.unmodifiableCollection(items.values()); 142 | } 143 | 144 | @Override 145 | public Set> entrySet() { 146 | return Collections.unmodifiableSet(items.entrySet()); 147 | } 148 | 149 | @Override 150 | public Iterator iterator() { 151 | return items.values().iterator(); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/configuration/ConfigurationValueHandler.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.configuration; 32 | 33 | import java.lang.annotation.ElementType; 34 | import java.lang.annotation.Retention; 35 | import java.lang.annotation.RetentionPolicy; 36 | import java.lang.annotation.Target; 37 | 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Target({ElementType.METHOD}) 40 | public @interface ConfigurationValueHandler { 41 | /** 42 | * The list of classes for value handlers. 43 | */ 44 | Class[] value() default {}; 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/configuration/ValueHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package fr.zcraft.quartzlib.components.configuration; 8 | 9 | import fr.zcraft.quartzlib.tools.reflection.Reflection; 10 | import java.lang.reflect.InvocationTargetException; 11 | import java.lang.reflect.Method; 12 | import java.util.HashMap; 13 | 14 | class ValueHandler { 15 | private final Class outputType; 16 | private final HashMap, Method> methods = new HashMap<>(); 17 | 18 | public ValueHandler(Class outputType) { 19 | this.outputType = outputType; 20 | } 21 | 22 | public void addHandler(Class inputType, Method method) { 23 | if (methods.containsKey(inputType)) { 24 | throw new IllegalStateException( 25 | "Value handler already registered for type " + outputType.getName() + " with input " + inputType); 26 | } 27 | 28 | methods.put(inputType, method); 29 | } 30 | 31 | public T handleValue(Object inputValue) 32 | throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { 33 | if (inputValue == null) { 34 | return null; 35 | } 36 | 37 | Method handler = null; 38 | 39 | Class inputType = Reflection.getClosestType(inputValue.getClass(), methods.keySet()); 40 | if (inputType != null) { 41 | handler = methods.get(inputType); 42 | } 43 | if (handler == null) { 44 | if (!methods.containsKey(String.class)) { 45 | throw new UnsupportedOperationException( 46 | "Unsupported input type '" + inputValue.getClass().getName() + "' for configuration type : " 47 | + outputType.getName()); 48 | } else { 49 | handler = methods.get(String.class); 50 | inputValue = inputValue.toString(); 51 | } 52 | } 53 | return (T) handler.invoke(null, inputValue); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/events/FutureEventHandler.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.events; 32 | 33 | import java.lang.annotation.ElementType; 34 | import java.lang.annotation.Retention; 35 | import java.lang.annotation.RetentionPolicy; 36 | import java.lang.annotation.Target; 37 | import org.bukkit.event.EventHandler; 38 | import org.bukkit.event.EventPriority; 39 | import org.bukkit.event.Listener; 40 | 41 | 42 | /** 43 | * Represents an event handler for a potentially non-existent event, like an 44 | * event added in 1.9 listened in a plugin for both 1.8 and 1.9. 45 | * 46 | *

The 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 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/events/WrappedEvent.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.events; 32 | 33 | import org.bukkit.event.Cancellable; 34 | import org.bukkit.event.Event; 35 | 36 | /** 37 | * A class used to wrap an event for {@link FutureEventHandler}s. 38 | */ 39 | public class WrappedEvent { 40 | private final Event wrappedEvent; 41 | 42 | public WrappedEvent(Event event) { 43 | this.wrappedEvent = event; 44 | } 45 | 46 | /** 47 | * The wrapped event. You can use reflection with that to execute methods on 48 | * it. 49 | * 50 | *

If 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/main/java/fr/zcraft/quartzlib/components/gui/ArrayPromptGui.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.gui; 32 | 33 | import fr.zcraft.quartzlib.tools.Callback; 34 | import org.apache.commons.lang.NotImplementedException; 35 | import org.bukkit.entity.Player; 36 | import org.bukkit.inventory.ItemStack; 37 | 38 | public abstract class ArrayPromptGui extends ExplorerGui { 39 | private final Callback cb; 40 | private final String title; 41 | private final T[] data; 42 | private final boolean closeOnChoice; 43 | 44 | /** 45 | * Creates a new Array prompt GUI. 46 | * 47 | * @param player The player making the choice 48 | * @param title The gui title 49 | * @param data An array of datas to display 50 | * @param closeOnChoice If true, close the interface when the player has choosen 51 | * @param callback Callback called when the player made a choice 52 | */ 53 | public ArrayPromptGui(Player player, String title, T[] data, boolean closeOnChoice, Callback callback) { 54 | this.cb = callback; 55 | this.title = title; 56 | this.data = data; 57 | this.closeOnChoice = closeOnChoice; 58 | 59 | Gui.open(player, this); 60 | } 61 | 62 | /** 63 | * @param player The player making the choice 64 | * @param title The gui title 65 | * @param data An array of datas to display 66 | * @param closeOnChoice Close the interface when the player has choosen if true 67 | * @see #onClick(Object) 68 | *

69 | * 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/gui/GuiAction.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.gui; 32 | 33 | import java.lang.annotation.ElementType; 34 | import java.lang.annotation.Retention; 35 | import java.lang.annotation.RetentionPolicy; 36 | import java.lang.annotation.Target; 37 | 38 | @Retention(RetentionPolicy.RUNTIME) 39 | @Target({ElementType.METHOD}) 40 | public @interface GuiAction { 41 | /** 42 | * The name of the GUI's Action. If not set, takes the method's name automatically. 43 | */ 44 | String value() default ""; 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/i18n/UnsupportedLocaleException.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; 32 | 33 | import java.util.Locale; 34 | 35 | public class UnsupportedLocaleException extends IllegalArgumentException { 36 | 37 | private static final long serialVersionUID = -2746324692893193071L; 38 | 39 | public UnsupportedLocaleException(Locale locale) { 40 | super("Unsupported locale " + locale); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/i18n/translators/Translation.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; 32 | 33 | import java.util.List; 34 | 35 | 36 | /** 37 | * Represents a translation. 38 | */ 39 | public class Translation { 40 | private final String original; 41 | private final String originalPlural; 42 | private final String context; 43 | private final List translations; 44 | 45 | /** 46 | * Creates a new translation. 47 | */ 48 | public Translation(String context, String original, String originalPlural, List translations) { 49 | this.context = context; 50 | this.original = original; 51 | this.originalPlural = originalPlural; 52 | this.translations = translations; 53 | } 54 | 55 | /** 56 | * Gets the original, untranslated, string. 57 | * @return The original, untranslated, string. 58 | */ 59 | public String getOriginal() { 60 | return original; 61 | } 62 | 63 | /** 64 | * Gets the original, untranslated, plural form. 65 | * @return The original, untranslated, plural form. 66 | */ 67 | public String getOriginalPlural() { 68 | return originalPlural; 69 | } 70 | 71 | /** 72 | * Gets the translation context. 73 | * @return The translation context, or {@code null} if no context was set. Note that an empty 74 | * context string and a {@code null} one do not mean the same thing. 75 | */ 76 | public String getContext() { 77 | return context; 78 | } 79 | 80 | /** 81 | * Gets all of the available translations. 82 | * @return All the available translations. 83 | */ 84 | public List getTranslations() { 85 | return translations; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/i18n/translators/gettext/GettextPOTranslator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of QuartzLib. 3 | * 4 | * Copyright or © or Copr. ProkopyL (2015 - 2021) 5 | * Copyright or © or Copr. Amaury Carrade (2015 – 2021) 6 | * Copyright or © or Copr. Vlammar (2019 – 2021) 7 | * 8 | * This software is a computer program whose purpose is to create Minecraft mods 9 | * with the Bukkit API easily. 10 | * 11 | * This software is governed by the CeCILL-B license under French law and 12 | * abiding by the rules of distribution of free software. You can use, 13 | * modify and/ or redistribute the software under the terms of the CeCILL-B 14 | * license as circulated by CEA, CNRS and INRIA at the following URL 15 | * "http://www.cecill.info". 16 | * 17 | * As a counterpart to the access to the source code and rights to copy, 18 | * modify and redistribute granted by the license, users are provided only 19 | * with a limited warranty and the software's author, the holder of the 20 | * economic rights, and the successive licensors have only limited 21 | * liability. 22 | * 23 | * In this respect, the user's attention is drawn to the risks associated 24 | * with loading, using, modifying and/or developing or reproducing the 25 | * software by the user in light of its specific status of free software, 26 | * that may mean that it is complicated to manipulate, and that also 27 | * therefore means that it is reserved for developers and experienced 28 | * professionals having in-depth computer knowledge. Users are therefore 29 | * encouraged to load and test the software's suitability as regards their 30 | * requirements in conditions enabling the security of their systems and/or 31 | * data to be ensured and, more generally, to use and operate it in the 32 | * same conditions as regards security. 33 | * 34 | * The fact that you are presently reading this means that you have had 35 | * knowledge of the CeCILL-B license and that you accept its terms. 36 | */ 37 | 38 | package fr.zcraft.quartzlib.components.i18n.translators.gettext; 39 | 40 | import fr.zcraft.quartzlib.components.i18n.translators.Translation; 41 | import fr.zcraft.quartzlib.components.i18n.translators.Translator; 42 | import fr.zcraft.quartzlib.tools.PluginLogger; 43 | import java.io.File; 44 | import java.io.Reader; 45 | import java.util.Locale; 46 | import javax.script.ScriptEngine; 47 | import javax.script.ScriptEngineManager; 48 | import javax.script.ScriptException; 49 | 50 | 51 | /** 52 | * Loads Gettext .po files (uncompiled). 53 | */ 54 | public class GettextPOTranslator extends Translator { 55 | private POFile source = null; 56 | 57 | public GettextPOTranslator(Locale locale, File file) { 58 | super(locale, file); 59 | } 60 | 61 | public GettextPOTranslator(Locale locale, String resourceReference) { 62 | super(locale, resourceReference); 63 | } 64 | 65 | @Override 66 | protected void load() { 67 | try { 68 | final Reader reader = getReader(); 69 | if (reader == null) { 70 | return; 71 | } 72 | 73 | source = new POFile(getReader()); 74 | 75 | source.parse(); 76 | 77 | for (final Translation translation : source.getTranslations()) { 78 | registerTranslation(translation); 79 | } 80 | } catch (POFile.CannotParsePOException e) { 81 | PluginLogger.error("Cannot parse the {0} translations file.", e, getFilePath()); 82 | source = null; 83 | } 84 | } 85 | 86 | @Override 87 | public Integer getPluralIndex(Integer count) { 88 | if (source == null) { 89 | return count != 1 ? 1 : 0; 90 | } 91 | 92 | return source.computePluralForm(count); 93 | } 94 | 95 | @Override 96 | public String getLastTranslator() { 97 | return source != null ? source.getLastTranslator() : null; 98 | } 99 | 100 | @Override 101 | public String getTranslationTeam() { 102 | return source != null ? source.getTranslationTeam() : null; 103 | } 104 | 105 | @Override 106 | public String getReportErrorsTo() { 107 | return source != null ? source.getReportErrorsTo() : null; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /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 | *
61 | * {@inheritDoc} 62 | */ 63 | @Override 64 | public String toBundleName(String baseName, Locale locale) { 65 | final String[] nameParts = (bundleFile != null ? bundleFile.getName() : resourceReference).split("\\."); 66 | 67 | if (nameParts.length >= 2) { 68 | nameParts[nameParts.length - 1] = ""; 69 | } 70 | 71 | return baseName + "." + StringUtils.join(nameParts, "."); 72 | } 73 | 74 | /** 75 | *

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 | *
79 | * {@inheritDoc} 80 | */ 81 | @Override 82 | public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) 83 | throws IllegalAccessException, InstantiationException, IOException { 84 | if (format.equals("java.properties") && bundleFile != null) { 85 | final ResourceBundle bundle; 86 | try (InputStream stream = new FileInputStream(bundleFile)) { 87 | bundle = new PropertyResourceBundle(stream); 88 | } 89 | 90 | return bundle; 91 | } 92 | 93 | return super.newBundle(baseName, locale, format, loader, reload); 94 | } 95 | 96 | /** 97 | *

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.

99 | * 100 | *
101 | * {@inheritDoc} 102 | */ 103 | @Override 104 | public boolean needsReload(String baseName, Locale locale, String format, ClassLoader loader, ResourceBundle bundle, 105 | long loadTime) { 106 | return true; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/nbt/NBTException.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.nbt; 32 | 33 | /** 34 | * Represents an exception thrown while accessing Minecraft NBT data. 35 | */ 36 | public class NBTException extends RuntimeException { 37 | public NBTException(String text, Throwable cause) { 38 | super(text, cause); 39 | } 40 | 41 | public NBTException(String text) { 42 | super(text); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/rawtext/RawTextSubPart.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.rawtext; 32 | 33 | class RawTextSubPart extends RawTextPart { 34 | public RawTextSubPart(String text) { 35 | super(text); 36 | } 37 | 38 | public RawTextSubPart(String text, RawTextPart parent) { 39 | super(text, parent); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/scoreboard/OnlinePlayersListener.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.scoreboard; 32 | 33 | import fr.zcraft.quartzlib.components.scoreboard.sender.ObjectiveSender; 34 | import org.bukkit.event.EventHandler; 35 | import org.bukkit.event.EventPriority; 36 | import org.bukkit.event.Listener; 37 | import org.bukkit.event.player.PlayerJoinEvent; 38 | import org.bukkit.event.player.PlayerKickEvent; 39 | import org.bukkit.event.player.PlayerQuitEvent; 40 | 41 | 42 | class OnlinePlayersListener implements Listener { 43 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 44 | public void onPlayerJoin(PlayerJoinEvent ev) { 45 | Sidebar.updateLoggedInPlayers(); 46 | ObjectiveSender.handleLogin(ev.getPlayer().getUniqueId()); 47 | } 48 | 49 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 50 | public void onPlayerLeft(PlayerQuitEvent ev) { 51 | Sidebar.updateLoggedInPlayers(); 52 | } 53 | 54 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 55 | public void onPlayerLeft(PlayerKickEvent ev) { 56 | Sidebar.updateLoggedInPlayers(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/scoreboard/SidebarMode.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.scoreboard; 32 | 33 | public enum SidebarMode { 34 | /** 35 | * A board (or title) per player. 36 | */ 37 | PER_PLAYER, 38 | 39 | /** 40 | * The board (or title) is the same for all players. 41 | */ 42 | GLOBAL 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/scoreboard/SidebarScoreboard.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.scoreboard; 32 | 33 | import fr.zcraft.quartzlib.core.QuartzComponent; 34 | 35 | 36 | public class SidebarScoreboard extends QuartzComponent { 37 | @Override 38 | protected void onEnable() { 39 | Sidebar.init(); 40 | } 41 | 42 | @Override 43 | protected void onDisable() { 44 | Sidebar.exit(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/worker/WorkerAttributes.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.worker; 32 | 33 | import java.lang.annotation.ElementType; 34 | import java.lang.annotation.Retention; 35 | import java.lang.annotation.RetentionPolicy; 36 | import java.lang.annotation.Target; 37 | 38 | 39 | /** 40 | * Defines various data about a given worker class. 41 | */ 42 | 43 | @Retention(RetentionPolicy.RUNTIME) 44 | @Target({ElementType.TYPE}) 45 | public @interface WorkerAttributes { 46 | /** 47 | * Defines the name of the Worker. 48 | * The named is used in various places, such as thread name or logging. 49 | * 50 | * @return The name of the worker. 51 | */ 52 | String name() default ""; 53 | 54 | /** 55 | * Defines if the Worker needs to query the main thread or not. 56 | * See the {@link Worker} class documentation for more information. 57 | * 58 | * @return If the Worker queries the main thread; 59 | */ 60 | boolean queriesMainThread() default false; 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/worker/WorkerCallback.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.worker; 32 | 33 | public interface WorkerCallback { 34 | void finished(T result); 35 | 36 | void errored(Throwable exception); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/worker/WorkerCallbackManager.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.worker; 32 | 33 | import fr.zcraft.quartzlib.core.QuartzLib; 34 | import java.util.ArrayDeque; 35 | import java.util.HashMap; 36 | import org.bukkit.Bukkit; 37 | import org.bukkit.scheduler.BukkitTask; 38 | 39 | class WorkerCallbackManager implements Runnable { 40 | private static final int WATCH_LOOP_DELAY = 5; 41 | 42 | private final HashMap callbacks; 43 | private final ArrayDeque callbackQueue; 44 | 45 | private final String name; 46 | 47 | private BukkitTask selfTask; 48 | 49 | public WorkerCallbackManager(String name) { 50 | callbacks = new HashMap<>(); 51 | callbackQueue = new ArrayDeque<>(); 52 | this.name = name; 53 | } 54 | 55 | public void init() { 56 | selfTask = Bukkit.getScheduler().runTaskTimer(QuartzLib.getPlugin(), this, 0, WATCH_LOOP_DELAY); 57 | } 58 | 59 | public void setupCallback(WorkerRunnable runnable, WorkerCallback callback) { 60 | synchronized (callbacks) { 61 | callbacks.put(runnable, new WorkerRunnableInfo(callback)); 62 | } 63 | } 64 | 65 | public void callback(WorkerRunnable runnable, T result) { 66 | callback(runnable, result, null); 67 | } 68 | 69 | public void callback(WorkerRunnable runnable, T result, Throwable exception) { 70 | WorkerRunnableInfo runnableInfo; 71 | synchronized (callbacks) { 72 | runnableInfo = callbacks.get(runnable); 73 | } 74 | if (runnableInfo == null) { 75 | return; 76 | } 77 | runnableInfo.setRunnableException(exception); 78 | runnableInfo.setResult(result); 79 | 80 | enqueueCallback(runnableInfo); 81 | } 82 | 83 | public void exit() { 84 | if (selfTask != null) { 85 | selfTask.cancel(); 86 | } 87 | } 88 | 89 | private void enqueueCallback(WorkerRunnableInfo runnableInfo) { 90 | synchronized (callbackQueue) { 91 | callbackQueue.add(runnableInfo); 92 | } 93 | } 94 | 95 | @Override 96 | public void run() { 97 | WorkerRunnableInfo currentRunnableInfo; 98 | synchronized (callbackQueue) { 99 | if (callbackQueue.isEmpty()) { 100 | return; 101 | } 102 | currentRunnableInfo = callbackQueue.pop(); 103 | } 104 | 105 | currentRunnableInfo.runCallback(); 106 | } 107 | 108 | private class WorkerRunnableInfo { 109 | private final WorkerCallback callback; 110 | private T result; 111 | private Throwable runnableException; 112 | 113 | public WorkerRunnableInfo(WorkerCallback callback) { 114 | this.callback = callback; 115 | this.runnableException = null; 116 | } 117 | 118 | public WorkerCallback getCallback() { 119 | return callback; 120 | } 121 | 122 | public void runCallback() { 123 | if (runnableCrashed()) { 124 | callback.errored(runnableException); 125 | } else { 126 | callback.finished(result); 127 | } 128 | } 129 | 130 | public void setResult(T result) { 131 | this.result = result; 132 | } 133 | 134 | public Throwable getRunnableException() { 135 | return runnableException; 136 | } 137 | 138 | public void setRunnableException(Throwable runnableException) { 139 | this.runnableException = runnableException; 140 | } 141 | 142 | public boolean runnableCrashed() { 143 | return this.runnableException != null; 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/components/worker/WorkerRunnable.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.worker; 32 | 33 | public abstract class WorkerRunnable { 34 | private Worker worker; 35 | 36 | public abstract T run() throws Throwable; 37 | 38 | Worker getWorker() { 39 | return worker; 40 | } 41 | 42 | void setWorker(Worker worker) { 43 | this.worker = worker; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/core/QuartzComponent.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.core; 32 | 33 | import org.bukkit.plugin.Plugin; 34 | 35 | /** 36 | * This abstract class represents a QuartzLib component that needs to be loaded 37 | * and/or unloaded. 38 | */ 39 | public abstract class QuartzComponent { 40 | private boolean enabled = false; 41 | 42 | /** 43 | * Called when this component is enabled, while the parent plugin is itself 44 | * enabled. 45 | */ 46 | protected void onEnable() { 47 | } 48 | 49 | /** 50 | * Called when this component is disabled, while the parent plugin is itself 51 | * disabled. 52 | */ 53 | protected void onDisable() { 54 | } 55 | 56 | /** 57 | * Checks if this component is enabled or not. 58 | * 59 | * @return {@code true} if enabled. 60 | */ 61 | public boolean isEnabled() { 62 | return enabled; 63 | } 64 | 65 | /** 66 | * Enables (load) or disable (unload) this QuartzLib component. 67 | * 68 | * @param enabled {@code true} to enable the component. 69 | */ 70 | public void setEnabled(boolean enabled) { 71 | if (enabled == this.enabled) { 72 | return; // The state is not changed. 73 | } 74 | 75 | this.enabled = enabled; 76 | 77 | if (enabled) { 78 | onEnable(); 79 | } else { 80 | onDisable(); 81 | } 82 | } 83 | 84 | /** 85 | * Gets the plugin owning this component. 86 | * @return The plugin owning this component. 87 | */ 88 | protected Plugin getPlugin() { 89 | return QuartzLib.getPlugin(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/core/QuartzPlugin.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.core; 32 | 33 | import fr.zcraft.quartzlib.tools.PluginLogger; 34 | import java.io.File; 35 | import java.io.IOException; 36 | import java.util.jar.JarFile; 37 | import org.bukkit.plugin.PluginDescriptionFile; 38 | import org.bukkit.plugin.java.JavaPlugin; 39 | import org.bukkit.plugin.java.JavaPluginLoader; 40 | 41 | /** 42 | * The base class of any plugin using QuartzLib. 43 | *

To 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... components) { 69 | for (Class componentClass : components) { 70 | QuartzLib.loadComponent(componentClass); 71 | } 72 | } 73 | 74 | /** 75 | * Tries to load a given component. 76 | * 77 | * @param The type of the component. 78 | * @param componentClass The component's class. 79 | * @return The component instance, or null if instanciation failed. 80 | */ 81 | public T loadComponent(Class componentClass) { 82 | return QuartzLib.loadComponent(componentClass); 83 | } 84 | 85 | /** 86 | * Gets the .jar file this plugin is loaded by, or null if it wasn't found. 87 | */ 88 | public JarFile getJarFile() { 89 | try { 90 | File file = getFile(); 91 | if (file == null) { 92 | return null; 93 | } 94 | return new JarFile(file); 95 | } catch (IOException e) { 96 | PluginLogger.error("Unable to load JAR file {0}", e, getFile().getAbsolutePath()); 97 | return null; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/exceptions/IncompatibleMinecraftVersionException.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.exceptions; 32 | 33 | 34 | /** 35 | * This runtime exception is thrown when an error is encountered due to an incompatible 36 | * Minecraft server version, as example while sending some packets. 37 | *

The 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 | -------------------------------------------------------------------------------- /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 The class of the plugin to interface with. 47 | */ 48 | public class ExternalPluginComponent extends QuartzComponent { 49 | private final String pluginName; 50 | private T plugin; 51 | 52 | /** 53 | * Instantiates a new external plugin component with the given name. 54 | * 55 | * @param pluginName The name of the plugin to interface with. 56 | */ 57 | protected ExternalPluginComponent(String pluginName) { 58 | this.pluginName = pluginName; 59 | } 60 | 61 | @Override 62 | protected final void onEnable() { 63 | Plugin bukkitPlugin = Bukkit.getServer().getPluginManager().getPlugin(pluginName); 64 | if (bukkitPlugin == null) { 65 | setEnabled(false); 66 | return; 67 | } else if (!bukkitPlugin.isEnabled()) { 68 | // We try to load the plugin (required if we're a startup plugin 69 | // depending on a non-startup one). 70 | Bukkit.getServer().getPluginManager().enablePlugin(bukkitPlugin); 71 | if (!bukkitPlugin.isEnabled()) { 72 | setEnabled(false); 73 | return; 74 | } 75 | } 76 | 77 | try { 78 | plugin = (T) bukkitPlugin; 79 | } catch (Exception e) { 80 | PluginLogger.error("Exception while loading plugin '{0}'. Is it up-to-date ?", e, pluginName); 81 | this.setEnabled(false); 82 | return; 83 | } 84 | 85 | onLoad(); 86 | } 87 | 88 | /** 89 | * Returns the external plugin. 90 | * If this component failed to inizialize, an IllegalStateException will be 91 | * thrown. 92 | * 93 | * @return The external plugin. 94 | */ 95 | protected T get() { 96 | if (!this.isEnabled()) { 97 | throw new IllegalStateException("External plugin " + pluginName + " could not be loaded."); 98 | } 99 | return plugin; 100 | } 101 | 102 | /** 103 | * This method is called after the external plugin has been found. 104 | * It replaces onEnable(). 105 | */ 106 | protected void onLoad() { 107 | } 108 | 109 | /** 110 | * Returns the name of the external plugin. 111 | * 112 | * @return The specified name of the external plugin. 113 | */ 114 | public String getPluginName() { 115 | return pluginName; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/tools/Callback.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; 32 | 33 | public interface Callback { 34 | 35 | void call(T parameter); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/tools/FileUtils.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; 32 | 33 | import java.io.BufferedReader; 34 | import java.io.File; 35 | import java.io.FileReader; 36 | import java.io.FileWriter; 37 | import java.io.IOException; 38 | 39 | 40 | public final class FileUtils { 41 | private FileUtils() { 42 | } 43 | 44 | /** 45 | * Reads a file, returns its content into a String. Returns an empty string if the file is 46 | * unreachable. 47 | * 48 | * @param file The file to read. 49 | * @return The file content. 50 | */ 51 | public static String readFile(File file) { 52 | BufferedReader reader = null; 53 | 54 | try { 55 | StringBuilder content = new StringBuilder(); 56 | reader = new BufferedReader(new FileReader(file)); 57 | 58 | for (String line; (line = reader.readLine()) != null; ) { 59 | content.append(line).append('\n'); 60 | } 61 | 62 | return content.toString(); 63 | } catch (IOException e) { 64 | return ""; 65 | } finally { 66 | if (reader != null) { 67 | try { 68 | reader.close(); 69 | } catch (IOException ignored) { 70 | } 71 | } 72 | } 73 | } 74 | 75 | /** 76 | * Writes the given content into the file, replacing its content. 77 | * 78 | * @param file The file to write into. 79 | * @param content The content to write into the file. 80 | */ 81 | public static void writeFile(File file, String content) throws IOException { 82 | writeFile(file, content, true); 83 | } 84 | 85 | /** 86 | * Writes the given content into the file. 87 | * 88 | * @param file The file to write into. 89 | * @param content The content to write into the file. 90 | * @param overwrite {@code true} to overwrite, {@code false} to append. 91 | * @throws IOException if the file cannot be written to. 92 | */ 93 | public static void writeFile(File file, String content, boolean overwrite) throws IOException { 94 | FileWriter writer = null; 95 | 96 | try { 97 | writer = new FileWriter(file, !overwrite); 98 | writer.write(content); 99 | writer.close(); 100 | } finally { 101 | if (writer != null) { 102 | writer.close(); 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/tools/PluginLogger.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; 32 | 33 | import fr.zcraft.quartzlib.core.QuartzLib; 34 | import java.util.HashMap; 35 | import java.util.logging.Level; 36 | import java.util.logging.LogRecord; 37 | import java.util.logging.Logger; 38 | 39 | public final class PluginLogger { 40 | private static Thread mainThread; 41 | private static HashMap loggers; 42 | 43 | private PluginLogger() { 44 | } 45 | 46 | public static void init() { 47 | mainThread = Thread.currentThread(); 48 | loggers = new HashMap<>(); 49 | } 50 | 51 | public static void log(Level level, String message, Throwable ex) { 52 | getLogger().log(level, message, ex); 53 | } 54 | 55 | public static void log(Level level, String message, Object... args) { 56 | getLogger().log(level, message, args); 57 | } 58 | 59 | public static void log(Level level, String message, Throwable ex, Object... args) { 60 | log(level, message, args); 61 | log(level, "Exception : ", ex); 62 | } 63 | 64 | public static void info(String message, Object... args) { 65 | log(Level.INFO, message, args); 66 | } 67 | 68 | public static void warning(String message, Object... args) { 69 | log(Level.WARNING, message, args); 70 | } 71 | 72 | public static void warning(String message, Throwable ex) { 73 | log(Level.WARNING, message, ex); 74 | } 75 | 76 | public static void warning(String message, Throwable ex, Object... args) { 77 | log(Level.WARNING, message, ex, args); 78 | } 79 | 80 | public static void error(String message) { 81 | log(Level.SEVERE, message); 82 | } 83 | 84 | public static void error(String message, Throwable ex) { 85 | log(Level.SEVERE, message, ex); 86 | } 87 | 88 | public static void error(String message, Throwable ex, Object... args) { 89 | log(Level.SEVERE, message, ex, args); 90 | } 91 | 92 | public static void error(String message, Object... args) { 93 | log(Level.SEVERE, message, args); 94 | } 95 | 96 | private static Logger getLogger() { 97 | Thread currentThread = Thread.currentThread(); 98 | if (currentThread.equals(mainThread)) { 99 | return QuartzLib.getPlugin().getLogger(); 100 | } 101 | return getLogger(currentThread); 102 | } 103 | 104 | private static Logger getLogger(Thread thread) { 105 | PluginThreadLogger logger = loggers.get(thread); 106 | if (logger == null) { 107 | logger = new PluginThreadLogger(thread); 108 | loggers.put(thread, logger); 109 | } 110 | return logger; 111 | } 112 | 113 | private static class PluginThreadLogger extends Logger { 114 | private final String loggerName; 115 | 116 | public PluginThreadLogger(Thread thread) { 117 | super(QuartzLib.getPlugin().getClass().getCanonicalName(), null); 118 | setParent(QuartzLib.getPlugin().getLogger()); 119 | setLevel(Level.ALL); 120 | loggerName = "[" + thread.getName() + "] "; 121 | } 122 | 123 | @Override 124 | public void log(LogRecord logRecord) { 125 | logRecord.setMessage(loggerName + logRecord.getMessage()); 126 | super.log(logRecord); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/tools/items/ColorableMaterial.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.items; 32 | 33 | import org.bukkit.ChatColor; 34 | import org.bukkit.DyeColor; 35 | import org.bukkit.Material; 36 | 37 | /** 38 | * A {@link Material} with color variants. 39 | * 40 | *

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/main/java/fr/zcraft/quartzlib/tools/mojang/MojangHead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Plugin UHCReloaded : Alliances 3 | * 4 | * Copyright ou © ou Copr. Amaury Carrade (2016) 5 | * Idées et réflexions : Alexandre Prokopowicz, Amaury Carrade, "Vayan". 6 | * 7 | * Ce logiciel est régi par la licence CeCILL soumise au droit français et 8 | * respectant les principes de diffusion des logiciels libres. Vous pouvez 9 | * utiliser, modifier et/ou redistribuer ce programme sous les conditions 10 | * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA 11 | * sur le site "http://www.cecill.info". 12 | * 13 | * En contrepartie de l'accessibilité au code source et des droits de copie, 14 | * de modification et de redistribution accordés par cette licence, il n'est 15 | * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, 16 | * seule une responsabilité restreinte pèse sur l'auteur du programme, le 17 | * titulaire des droits patrimoniaux et les concédants successifs. 18 | * 19 | * A cet égard l'attention de l'utilisateur est attirée sur les risques 20 | * associés au chargement, à l'utilisation, à la modification et/ou au 21 | * développement et à la reproduction du logiciel par l'utilisateur étant 22 | * donné sa spécificité de logiciel libre, qui peut le rendre complexe à 23 | * manipuler et qui le réserve donc à des développeurs et des professionnels 24 | * avertis possédant des connaissances informatiques approfondies. Les 25 | * utilisateurs sont donc invités à charger et tester l'adéquation du 26 | * logiciel à leurs besoins dans des conditions permettant d'assurer la 27 | * sécurité de leurs systèmes et ou de leurs données et, plus généralement, 28 | * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. 29 | * 30 | * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez 31 | * pris connaissance de la licence CeCILL, et que vous en avez accepté les 32 | * termes. 33 | */ 34 | 35 | package fr.zcraft.quartzlib.tools.mojang; 36 | 37 | import com.google.common.base.CaseFormat; 38 | import fr.zcraft.quartzlib.tools.items.ItemStackBuilder; 39 | import org.bukkit.Material; 40 | import org.bukkit.inventory.ItemStack; 41 | import org.bukkit.inventory.meta.SkullMeta; 42 | 43 | /** 44 | * Easier access to Mojang's “Marc's Head Format” Heads, e.g. for use in GUIs. 45 | * 46 | *

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/tools/reflection/NMSException.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 | /** 34 | * Represents an exception thrown while accessing Minecraft NMS classes. 35 | */ 36 | public class NMSException extends Exception { 37 | public NMSException(String text, Throwable cause) { 38 | super(text, cause); 39 | } 40 | 41 | public NMSException(String text) { 42 | super(text); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/tools/runners/RunTask.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.runners; 32 | 33 | import fr.zcraft.quartzlib.core.QuartzLib; 34 | import org.bukkit.Bukkit; 35 | import org.bukkit.scheduler.BukkitRunnable; 36 | import org.bukkit.scheduler.BukkitScheduler; 37 | import org.bukkit.scheduler.BukkitTask; 38 | 39 | 40 | /** 41 | * This utility class shortens the code used to execute tasks. 42 | */ 43 | public final class RunTask { 44 | private static final BukkitScheduler scheduler = Bukkit.getScheduler(); 45 | 46 | private RunTask() { 47 | } 48 | 49 | /** 50 | * Returns a task that will run on the next server tick. 51 | * 52 | * @param runnable The task to be run. 53 | * @return The BukkitTask that will run. 54 | */ 55 | public static BukkitTask nextTick(Runnable runnable) { 56 | return scheduler.runTask(QuartzLib.getPlugin(), runnable); 57 | } 58 | 59 | /** 60 | * Returns a task that will run on the next server tick. 61 | * 62 | * @param runnable The task to be run. 63 | * @return The BukkitTask that will run. 64 | */ 65 | public static BukkitTask nextTick(BukkitRunnable runnable) { 66 | return runnable.runTask(QuartzLib.getPlugin()); 67 | } 68 | 69 | /** 70 | * Returns a task that will run after the specified number of server ticks. 71 | * 72 | * @param runnable The task to be run. 73 | * @param delay The ticks to wait before running the task. 74 | * @return The BukkitTask that will run. 75 | */ 76 | public static BukkitTask later(Runnable runnable, long delay) { 77 | return scheduler.runTaskLater(QuartzLib.getPlugin(), runnable, delay); 78 | } 79 | 80 | /** 81 | * Returns a task that will run after the specified number of server ticks. 82 | * 83 | * @param runnable The task to be run. 84 | * @param delay The ticks to wait before running the task. 85 | * @return The BukkitTask that will run. 86 | */ 87 | public static BukkitTask later(BukkitRunnable runnable, long delay) { 88 | return runnable.runTaskLater(QuartzLib.getPlugin(), delay); 89 | } 90 | 91 | /** 92 | * Returns a task that will repeatedly run until cancelled, starting after the specified number 93 | * of server ticks. 94 | * 95 | * @param runnable The task to be run. 96 | * @param wait The ticks to wait before running the task. 97 | * @param period The ticks to wait between runs 98 | * @return The BukkitTask that will run. 99 | */ 100 | public static BukkitTask timer(Runnable runnable, long wait, long period) { 101 | return scheduler.runTaskTimer(QuartzLib.getPlugin(), runnable, wait, period); 102 | } 103 | 104 | /** 105 | * Returns a task that will repeatedly run until cancelled, starting after the specified number 106 | * of server ticks. 107 | * 108 | * @param runnable The task to be run. 109 | * @param wait The ticks to wait before running the task. 110 | * @param period The ticks to wait between runs 111 | * @return The BukkitTask that will run. 112 | */ 113 | public static BukkitTask timer(BukkitRunnable runnable, long wait, long period) { 114 | return runnable.runTaskTimer(QuartzLib.getPlugin(), wait, period); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/tools/text/ChatColorParser.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.text; 32 | 33 | import java.util.EnumSet; 34 | import java.util.Iterator; 35 | import java.util.NoSuchElementException; 36 | import java.util.Set; 37 | import org.bukkit.ChatColor; 38 | import org.jetbrains.annotations.NotNull; 39 | 40 | public class ChatColorParser implements Iterator, Iterable { 41 | private final char delimiter; 42 | private final String string; 43 | private final Set currentModifiers = EnumSet.noneOf(ChatColor.class); 44 | private int previousPos = -2; 45 | private int currentPos = -1; 46 | private boolean done = false; 47 | private ChatColoredString nextString; 48 | 49 | public ChatColorParser(String string) { 50 | this('§', string); 51 | } 52 | 53 | /** 54 | * Creates a new chat color parser. 55 | */ 56 | public ChatColorParser(char delimiter, String string) { 57 | this.string = string; 58 | this.delimiter = delimiter; 59 | 60 | nextString = fetchNextPos(); 61 | } 62 | 63 | /** 64 | * Apply a given modifier to the current mutable set of modifiers. 65 | */ 66 | public static void applyModifier(Set currentModifiers, ChatColor newModifier) { 67 | if (newModifier == ChatColor.RESET) { 68 | currentModifiers.clear(); 69 | return; 70 | } else if (newModifier.isColor()) { 71 | for (ChatColor color : ChatColor.values()) { 72 | if (!color.isColor()) { 73 | continue; 74 | } 75 | currentModifiers.remove(color); 76 | } 77 | } 78 | 79 | currentModifiers.add(newModifier); 80 | } 81 | 82 | @Override 83 | public boolean hasNext() { 84 | return nextString != null; 85 | } 86 | 87 | @Override 88 | public ChatColoredString next() { 89 | if (nextString == null) { 90 | throw new NoSuchElementException(); 91 | } 92 | 93 | ChatColoredString currentString = nextString; 94 | nextString = fetchNextPos(); 95 | return currentString; 96 | } 97 | 98 | @Override 99 | public void remove() { 100 | throw new UnsupportedOperationException("remove"); 101 | } 102 | 103 | @Override 104 | public @NotNull Iterator iterator() { 105 | return this; 106 | } 107 | 108 | private ChatColor getCurrentColor() { 109 | ChatColor color = ChatColor.getByChar(string.charAt(currentPos + 1)); 110 | if (color == null) { 111 | throw new IllegalArgumentException("Invalid token : invalid color code :" + string.charAt(currentPos + 1)); 112 | } 113 | 114 | return color; 115 | } 116 | 117 | private ChatColoredString fetchNextPos() { 118 | if (done) { 119 | return null; 120 | } 121 | 122 | while (true) { 123 | currentPos = string.indexOf(delimiter, currentPos + 1); 124 | if (currentPos == -1) { 125 | done = true; 126 | break; 127 | } 128 | 129 | if (currentPos >= string.length() - 1) { 130 | throw new IllegalArgumentException("Invalid token : found delimiter without color code."); 131 | } 132 | 133 | //Color code mode 134 | if (currentPos == previousPos + 2) { 135 | applyModifier(currentModifiers, getCurrentColor()); 136 | } else { 137 | ChatColoredString str = 138 | new ChatColoredString(currentModifiers, string.substring(previousPos + 2, currentPos)); 139 | 140 | applyModifier(currentModifiers, getCurrentColor()); 141 | previousPos = currentPos; 142 | return str; 143 | } 144 | 145 | previousPos = currentPos; 146 | } 147 | 148 | return new ChatColoredString(currentModifiers, string.substring(previousPos + 2)); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/tools/text/ChatColoredString.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.text; 32 | 33 | import java.util.Collection; 34 | import java.util.Collections; 35 | import java.util.EnumSet; 36 | import java.util.Set; 37 | import org.bukkit.ChatColor; 38 | 39 | public class ChatColoredString { 40 | private final Set modifiers; 41 | private final String string; 42 | 43 | public ChatColoredString(Collection modifiers, String string) { 44 | this.modifiers = Collections.unmodifiableSet(EnumSet.copyOf(modifiers)); 45 | this.string = string; 46 | } 47 | 48 | public String getString() { 49 | return string; 50 | } 51 | 52 | public Set getModifiers() { 53 | return modifiers; 54 | } 55 | 56 | /** 57 | * Builds a string of the chat color using the given delimiter. 58 | */ 59 | public String toString(char delimiter) { 60 | StringBuilder builder = new StringBuilder(); 61 | 62 | for (ChatColor modifier : modifiers) { 63 | builder.append(delimiter); 64 | builder.append(modifier.getChar()); 65 | } 66 | 67 | builder.append(string); 68 | return builder.toString(); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return toString('§'); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/fr/zcraft/quartzlib/tools/world/WorldUtils.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.world; 32 | 33 | import org.bukkit.Location; 34 | import org.bukkit.block.BlockFace; 35 | 36 | /** 37 | * Utility class for dealing with worlds and locations. 38 | */ 39 | public class WorldUtils { 40 | /** 41 | * Returns if the two given locations point to the same block, i.e if their 42 | * block coordinates are equal. 43 | * 44 | * @param loc1 The first location 45 | * @param loc2 The second location 46 | * @return True if the two given locations point to the same block. 47 | */ 48 | public static boolean blockEquals(Location loc1, Location loc2) { 49 | return loc1.getBlockX() == loc2.getBlockX() 50 | && loc1.getBlockY() == loc2.getBlockY() 51 | && loc1.getBlockZ() == loc2.getBlockZ(); 52 | } 53 | 54 | /** 55 | * Returns the orientation of the specified location, as a BlockFace. 56 | * The precision of the returned BlockFace is restricted to NORTH, SOUTH, 57 | * EAST and WEST only. 58 | * 59 | * @param loc The location. 60 | * @return the orientation of the specified location, as a BlockFace. 61 | */ 62 | public static BlockFace get4thOrientation(Location loc) { 63 | float yaw = Math.abs(loc.getYaw()) - 180f; 64 | 65 | if (yaw <= 45 && yaw > -45) { 66 | return BlockFace.NORTH; 67 | } 68 | 69 | if (yaw <= -45 && yaw > -135) { 70 | return BlockFace.WEST; 71 | } 72 | 73 | if (yaw <= -135 || yaw > 135) { 74 | return BlockFace.SOUTH; 75 | } 76 | 77 | if (yaw <= 135 && yaw > 45) { 78 | return BlockFace.EAST; 79 | } 80 | 81 | return BlockFace.SELF; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/test/java/fr/zcraft/quartzlib/TestsUtils.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; 32 | 33 | import java.io.File; 34 | import java.io.FileOutputStream; 35 | import java.io.IOException; 36 | import java.io.InputStream; 37 | import java.io.OutputStream; 38 | 39 | 40 | public class TestsUtils { 41 | public static InputStream getResource(String name) { 42 | ClassLoader loader = Thread.currentThread().getContextClassLoader(); 43 | return loader.getResourceAsStream(name); 44 | } 45 | 46 | /** 47 | * Writes a resource to a temporary file. 48 | */ 49 | public static File tempResource(String name) throws IOException { 50 | String[] fileNameParts = name.split("\\."); 51 | String extension = null; 52 | if (fileNameParts.length >= 2) { 53 | extension = fileNameParts[fileNameParts.length - 1]; 54 | } 55 | 56 | InputStream inputStream = getResource(name); 57 | File tempFile = File.createTempFile("quartzlib-unit-tests-" + name.replace(".", "-"), 58 | ".tmp" + (extension != null ? "." + extension : "")); 59 | 60 | OutputStream outputStream = new FileOutputStream(tempFile); 61 | 62 | int read; 63 | byte[] bytes = new byte[1024]; 64 | 65 | while ((read = inputStream.read(bytes)) != -1) { 66 | outputStream.write(bytes, 0, read); 67 | } 68 | 69 | return tempFile; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/fr/zcraft/quartzlib/Toaster.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.quartzlib; 32 | 33 | import fr.zcraft.quartzlib.core.QuartzPlugin; 34 | import fr.zcraft.quartzlib.tools.PluginLogger; 35 | import java.io.File; 36 | import org.bukkit.plugin.PluginDescriptionFile; 37 | import org.bukkit.plugin.java.JavaPluginLoader; 38 | 39 | public class Toaster extends QuartzPlugin { 40 | protected Toaster(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { 41 | super(loader, description, dataFolder, file); 42 | } 43 | 44 | @Override 45 | public void onEnable() { 46 | PluginLogger.info("Setting up toaster."); 47 | } 48 | 49 | @Override 50 | public void onDisable() { 51 | PluginLogger.info("Unplugging toaster."); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/fr/zcraft/quartzlib/components/rawtext/ChatColorParserTest.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.rawtext; 32 | 33 | import fr.zcraft.quartzlib.tools.text.ChatColorParser; 34 | import fr.zcraft.quartzlib.tools.text.ChatColoredString; 35 | import java.util.EnumSet; 36 | import org.bukkit.ChatColor; 37 | import org.junit.Assert; 38 | import org.junit.jupiter.api.Test; 39 | 40 | public class ChatColorParserTest { 41 | @Test 42 | public void helloWorldTest() { 43 | String chatColoredText = ChatColor.RED + "Hello" + ChatColor.GREEN + " world !"; 44 | ChatColorParser parser = new ChatColorParser(chatColoredText); 45 | 46 | Assert.assertTrue(parser.hasNext()); 47 | ChatColoredString str = parser.next(); 48 | Assert.assertEquals("Hello", str.getString()); 49 | Assert.assertEquals(str.getModifiers(), EnumSet.of(ChatColor.RED)); 50 | 51 | Assert.assertTrue(parser.hasNext()); 52 | str = parser.next(); 53 | Assert.assertEquals(" world !", str.getString()); 54 | Assert.assertEquals(str.getModifiers(), EnumSet.of(ChatColor.GREEN)); 55 | 56 | Assert.assertFalse(parser.hasNext()); 57 | } 58 | 59 | @Test 60 | public void emptyTest() { 61 | ChatColorParser parser = new ChatColorParser(""); 62 | 63 | Assert.assertTrue(parser.hasNext()); 64 | ChatColoredString str = parser.next(); 65 | Assert.assertEquals("", str.getString()); 66 | Assert.assertEquals(str.getModifiers(), EnumSet.noneOf(ChatColor.class)); 67 | 68 | Assert.assertFalse(parser.hasNext()); 69 | } 70 | 71 | @Test 72 | public void delimiterAtTheEndTest() { 73 | ChatColorParser parser = new ChatColorParser(ChatColor.RED.toString()); 74 | 75 | Assert.assertTrue(parser.hasNext()); 76 | ChatColoredString str = parser.next(); 77 | Assert.assertEquals("", str.getString()); 78 | Assert.assertEquals(str.getModifiers(), EnumSet.of(ChatColor.RED)); 79 | 80 | Assert.assertFalse(parser.hasNext()); 81 | } 82 | 83 | @Test 84 | public void resetTest() { 85 | ChatColorParser parser = new ChatColorParser(ChatColor.RED + "Hello" + ChatColor.RESET + " world !"); 86 | 87 | Assert.assertTrue(parser.hasNext()); 88 | ChatColoredString str = parser.next(); 89 | Assert.assertEquals("Hello", str.getString()); 90 | Assert.assertEquals(str.getModifiers(), EnumSet.of(ChatColor.RED)); 91 | 92 | Assert.assertTrue(parser.hasNext()); 93 | str = parser.next(); 94 | Assert.assertEquals(" world !", str.getString()); 95 | Assert.assertEquals(str.getModifiers(), EnumSet.noneOf(ChatColor.class)); 96 | 97 | Assert.assertFalse(parser.hasNext()); 98 | } 99 | 100 | @Test 101 | public void doubleCodeTest() { 102 | ChatColorParser parser = new ChatColorParser(ChatColor.RED + "" + ChatColor.UNDERLINE + "Hello"); 103 | 104 | Assert.assertTrue(parser.hasNext()); 105 | ChatColoredString str = parser.next(); 106 | Assert.assertEquals("Hello", str.getString()); 107 | Assert.assertEquals(str.getModifiers(), EnumSet.of(ChatColor.RED, ChatColor.UNDERLINE)); 108 | 109 | Assert.assertFalse(parser.hasNext()); 110 | } 111 | 112 | @Test 113 | public void colorTest() { 114 | String chatColoredText = ChatColor.RED + "" + ChatColor.UNDERLINE + "Hello" + ChatColor.GREEN + " world !"; 115 | ChatColorParser parser = new ChatColorParser(chatColoredText); 116 | 117 | Assert.assertTrue(parser.hasNext()); 118 | ChatColoredString str = parser.next(); 119 | Assert.assertEquals("Hello", str.getString()); 120 | Assert.assertEquals(str.getModifiers(), EnumSet.of(ChatColor.RED, ChatColor.UNDERLINE)); 121 | 122 | Assert.assertTrue(parser.hasNext()); 123 | str = parser.next(); 124 | Assert.assertEquals(" world !", str.getString()); 125 | Assert.assertEquals(str.getModifiers(), EnumSet.of(ChatColor.GREEN, ChatColor.UNDERLINE)); 126 | 127 | Assert.assertFalse(parser.hasNext()); 128 | 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /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 | HashMap headNames = new HashMap<>(); 33 | 34 | headNames.put(MojangHead.ALEX, "MHF_Alex"); 35 | headNames.put(MojangHead.BLAZE, "MHF_Blaze"); 36 | headNames.put(MojangHead.CAVE_SPIDER, "MHF_CaveSpider"); 37 | headNames.put(MojangHead.CHICKEN, "MHF_Chicken"); 38 | headNames.put(MojangHead.COW, "MHF_Cow"); 39 | headNames.put(MojangHead.CREEPER, "MHF_Creeper"); 40 | headNames.put(MojangHead.ENDERMAN, "MHF_Enderman"); 41 | headNames.put(MojangHead.GHAST, "MHF_Ghast"); 42 | headNames.put(MojangHead.GOLEM, "MHF_Golem"); 43 | headNames.put(MojangHead.HEROBRINE, "MHF_Herobrine"); 44 | headNames.put(MojangHead.LAVA_SLIME, "MHF_LavaSlime"); 45 | headNames.put(MojangHead.MUSHROOM_COW, "MHF_MushroomCow"); 46 | headNames.put(MojangHead.OCELOT, "MHF_Ocelot"); 47 | headNames.put(MojangHead.PIG, "MHF_Pig"); 48 | headNames.put(MojangHead.PIG_ZOMBIE, "MHF_PigZombie"); 49 | headNames.put(MojangHead.SHEEP, "MHF_Sheep"); 50 | headNames.put(MojangHead.SKELETON, "MHF_Skeleton"); 51 | headNames.put(MojangHead.SLIME, "MHF_Slime"); 52 | headNames.put(MojangHead.SPIDER, "MHF_Spider"); 53 | headNames.put(MojangHead.SQUID, "MHF_Squid"); 54 | headNames.put(MojangHead.STEVE, "MHF_Steve"); 55 | headNames.put(MojangHead.VILLAGER, "MHF_Villager"); 56 | headNames.put(MojangHead.WITHER_SKELETON, "MHF_WSkeleton"); 57 | headNames.put(MojangHead.ZOMBIE, "MHF_Zombie"); 58 | 59 | headNames.put(MojangHead.CACTUS, "MHF_Cactus"); 60 | headNames.put(MojangHead.CAKE, "MHF_Cake"); 61 | headNames.put(MojangHead.CHEST, "MHF_Chest"); 62 | headNames.put(MojangHead.COCONUT_BROWN, "MHF_CoconutB"); 63 | headNames.put(MojangHead.COCONUT_GREEN, "MHF_CoconutG"); 64 | headNames.put(MojangHead.MELON, "MHF_Melon"); 65 | headNames.put(MojangHead.OAK_LOG, "MHF_OakLog"); 66 | headNames.put(MojangHead.PRESENT, "MHF_Present1"); 67 | headNames.put(MojangHead.PRESENT_2, "MHF_Present2"); 68 | headNames.put(MojangHead.PUMPKIN, "MHF_Pumpkin"); 69 | headNames.put(MojangHead.TNT, "MHF_TNT"); 70 | headNames.put(MojangHead.TNT_2, "MHF_TNT2"); 71 | 72 | headNames.put(MojangHead.ARROW_UP, "MHF_ArrowUp"); 73 | headNames.put(MojangHead.ARROW_DOWN, "MHF_ArrowDown"); 74 | headNames.put(MojangHead.ARROW_LEFT, "MHF_ArrowLeft"); 75 | headNames.put(MojangHead.ARROW_RIGHT, "MHF_ArrowRight"); 76 | headNames.put(MojangHead.EXCLAMATION, "MHF_Exclamation"); 77 | headNames.put(MojangHead.QUESTION, "MHF_Question"); 78 | 79 | Assert.assertEquals(headNames.size(), MojangHead.values().length); 80 | Assert.assertTrue(headNames.keySet().containsAll(Arrays.asList(MojangHead.values().clone()))); 81 | 82 | headNames.forEach((head, name) -> Assert.assertEquals(name, head.getHeadName())); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/en_US.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "Project-Id-Version: PACKAGE VERSION\n" 9 | "Report-Msgid-Bugs-To: AmauryCarrade\n" 10 | "POT-Creation-Date: 2016-01-15 23:46+0100\n" 11 | "PO-Revision-Date: 2016-01-16 04:04+0100\n" 12 | "Last-Translator: Amaury Carrade\n" 13 | "Language-Team: Amaury Carrade\n" 14 | "Language: fr_FR\n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=UTF-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Plural-Forms: nplurals=2; plural=n>1;\n" 19 | 20 | #: fr/zcraft/ztoaster/ToasterSidebar.java:75 21 | msgid "{darkgreen}{bold}Cook" 22 | msgstr "{darkgreen}{bold}Cook" 23 | 24 | #: fr/zcraft/ztoaster/ToasterSidebar.java:78 25 | msgid "{yellow}{bold}Inside the toaster" 26 | msgstr "{yellow}{bold}Inside da toasterr" 27 | 28 | #: fr/zcraft/ztoaster/ToasterSidebar.java:81 29 | msgid "{gold}{bold}Cooked" 30 | msgstr "{gold}{bold}Cooked" 31 | 32 | #: fr/zcraft/ztoaster/ToasterSidebar.java:90 33 | msgid "{red}{bold}♨ Toaster ♨" 34 | msgstr "{red}{bold}♨ Toaster ♨" 35 | 36 | #: fr/zcraft/ztoaster/ToasterSidebar.java:93 37 | msgid "{blue}Toaster" 38 | msgstr "{blue}Toaster" 39 | 40 | #: fr/zcraft/ztoaster/ToastExplorer.java:44 41 | msgid "{black}Toaster contents" 42 | msgstr "{black}Toaster contents" 43 | 44 | #. Title of the cooked toast item in GUI 45 | #: fr/zcraft/ztoaster/ToastExplorer.java:57 46 | msgid "{white}Cooked toast #{0}" 47 | msgstr "{white}Cooked toast #{0}" 48 | 49 | #. Title of the raw toast item in GUI 50 | #: fr/zcraft/ztoaster/ToastExplorer.java:60 51 | msgid "{white}Raw toast #{0}" 52 | msgstr "{white}Raw toast #{0}" 53 | 54 | #: fr/zcraft/ztoaster/commands/AddCommand.java:56 55 | #, possible-java-format 56 | msgid "DING! Toast {0} is ready !" 57 | msgstr "DING! Toast {0} is ready !" 58 | 59 | #: fr/zcraft/ztoaster/commands/AddCommand.java:64 60 | msgid "{ce}Oh no! A toasted exception !" 61 | msgstr "{ce}Oh no! A toasted exception !" 62 | 63 | #: fr/zcraft/ztoaster/commands/AddCommand.java:65 64 | msgid "{ce}See toaster logs for details." 65 | msgstr "{ce}See toaster logs for details." 66 | 67 | #: fr/zcraft/ztoaster/commands/AddCommand.java:69 68 | #, possible-java-format 69 | msgid "Toast {0} added." 70 | msgstr "Toast {0} added." 71 | 72 | #: fr/zcraft/ztoaster/commands/AddCommand.java:63 73 | #, java-format 74 | msgid "One toast added." 75 | msgid_plural "{0} toasts added." 76 | msgstr[0] "One toast added." 77 | msgstr[1] "{0} toasts added." 78 | 79 | #. Output of the command /toaster list, without toasts. 80 | #: fr/zcraft/ztoaster/commands/ListCommand.java:74 81 | msgid "There are no toasts here ..." 82 | msgstr "There are no toasts here ..." 83 | 84 | #: fr/zcraft/ztoaster/commands/ListCommand.java:79 85 | #, java-format 86 | msgid " Toast #{0}" 87 | msgstr " Toast #{0}" 88 | -------------------------------------------------------------------------------- /src/test/resources/i18n/fr_FR.po: -------------------------------------------------------------------------------- 1 | # Testing data for the PO parser and translator 2 | # Copyright (C) 2015-2020 QuartzLib contributors 3 | # This file is distributed under the CeCILL-B license. 4 | # 5 | #, fuzzy 6 | msgid "" 7 | msgstr "Project-Id-Version: PACKAGE VERSION\n" 8 | "Report-Msgid-Bugs-To: AmauryCarrade\n" 9 | "POT-Creation-Date: 2016-01-15 23:46+0100\n" 10 | "PO-Revision-Date: 2016-01-16 04:04+0100\n" 11 | "Last-Translator: Amaury Carrade\n" 12 | "Language-Team: Amaury Carrade\n" 13 | "Language: fr_FR\n" 14 | "MIME-Version: 1.0\n" 15 | "Content-Type: text/plain; charset=UTF-8\n" 16 | "Content-Transfer-Encoding: 8bit\n" 17 | "Plural-Forms: nplurals=2; plural=n>1;\n" 18 | 19 | #: fr/zcraft/ztoaster/ToasterSidebar.java:75 20 | msgctxt "sidebar" 21 | msgid "{darkgreen}{bold}Cook" 22 | msgstr "{darkgreen}{bold}Cuistot" 23 | 24 | #: fr/zcraft/ztoaster/ToasterSidebar.java:78 25 | msgctxt "sidebar" 26 | msgid "{yellow}{bold}Inside the toaster" 27 | msgstr "{yellow}{bold}Dans le grille-pain" 28 | 29 | #: fr/zcraft/ztoaster/ToasterSidebar.java:81 30 | msgctxt "sidebar" 31 | msgid "{gold}{bold}Cooked" 32 | msgstr "{gold}{bold}Cuit" 33 | 34 | #: fr/zcraft/ztoaster/ToasterSidebar.java:90 35 | msgctxt "sidebar" 36 | msgid "{red}{bold}♨ Toaster ♨" 37 | msgstr "{red}{bold}♨ Grille-pain ♨" 38 | 39 | #: fr/zcraft/ztoaster/ToasterSidebar.java:93 40 | msgctxt "sidebar" 41 | msgid "{blue}Toaster" 42 | msgstr "{blue}Grille-pain" 43 | 44 | #: fr/zcraft/ztoaster/ToastExplorer.java:44 45 | msgid "{black}Toaster contents" 46 | msgstr "{black}Contenu du grille-pain" 47 | 48 | #. Title of the cooked toast item in GUI 49 | #: fr/zcraft/ztoaster/ToastExplorer.java:57 50 | msgid "{white}Cooked toast #{0}" 51 | msgstr "{white}Pain grillé no. {0}" 52 | 53 | #. Title of the raw toast item in GUI 54 | #: fr/zcraft/ztoaster/ToastExplorer.java:60 55 | msgid "{white}Raw toast #{0}" 56 | msgstr "{white}Pain pas grillé no. {0}" 57 | 58 | #: fr/zcraft/ztoaster/commands/AddCommand.java:56 59 | #, possible-java-format 60 | msgid "DING! Toast {0} is ready !" 61 | msgstr "DING ! Le pain grillé {0} est prêt !" 62 | 63 | #: fr/zcraft/ztoaster/commands/AddCommand.java:64 64 | msgid "{ce}Oh no! A toasted exception !" 65 | msgstr "{ce}Oh non ! Une exception grillée !" 66 | 67 | #: fr/zcraft/ztoaster/commands/AddCommand.java:65 68 | msgid "{ce}See toaster logs for details." 69 | msgstr "{ce}Voir les logs du grille-pain pour plus de détails." 70 | 71 | #: fr/zcraft/ztoaster/commands/AddCommand.java:69 72 | #, possible-java-format 73 | msgid "Toast {0} added." 74 | msgstr "Pain {0} ajouté." 75 | 76 | #: fr/zcraft/ztoaster/commands/AddCommand.java:63 77 | #, java-format 78 | msgid "One toast added." 79 | msgid_plural "{0} toasts added." 80 | msgstr[0] "Un pain ajouté." 81 | msgstr[1] "{0} pains ajoutés." 82 | 83 | #. Output of the command /toaster list, without toasts. 84 | #: fr/zcraft/ztoaster/commands/ListCommand.java:74 85 | msgid "There are no toasts here ..." 86 | msgstr "Il n'y a pas de pain grillé ici..." 87 | 88 | #: fr/zcraft/ztoaster/commands/ListCommand.java:79 89 | #, java-format 90 | msgid " Toast #{0}" 91 | msgstr " Pain grillé no. {0}" 92 | 93 | #: fr/zcraft/ztoaster/Nowhere.java:4269 94 | msgid "It's just a \"toaster\"" 95 | msgstr "Ce n'est qu'un \"toaster\"" 96 | 97 | #: fr/zcraft/ztoaster/Nowhere.java:1984 98 | msgid "Multi-lines" 99 | "message" 100 | msgstr "Message" 101 | "multi-ligne" 102 | 103 | #: fr/zcraft/ztoaster/Nowhere.java:1984 104 | msgid "Multi-lines " 105 | "message with trailing space" 106 | msgstr "Message" 107 | " multi-ligne avec une espace séparatrice explicite" 108 | 109 | #: fr/zcraft/ztoaster/Nowhere.java:1337 110 | msgid "Multi-lines " 111 | " message with multiple trailing spaces" 112 | msgstr "Message " 113 | " multi-ligne avec plusieurs espaces séparatrices explicites" 114 | 115 | #: src/main/java/eu/carrade/amaury/UHCReloaded/borders/BorderManager.java:426 116 | msgid "" 117 | "{gray}It will shrink by one block every {0} second(s) until {1} blocks in " 118 | "diameter." 119 | msgstr "" 120 | "{gray}Elle réduira d'un bloc toutes les {0} seconde(s) jusqu'à atteindre " 121 | "{1} blocs de diamètre." 122 | 123 | #msgid "{gray}When clicked, a sign will open; write the name of the team inside." 124 | #msgstr "" 125 | #"{gray}Cliquez ici pour ouvrir un panneau, et écrivez le nom de l'équipe " 126 | #"dedans." -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | fr.zcraft 8 | ztoaster 9 | 0.0.1-SNAPSHOT 10 | jar 11 | 12 | Ztoaster 13 | 14 | 15 | 1.8 16 | UTF-8 17 | 18 | 19 | 20 | 21 | 22 | org.apache.maven.plugins 23 | maven-compiler-plugin 24 | 3.8.1 25 | 26 | ${java.version} 27 | ${java.version} 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-shade-plugin 33 | 3.2.4 34 | 35 | 36 | package 37 | 38 | shade 39 | 40 | 41 | false 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | src/main/resources 50 | true 51 | 52 | 53 | 54 | 55 | 56 | 57 | spigotmc-repo 58 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 59 | 60 | 61 | 62 | 63 | 64 | org.bukkit 65 | bukkit 66 | 1.15.2-R0.1-SNAPSHOT 67 | provided 68 | 69 | 70 | fr.zcraft 71 | quartzlib 72 | 0.0.1-SNAPSHOT 73 | 74 | 75 | com.github.seeseemelk 76 | MockBukkit-v1.16 77 | 0.16.0 78 | test 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /ztoaster/src/main/java/fr/zcraft/ztoaster/Toast.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 | public class Toast { 34 | private final int toastId; 35 | private CookingStatus status = CookingStatus.NOT_COOKED; 36 | 37 | public Toast() { 38 | toastId = Toaster.newToastId(); 39 | } 40 | 41 | public CookingStatus getStatus() { 42 | return status; 43 | } 44 | 45 | public void setStatus(CookingStatus status) { 46 | this.status = status; 47 | } 48 | 49 | public int getToastId() { 50 | return toastId; 51 | } 52 | 53 | public enum CookingStatus { 54 | COOKED, IN_OVEN, NOT_COOKED 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ztoaster/src/main/java/fr/zcraft/ztoaster/ToastExplorer.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.gui.ExplorerGui; 34 | import fr.zcraft.quartzlib.components.gui.GuiUtils; 35 | import fr.zcraft.quartzlib.components.i18n.I; 36 | import fr.zcraft.quartzlib.tools.items.ItemStackBuilder; 37 | import org.bukkit.Material; 38 | import org.bukkit.inventory.ItemStack; 39 | 40 | public class ToastExplorer extends ExplorerGui { 41 | @Override 42 | protected void onUpdate() { 43 | setTitle(I.t(getPlayerLocale(), "{black}Toaster contents")); 44 | 45 | setData(Toaster.getToasts()); 46 | 47 | // DO NOT TOUCH THE TOASTS ! 48 | setMode(ExplorerGui.Mode.READONLY); 49 | } 50 | 51 | @Override 52 | protected ItemStack getViewItem(Toast toast) { 53 | if (toast.getStatus().equals(Toast.CookingStatus.COOKED)) { // Title of the cooked toast item in GUI 54 | return GuiUtils.makeItem(Material.COOKED_PORKCHOP, 55 | I.t(getPlayerLocale(), "{white}Cooked toast #{0}", toast.getToastId())); 56 | } else { // Title of the raw toast item in GUI 57 | return new ItemStackBuilder(Material.PORKCHOP) 58 | .title(I.tl(getPlayerLocale(), "{white}Raw toast #{0}", toast.getToastId())) 59 | .glow(toast.getStatus() == Toast.CookingStatus.IN_OVEN) 60 | .item(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ztoaster/src/main/java/fr/zcraft/ztoaster/Toaster.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.commands.Commands; 34 | import fr.zcraft.quartzlib.components.gui.Gui; 35 | import fr.zcraft.quartzlib.components.i18n.I18n; 36 | import fr.zcraft.quartzlib.components.scoreboard.Sidebar; 37 | import fr.zcraft.quartzlib.components.scoreboard.SidebarScoreboard; 38 | import fr.zcraft.quartzlib.core.QuartzPlugin; 39 | import fr.zcraft.quartzlib.tools.PluginLogger; 40 | import fr.zcraft.quartzlib.tools.items.GlowEffect; 41 | import fr.zcraft.ztoaster.commands.AddCommand; 42 | import fr.zcraft.ztoaster.commands.ListCommand; 43 | import fr.zcraft.ztoaster.commands.OpenCommand; 44 | import java.io.File; 45 | import java.util.ArrayList; 46 | import java.util.Locale; 47 | import org.bukkit.entity.Player; 48 | import org.bukkit.event.EventHandler; 49 | import org.bukkit.event.EventPriority; 50 | import org.bukkit.event.Listener; 51 | import org.bukkit.event.player.PlayerJoinEvent; 52 | import org.bukkit.plugin.PluginDescriptionFile; 53 | import org.bukkit.plugin.java.JavaPluginLoader; 54 | 55 | 56 | public class Toaster extends QuartzPlugin implements Listener { 57 | /** 58 | * A counter for all the toasts created (until toaster restart). 59 | */ 60 | private static int toastCounter = 0; 61 | 62 | /** 63 | * A list of all the toasts. 64 | */ 65 | private static ArrayList toasts; 66 | 67 | /** 68 | * The screen of the toaster. 69 | */ 70 | private Sidebar toasterSidebar; 71 | 72 | public Toaster () {} 73 | 74 | protected Toaster(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { 75 | super(loader, description, dataFolder, file); 76 | } 77 | 78 | /** 79 | * . 80 | * @return The id for a new toast. 81 | */ 82 | public static int newToastId() { 83 | return toastCounter++; 84 | } 85 | 86 | /** 87 | * . 88 | * @return an array of all the toasts ever created (until toaster restart). 89 | */ 90 | public static Toast[] getToasts() { 91 | return toasts.toArray(new Toast[toasts.size()]); 92 | } 93 | 94 | /** 95 | * Adds a new toast to the world. 96 | * 97 | * @return the newly created toast. 98 | */ 99 | public static Toast newToast() { 100 | Toast toast = new Toast(); 101 | toasts.add(toast); 102 | return toast; 103 | } 104 | 105 | @Override 106 | public void onEnable() { 107 | PluginLogger.info("Setting up toaster."); 108 | 109 | toasts = new ArrayList<>(); 110 | toastCounter = 0; 111 | 112 | loadComponents(Gui.class, Commands.class, ToasterWorker.class, SidebarScoreboard.class, I18n.class, GlowEffect.class); 113 | 114 | Commands.register("toaster", AddCommand.class, OpenCommand.class, ListCommand.class); 115 | 116 | I18n.useDefaultPrimaryLocale(); 117 | I18n.setFallbackLocale(Locale.US); 118 | 119 | getServer().getPluginManager().registerEvents(this, this); 120 | 121 | 122 | toasterSidebar = new ToasterSidebar(); 123 | 124 | for (Player player : getServer().getOnlinePlayers()) { 125 | toasterSidebar.addRecipient(player); 126 | } 127 | 128 | toasterSidebar.runAutoRefresh(true); 129 | } 130 | 131 | @Override 132 | public void onDisable() { 133 | PluginLogger.info("Unplugging toaster."); 134 | } 135 | 136 | @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) 137 | public void onPlayerJoin(PlayerJoinEvent ev) { 138 | toasterSidebar.addRecipient(ev.getPlayer()); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /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 List getContent(Player player) { 67 | Locale playerLocale = I18n.getPlayerLocale(player); 68 | return Arrays.asList( 69 | I.tl(playerLocale, "{darkgreen}{bold}Cook"), 70 | player.getDisplayName(), 71 | "", 72 | I.tl(playerLocale, "{yellow}{bold}Inside the toaster"), 73 | insideTheToaster + "", 74 | "", 75 | I.tl(playerLocale, "{gold}{bold}Cooked"), 76 | (toastsCount - insideTheToaster) + "" 77 | ); 78 | } 79 | 80 | @Override 81 | public String getTitle(Player player) { 82 | if (insideTheToaster > 0) { 83 | return I.tl(I18n.getPlayerLocale(player), "{red}{bold}♨ Toaster ♨"); 84 | } else { 85 | return I.tl(I18n.getPlayerLocale(player), "{blue}Toaster"); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /ztoaster/src/main/java/fr/zcraft/ztoaster/ToasterWorker.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 | 32 | package fr.zcraft.ztoaster; 33 | 34 | import fr.zcraft.quartzlib.components.gui.Gui; 35 | import fr.zcraft.quartzlib.components.i18n.I; 36 | import fr.zcraft.quartzlib.components.worker.Worker; 37 | import fr.zcraft.quartzlib.components.worker.WorkerCallback; 38 | import fr.zcraft.quartzlib.components.worker.WorkerRunnable; 39 | import fr.zcraft.quartzlib.tools.PluginLogger; 40 | import org.bukkit.entity.Player; 41 | 42 | public class ToasterWorker extends Worker { 43 | /** 44 | * Optimal cooking time for making carefully baked toasts. 45 | */ 46 | public static int TOAST_COOKING_TIME = 4269; 47 | 48 | public static Toast addToast(final Player cook) { 49 | return ToasterWorker.addToast(new WorkerCallback() { 50 | @Override 51 | public void finished(Integer toastId) { 52 | I.sendT(cook, "DING! Toast {0} is ready !", toastId); 53 | Gui.update(ToastExplorer.class); 54 | } 55 | 56 | @Override 57 | public void errored(Throwable exception) { 58 | PluginLogger.error("Error while toasting", exception); 59 | I.sendT(cook, "{ce}Oh no! A toasted exception !"); 60 | I.sendT(cook, "{ce}See toaster logs for details."); 61 | } 62 | }); 63 | } 64 | 65 | /** 66 | * Creates a new toast, and adds it to the toaster queue. 67 | * 68 | * @param callback The callback to call when a toast is cooked. 69 | * @return the newly created toast. 70 | */ 71 | public static Toast addToast(WorkerCallback callback) { 72 | final Toast newToast = Toaster.newToast(); 73 | final int toastId = newToast.getToastId(); 74 | 75 | submitQuery(new WorkerRunnable() { 76 | @Override 77 | public Object run() throws Throwable { 78 | PluginLogger.info("Cooking toast #{0} ...", toastId); 79 | 80 | newToast.setStatus(Toast.CookingStatus.IN_OVEN); 81 | Thread.sleep(TOAST_COOKING_TIME); 82 | 83 | PluginLogger.info("Toast #{0} cooked !", toastId); 84 | 85 | newToast.setStatus(Toast.CookingStatus.COOKED); 86 | 87 | return toastId; 88 | } 89 | }, callback); 90 | 91 | return newToast; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /ztoaster/src/main/java/fr/zcraft/ztoaster/commands/AddCommand.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.commands; 32 | 33 | import fr.zcraft.quartzlib.components.commands.Command; 34 | import fr.zcraft.quartzlib.components.commands.CommandException; 35 | import fr.zcraft.quartzlib.components.commands.CommandInfo; 36 | import fr.zcraft.quartzlib.components.i18n.I; 37 | import fr.zcraft.ztoaster.Toast; 38 | import fr.zcraft.ztoaster.ToasterWorker; 39 | import org.bukkit.entity.Player; 40 | 41 | 42 | @CommandInfo(name = "add", usageParameters = "[toast count]") 43 | public class AddCommand extends Command { 44 | @Override 45 | protected void run() throws CommandException { 46 | Player cook = playerSender(); 47 | 48 | if (args.length == 0) { 49 | Toast toast = ToasterWorker.addToast(cook); 50 | cook.sendMessage(I.tl(cook, "Toast {0} added.", toast.getToastId())); 51 | } else { 52 | int toastCount = getIntegerParameter(0); 53 | for (int i = toastCount; i-- > 0; ) { 54 | ToasterWorker.addToast(cook); 55 | } 56 | 57 | cook.sendMessage(I.tln(cook, "One toast added.", "{0} toasts added.", toastCount, toastCount)); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ztoaster/src/main/java/fr/zcraft/ztoaster/commands/ListCommand.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.commands; 32 | 33 | import fr.zcraft.quartzlib.components.commands.Command; 34 | import fr.zcraft.quartzlib.components.commands.CommandException; 35 | import fr.zcraft.quartzlib.components.commands.CommandInfo; 36 | import fr.zcraft.quartzlib.components.i18n.I; 37 | import fr.zcraft.ztoaster.Toast; 38 | import fr.zcraft.ztoaster.Toaster; 39 | import java.util.ArrayList; 40 | import java.util.Arrays; 41 | import java.util.Collection; 42 | 43 | @CommandInfo(name = "list", usageParameters = "[cooked|in_oven|not_cooked]") 44 | public class ListCommand extends Command { 45 | @Override 46 | protected void run() throws CommandException { 47 | if (args.length == 0) { 48 | showToasts(Arrays.asList(Toaster.getToasts())); 49 | } else { 50 | ArrayList toasts = new ArrayList(); 51 | Toast.CookingStatus status = getEnumParameter(0, Toast.CookingStatus.class); 52 | 53 | for (Toast toast : Toaster.getToasts()) { 54 | if (toast.getStatus().equals(status)) { 55 | toasts.add(toast); 56 | } 57 | } 58 | 59 | showToasts(toasts); 60 | } 61 | } 62 | 63 | private void showToasts(Collection toasts) { 64 | if (toasts.isEmpty()) { 65 | // Output of the command /toaster list, without toasts. 66 | info(I.t("There are no toasts here...")); 67 | } 68 | 69 | for (Toast toast : toasts) { 70 | sender.sendMessage(I.t(" Toast #{0}", toast.getToastId())); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ztoaster/src/main/java/fr/zcraft/ztoaster/commands/OpenCommand.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 | 32 | package fr.zcraft.ztoaster.commands; 33 | 34 | import fr.zcraft.quartzlib.components.commands.Command; 35 | import fr.zcraft.quartzlib.components.commands.CommandException; 36 | import fr.zcraft.quartzlib.components.commands.CommandInfo; 37 | import fr.zcraft.quartzlib.components.gui.Gui; 38 | import fr.zcraft.ztoaster.ToastExplorer; 39 | 40 | @CommandInfo(name = "open") 41 | public class OpenCommand extends Command { 42 | @Override 43 | protected void run() throws CommandException { 44 | Gui.open(playerSender(), new ToastExplorer()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ztoaster/src/main/resources/i18n/en_US.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "Project-Id-Version: PACKAGE VERSION\n" 9 | "Report-Msgid-Bugs-To: AmauryCarrade\n" 10 | "POT-Creation-Date: 2016-01-15 23:46+0100\n" 11 | "PO-Revision-Date: 2016-01-16 04:04+0100\n" 12 | "Last-Translator: Amaury Carrade\n" 13 | "Language-Team: Amaury Carrade\n" 14 | "Language: fr_FR\n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=UTF-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Plural-Forms: nplurals=2; plural=n>1;\n" 19 | 20 | #: fr/zcraft/ztoaster/ToasterSidebar.java:75 21 | msgid "{darkgreen}{bold}Cook" 22 | msgstr "{darkgreen}{bold}Cook" 23 | 24 | #: fr/zcraft/ztoaster/ToasterSidebar.java:78 25 | msgid "{yellow}{bold}Inside the toaster" 26 | msgstr "{yellow}{bold}Inside da toasterr" 27 | 28 | #: fr/zcraft/ztoaster/ToasterSidebar.java:81 29 | msgid "{gold}{bold}Cooked" 30 | msgstr "{gold}{bold}Cooked" 31 | 32 | #: fr/zcraft/ztoaster/ToasterSidebar.java:90 33 | msgid "{red}{bold}♨ Toaster ♨" 34 | msgstr "{red}{bold}♨ Toaster ♨" 35 | 36 | #: fr/zcraft/ztoaster/ToasterSidebar.java:93 37 | msgid "{blue}Toaster" 38 | msgstr "{blue}Toaster" 39 | 40 | #: fr/zcraft/ztoaster/ToastExplorer.java:44 41 | msgid "{black}Toaster contents" 42 | msgstr "{black}Toaster contents" 43 | 44 | #. Title of the cooked toast item in GUI 45 | #: fr/zcraft/ztoaster/ToastExplorer.java:57 46 | msgid "{white}Cooked toast #{0}" 47 | msgstr "{white}Cooked toast #{0}" 48 | 49 | #. Title of the raw toast item in GUI 50 | #: fr/zcraft/ztoaster/ToastExplorer.java:60 51 | msgid "{white}Raw toast #{0}" 52 | msgstr "{white}Raw toast #{0}" 53 | 54 | #: fr/zcraft/ztoaster/commands/AddCommand.java:56 55 | #, possible-java-format 56 | msgid "DING! Toast {0} is ready !" 57 | msgstr "DING! Toast {0} is ready !" 58 | 59 | #: fr/zcraft/ztoaster/commands/AddCommand.java:64 60 | msgid "{ce}Oh no! A toasted exception !" 61 | msgstr "{ce}Oh no! A toasted exception !" 62 | 63 | #: fr/zcraft/ztoaster/commands/AddCommand.java:65 64 | msgid "{ce}See toaster logs for details." 65 | msgstr "{ce}See toaster logs for details." 66 | 67 | #: fr/zcraft/ztoaster/commands/AddCommand.java:69 68 | #, possible-java-format 69 | msgid "Toast {0} added." 70 | msgstr "Toast {0} added." 71 | 72 | #: fr/zcraft/ztoaster/commands/AddCommand.java:63 73 | #, java-format 74 | msgid "One toast added." 75 | msgid_plural "{0} toasts added." 76 | msgstr[0] "One toast added." 77 | msgstr[1] "{0} toasts added." 78 | 79 | #. Output of the command /toaster list, without toasts. 80 | #: fr/zcraft/ztoaster/commands/ListCommand.java:74 81 | msgid "There are no toasts here ..." 82 | msgstr "There are no toasts here ..." 83 | 84 | #: fr/zcraft/ztoaster/commands/ListCommand.java:79 85 | #, java-format 86 | msgid " Toast #{0}" 87 | msgstr " Toast #{0}" 88 | -------------------------------------------------------------------------------- /ztoaster/src/main/resources/i18n/fr_FR.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "Project-Id-Version: PACKAGE VERSION\n" 9 | "Report-Msgid-Bugs-To: AmauryCarrade\n" 10 | "POT-Creation-Date: 2016-01-15 23:46+0100\n" 11 | "PO-Revision-Date: 2016-01-16 04:04+0100\n" 12 | "Last-Translator: Amaury Carrade\n" 13 | "Language-Team: Amaury Carrade\n" 14 | "Language: fr_FR\n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=UTF-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Plural-Forms: nplurals=2; plural=n>1;\n" 19 | 20 | #: fr/zcraft/ztoaster/ToasterSidebar.java:75 21 | msgid "{darkgreen}{bold}Cook" 22 | msgstr "{darkgreen}{bold}Cuistot" 23 | 24 | #: fr/zcraft/ztoaster/ToasterSidebar.java:78 25 | msgid "{yellow}{bold}Inside the toaster" 26 | msgstr "{yellow}{bold}Dans le grille-pain" 27 | 28 | #: fr/zcraft/ztoaster/ToasterSidebar.java:81 29 | msgid "{gold}{bold}Cooked" 30 | msgstr "{gold}{bold}Cuit" 31 | 32 | #: fr/zcraft/ztoaster/ToasterSidebar.java:90 33 | msgid "{red}{bold}♨ Toaster ♨" 34 | msgstr "{red}{bold}♨ Grille-pain ♨" 35 | 36 | #: fr/zcraft/ztoaster/ToasterSidebar.java:93 37 | msgid "{blue}Toaster" 38 | msgstr "{blue}Grille-pain" 39 | 40 | #: fr/zcraft/ztoaster/ToastExplorer.java:44 41 | msgid "{black}Toaster contents" 42 | msgstr "{black}Contenu du grille-pain" 43 | 44 | #. Title of the cooked toast item in GUI 45 | #: fr/zcraft/ztoaster/ToastExplorer.java:57 46 | msgid "{white}Cooked toast #{0}" 47 | msgstr "{white}Pain grillé no. {0}" 48 | 49 | #. Title of the raw toast item in GUI 50 | #: fr/zcraft/ztoaster/ToastExplorer.java:60 51 | msgid "{white}Raw toast #{0}" 52 | msgstr "{white}Pain pas grillé no. {0}" 53 | 54 | #: fr/zcraft/ztoaster/commands/AddCommand.java:56 55 | #, possible-java-format 56 | msgid "DING! Toast {0} is ready !" 57 | msgstr "DING ! Le pain grillé {0} est prêt !" 58 | 59 | #: fr/zcraft/ztoaster/commands/AddCommand.java:64 60 | msgid "{ce}Oh no! A toasted exception !" 61 | msgstr "{ce}Oh non ! Une exception grillée !" 62 | 63 | #: fr/zcraft/ztoaster/commands/AddCommand.java:65 64 | msgid "{ce}See toaster logs for details." 65 | msgstr "{ce}Voir les logs du grille-pain pour plus de détails." 66 | 67 | #: fr/zcraft/ztoaster/commands/AddCommand.java:69 68 | #, possible-java-format 69 | msgid "Toast {0} added." 70 | msgstr "Pain {0} ajouté." 71 | 72 | #: fr/zcraft/ztoaster/commands/AddCommand.java:63 73 | #, java-format 74 | msgid "One toast added." 75 | msgid_plural "{0} toasts added." 76 | msgstr[0] "Un pain ajouté." 77 | msgstr[1] "{0} pains ajoutés." 78 | 79 | #. Output of the command /toaster list, without toasts. 80 | #: fr/zcraft/ztoaster/commands/ListCommand.java:74 81 | msgid "There are no toasts here ..." 82 | msgstr "Il n'y a pas de pain grillé ici..." 83 | 84 | #: fr/zcraft/ztoaster/commands/ListCommand.java:79 85 | #, java-format 86 | msgid " Toast #{0}" 87 | msgstr " Pain grillé no. {0}" 88 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------